Commit 3226117c authored by Zhang Xin's avatar Zhang Xin
Browse files

Merge branch 'develop' into 'release_v2.0'

version 2.1.0

See merge request csst_sim/csst-simulation!16
parents 81589f9d f540664f
This diff is collapsed.
...@@ -83,7 +83,7 @@ class Catalog(CatalogBase): ...@@ -83,7 +83,7 @@ class Catalog(CatalogBase):
self._load_SED_lib_AGN() self._load_SED_lib_AGN()
if "rotateEll" in config["catalog_options"]: if "rotateEll" in config["catalog_options"]:
self.rotation = float(int(config["catalog_options"]["rotateEll"]/45.)) self.rotation = np.radians(float(config["catalog_options"]["rotateEll"]))
else: else:
self.rotation = 0. self.rotation = 0.
...@@ -259,7 +259,7 @@ class Catalog(CatalogBase): ...@@ -259,7 +259,7 @@ class Catalog(CatalogBase):
param['id'] = '%06d'%(int(pix_id)) + '%06d'%(cat_id) + '%08d'%(igals) param['id'] = '%06d'%(int(pix_id)) + '%06d'%(cat_id) + '%08d'%(igals)
if param['star'] == 0: if param['star'] == 0:
obj = Galaxy(param, self.rotation, logger=self.logger) obj = Galaxy(param, logger=self.logger)
# Need to deal with additional output columns # Need to deal with additional output columns
obj.additional_output_str = self.add_fmt%("n", 0., 0., 0., obj.additional_output_str = self.add_fmt%("n", 0., 0., 0.,
......
...@@ -94,7 +94,7 @@ class Catalog(CatalogBase): ...@@ -94,7 +94,7 @@ class Catalog(CatalogBase):
###mock_stamp_END ###mock_stamp_END
if "rotateEll" in config["catalog_options"]: if "rotateEll" in config["catalog_options"]:
self.rotation = float(int(config["catalog_options"]["rotateEll"]/45.)) self.rotation = np.radians(float(config["catalog_options"]["rotateEll"]))
else: else:
self.rotation = 0. self.rotation = 0.
...@@ -272,7 +272,7 @@ class Catalog(CatalogBase): ...@@ -272,7 +272,7 @@ class Catalog(CatalogBase):
param['id'] = '%06d'%(int(pix_id)) + '%06d'%(cat_id) + '%08d'%(igals) param['id'] = '%06d'%(int(pix_id)) + '%06d'%(cat_id) + '%08d'%(igals)
if param['star'] == 0: if param['star'] == 0:
obj = Galaxy(param, self.rotation, logger=self.logger) obj = Galaxy(param, logger=self.logger)
# Need to deal with additional output columns # Need to deal with additional output columns
obj.additional_output_str = self.add_fmt%("n", 0., 0., 0., obj.additional_output_str = self.add_fmt%("n", 0., 0., 0.,
......
...@@ -84,7 +84,7 @@ class Catalog(CatalogBase): ...@@ -84,7 +84,7 @@ class Catalog(CatalogBase):
self._load_SED_lib_AGN() self._load_SED_lib_AGN()
if "rotateEll" in config["catalog_options"]: if "rotateEll" in config["catalog_options"]:
self.rotation = float(int(config["catalog_options"]["rotateEll"]/45.)) self.rotation = np.radians(float(config["catalog_options"]["rotateEll"]))
else: else:
self.rotation = 0. self.rotation = 0.
...@@ -260,7 +260,7 @@ class Catalog(CatalogBase): ...@@ -260,7 +260,7 @@ class Catalog(CatalogBase):
param['id'] = '%06d'%(int(pix_id)) + '%06d'%(cat_id) + '%08d'%(igals) param['id'] = '%06d'%(int(pix_id)) + '%06d'%(cat_id) + '%08d'%(igals)
if param['star'] == 0: if param['star'] == 0:
obj = Galaxy(param, self.rotation, logger=self.logger) obj = Galaxy(param, logger=self.logger)
# Need to deal with additional output columns # Need to deal with additional output columns
obj.additional_output_str = self.add_fmt%("n", 0., 0., 0., obj.additional_output_str = self.add_fmt%("n", 0., 0., 0.,
......
...@@ -52,7 +52,7 @@ class Catalog(CatalogBase): ...@@ -52,7 +52,7 @@ class Catalog(CatalogBase):
self.galaxy_SED_path = os.path.join(config["data_dir"], config["catalog_options"]["SED_templates_path"]["galaxy_SED"]) self.galaxy_SED_path = os.path.join(config["data_dir"], config["catalog_options"]["SED_templates_path"]["galaxy_SED"])
self._load_SED_lib_gals() self._load_SED_lib_gals()
if "rotateEll" in config["catalog_options"]: if "rotateEll" in config["catalog_options"]:
self.rotation = float(int(config["catalog_options"]["rotateEll"]/45.)) self.rotation = np.radians(float(config["catalog_options"]["rotateEll"]))
else: else:
self.rotation = 0. self.rotation = 0.
...@@ -191,7 +191,7 @@ class Catalog(CatalogBase): ...@@ -191,7 +191,7 @@ class Catalog(CatalogBase):
param['id'] = gals['galaxyID'][igals] param['id'] = gals['galaxyID'][igals]
if param['star'] == 0: if param['star'] == 0:
obj = Galaxy(param, self.rotation, logger=self.logger) obj = Galaxy(param, logger=self.logger)
if param['star'] == 2: if param['star'] == 2:
obj = Quasar(param, logger=self.logger) obj = Quasar(param, logger=self.logger)
......
This diff is collapsed.
...@@ -81,7 +81,7 @@ class Catalog(CatalogBase): ...@@ -81,7 +81,7 @@ class Catalog(CatalogBase):
self._load_SED_lib_AGN() self._load_SED_lib_AGN()
if "rotateEll" in config["catalog_options"]: if "rotateEll" in config["catalog_options"]:
self.rotation = float(int(config["catalog_options"]["rotateEll"]/45.)) self.rotation = np.radians(float(config["catalog_options"]["rotateEll"]))
else: else:
self.rotation = 0. self.rotation = 0.
...@@ -253,7 +253,7 @@ class Catalog(CatalogBase): ...@@ -253,7 +253,7 @@ class Catalog(CatalogBase):
param['id'] = '%06d'%(int(pix_id)) + '%06d'%(cat_id) + '%08d'%(igals) param['id'] = '%06d'%(int(pix_id)) + '%06d'%(cat_id) + '%08d'%(igals)
if param['star'] == 0: if param['star'] == 0:
obj = Galaxy(param, self.rotation, logger=self.logger) obj = Galaxy(param, logger=self.logger)
# Need to deal with additional output columns # Need to deal with additional output columns
obj.additional_output_str = self.add_fmt%("n", 0., 0., 0., obj.additional_output_str = self.add_fmt%("n", 0., 0., 0.,
......
This diff is collapsed.
...@@ -18,6 +18,10 @@ from astropy.wcs.utils import fit_wcs_from_points ...@@ -18,6 +18,10 @@ from astropy.wcs.utils import fit_wcs_from_points
from astropy.time import Time from astropy.time import Time
from astropy import wcs from astropy import wcs
from datetime import datetime
# import socket
import platform
def chara2digit(char): def chara2digit(char):
""" Function to judge and convert characters to digitals """ Function to judge and convert characters to digitals
...@@ -287,7 +291,8 @@ def WCS_def(xlen = 9216, ylen = 9232, gapy = 898.0, gapx1 = 534, gapx2 = 1309, r ...@@ -287,7 +291,8 @@ def WCS_def(xlen = 9216, ylen = 9232, gapy = 898.0, gapx1 = 534, gapx2 = 1309, r
r_dat['CRPIX1'] = -x1 r_dat['CRPIX1'] = -x1
r_dat['CRPIX2'] = -y1 r_dat['CRPIX2'] = -y1
cd = np.array([[ pixel_scale, 0], [0, pixel_scale]])/3600.*flag_x[1] # cd = np.array([[ pixel_scale, 0], [0, pixel_scale]])/3600.*flag_x[1]
cd = np.array([[ pixel_scale, 0], [0, -pixel_scale]])/3600.
cd_rot = rotate_CD_matrix(cd, pa_aper) cd_rot = rotate_CD_matrix(cd, pa_aper)
r_dat['CD1_1'] = cd_rot[0,0] r_dat['CD1_1'] = cd_rot[0,0]
r_dat['CD1_2'] = cd_rot[0,1] r_dat['CD1_2'] = cd_rot[0,1]
...@@ -381,7 +386,7 @@ def generatePrimaryHeader(xlen = 9216, ylen = 9232, pointNum = '1', ra = 60, dec ...@@ -381,7 +386,7 @@ def generatePrimaryHeader(xlen = 9216, ylen = 9232, pointNum = '1', ra = 60, dec
h_prim['EXPTIME'] = exptime h_prim['EXPTIME'] = exptime
# Define file types # Define file types
file_type = {'SCI':'SCIE', 'BIAS':'BIAS', 'DARK':'DARK', 'FLAT':'FLAT', 'CRS':'cosmic_ray', 'CRD':'cosmic_ray','CALS':'CALS','CALF':'CALF'} file_type = {'SCI':'SCIE', 'BIAS':'BIAS', 'DARK':'DARK', 'FLAT':'FLAT', 'CRS':'CRS', 'CRD':'CRD','CALS':'CALS','CALF':'CALF'}
h_prim['FILETYPE'] = file_type[im_type] h_prim['FILETYPE'] = file_type[im_type]
co = coord.SkyCoord(ra, dec, unit='deg') co = coord.SkyCoord(ra, dec, unit='deg')
...@@ -417,7 +422,7 @@ def generatePrimaryHeader(xlen = 9216, ylen = 9232, pointNum = '1', ra = 60, dec ...@@ -417,7 +422,7 @@ def generatePrimaryHeader(xlen = 9216, ylen = 9232, pointNum = '1', ra = 60, dec
file_end_time = end_time_str[0:4] + end_time_str[5:7]+end_time_str[8:10] + end_time_str[11:13] + end_time_str[14:16] + end_time_str[17:19] file_end_time = end_time_str[0:4] + end_time_str[5:7]+end_time_str[8:10] + end_time_str[11:13] + end_time_str[14:16] + end_time_str[17:19]
# h_prim['FILENAME'] = 'CSST_MSC_MS_' + im_type + '_' + file_start_time + '_' + file_end_time + '_' + OBS_id + '_' + CCDID[ # h_prim['FILENAME'] = 'CSST_MSC_MS_' + im_type + '_' + file_start_time + '_' + file_end_time + '_' + OBS_id + '_' + CCDID[
# k - 1].rjust(2, '0') + '_L0_V01' # k - 1].rjust(2, '0') + '_L0_V01'
h_prim['FILENAME'] = 'CSST_MSC_MS_' + im_type + '_' + file_start_time + '_' + file_end_time + '_' + OBS_id + '_' + chip_name + '_L0_V01' h_prim['FILENAME'] = 'CSST_MSC_MS_' + file_type[im_type] + '_' + file_start_time + '_' + file_end_time + '_' + OBS_id + '_' + chip_name + '_L0_V01'
h_prim['POSI0_X'] = sat_pos[0] h_prim['POSI0_X'] = sat_pos[0]
...@@ -433,12 +438,15 @@ def generatePrimaryHeader(xlen = 9216, ylen = 9232, pointNum = '1', ra = 60, dec ...@@ -433,12 +438,15 @@ def generatePrimaryHeader(xlen = 9216, ylen = 9232, pointNum = '1', ra = 60, dec
# Get version of CSSTSim Package # Get version of CSSTSim Package
from pkg_resources import get_distribution from pkg_resources import get_distribution
# h_prim['SIM_VER'] = (get_distribution("CSSTSim").version, "Version of CSST MSC simulation software") # h_prim['SIM_VER'] = (get_distribution("CSSTSim").version, "Version of CSST MSC simulation software")
h_prim['FITSCREA'] = get_distribution("CSSTSim").version currentDateAndTime = datetime.now()
compute_name = platform.node()
h_prim['FITSCREA'] = get_distribution("CSSTSim").version +'_' + currentDateAndTime.strftime("%Y%m%d") + '_' +compute_name
h_prim['EPOCH'] = round((Time(h_prim['EXPSTART'], format='mjd', scale='tcb')).jyear, 1)
return h_prim return h_prim
def generateExtensionHeader(chip, xlen = 9216, ylen = 9232,ra = 60, dec = -40, pa = -23.433, gain = 1.0, readout = 5.0, dark = 0.02, saturation=90000, pixel_scale = 0.074, pixel_size=1e-2, def generateExtensionHeader(chip, xlen = 9216, ylen = 9232,ra = 60, dec = -40, pa = -23.433, gain = 1.0, readout = 5.0, dark = 0.02, saturation=90000, pixel_scale = 0.074, pixel_size=1e-2,
extName='SCI', row_num = None, col_num = None, xcen=None, ycen=None): extName='SCI', row_num = None, col_num = None, xcen=None, ycen=None, timestamp = 1621915200,exptime = 150., readoutTime = 40.):
e_header_fn = os.path.split(os.path.realpath(__file__))[0] + '/extension_header.header' e_header_fn = os.path.split(os.path.realpath(__file__))[0] + '/extension_header.header'
f = open(os.path.split(os.path.realpath(__file__))[0] + '/filter.lst') f = open(os.path.split(os.path.realpath(__file__))[0] + '/filter.lst')
...@@ -460,47 +468,60 @@ def generateExtensionHeader(chip, xlen = 9216, ylen = 9232,ra = 60, dec = -40, p ...@@ -460,47 +468,60 @@ def generateExtensionHeader(chip, xlen = 9216, ylen = 9232,ra = 60, dec = -40, p
# h_ext['CCDCHIP'] = CCDID[k - 1].rjust(2, '0') # h_ext['CCDCHIP'] = CCDID[k - 1].rjust(2, '0')
# h_ext['CCDLABEL'] = filters[k-1] + '-' + filterID[k-1] # h_ext['CCDLABEL'] = filters[k-1] + '-' + filterID[k-1]
# h_ext['FILTER'] = filters[k-1] # h_ext['FILTER'] = filters[k-1]
h_ext['CCDCHIP'] = chip.chip_name h_ext['CHIPID'] = str(chip.chipID).rjust(2, '0')
h_ext['CCDLABEL'] = chip.filter_type + '-' + str(chip.chipID).rjust(2, '0') h_ext['CHIPLAB'] = chip.chip_name
h_ext['FILTER'] = chip.filter_type h_ext['FILTER'] = chip.filter_type
h_ext['NAXIS1'] = xlen h_ext['NAXIS1'] = xlen
h_ext['NAXIS2'] = ylen h_ext['NAXIS2'] = ylen
h_ext['EXTNAME'] = extName h_ext['EXTNAME'] = extName
h_ext['GAIN1'] = gain h_ext['GAIN01'] = chip.gain_channel[0]
h_ext['GAIN2'] = gain h_ext['GAIN02'] = chip.gain_channel[1]
h_ext['GAIN3'] = gain h_ext['GAIN03'] = chip.gain_channel[2]
h_ext['GAIN4'] = gain h_ext['GAIN04'] = chip.gain_channel[3]
h_ext['GAIN5'] = gain h_ext['GAIN05'] = chip.gain_channel[4]
h_ext['GAIN6'] = gain h_ext['GAIN06'] = chip.gain_channel[5]
h_ext['GAIN7'] = gain h_ext['GAIN07'] = chip.gain_channel[6]
h_ext['GAIN8'] = gain h_ext['GAIN08'] = chip.gain_channel[7]
h_ext['GAIN9'] = gain h_ext['GAIN09'] = chip.gain_channel[8]
h_ext['GAIN10'] = gain h_ext['GAIN10'] = chip.gain_channel[9]
h_ext['GAIN11'] = gain h_ext['GAIN11'] = chip.gain_channel[10]
h_ext['GAIN12'] = gain h_ext['GAIN12'] = chip.gain_channel[11]
h_ext['GAIN13'] = gain h_ext['GAIN13'] = chip.gain_channel[12]
h_ext['GAIN14'] = gain h_ext['GAIN14'] = chip.gain_channel[13]
h_ext['GAIN15'] = gain h_ext['GAIN15'] = chip.gain_channel[14]
h_ext['GAIN16'] = gain h_ext['GAIN16'] = chip.gain_channel[15]
h_ext['RDNOIS1'] = readout h_ext['RON01'] = readout
h_ext['RDNOIS2'] = readout h_ext['RON02'] = readout
h_ext['RDNOIS3'] = readout h_ext['RON03'] = readout
h_ext['RDNOIS4'] = readout h_ext['RON04'] = readout
h_ext['RDNOIS5'] = readout h_ext['RON05'] = readout
h_ext['RDNOIS6'] = readout h_ext['RON06'] = readout
h_ext['RDNOIS7'] = readout h_ext['RON07'] = readout
h_ext['RDNOIS8'] = readout h_ext['RON08'] = readout
h_ext['RDNOIS9'] = readout h_ext['RON09'] = readout
h_ext['RDNOIS10'] = readout h_ext['RON10'] = readout
h_ext['RDNOIS11'] = readout h_ext['RON11'] = readout
h_ext['RDNOIS12'] = readout h_ext['RON12'] = readout
h_ext['RDNOIS13'] = readout h_ext['RON13'] = readout
h_ext['RDNOIS14'] = readout h_ext['RON14'] = readout
h_ext['RDNOIS15'] = readout h_ext['RON15'] = readout
h_ext['RDNOIS16'] = readout h_ext['RON16'] = readout
h_ext['PIXSCAL1'] = pixel_scale h_ext['PIXSCAL1'] = pixel_scale
h_ext['PIXSCAL2'] = pixel_scale h_ext['PIXSCAL2'] = pixel_scale
h_ext['EXPTIME'] = exptime
h_ext['DARKTIME'] = exptime + 2
datetime_obs = datetime.utcfromtimestamp(timestamp)
tstart = Time(datetime_obs)
tstart_read = Time(tstart.mjd + exptime / 86400., format="mjd")
tend_read = Time(tstart.mjd + (exptime + readoutTime) / 86400., format="mjd")
t_s1 = str(tstart_read.datetime).split()
h_ext['READT0'] = t_s1[0]+'T'+t_s1[1]
t_s2 = str(tend_read.datetime).split()
h_ext['READT1'] = t_s2[0] + 'T' + t_s2[1]
# h_ext['POS_ANG'] = pa # h_ext['POS_ANG'] = pa
header_wcs = WCS_def(xlen=xlen, ylen=ylen, gapy=898.0, gapx1=534, gapx2=1309, ra_ref=ra, dec_ref=dec, pa=pa, pixel_scale=pixel_scale, pixel_size=pixel_size, header_wcs = WCS_def(xlen=xlen, ylen=ylen, gapy=898.0, gapx1=534, gapx2=1309, ra_ref=ra, dec_ref=dec, pa=pa, pixel_scale=pixel_scale, pixel_size=pixel_size,
...@@ -514,8 +535,8 @@ def generateExtensionHeader(chip, xlen = 9216, ylen = 9232,ra = 60, dec = -40, p ...@@ -514,8 +535,8 @@ def generateExtensionHeader(chip, xlen = 9216, ylen = 9232,ra = 60, dec = -40, p
h_ext['CD1_2'] = header_wcs['CD1_2'] h_ext['CD1_2'] = header_wcs['CD1_2']
h_ext['CD2_1'] = header_wcs['CD2_1'] h_ext['CD2_1'] = header_wcs['CD2_1']
h_ext['CD2_2'] = header_wcs['CD2_2'] h_ext['CD2_2'] = header_wcs['CD2_2']
h_ext['EQUINOX'] = header_wcs['EQUINOX'] # h_ext['EQUINOX'] = header_wcs['EQUINOX']
h_ext['WCSDIM'] = header_wcs['WCSDIM'] # h_ext['WCSDIM'] = header_wcs['WCSDIM']
h_ext['CTYPE1'] = header_wcs['CTYPE1'] h_ext['CTYPE1'] = header_wcs['CTYPE1']
h_ext['CTYPE2'] = header_wcs['CTYPE2'] h_ext['CTYPE2'] = header_wcs['CTYPE2']
......
SIMPLE = T / conforms to FITS standard BITPIX = 8 / array data type NAXIS = 0 / number of array dimensions EXTEND = T NEXTEND = 1 GROUPS = F DATE = '2021-03-04T09:30:00'/ date this file was written FILENAME= 'MSC_MS_210304093000_100000000_06_raw' / file name FILETYPE= 'SCI ' / observation type TELESCOP= 'CSST ' / telescope used to acquire data INSTRUME= 'MSC ' / instrument used to acquire data RADECSYS= 'ICRS ' / frame of reference of coordinates EQUINOX = 2000.0 / FITSCREA= 'C6' / FITS create software version COMMENT ================================================================== COMMENT Object information COMMENT ================================================================== OBJECT = '00000000' / object name TARGET = '+000000000000' / target name (hhmmss+ddmmss) OBSID = '00000000' / observation ID OBJ_RA = 62.228226 / R.A. of the object (degrees) OBJ_DEC = -42.316932 / declination of the object (degrees) COMMENT ================================================================== COMMENT Telescope information COMMENT ================================================================== REFFRAME= 'CSSTGSC-1.0' / guide star catalog version DATE-OBS= '2021-03-04T09:30:00'/ date of the observation (yyyy-mm-dd hh:mm:ss) SATESWV = '0001' / software version in the satellite EXPSTART= 59130.5 / exposure start time (MJD) CABSTART= 59130.5 / (MJD) SUNANGL0= 50.0 / angle between sun and optical axis at CABSTART MOONANG0= 30.0 / angle moon and opt axis at CABSTART at CABST TEL_ALT0= 20.0 / angle opt axis and the ground-piston at CABST POS_ANG0= 20.0 / angle bwt y axis and the North Pole at CABST POSI0_X = 0.0 / the orbital position in X at CABSTART POSI0_Y = 0.0 / the orbital position in Y at CABSTART POSI0_Z = 0.0 / the orbital position in Z at CABSTART VELO0_X = 0.0 / the orbital velocity in X at CABSTART VELO0_Y = 0.0 / the orbital velocity in Y at CABSTART VELO0_Z = 0.0 / the orbital velocity in Z at CABSTART EULER0_1= 0.0 / Euler angle 1 at CABSTART EULER0_2= 0.0 / Euler angle 2 at CABSTART EULER0_3= 0.0 / Euler angle 3 at CABSTART RA_PNT0 = 0.0 / RA of the pointing (degrees) at CABSTART DEC_PNT0= 0.0 / DEC of the pointing (degrees) at CABSTART EXPEND = 0.0 / exposure end time (MJD) CABEND = 0.0 / (MJD) SUNANGL1= 50.0 / angle between sun and optical axis at CABEND MOONANG1= 30.0 / angle btw moon and optical axis at CABEND TEL_ALT1= 20.0 / angle opt axis and the ground-piston at CAEND POS_ANG1= 20.0 / angle bwt y axis and the North Pole at CABEND POSI1_X = 0.0 / the orbital position in X at CABEND POSI1_Y = 0.0 / the orbital position in Y at CABEND POSI1_Z = 0.0 / the orbital position in Z at CABEND VELO1_X = 0.0 / The orbital velocity in X at CABEND VELO1_Y = 0.0 / The orbital velocity in Y at CABEND VELO1_Z = 0.0 / The orbital velocity in Z at CABEND EULER1_1= 0.0 / Euler angle 1 at CABEND EULER1_2= 0.0 / Euler angle 2 at CABEND EULER1_3= 0.0 / Euler angle 3 at CABEND RA_PNT1 = 0.0 / RA of the pointing (degrees) at CABEND DEC_PNT1= 0.0 / DEC of the pointing (degrees) at CABEND EXPTIME = 150.0 / exposure duration EPOCH = 2000 / coordinate epoch COMMENT Other information COMMENT ================================================================== CHECKSUM= 'abcdefg ' / SHA256 checksum of global headers END SIMPLE = T / conforms to FITS standard BITPIX = 8 / array data type NAXIS = 0 / number of array dimensions EXTEND = T NEXTEND = 1 / number of array dimensions GROUPS = F / ' ' DATE = '2021-03-04T09:30:00'/ the date on which this file was written FILENAME= 'MSC_MS_210304093000_100000000_06_raw' / file name FILETYPE= 'SCIE ' / observation type TELESCOP= 'CSST ' / telescope used to acquire data INSTRUME= 'MSC ' / instrument used to acquire data RADECSYS= 'ICRS ' / reference coordinates system EQUINOX = 2000.0 / FITSCREA= 'C6' / FITS create software version COMMENT ================================================================== COMMENT Object information COMMENT ================================================================== OBJECT = '00000000' / object name TARGET = '+000000000000' / target name (hhmmss+ddmmss) OBSID = '00000000' / observation ID OBJ_RA = 62.228226 / R.A. of the object (degrees) OBJ_DEC = -42.316932 / declination of the object (degrees) COMMENT ================================================================== COMMENT Telescope information COMMENT ================================================================== REFFRAME= 'CSSTGSC-1.0' / guide star catalog version DATE-OBS= '2021-03-04T09:30:00'/ date of the observation (yyyy-mm-dd hh:mm:ss) SATESWV = '0001' / software version in the satellite EXPSTART= 59130.5 / exposure start time (MJD) CABSTART= 59130.5 / (MJD) SUNANGL0= 50.0 / angle between sun and opt axis at CABSTART MOONANG0= 30.0 / angle between moon and opt axis at CABSTART TEL_ALT0= 20.0 / angle between opt axis and Elimb at CABSTART POS_ANG0= 20.0 / angle between y axis and NP at CABSTART POSI0_X = 0.0 / the orbital position in X at CABSTART POSI0_Y = 0.0 / the orbital position in Y at CABSTART POSI0_Z = 0.0 / the orbital position in Z at CABSTART VELO0_X = 0.0 / the orbital velocity in X at CABSTART VELO0_Y = 0.0 / the orbital velocity in Y at CABSTART VELO0_Z = 0.0 / the orbital velocity in Z at CABSTART EULER0_1= 0.0 / euler angle 1 at CABSTART EULER0_2= 0.0 / euler angle 2 at CABSTART EULER0_3= 0.0 / euler angle 3 at CABSTART RA_PNT0 = 0.0 / RA of the pointing (degrees) at CABSTART DEC_PNT0= 0.0 / DEC of the pointing (degrees) at CABSTART EXPEND = 0.0 / exposure end time (MJD) CABEND = 0.0 / (MJD) SUNANGL1= 50.0 / angle between sun and opt axis at CABEND MOONANG1= 30.0 / angle between moon and opt axis at CABEND TEL_ALT1= 20.0 / angle between opt axis and Elimb at CABEND POS_ANG1= 20.0 / angle between y axis and NP at CABEND POSI1_X = 0.0 / the orbital position in X at CABEND POSI1_Y = 0.0 / the orbital position in Y at CABEND POSI1_Z = 0.0 / the orbital position in Z at CABEND VELO1_X = 0.0 / the orbital velocity in X at CABEND VELO1_Y = 0.0 / the orbital velocity in Y at CABEND VELO1_Z = 0.0 / the orbital velocity in Z at CABEND EULER1_1= 0.0 / euler angle 1 at CABEND EULER1_2= 0.0 / euler angle 2 at CABEND EULER1_3= 0.0 / euler angle 3 at CABEND RA_PNT1 = 0.0 / RA of the pointing (degrees) at CABEND DEC_PNT1= 0.0 / DEC of the pointing (degrees) at CABEND EXPTIME = 150.0 / exposure duration EPOCH = 2000.0 / coordinate epoch COMMENT Other information COMMENT ================================================================== CHECKSUM= 'abcdefg ' / HDU checksum updated yyyy-mm-ddTHH:MM:SS DATASUM = 'abcdefg ' / data unit checksum updated yyyy-mm-ddTHH:MM:SS END
...@@ -3,16 +3,18 @@ import galsim ...@@ -3,16 +3,18 @@ import galsim
from astropy.time import Time from astropy.time import Time
class Pointing(object): class Pointing(object):
def __init__(self, id=0, ra=0., dec=0., img_pa=0., timestamp=1621915200, sat_x=0., sat_y=0., sat_z=0., sat_vx=0., sat_vy=0., sat_vz=0., exp_time=150., pointing_type='MS'): def __init__(self, id=0, ra=0., dec=0., img_pa=0., timestamp=1621915200, sat_x=0., sat_y=0., sat_z=0., sun_x=0., sun_y=0., sun_z=0., sat_vx=0., sat_vy=0., sat_vz=0., exp_time=150., pointing_type='MS'):
self.id = id self.id = id
self.ra = ra self.ra = ra
self.dec = dec self.dec = dec
self.img_pa = img_pa * galsim.degrees self.img_pa = img_pa * galsim.degrees
self.timestamp = timestamp self.timestamp = timestamp
self.sat_x, self.sat_y, self.sat_z = sat_x, sat_y, sat_z self.sat_x, self.sat_y, self.sat_z = sat_x, sat_y, sat_z
self.sun_x, self.sun_y, self.sun_z = sun_x, sun_y, sun_z
self.sat_vx, self.sat_vy, self.sat_vz = sat_vx, sat_vy, sat_vz self.sat_vx, self.sat_vy, self.sat_vz = sat_vx, sat_vy, sat_vz
self.exp_time = exp_time self.exp_time = exp_time
self.pointing_type = pointing_type self.pointing_type = pointing_type
self.jdt = 0.
def read_pointing_columns(self, columns, id=0, t=1621915200, pointing_type='MS'): def read_pointing_columns(self, columns, id=0, t=1621915200, pointing_type='MS'):
self.id = id self.id = id
...@@ -24,10 +26,14 @@ class Pointing(object): ...@@ -24,10 +26,14 @@ class Pointing(object):
if col_len > 5: if col_len > 5:
jdt = np.double(columns[5]) jdt = np.double(columns[5])
t_temp = Time(jdt, format='jd') t_temp = Time(jdt, format='jd')
self.jdt = jdt
self.timestamp = t_temp.unix self.timestamp = t_temp.unix
self.sat_x = float(columns[6]) self.sat_x = float(columns[6])
self.sat_y = float(columns[7]) self.sat_y = float(columns[7])
self.sat_z = float(columns[8]) self.sat_z = float(columns[8])
self.sun_x = float(columns[9])
self.sun_y = float(columns[10])
self.sun_z = float(columns[1])
self.sat_vx = float(columns[15]) self.sat_vx = float(columns[15])
self.sat_vy = float(columns[16]) self.sat_vy = float(columns[16])
self.sat_vz = float(columns[17]) self.sat_vz = float(columns[17])
......
...@@ -27,7 +27,9 @@ class Chip(FocalPlane): ...@@ -27,7 +27,9 @@ class Chip(FocalPlane):
# self.npix_x = 9216 # self.npix_x = 9216
# self.npix_y = 9232 # self.npix_y = 9232
# self.pix_scale = 0.074 # pixel scale # self.pix_scale = 0.074 # pixel scale
self.nsecy = 2
self.nsecx = 8
self.gain_channel = np.ones(self.nsecy* self.nsecx)
self._set_attributes_from_config(config) self._set_attributes_from_config(config)
self.logger = logger self.logger = logger
...@@ -75,7 +77,8 @@ class Chip(FocalPlane): ...@@ -75,7 +77,8 @@ class Chip(FocalPlane):
self.fdModel = None self.fdModel = None
else: else:
try: try:
with pkg_resources.files('ObservationSim.Instrument.data.field_distortion').joinpath("FieldDistModelGlobal_mainFP_v1.0.pickle") as field_distortion: # with pkg_resources.files('ObservationSim.Instrument.data.field_distortion').joinpath("FieldDistModelGlobal_mainFP_v1.0.pickle") as field_distortion:
with pkg_resources.files('ObservationSim.Instrument.data.field_distortion').joinpath("FieldDistModel_v2.0.pickle") as field_distortion:
with open(field_distortion, "rb") as f: with open(field_distortion, "rb") as f:
self.fdModel = pickle.load(f) self.fdModel = pickle.load(f)
except AttributeError: except AttributeError:
...@@ -115,7 +118,7 @@ class Chip(FocalPlane): ...@@ -115,7 +118,7 @@ class Chip(FocalPlane):
self._getCRdata() self._getCRdata()
# Define the sensor model # Define the sensor model
if config["ins_effects"]["bright_fatter"] == True and self.survey_type == "photometric": if "bright_fatter" in config["ins_effects"] and config["ins_effects"]["bright_fatter"] == True and self.survey_type == "photometric":
self.sensor = galsim.SiliconSensor(strength=self.df_strength, treering_func=treering_func) self.sensor = galsim.SiliconSensor(strength=self.df_strength, treering_func=treering_func)
else: else:
self.sensor = galsim.Sensor() self.sensor = galsim.Sensor()
...@@ -144,18 +147,18 @@ class Chip(FocalPlane): ...@@ -144,18 +147,18 @@ class Chip(FocalPlane):
def _getSurveyType(self): def _getSurveyType(self):
if self.filter_type in ["GI", "GV", "GU"]: if self.filter_type in ["GI", "GV", "GU"]:
return "spectroscopic" return "spectroscopic"
elif self.filter_type in ["nuv", "u", "g", 'r', 'i', 'z', 'y', 'FGS']: elif self.filter_type in ["NUV", "u", "g", 'r', 'i', 'z', 'y', 'FGS']:
return "photometric" return "photometric"
# elif self.filter_type in ["FGS"]: # elif self.filter_type in ["FGS"]:
# return "FGS" # return "FGS"
def _getChipEffCurve(self, filter_type): def _getChipEffCurve(self, filter_type):
# CCD efficiency curves # CCD efficiency curves
if filter_type in ['nuv', 'u', 'GU']: filename = 'UV0.txt' if filter_type in ['NUV', 'u', 'GU']: filename = 'UV0.txt'
if filter_type in ['g', 'r', 'GV', 'FGS']: filename = 'Astro_MB.txt' # TODO, need to switch to the right efficiency curvey for FGS CMOS if filter_type in ['g', 'r', 'GV', 'FGS']: filename = 'Astro_MB.txt' # TODO, need to switch to the right efficiency curvey for FGS CMOS
if filter_type in ['i', 'z', 'y', 'GI']: filename = 'Basic_NIR.txt' if filter_type in ['i', 'z', 'y', 'GI']: filename = 'Basic_NIR.txt'
# Mirror efficiency: # Mirror efficiency:
# if filter_type == 'nuv': mirror_eff = 0.54 # if filter_type == 'NUV': mirror_eff = 0.54
# if filter_type == 'u': mirror_eff = 0.68 # if filter_type == 'u': mirror_eff = 0.68
# if filter_type in ['g', 'r', 'i', 'z', 'y']: mirror_eff = 0.8 # if filter_type in ['g', 'r', 'i', 'z', 'y']: mirror_eff = 0.8
# if filter_type in ['GU', 'GV', 'GI']: mirror_eff = 1. # Not sure if this is right # if filter_type in ['GU', 'GV', 'GI']: mirror_eff = 1. # Not sure if this is right
...@@ -182,7 +185,7 @@ class Chip(FocalPlane): ...@@ -182,7 +185,7 @@ class Chip(FocalPlane):
def getChipFilter(self, chipID=None, filter_layout=None): def getChipFilter(self, chipID=None, filter_layout=None):
"""Return the filter index and type for a given chip #(chipID) """Return the filter index and type for a given chip #(chipID)
""" """
filter_type_list = ["nuv","u", "g", "r", "i","z","y","GU", "GV", "GI", "FGS"] filter_type_list = ["NUV","u", "g", "r", "i","z","y","GU", "GV", "GI", "FGS"]
if filter_layout is not None: if filter_layout is not None:
return filter_layout[chipID][0], filter_layout[chipID][1] return filter_layout[chipID][0], filter_layout[chipID][1]
if chipID == None: if chipID == None:
...@@ -195,7 +198,7 @@ class Chip(FocalPlane): ...@@ -195,7 +198,7 @@ class Chip(FocalPlane):
if chipID in [7, 24]: filter_type = "i" if chipID in [7, 24]: filter_type = "i"
if chipID in [14, 17]: filter_type = "u" if chipID in [14, 17]: filter_type = "u"
if chipID in [9, 22]: filter_type = "r" if chipID in [9, 22]: filter_type = "r"
if chipID in [12, 13, 18, 19]: filter_type = "nuv" if chipID in [12, 13, 18, 19]: filter_type = "NUV"
if chipID in [8, 23]: filter_type = "g" if chipID in [8, 23]: filter_type = "g"
if chipID in [1, 10, 21, 30]: filter_type = "GI" if chipID in [1, 10, 21, 30]: filter_type = "GI"
if chipID in [2, 5, 26, 29]: filter_type = "GV" if chipID in [2, 5, 26, 29]: filter_type = "GV"
...@@ -304,7 +307,10 @@ class Chip(FocalPlane): ...@@ -304,7 +307,10 @@ class Chip(FocalPlane):
if self.chipID == 30: confFile = ['CSST_GI8.conf', 'CSST_GI7.conf'] if self.chipID == 30: confFile = ['CSST_GI8.conf', 'CSST_GI7.conf']
return confFile return confFile
def generateHeader(self, ra_cen, dec_cen, img_rot, im_type, pointing_ID, date_obs, time_obs, exptime=150.): def generateHeader(self, ra_cen, dec_cen, img_rot, im_type, pointing_ID, exptime=150., timestamp = 1621915200):
datetime_obs = datetime.utcfromtimestamp(timestamp)
date_obs = datetime_obs.strftime("%y%m%d")
time_obs = datetime_obs.strftime("%H%M%S")
h_prim = generatePrimaryHeader( h_prim = generatePrimaryHeader(
xlen=self.npix_x, xlen=self.npix_x,
ylen=self.npix_y, ylen=self.npix_y,
...@@ -333,23 +339,30 @@ class Chip(FocalPlane): ...@@ -333,23 +339,30 @@ class Chip(FocalPlane):
pixel_size=self.pix_size, pixel_size=self.pix_size,
xcen=self.x_cen, xcen=self.x_cen,
ycen=self.y_cen, ycen=self.y_cen,
extName='raw') extName='SCI',
timestamp = timestamp,
exptime = exptime,
readoutTime = 40.)
return h_prim, h_ext return h_prim, h_ext
def outputCal(self, img, ra_cen, dec_cen, img_rot, im_type, pointing_ID, date_obs, time_obs, output_dir, exptime=150.): def outputCal(self, img, ra_cen, dec_cen, img_rot, im_type, pointing_ID, output_dir, exptime=150., timestamp = 1621915200):
h_prim, h_ext = self.generateHeader( h_prim, h_ext = self.generateHeader(
ra_cen=ra_cen, ra_cen=ra_cen,
dec_cen=dec_cen, dec_cen=dec_cen,
img_rot=img_rot, img_rot=img_rot,
im_type=im_type, im_type=im_type,
pointing_ID=pointing_ID, pointing_ID=pointing_ID,
date_obs=date_obs, exptime=exptime,
time_obs=time_obs, timestamp = timestamp)
exptime=exptime)
hdu1 = fits.PrimaryHDU(header=h_prim) hdu1 = fits.PrimaryHDU(header=h_prim)
hdu1.add_checksum() hdu1.add_checksum()
hdu1.header.comments['CHECKSUM'] = 'HDU checksum'
hdu1.header.comments['DATASUM'] = 'data unit checksum'
hdu2 = fits.ImageHDU(img.array, header=h_ext) hdu2 = fits.ImageHDU(img.array, header=h_ext)
hdu2.add_checksum() hdu2.add_checksum()
hdu2.header.comments['XTENSION'] = 'extension type'
hdu2.header.comments['CHECKSUM'] = 'HDU checksum'
hdu2.header.comments['DATASUM'] = 'data unit checksum'
hdu1 = fits.HDUList([hdu1, hdu2]) hdu1 = fits.HDUList([hdu1, hdu2])
fname = os.path.join(output_dir, h_prim['FILENAME']+'.fits') fname = os.path.join(output_dir, h_prim['FILENAME']+'.fits')
hdu1.writeto(fname, output_verify='ignore', overwrite=True) hdu1.writeto(fname, output_verify='ignore', overwrite=True)
...@@ -456,9 +469,9 @@ class Chip(FocalPlane): ...@@ -456,9 +469,9 @@ class Chip(FocalPlane):
del cr_map del cr_map
# crmap_gsimg.write("%s/CosmicRay_%s_1.fits" % (chip_output.subdir, self.chipID)) # crmap_gsimg.write("%s/CosmicRay_%s_1.fits" % (chip_output.subdir, self.chipID))
# crmap_gsimg.write("%s/CosmicRay_%s.fits" % (chip_output.subdir, self.chipID)) # crmap_gsimg.write("%s/CosmicRay_%s.fits" % (chip_output.subdir, self.chipID))
datetime_obs = datetime.utcfromtimestamp(timestamp_obs) # datetime_obs = datetime.utcfromtimestamp(timestamp_obs)
date_obs = datetime_obs.strftime("%y%m%d") # date_obs = datetime_obs.strftime("%y%m%d")
time_obs = datetime_obs.strftime("%H%M%S") # time_obs = datetime_obs.strftime("%H%M%S")
self.outputCal( self.outputCal(
img=crmap_gsimg, img=crmap_gsimg,
ra_cen=ra_cen, ra_cen=ra_cen,
...@@ -466,10 +479,9 @@ class Chip(FocalPlane): ...@@ -466,10 +479,9 @@ class Chip(FocalPlane):
img_rot=img_rot, img_rot=img_rot,
im_type='CRS', im_type='CRS',
pointing_ID=pointing_ID, pointing_ID=pointing_ID,
date_obs=date_obs,
time_obs=time_obs,
output_dir=chip_output.subdir, output_dir=chip_output.subdir,
exptime=exptime) exptime=exptime,
timestamp=timestamp_obs)
del crmap_gsimg del crmap_gsimg
# Apply PRNU effect and output PRNU flat file: # Apply PRNU effect and output PRNU flat file:
...@@ -503,21 +515,6 @@ class Chip(FocalPlane): ...@@ -503,21 +515,6 @@ class Chip(FocalPlane):
if config["ins_effects"]["add_badcolumns"] == True: if config["ins_effects"]["add_badcolumns"] == True:
img = effects.BadColumns(img, seed=SeedBadColumns, chipid=self.chipID, logger=self.logger) img = effects.BadColumns(img, seed=SeedBadColumns, chipid=self.chipID, logger=self.logger)
# Add Bias level
if config["ins_effects"]["add_bias"] == True:
if self.logger is not None:
self.logger.info(" Adding Bias level and 16-channel non-uniformity")
else:
print(" Adding Bias level and 16-channel non-uniformity")
if config["ins_effects"]["bias_16channel"] == True:
img = effects.AddBiasNonUniform16(img,
bias_level=float(self.bias_level),
nsecy = 2, nsecx=8,
seed=SeedBiasNonuni+self.chipID,
logger=self.logger)
elif config["ins_effects"]["bias_16channel"] == False:
img += self.bias_level
# Apply Nonlinearity on the chip image # Apply Nonlinearity on the chip image
if config["ins_effects"]["non_linear"] == True: if config["ins_effects"]["non_linear"] == True:
if self.logger is not None: if self.logger is not None:
...@@ -542,6 +539,21 @@ class Chip(FocalPlane): ...@@ -542,6 +539,21 @@ class Chip(FocalPlane):
print(" Apply CTE Effect") print(" Apply CTE Effect")
img = effects.CTE_Effect(GSImage=img, threshold=27) img = effects.CTE_Effect(GSImage=img, threshold=27)
# Add Bias level
if config["ins_effects"]["add_bias"] == True:
if self.logger is not None:
self.logger.info(" Adding Bias level and 16-channel non-uniformity")
else:
print(" Adding Bias level and 16-channel non-uniformity")
if config["ins_effects"]["bias_16channel"] == True:
img = effects.AddBiasNonUniform16(img,
bias_level=float(self.bias_level),
nsecy = 2, nsecx=8,
seed=SeedBiasNonuni+self.chipID,
logger=self.logger)
elif config["ins_effects"]["bias_16channel"] == False:
img += self.bias_level
# Add Read-out Noise # Add Read-out Noise
if config["ins_effects"]["add_readout"] == True: if config["ins_effects"]["add_readout"] == True:
seed = int(config["random_seeds"]["seed_readout"]) + pointing_ID*30 + self.chipID seed = int(config["random_seeds"]["seed_readout"]) + pointing_ID*30 + self.chipID
...@@ -555,7 +567,7 @@ class Chip(FocalPlane): ...@@ -555,7 +567,7 @@ class Chip(FocalPlane):
else: else:
print(" Applying Gain (and 16 channel non-uniformity) & Quantization", flush=True) print(" Applying Gain (and 16 channel non-uniformity) & Quantization", flush=True)
if config["ins_effects"]["gain_16channel"] == True: if config["ins_effects"]["gain_16channel"] == True:
img = effects.ApplyGainNonUniform16( img, self.gain_channel = effects.ApplyGainNonUniform16(
img, gain=self.gain, img, gain=self.gain,
nsecy = 2, nsecx=8, nsecy = 2, nsecx=8,
seed=SeedGainNonuni+self.chipID, seed=SeedGainNonuni+self.chipID,
...@@ -610,7 +622,7 @@ class Chip(FocalPlane): ...@@ -610,7 +622,7 @@ class Chip(FocalPlane):
if config["ins_effects"]["add_badcolumns"] == True: if config["ins_effects"]["add_badcolumns"] == True:
BiasCombImg = effects.BadColumns(BiasCombImg-float(self.bias_level)+5, seed=SeedBadColumns, chipid=self.chipID, logger=self.logger) + float(self.bias_level)-5 BiasCombImg = effects.BadColumns(BiasCombImg-float(self.bias_level)+5, seed=SeedBadColumns, chipid=self.chipID, logger=self.logger) + float(self.bias_level)-5
BiasCombImg = effects.ApplyGainNonUniform16(BiasCombImg, gain=self.gain, BiasCombImg, self.gain_channel = effects.ApplyGainNonUniform16(BiasCombImg, gain=self.gain,
nsecy = 2, nsecx=8, nsecy = 2, nsecx=8,
seed=SeedGainNonuni+self.chipID, seed=SeedGainNonuni+self.chipID,
logger=self.logger) logger=self.logger)
...@@ -622,9 +634,9 @@ class Chip(FocalPlane): ...@@ -622,9 +634,9 @@ class Chip(FocalPlane):
BiasCombImg.quantize() BiasCombImg.quantize()
BiasCombImg = galsim.ImageUS(BiasCombImg) BiasCombImg = galsim.ImageUS(BiasCombImg)
# BiasCombImg.write("%s/BiasImg_%s_%s_%s.fits" % (chip_output.subdir, BiasTag, self.chipID, i+1)) # BiasCombImg.write("%s/BiasImg_%s_%s_%s.fits" % (chip_output.subdir, BiasTag, self.chipID, i+1))
datetime_obs = datetime.utcfromtimestamp(timestamp_obs) # datetime_obs = datetime.utcfromtimestamp(timestamp_obs)
date_obs = datetime_obs.strftime("%y%m%d") # date_obs = datetime_obs.strftime("%y%m%d")
time_obs = datetime_obs.strftime("%H%M%S") # time_obs = datetime_obs.strftime("%H%M%S")
timestamp_obs += 10 * 60 timestamp_obs += 10 * 60
self.outputCal( self.outputCal(
img=BiasCombImg, img=BiasCombImg,
...@@ -633,10 +645,9 @@ class Chip(FocalPlane): ...@@ -633,10 +645,9 @@ class Chip(FocalPlane):
img_rot=img_rot, img_rot=img_rot,
im_type='BIAS', im_type='BIAS',
pointing_ID=pointing_ID, pointing_ID=pointing_ID,
date_obs=date_obs,
time_obs=time_obs,
output_dir=chip_output.subdir, output_dir=chip_output.subdir,
exptime=0.0) exptime=0.0,
timestamp=timestamp_obs)
del BiasCombImg del BiasCombImg
# Export combined (ncombine, Vignetting + PRNU) & single vignetting flat-field file # Export combined (ncombine, Vignetting + PRNU) & single vignetting flat-field file
...@@ -717,7 +728,7 @@ class Chip(FocalPlane): ...@@ -717,7 +728,7 @@ class Chip(FocalPlane):
readout_noise = galsim.GaussianNoise(rng=rng_readout, sigma=self.read_noise) readout_noise = galsim.GaussianNoise(rng=rng_readout, sigma=self.read_noise)
FlatCombImg.addNoise(readout_noise) FlatCombImg.addNoise(readout_noise)
FlatCombImg = effects.ApplyGainNonUniform16(FlatCombImg, gain=self.gain, FlatCombImg, self.gain_channel = effects.ApplyGainNonUniform16(FlatCombImg, gain=self.gain,
nsecy = 2, nsecx=8, nsecy = 2, nsecx=8,
seed=SeedGainNonuni+self.chipID, seed=SeedGainNonuni+self.chipID,
logger=self.logger) logger=self.logger)
...@@ -726,9 +737,9 @@ class Chip(FocalPlane): ...@@ -726,9 +737,9 @@ class Chip(FocalPlane):
FlatCombImg.quantize() FlatCombImg.quantize()
FlatCombImg = galsim.ImageUS(FlatCombImg) FlatCombImg = galsim.ImageUS(FlatCombImg)
# FlatCombImg.write("%s/FlatImg_%s_%s_%s.fits" % (chip_output.subdir, FlatTag, self.chipID, i+1)) # FlatCombImg.write("%s/FlatImg_%s_%s_%s.fits" % (chip_output.subdir, FlatTag, self.chipID, i+1))
datetime_obs = datetime.utcfromtimestamp(timestamp_obs) # datetime_obs = datetime.utcfromtimestamp(timestamp_obs)
date_obs = datetime_obs.strftime("%y%m%d") # date_obs = datetime_obs.strftime("%y%m%d")
time_obs = datetime_obs.strftime("%H%M%S") # time_obs = datetime_obs.strftime("%H%M%S")
timestamp_obs += 10 * 60 timestamp_obs += 10 * 60
self.outputCal( self.outputCal(
img=FlatCombImg, img=FlatCombImg,
...@@ -737,10 +748,9 @@ class Chip(FocalPlane): ...@@ -737,10 +748,9 @@ class Chip(FocalPlane):
img_rot=img_rot, img_rot=img_rot,
im_type='FLAT', im_type='FLAT',
pointing_ID=pointing_ID, pointing_ID=pointing_ID,
date_obs=date_obs,
time_obs=time_obs,
output_dir=chip_output.subdir, output_dir=chip_output.subdir,
exptime=self.flat_exptime) exptime=self.flat_exptime,
timestamp=timestamp_obs)
del FlatCombImg, FlatSingle, prnu_img del FlatCombImg, FlatSingle, prnu_img
# flat_img.replaceNegative(replace_value=0) # flat_img.replaceNegative(replace_value=0)
...@@ -783,9 +793,9 @@ class Chip(FocalPlane): ...@@ -783,9 +793,9 @@ class Chip(FocalPlane):
cr_map[cr_map < 0] = 0 cr_map[cr_map < 0] = 0
crmap_gsimg = galsim.Image(cr_map, dtype=np.uint16) crmap_gsimg = galsim.Image(cr_map, dtype=np.uint16)
del cr_map del cr_map
datetime_obs = datetime.utcfromtimestamp(timestamp_obs) # datetime_obs = datetime.utcfromtimestamp(timestamp_obs)
date_obs = datetime_obs.strftime("%y%m%d") # date_obs = datetime_obs.strftime("%y%m%d")
time_obs = datetime_obs.strftime("%H%M%S") # time_obs = datetime_obs.strftime("%H%M%S")
self.outputCal( self.outputCal(
img=crmap_gsimg, img=crmap_gsimg,
ra_cen=ra_cen, ra_cen=ra_cen,
...@@ -793,10 +803,9 @@ class Chip(FocalPlane): ...@@ -793,10 +803,9 @@ class Chip(FocalPlane):
img_rot=img_rot, img_rot=img_rot,
im_type='CRD', im_type='CRD',
pointing_ID=pointing_ID, pointing_ID=pointing_ID,
date_obs=date_obs,
time_obs=time_obs,
output_dir=chip_output.subdir, output_dir=chip_output.subdir,
exptime=self.dark_exptime) exptime=self.dark_exptime,
timestamp=timestamp_obs)
del crmap_gsimg del crmap_gsimg
# Non-Linearity for Dark # Non-Linearity for Dark
...@@ -839,7 +848,7 @@ class Chip(FocalPlane): ...@@ -839,7 +848,7 @@ class Chip(FocalPlane):
readout_noise = galsim.GaussianNoise(rng=rng_readout, sigma=self.read_noise) readout_noise = galsim.GaussianNoise(rng=rng_readout, sigma=self.read_noise)
DarkCombImg.addNoise(readout_noise) DarkCombImg.addNoise(readout_noise)
DarkCombImg = effects.ApplyGainNonUniform16( DarkCombImg, self.gain_channel = effects.ApplyGainNonUniform16(
DarkCombImg, gain=self.gain, DarkCombImg, gain=self.gain,
nsecy = 2, nsecx=8, nsecy = 2, nsecx=8,
seed=SeedGainNonuni+self.chipID, seed=SeedGainNonuni+self.chipID,
...@@ -852,9 +861,9 @@ class Chip(FocalPlane): ...@@ -852,9 +861,9 @@ class Chip(FocalPlane):
DarkCombImg.quantize() DarkCombImg.quantize()
DarkCombImg = galsim.ImageUS(DarkCombImg) DarkCombImg = galsim.ImageUS(DarkCombImg)
# DarkCombImg.write("%s/DarkImg_%s_%s_%s.fits" % (chip_output.subdir, DarkTag, self.chipID, i+1)) # DarkCombImg.write("%s/DarkImg_%s_%s_%s.fits" % (chip_output.subdir, DarkTag, self.chipID, i+1))
datetime_obs = datetime.utcfromtimestamp(timestamp_obs) # datetime_obs = datetime.utcfromtimestamp(timestamp_obs)
date_obs = datetime_obs.strftime("%y%m%d") # date_obs = datetime_obs.strftime("%y%m%d")
time_obs = datetime_obs.strftime("%H%M%S") # time_obs = datetime_obs.strftime("%H%M%S")
timestamp_obs += 10 * 60 timestamp_obs += 10 * 60
self.outputCal( self.outputCal(
img=DarkCombImg, img=DarkCombImg,
...@@ -863,10 +872,9 @@ class Chip(FocalPlane): ...@@ -863,10 +872,9 @@ class Chip(FocalPlane):
img_rot=img_rot, img_rot=img_rot,
im_type='DARK', im_type='DARK',
pointing_ID=pointing_ID, pointing_ID=pointing_ID,
date_obs=date_obs,
time_obs=time_obs,
output_dir=chip_output.subdir, output_dir=chip_output.subdir,
exptime=self.dark_exptime) exptime=self.dark_exptime,
timestamp = timestamp_obs)
del DarkCombImg del DarkCombImg
# img = galsim.ImageUS(img) # img = galsim.ImageUS(img)
......
...@@ -152,6 +152,7 @@ def ApplyGainNonUniform16(GSImage, gain=1, nsecy = 2, nsecx=8, seed=202102, logg ...@@ -152,6 +152,7 @@ def ApplyGainNonUniform16(GSImage, gain=1, nsecy = 2, nsecx=8, seed=202102, logg
rg = Generator(PCG64(int(seed))) rg = Generator(PCG64(int(seed)))
Random16 = (rg.random(nsecy*nsecx)-0.5)*0.04+1 # sigma~1% Random16 = (rg.random(nsecy*nsecx)-0.5)*0.04+1 # sigma~1%
Gain16 = Random16.reshape((nsecy,nsecx))/gain Gain16 = Random16.reshape((nsecy,nsecx))/gain
gain_array = np.ones(nsecy*nsecx)*gain
if logger is not None: if logger is not None:
msg = str("Gain of 16 channels: " + str(Gain16)) msg = str("Gain of 16 channels: " + str(Gain16))
logger.info(msg) logger.info(msg)
...@@ -163,7 +164,8 @@ def ApplyGainNonUniform16(GSImage, gain=1, nsecy = 2, nsecx=8, seed=202102, logg ...@@ -163,7 +164,8 @@ def ApplyGainNonUniform16(GSImage, gain=1, nsecy = 2, nsecx=8, seed=202102, logg
for rowi in range(nsecy): for rowi in range(nsecy):
for coli in range(nsecx): for coli in range(nsecx):
GSImage.array[rowi*secsize_y:(rowi+1)*secsize_y,coli*secsize_x:(coli+1)*secsize_x] *= Gain16[rowi,coli] GSImage.array[rowi*secsize_y:(rowi+1)*secsize_y,coli*secsize_x:(coli+1)*secsize_x] *= Gain16[rowi,coli]
return GSImage gain_array[rowi*nsecx+coli] = 1/Gain16[rowi,coli]
return GSImage, gain_array
def GainsNonUniform16(GSImage, gain=1, nsecy = 2, nsecx=8, seed=202102, logger=None): def GainsNonUniform16(GSImage, gain=1, nsecy = 2, nsecx=8, seed=202102, logger=None):
......
...@@ -2,9 +2,11 @@ import galsim ...@@ -2,9 +2,11 @@ import galsim
import pylab as pl import pylab as pl
import os import os
import numpy as np import numpy as np
import gc
from ObservationSim.Instrument._util import photonEnergy, calculateLimitMag from ObservationSim.Instrument._util import photonEnergy, calculateLimitMag
from ObservationSim.Instrument.FilterParam import FilterParam from ObservationSim.Instrument.FilterParam import FilterParam
from ObservationSim.Straylight import Straylight
try: try:
import importlib.resources as pkg_resources import importlib.resources as pkg_resources
...@@ -38,6 +40,7 @@ class Filter(object): ...@@ -38,6 +40,7 @@ class Filter(object):
self.sky_background = filter_param.param[filter_type][5] self.sky_background = filter_param.param[filter_type][5]
self.mag_saturation = filter_param.param[filter_type][6] self.mag_saturation = filter_param.param[filter_type][6]
self.mag_limiting = filter_param.param[filter_type][7] self.mag_limiting = filter_param.param[filter_type][7]
self.zodical_spec = None
def is_too_bright(self, mag, margin=-2.5): def is_too_bright(self, mag, margin=-2.5):
return mag <= self.mag_saturation + margin return mag <= self.mag_saturation + margin
...@@ -108,6 +111,24 @@ class Filter(object): ...@@ -108,6 +111,24 @@ class Filter(object):
def getSkyNoise(self, exptime, gain=1.): def getSkyNoise(self, exptime, gain=1.):
return self.sky_background * exptime / gain return self.sky_background * exptime / gain
def setFilterStrayLightPixel(self,jtime = 2460843., sat_pos = np.array([0,0,0]), pointing_radec = np.array([0,0]), sun_pos = np.array([0,0,0])):
sl = Straylight(jtime=jtime, sat_pos=sat_pos, pointing_radec=pointing_radec,sun_pos=sun_pos)
if self.filter_type in ["GU","GV","GI"]:
s_pix, spec = sl.calculateStrayLightGrating(grating = self.filter_type.upper())
if s_pix>0.8:
s_pix = 0.8
self.sky_background = s_pix
self.zodical_spec = spec
elif self.filter_type.lower() in ["nuv","u","g","r","i","z","y"]:
s_pix = sl.calculateStrayLightFilter(filter=self.filter_type.lower())
if s_pix>1:
s_pix = 1
self.sky_background = s_pix
self.zodical_spec = None
del sl
gc.collect()
def update_limit_saturation_mags(self, exptime=150., psf_fwhm=0.1969, skyFn='sky_emiss_hubble_50_50_A.dat', chip=None): def update_limit_saturation_mags(self, exptime=150., psf_fwhm=0.1969, skyFn='sky_emiss_hubble_50_50_A.dat', chip=None):
if self.filter_type in ["GI", "GV", "GU"]: if self.filter_type in ["GI", "GV", "GU"]:
return return
......
...@@ -26,7 +26,7 @@ class FilterParam(object): ...@@ -26,7 +26,7 @@ class FilterParam(object):
# 8) dim end magnitude # 8) dim end magnitude
if filter_param == None: if filter_param == None:
filtP = { filtP = {
"nuv": [2867.7, 705.4, 2470.0, 3270.0, 0.1404, 0.004, 15.7, 25.4], "NUV": [2867.7, 705.4, 2470.0, 3270.0, 0.1404, 0.004, 15.7, 25.4],
"u": [3601.1, 852.1, 3120.0, 4090.0, 0.2176, 0.021, 16.1, 25.4], "u": [3601.1, 852.1, 3120.0, 4090.0, 0.2176, 0.021, 16.1, 25.4],
"g": [4754.5, 1569.8, 3900.0, 5620.0, 0.4640, 0.164, 17.2, 26.3], "g": [4754.5, 1569.8, 3900.0, 5620.0, 0.4640, 0.164, 17.2, 26.3],
"r": [6199.8, 1481.2, 5370.0, 7030.0, 0.5040, 0.207, 17.0, 26.0], "r": [6199.8, 1481.2, 5370.0, 7030.0, 0.5040, 0.207, 17.0, 26.0],
......
...@@ -86,15 +86,16 @@ class FocalPlane(object): ...@@ -86,15 +86,16 @@ class FocalPlane(object):
if (xcen == None) or (ycen == None): if (xcen == None) or (ycen == None):
xcen = self.cen_pix_x xcen = self.cen_pix_x
ycen = self.cen_pix_y ycen = self.cen_pix_y
# dudx = -np.cos(img_rot.rad) * pix_scale
# dudy = -np.sin(img_rot.rad) * pix_scale
# dvdx = -np.sin(img_rot.rad) * pix_scale
# dvdy = +np.cos(img_rot.rad) * pix_scale
dudx = -np.cos(img_rot.rad) * pix_scale dudx = -np.cos(img_rot.rad) * pix_scale
dudy = -np.sin(img_rot.rad) * pix_scale dudy = +np.sin(img_rot.rad) * pix_scale
dvdx = -np.sin(img_rot.rad) * pix_scale dvdx = -np.sin(img_rot.rad) * pix_scale
dvdy = +np.cos(img_rot.rad) * pix_scale dvdy = -np.cos(img_rot.rad) * pix_scale
# dudx = +np.sin(img_rot.rad) * pix_scale
# dudy = +np.cos(img_rot.rad) * pix_scale
# dvdx = -np.cos(img_rot.rad) * pix_scale
# dvdy = +np.sin(img_rot.rad) * pix_scale
moscen = galsim.PositionD(x=xcen, y=ycen) moscen = galsim.PositionD(x=xcen, y=ycen)
sky_center = galsim.CelestialCoord(ra=ra*galsim.degrees, dec=dec*galsim.degrees) sky_center = galsim.CelestialCoord(ra=ra*galsim.degrees, dec=dec*galsim.degrees)
affine = galsim.AffineTransform(dudx, dudy, dvdx, dvdy, origin=moscen) affine = galsim.AffineTransform(dudx, dudy, dvdx, dvdy, origin=moscen)
......
...@@ -468,7 +468,7 @@ ...@@ -468,7 +468,7 @@
"full_well": 90000 "full_well": 90000
}, },
"15": { "15": {
"chip_name": "y-4", "chip_name": "y-2",
"pix_size": 0.01, "pix_size": 0.01,
"pix_scale": 0.074, "pix_scale": 0.074,
"npix_x": 9216, "npix_x": 9216,
...@@ -648,7 +648,7 @@ ...@@ -648,7 +648,7 @@
"full_well": 90000 "full_well": 90000
}, },
"25": { "25": {
"chip_name": "y-2", "chip_name": "y-4",
"pix_size": 0.01, "pix_size": 0.01,
"pix_scale": 0.074, "pix_scale": 0.074,
"npix_x": 9216, "npix_x": 9216,
......
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