Commit f957f062 authored by chenwei@shao.ac.cn's avatar chenwei@shao.ac.cn
Browse files

build

parent 3a19183e
Pipeline #566 failed with stages
in 1 minute and 12 seconds
MIT License
Copyright (c) 2022 CSST-L1
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
# mci
# csst_ifs_common
......@@ -15,14 +15,14 @@ Already a pro? Just edit this README.md and make it your own. Want to make it ea
```
cd existing_repo
git remote add origin https://csst-tb.bao.ac.cn/code/shaosim/mci.git
git remote add origin https://csst-tb.bao.ac.cn/code/csst-l1/ifs/csst_ifs_common.git
git branch -M main
git push -uf origin main
```
## Integrate with your tools
- [ ] [Set up project integrations](https://csst-tb.bao.ac.cn/code/shaosim/mci/-/settings/integrations)
- [ ] [Set up project integrations](http://10.3.10.28/code/csst-l1/ifs/csst_ifs_common/-/settings/integrations)
## Collaborate with your team
......
This diff is collapsed.
This diff is collapsed.
[TEST]
### user should define file path below
inData_path =/home/yan/MCI_sim_Fabu/MCI_inputData
result_path =/home/yan/MCI_sim_Fabu/mci_sim_result
#size of the output image array, xsize is column, ysize is row, xsize = 9216,ysize = 9232
xsize = 1000
ysize = 1000
##prescan and overscan , do not change!!!
prescan = 27
overscan = 320
###sourcein = XDF, DARK, FLAT, BIAS
sourcein=XDF
##################################################
#### ####
####Control flags (can be yes/no) ####
##################################################
cosmicRays = yes
darknoise = yes
cosmetics = yes
radiationDamage= no
bleeding = yes
overscans = yes
nonlinearity = yes
readoutNoise = yes
skyback = yes
TianceEffect = yes
intscale = yes
ghosts = yes
shutterEffect = yes
flatfieldM = yes
PRNUeffect = yes
appFatt = no
sky_shift_rot = yes
distortion = no
sim_star = yes
sim_galaxy = yes
##############################################
##############################################
#CCD properties
fullwellcapacity = 90000
#dark noise in electrons per second
dark = 0.001
#exposure to simulate, exposure time
exptime = 300.0
###PNRU matrix sigma
prnu_sigma=0.001
### cosmicray coveringFraction
coveringFraction=1.0
#offset from the object, note that at the moment this is fixed, but in reality a focal plane position dependent.
ghostOffsetX = 50
ghostOffsetY = 50
ghostRatio = 1e-04
####treering effect,bright fatter effect and difusion effect
treering=0.1
fatter=1.0
difusion=0.1
### the choosen Filters in three CCDs
filter_g=u
filter_r=F555W
filter_i=F814W
##['G_filters']=["F275W", "F280N","NUV", "WU", "CBU", "F343N", "u", "F373N", "F395N"," F336W"]
##['R_filters']=["F487N", "F502N", "CBV", "r", "F656N", "F658N", "F467M", "F555W", "F606W", "F673N"]
##['I_filters']=["z", "y", "F815N", "CBI", "F925N", "F960M", "F968N", "F845M" ,"F850LP" ,"F814W"]
####################
g_gain1=1.53
g_gain2=1.54
g_gain3=1.55
g_gain4=1.53
g_gain5=1.51
g_gain6=1.56
g_gain7=1.58
g_gain8=1.53
g_gain9=1.54
g_gain10=1.57
g_gain11=1.51
g_gain12=1.53
g_gain13=1.55
g_gain14=1.57
g_gain15=1.53
g_gain16=1.52
#######################
g_rdnois1=4.53
g_rdnois2=4.54
g_rdnois3=4.55
g_rdnois4=4.53
g_rdnois5=4.51
g_rdnois6=4.56
g_rdnois7=4.58
g_rdnois8=4.53
g_rdnois9=4.54
g_rdnois10=4.57
g_rdnois11=4.51
g_rdnois12=4.53
g_rdnois13=4.55
g_rdnois14=4.57
g_rdnois15=4.53
g_rdnois16=4.52
############################
g_detbia1=500
g_detbia2=510
g_detbia3=514
g_detbia4=520
g_detbia5=524
g_detbia6=540
g_detbia7=530
g_detbia8=532
g_detbia9=534
g_detbia10=526
g_detbia11=532
g_detbia12=516
g_detbia13=540
g_detbia14=560
g_detbia15=536
g_detbia16=528
############################
r_gain1=1.52
r_gain2=1.54
r_gain3=1.52
r_gain4=1.55
r_gain5=1.56
r_gain6=1.52
r_gain7=1.54
r_gain8=1.6
r_gain9=1.54
r_gain10=1.52
r_gain11=1.54
r_gain12=1.57
r_gain13=1.52
r_gain14=1.55
r_gain15=1.52
r_gain16=1.55
################################
r_rdnois1=4.23
r_rdnois2=4.24
r_rdnois3=4.25
r_rdnois4=4.23
r_rdnois5=4.21
r_rdnois6=4.26
r_rdnois7=4.28
r_rdnois8=4.23
r_rdnois9=4.24
r_rdnois10=4.27
r_rdnois11=4.21
r_rdnois12=4.23
r_rdnois13=4.25
r_rdnois14=4.27
r_rdnois15=4.23
r_rdnois16=4.22
###################################
r_detbia1=600
r_detbia2=610
r_detbia3=614
r_detbia4=620
r_detbia5=624
r_detbia6=640
r_detbia7=630
r_detbia8=632
r_detbia9=634
r_detbia10=626
r_detbia11=632
r_detbia12=616
r_detbia13=640
r_detbia14=660
r_detbia15=636
r_detbia16=628
###################################
i_gain1=1.62
i_gain2=1.64
i_gain3=1.62
i_gain4=1.65
i_gain5=1.66
i_gain6=1.62
i_gain7=1.64
i_gain8=1.6
i_gain9=1.64
i_gain10=1.62
i_gain11=1.64
i_gain12=1.67
i_gain13=1.62
i_gain14=1.65
i_gain15=1.62
i_gain16=1.65
###################################
i_rdnois1=4.63
i_rdnois2=4.64
i_rdnois3=4.65
i_rdnois4=4.63
i_rdnois5=4.61
i_rdnois6=4.66
i_rdnois7=4.68
i_rdnois8=4.63
i_rdnois9=4.64
i_rdnois10=4.67
i_rdnois11=4.61
i_rdnois12=4.63
i_rdnois13=4.65
i_rdnois14=4.67
i_rdnois15=4.63
i_rdnois16=4.62
#######################################
i_detbia1=400
i_detbia2=410
i_detbia3=414
i_detbia4=420
i_detbia5=424
i_detbia6=440
i_detbia7=430
i_detbia8=432
i_detbia9=434
i_detbia10=426
i_detbia11=432
i_detbia12=416
i_detbia13=440
i_detbia14=460
i_detbia15=436
i_detbia16=428
####### end #######################
"""
VIS Instrument Model
====================
The file provides a function that returns VIS related information such as pixel
size, dark current, gain, zeropoint, and sky background.
:requires: NumPy
:requires: numexpr
:version: 0.7
"""
# import matplotlib
# import matplotlib.pyplot as plt
# import datetime, math
# import numpy as np
# import numexpr as ne
def MCIinformation():
"""
Returns a dictionary describing MCI CCD. The following information is provided (id: value - reference)::
dob: 0 - CDM03 (Short et al. 2010)
fwc: 90000 - CCD spec EUCL-EST-RS-6-002 (for CDM03)
rdose: 30000000000.0 - derived (above the PLM requirement)
sfwc: 730000.0 - CDM03 (Short et al. 2010), see also the CCD spec EUCL-EST-RS-6-002
st: 5e-06 - CDM03 (Short et al. 2010)
svg: 1e-10 - CDM03 (Short et al. 2010)
t: 0.01024 - CDM03 (Short et al. 2010)
trapfile: cdm_euclid.dat - CDM03 (derived, refitted to CCD204 data)
vg: 6e-11 - CDM03 (Short et al. 2010)
vth: 11680000.0 - CDM03 (Short et al. 2010)
:return: instrument model parameters
:rtype: dict
"""
#########################################################################################################
out=dict()
out.update({'dob' : 0, 'rdose' : 8.0e9,
'parallelTrapfile' : 'cdm_euclid_parallel.dat', 'serialTrapfile' : 'cdm_euclid_serial.dat',
'beta_s' : 0.6, 'beta_p': 0.6, 'fwc' : 90000, 'vth' : 1.168e7, 't' : 20.48e-3, 'vg' : 6.e-11,
'st' : 5.0e-6, 'sfwc' : 730000., 'svg' : 1.0e-10})
return out
def CCDnonLinearityModel(data, beta=6e-7):
"""
The non-linearity is modelled based on the results presented.
:param data: data to which the non-linearity model is being applied to
:type data: ndarray
:return: input data after conversion with the non-linearity model
:rtype: float or ndarray
"""
out = data-beta*data**2
return out
###################################################################
if __name__ == '__main__':
print()
This diff is collapsed.
"""
These functions can be used for logging information.
.. Warning:: logger is not multiprocessing safe.
:version: 0.3
"""
import logging
import logging.handlers
def setUpLogger(log_filename, loggername='logger'):
"""
Sets up a logger.
:param: log_filename: name of the file to save the log.
:param: loggername: name of the logger
:return: logger instance
"""
# create logger
logger = logging.getLogger(loggername)
logger.setLevel(logging.DEBUG)
# Add the log message handler to the logger
handler = logging.handlers.RotatingFileHandler(log_filename)
#maxBytes=20, backupCount=5)
# create formatter
formatter = logging.Formatter('%(asctime)s - %(module)s - %(funcName)s - %(levelname)s - %(message)s')
# add formatter to ch
handler.setFormatter(formatter)
# add handler to logger
if (logger.hasHandlers()):
logger.handlers.clear()
logger.addHandler(handler)
return logger
class SimpleLogger(object):
"""
A simple class to create a log file or print the information on screen.
"""
def __init__(self, filename, verbose=False):
self.file = open(filename, 'w')
self.verbose = verbose
def write(self, text):
"""
Writes text either to file or screen.
"""
print >> self.file, text
if self.verbose: print( text)
#!/usr/bin/env python
# -*- coding:utf-8 -*-
# @Author: Shuai Feng (hebtu.edu.cn)
# @Time: 2022-09-25
import numpy as np
from scipy.interpolate import interp1d
from astropy.io import fits
from astropy.io import ascii
from astropy import units as u
# ----------------
# Magnitude Module
from scipy.interpolate import interp1d
def Calzetti_Law(wave, Rv = 4.05):
"""Dust Extinction Curve by Calzetti et al. (2000)
Args:
wave (float): Wavelength
Rv (float, optional): Extinction curve. Defaults to 4.05.
Returns:
float: Extinction value E(B-V)
"""
wave_number = 1./(wave * 1e-4)
reddening_curve = np.zeros(len(wave))
idx = np.logical_and(wave >= 1200, wave <= 6300)
reddening_curve[idx] = 2.659 * ( -2.156 + 1.509 * wave_number[idx] - 0.198 * \
(wave_number[idx] ** 2)) + 0.011 * (wave_number[idx] **3 ) + Rv
idx = np.logical_and(wave >= 6300, wave <= 22000)
reddening_curve[idx] = 2.659 * ( -1.857 + 1.040 * wave_number[idx]) + Rv
return reddening_curve
def reddening(wave, flux, ebv = 0.0, law = 'calzetti', Rv = 4.05):
"""
Reddening an input spectra through a given reddening curve.
Args:
wave (float): Wavelength of input spectra
flux (float): Flux of input spectra
ebv (float, optional): Extinction value. Defaults to 0.
law (str, optional): Extinction curve. Defaults to 'calzetti'.
Rv (float, optional): _description_. Defaults to 4.05.
Returns:
float: Flux of spectra after reddening.
"""
if law == 'calzetti':
curve = Calzetti_Law(wave, Rv = Rv)
fluxNew = flux / (10. ** (0.4 * ebv * curve))
return fluxNew
def flux_to_mag(wave, flux, filepath, band='GAIA_bp'):
"""Convert flux of given spectra to magnitude
Args:
wave (float): Wavelength
flux (float): Flux of spectra
band (str, optional): Filter band name. Defaults to 'GAIA_bp'.
Returns:
float: value of magnitude
"""
# /home/yan/MCI_sim/MCI_input/SED_Code/data
import os
#parent = os.path.dirname(os.path.realpath(__file__))
parent=filepath
band = ascii.read(parent+'/SED_Code/seddata/' + band + '.dat')
wave0= band['col1']
curv0= band['col2']
# Setting the response
func = interp1d(wave0, curv0)
response = np.copy(wave)
ind_extra = (wave > max(wave0)) | (wave < min(wave0))
response[ind_extra] = 0
ind_inside = (wave < max(wave0)) & (wave > min(wave0))
response[ind_inside] = func(wave[ind_inside])
# Total Flux
Tflux = np.trapz(flux * response, wave) / np.trapz(response, wave)
return -2.5 * np.log10(Tflux)
def calibrate(wave, flux, mag, filepath,band='GAIA_bp'):
"""
Calibrate the spectra according to the magnitude.
Args:
wave (float): Wavelength
flux (float): Flux of spectra
mag (float): Input magnitude.
band (str, optional): Filter band name. Defaults to 'GAIA_bp'.
Returns:
float: Flux of calibrated spectra. Units: 1e-17 erg/s/A/cm^2
"""
inst_mag = flux_to_mag(wave, flux,filepath ,band = band)
instflux = 10 ** (-0.4 * inst_mag)
realflux = (mag * u.STmag).to(u.erg/u.s/u.cm**2/u.AA).value
# Normalization
flux_ratio = realflux / instflux
flux_calibrate = flux * flux_ratio * 1e17 # Units: 10^-17 erg/s/A/cm^2
return flux_calibrate
# ------------
# SED Template
class Gal_Temp():
"""
Template of Galaxy SED
"""
def __init__(self,parent):
import os
self.parent = parent
hdulist = fits.open(self.parent+'/SED_Code/seddata/galaxy_temp.fits')
self.wave = hdulist[1].data['wave']
self.flux = hdulist[2].data
self.age_grid = hdulist[3].data['logAge']
self.feh_grid = hdulist[3].data['FeH']
def toMag(self, redshift = 0):
"""Calculating magnitude
Args:
redshift (float, optional): redshift of spectra. Defaults to 0.
"""
wave = self.wave * (1 + redshift)
self.umag = flux_to_mag(wave, self.flux, self.parent,band='SDSS_u')
self.gmag = flux_to_mag(wave, self.flux, self.parent,band='SDSS_g')
self.rmag = flux_to_mag(wave, self.flux, self.parent,band='SDSS_r')
self.imag = flux_to_mag(wave, self.flux, self.parent,band='SDSS_i')
self.zmag = flux_to_mag(wave, self.flux, self.parent,band='SDSS_z')
class Star_Temp():
"""
Template of Stellar SED
"""
def __init__(self, parent):
#import os
#parent = os.path.dirname(os.path.realpath(__file__))
##/home/yan/MCI_sim_Fabu/MCI_inputData/SED_Code
self.parent = parent
hdulist = fits.open(parent+'/SED_Code/seddata/stellar_temp.fits')
self.wave = hdulist[1].data['wave']
self.flux = hdulist[2].data
self.Teff_grid = hdulist[3].data['Teff']
self.FeH_grid = hdulist[3].data['FeH']
def toMag(self):
wave = self.wave
self.bpmag = flux_to_mag(wave, self.flux, self.parent,band='GAIA_bp')
self.rpmag = flux_to_mag(wave, self.flux, self.parent,band='GAIA_rp')
# -------------
# SED Modelling
def Model_Stellar_SED(wave, bp, rp, temp, filepath):
"""Modelling stellar SED based on bp, rp magnitude
Args:
wave (float): Wavelength
bp (float): Magnitude of GAIA BP band
rp (float): Magnitude of GAIA RP band
temp (class): Class of stellar template
Returns:
float array: Spectral energy distribution of stellar SED,
which have the same length to the input wave
"""
color0 = bp - rp
colors = temp.bpmag - temp.rpmag
idx = np.argmin(np.abs(colors - color0))
flux0 = temp.flux[idx]
flux1 = np.interp(wave, temp.wave, flux0)
flux = calibrate(wave, flux1, rp, filepath, band = 'GAIA_rp')
return flux
def Model_Galaxy_SED(wave, ugriz, z, temp):
"""Modelling galaxy SED based on u,g,r,i,z magnitude
Args:
wave (float): Wavelength
ugriz (float, array): The array of magnitude of SDSS ugriz band
z (float): Redshift
temp (class): Class of gaalxy template
Returns:
float array: Spectral energy distribution of stellar SED,
which have the same length to the input wave
"""
sed = 10. ** (-0.4 * ugriz)
sed = sed / sed[2]
ntemp = len(temp.rmag)
dmag = np.zeros(ntemp)
for j in range(ntemp):
ugriz0 = np.array([temp.umag[j], temp.gmag[j], temp.rmag[j],
temp.imag[j], temp.zmag[j]])
sed0 = 10. ** (-0.4 * ugriz0)
sed0 = sed0 / sed0[2]
dmag[j] = np.sum(np.abs(sed - sed0))
idx = np.argmin(dmag)
flux0 = temp.flux[idx]
# Effect of E(B-V)
ri0 = ugriz[2] - ugriz[3]
ri = temp.rmag - temp.imag
dri = ri0 - ri[idx]
Alambda = Calzetti_Law(np.array([6213 / (1 + z), 7625 / (1 + z)]))
eri0 = (Alambda[0] - Alambda[1])
ebv = dri/eri0
if ebv<0:
ebv=0
if ebv>0.5:
ebv=0.5
flux1 = reddening(temp.wave, flux0, ebv = ebv)
flux2 = np.interp(wave, temp.wave * (1 + z), flux1)
flux = calibrate(wave, flux2, ugriz[2], band = 'SDSS_r')
return flux
\ No newline at end of file
This diff is collapsed.
import setuptools
with open("README.md", "r") as fh:
long_description = fh.read()
setuptools.setup(
name='csst_mci_sim',
version='2.0.0-MCI1.0.0',
author='CSST Team',
author_email='zhaojunyan@shao.ac.cn',
description='The CSST - mci - sim', # short description
long_description=long_description,
long_description_content_type="text/markdown",
url='https://csst-tb.bao.ac.cn/',
# project_urls={
# 'Source': 'https://csst-tb.bao.ac.cn/code/csst-l1/ifs/csst_mci_sim',
# },
packages=setuptools.find_packages(),
license='MIT',
classifiers=["Development Status :: 5 - Production/Stable",
"Intended Audience :: Science/Research",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3.8",
"Topic :: Scientific/Engineering :: Physics",
"Topic :: Scientific/Engineering :: Astronomy"],
package_dir={'csst_mci_sim': 'csst_mci_sim'},
# include_package_data=True,
package_data={"": ["LICENSE", "README.md"],
"csst_mci_sim": ["mci_so/*", "mci_data/*"]},
# install_requires=['sphinx',
# 'numpy',
# 'scipy', 'matplotlib',
# 'astropy', 'healpy', 'ccdproc', 'deepCR', 'photutils'],
python_requires='>=3.8',
)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment