Commit 964a402e authored by Fang Yuedong's avatar Fang Yuedong
Browse files

Merge remote-tracking branch 'origin/sim_scheduler' into sim_scheduler

Conflicts:
	ObservationSim/Config/Pointing.py
	config/obs_config_SCI_WIDE_phot.yaml
parents 524d234b 86cb9fdb
...@@ -60,7 +60,7 @@ class ChipOutput(object): ...@@ -60,7 +60,7 @@ class ChipOutput(object):
self.hdr += additional_column_names self.hdr += additional_column_names
def create_output_file(self): def create_output_file(self):
if self.pointing_type == 'SCIE': if self.pointing_type == 'SCI':
self.cat = open(os.path.join(self.subdir, self.cat_name), "w") self.cat = open(os.path.join(self.subdir, self.cat_name), "w")
self.logger.info("Creating catalog file %s ...\n"%(os.path.join(self.subdir, self.cat_name))) self.logger.info("Creating catalog file %s ...\n"%(os.path.join(self.subdir, self.cat_name)))
if not self.hdr.endswith("\n"): if not self.hdr.endswith("\n"):
......
...@@ -22,6 +22,7 @@ from ObservationSim.Config._util import get_obs_id, get_file_type ...@@ -22,6 +22,7 @@ from ObservationSim.Config._util import get_obs_id, get_file_type
from datetime import datetime from datetime import datetime
# import socket # import socket
import platform import platform
import toml
def chara2digit(char): def chara2digit(char):
""" Function to judge and convert characters to digitals """ Function to judge and convert characters to digitals
...@@ -342,7 +343,7 @@ def WCS_def(xlen = 9216, ylen = 9232, gapy = 898.0, gapx1 = 534, gapx2 = 1309, r ...@@ -342,7 +343,7 @@ def WCS_def(xlen = 9216, ylen = 9232, gapy = 898.0, gapx1 = 534, gapx2 = 1309, r
#TODO project_cycle is temporary, is not in header defined, delete in future #TODO project_cycle is temporary, is not in header defined, delete in future
def generatePrimaryHeader(xlen = 9216, ylen = 9232, pointNum = '1', ra = 60, dec = -40, pixel_scale = 0.074, date='200930', time_obs='120000', im_type = 'SCIE', exptime=150., sat_pos = [0.,0.,0.], sat_vel = [0., 0., 0.], project_cycle=6, run_counter=0, chip_name="01"): def generatePrimaryHeader(xlen = 9216, ylen = 9232, pointNum = '1', ra = 60, dec = -40, pixel_scale = 0.074, time_pt = None, im_type = 'SCI', exptime=150., sat_pos = [0.,0.,0.], sat_vel = [0., 0., 0.], project_cycle=6, run_counter=0, chip_name="01"):
# array_size1, array_size2, flux, sigma = int(argv[1]), int(argv[2]), 1000.0, 5.0 # array_size1, array_size2, flux, sigma = int(argv[1]), int(argv[2]), 1000.0, 5.0
...@@ -350,7 +351,12 @@ def generatePrimaryHeader(xlen = 9216, ylen = 9232, pointNum = '1', ra = 60, dec ...@@ -350,7 +351,12 @@ def generatePrimaryHeader(xlen = 9216, ylen = 9232, pointNum = '1', ra = 60, dec
# k = (row_num-1)*6+col_num # k = (row_num-1)*6+col_num
# ccdnum = str(k) # ccdnum = str(k)
g_header_fn = os.path.split(os.path.realpath(__file__))[0] + '/global_header.header' datetime_obs = datetime.utcfromtimestamp(time_pt)
datetime_obs = datetime_obs.replace(microsecond=round(datetime_obs.microsecond, -5))
# date_obs = datetime_obs.strftime("%y%m%d")
# time_obs = datetime_obs.strftime("%H%M%S%f")[:-5]
g_header_fn = os.path.split(os.path.realpath(__file__))[0] + '/csst_msc_l0_ms.fits'
f = open(os.path.split(os.path.realpath(__file__))[0] + '/filter.lst') f = open(os.path.split(os.path.realpath(__file__))[0] + '/filter.lst')
s = f.readline() s = f.readline()
s = s.strip("\n") s = s.strip("\n")
...@@ -363,19 +369,33 @@ def generatePrimaryHeader(xlen = 9216, ylen = 9232, pointNum = '1', ra = 60, dec ...@@ -363,19 +369,33 @@ def generatePrimaryHeader(xlen = 9216, ylen = 9232, pointNum = '1', ra = 60, dec
s = s.strip("\n") s = s.strip("\n")
CCDID = s.split() CCDID = s.split()
h_prim = fits.Header() # h_prim = fits.Header()
h_prim = fits.Header.fromfile(g_header_fn) # h_prim = fits.Header.fromfile(g_header_fn)
header_fits = fits.open(g_header_fn)
h_prim = header_fits[0].header
# h_prim = fits.Header()
# with open(g_header_fn, 'r') as file:
# header_toml = toml.load(file)
# h_key='HDU0'
# for key, value in header_toml[h_key].items():
# h_card = fits.card.Card(header_toml[h_key][key]['key'],header_toml[h_key][key]['example'],header_toml[h_key][key]['comment'])
# h_prim.append(h_card)
# h_prim['PIXSIZE1'] = xlen # h_prim['PIXSIZE1'] = xlen
# h_prim['PIXSIZE2'] = ylen # h_prim['PIXSIZE2'] = ylen
h_prim['DATE'] = '20'+date[0:2]+'-' + date[2:4]+'-'+date[4:6] + 'T' + time_obs[0:2]+':'+time_obs[2:4]+':'+time_obs[4:6] h_prim['DATE'] = datetime_obs.strftime("%Y-%m-%dT%H:%M:%S.%f")[:-5]
h_prim['DATE-OBS'] = datetime_obs.strftime("%Y-%m-%dT%H:%M:%S.%f")[:-5]
# h_prim['DATE'] = '20'+date[0:2]+'-' + date[2:4]+'-'+date[4:6] + 'T' + time_obs[0:2]+':'+time_obs[2:4]+':'+time_obs[4:6]
# h_prim['TIME'] = time_obs[0:2]+':'+time_obs[2:4]+':'+time_obs[4:6] # h_prim['TIME'] = time_obs[0:2]+':'+time_obs[2:4]+':'+time_obs[4:6]
h_prim['DATE-OBS'] = '20'+date[0:2]+'-' + date[2:4]+'-'+date[4:6] + 'T' + time_obs[0:2]+':'+time_obs[2:4]+':'+time_obs[4:6] # h_prim['DATE-OBS'] = '20'+date[0:2]+'-' + date[2:4]+'-'+date[4:6] + 'T' + time_obs[0:2]+':'+time_obs[2:4]+':'+time_obs[4:6]
# h_prim['TIME-OBS'] = time_obs[0:2]+':'+time_obs[2:4]+':'+time_obs[4:6] # h_prim['TIME-OBS'] = time_obs[0:2]+':'+time_obs[2:4]+':'+time_obs[4:6]
# h_prim['DETECTOR'] = 'CHIP'+CCDID[k-1].rjust(2,'0') # h_prim['DETECTOR'] = 'CHIP'+CCDID[k-1].rjust(2,'0')
h_prim['OBJ_RA'] = ra h_prim['RA_OBJ'] = ra
h_prim['OBJ_DEC'] = dec h_prim['DEC_OBJ'] = dec
# obs_type = {'SCI': '01', 'BIAS': '03', 'DARK': '07', 'FLAT': '11', 'CRS': '98', 'CRD': '99'} # obs_type = {'SCI': '01', 'BIAS': '03', 'DARK': '07', 'FLAT': '11', 'CRS': '98', 'CRD': '99'}
...@@ -396,7 +416,7 @@ def generatePrimaryHeader(xlen = 9216, ylen = 9232, pointNum = '1', ra = 60, dec ...@@ -396,7 +416,7 @@ def generatePrimaryHeader(xlen = 9216, ylen = 9232, pointNum = '1', ra = 60, dec
co = coord.SkyCoord(ra, dec, unit='deg') co = coord.SkyCoord(ra, dec, unit='deg')
ra_hms = format(co.ra.hms.h, '02.0f') + format(co.ra.hms.m, '02.0f') + format(co.ra.hms.s, '02.0f') ra_hms = format(co.ra.hms.h, '02.0f') + format(co.ra.hms.m, '02.0f') + format(co.ra.hms.s, '02.1f')
dec_hms = format(co.dec.dms.d, '02.0f') + format(abs(co.dec.dms.m), '02.0f') + format(abs(co.dec.dms.s), '02.0f') dec_hms = format(co.dec.dms.d, '02.0f') + format(abs(co.dec.dms.m), '02.0f') + format(abs(co.dec.dms.s), '02.0f')
h_prim['TARGET'] = ra_hms + '+' + dec_hms h_prim['TARGET'] = ra_hms + '+' + dec_hms
# #
...@@ -422,7 +442,8 @@ def generatePrimaryHeader(xlen = 9216, ylen = 9232, pointNum = '1', ra = 60, dec ...@@ -422,7 +442,8 @@ def generatePrimaryHeader(xlen = 9216, ylen = 9232, pointNum = '1', ra = 60, dec
h_prim['EXPEND'] = round(tend.mjd, 5) h_prim['EXPEND'] = round(tend.mjd, 5)
h_prim['CABEND'] = h_prim['EXPEND'] h_prim['CABEND'] = h_prim['EXPEND']
file_start_time = '20' + date[0:6] + time_obs[0:6] # file_start_time = '20' + date[0:6] + time_obs[0:6]
file_start_time = datetime_obs.strftime("%Y%m%d%H%M%S")
end_time_str = str(tend.datetime) end_time_str = str(tend.datetime)
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[
...@@ -445,7 +466,7 @@ def generatePrimaryHeader(xlen = 9216, ylen = 9232, pointNum = '1', ra = 60, dec ...@@ -445,7 +466,7 @@ def generatePrimaryHeader(xlen = 9216, ylen = 9232, pointNum = '1', ra = 60, dec
# 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")
currentDateAndTime = datetime.now() currentDateAndTime = datetime.now()
compute_name = platform.node() compute_name = platform.node()
h_prim['FITSCREA'] = get_distribution("CSSTSim").version +'_' + currentDateAndTime.strftime("%Y%m%d") + '_' +compute_name h_prim['FITSSWV'] = 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) h_prim['EPOCH'] = round((Time(h_prim['EXPSTART'], format='mjd', scale='tcb')).jyear, 1)
return h_prim return h_prim
...@@ -453,7 +474,7 @@ def generatePrimaryHeader(xlen = 9216, ylen = 9232, pointNum = '1', ra = 60, dec ...@@ -453,7 +474,7 @@ def generatePrimaryHeader(xlen = 9216, ylen = 9232, pointNum = '1', ra = 60, dec
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='SCIE', row_num = None, col_num = None, xcen=None, ycen=None, timestamp = 1621915200,exptime = 150., readoutTime = 40.): extName='SCIE', 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] + '/csst_msc_l0_ms.fits'
f = open(os.path.split(os.path.realpath(__file__))[0] + '/filter.lst') f = open(os.path.split(os.path.realpath(__file__))[0] + '/filter.lst')
s = f.readline() s = f.readline()
s = s.strip("\n") s = s.strip("\n")
...@@ -468,13 +489,24 @@ def generateExtensionHeader(chip, xlen = 9216, ylen = 9232,ra = 60, dec = -40, p ...@@ -468,13 +489,24 @@ def generateExtensionHeader(chip, xlen = 9216, ylen = 9232,ra = 60, dec = -40, p
# k = (row_num - 1) * 6 + col_num # k = (row_num - 1) * 6 + col_num
h_ext = fits.Header.fromfile(e_header_fn) # h_ext = fits.Header.fromfile(e_header_fn)
header_fits = fits.open(e_header_fn)
h_ext = header_fits[1].header
# h_ext = fits.Header()
# with open(e_header_fn, 'r') as file:
# header_toml = toml.load(file)
# h_key='HDU1'
# for key, value in header_toml[h_key].items():
# h_card = fits.card.Card(header_toml[h_key][key]['key'],header_toml[h_key][key]['example'],header_toml[h_key][key]['comment'])
# h_ext.append(h_card)
# 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['CHIPID'] = str(chip.chipID).rjust(2, '0') h_ext['CHIPID'] = str(chip.chipID).rjust(2, '0')
h_ext['CHIPLAB'] = chip.chip_name h_ext['CHIPLABL'] = 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
...@@ -521,13 +553,15 @@ def generateExtensionHeader(chip, xlen = 9216, ylen = 9232,ra = 60, dec = -40, p ...@@ -521,13 +553,15 @@ def generateExtensionHeader(chip, xlen = 9216, ylen = 9232,ra = 60, dec = -40, p
tstart = Time(datetime_obs) tstart = Time(datetime_obs)
tstart_read = Time(tstart.mjd + exptime / 86400., format="mjd") tstart_read = Time(tstart.mjd + exptime / 86400., format="mjd")
tend_read = Time(tstart.mjd + (exptime + readoutTime) / 86400., format="mjd") tend_read = Time(tstart.mjd + (exptime + readoutTime) / 86400., format="mjd")
t_s1 = str(tstart_read.datetime).split() # t_s1 = str(tstart_read.datetime).split()
h_ext['READT0'] = t_s1[0]+'T'+t_s1[1] # h_ext['ROTIME0'] = t_s1[0]+'T'+t_s1[1]
t_s2 = str(tend_read.datetime).split() # t_s2 = str(tend_read.datetime).split()
h_ext['READT1'] = t_s2[0] + 'T' + t_s2[1] # h_ext['ROTIME1'] = t_s2[0] + 'T' + t_s2[1]
tstart1=tstart.datetime.replace(microsecond=round(tstart.datetime.microsecond, -5))
h_ext['ROTIME0'] = tstart1.strftime("%Y-%m-%dT%H:%M:%S.%f")[:-5]
tend_read1 = tend_read.datetime.replace(microsecond=round(tend_read.datetime.microsecond, -5))
h_ext['ROTIME1'] = tend_read1.strftime("%Y-%m-%dT%H:%M:%S.%f")[:-5]
# 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,
rotate_chip=chip.rotate_angle, filter = h_ext['FILTER'], row_num=row_num, col_num=col_num, xcen = xcen, ycen = ycen) rotate_chip=chip.rotate_angle, filter = h_ext['FILTER'], row_num=row_num, col_num=col_num, xcen = xcen, ycen = ycen)
...@@ -545,6 +579,9 @@ def generateExtensionHeader(chip, xlen = 9216, ylen = 9232,ra = 60, dec = -40, p ...@@ -545,6 +579,9 @@ def generateExtensionHeader(chip, xlen = 9216, ylen = 9232,ra = 60, dec = -40, p
h_ext['CTYPE1'] = header_wcs['CTYPE1'] h_ext['CTYPE1'] = header_wcs['CTYPE1']
h_ext['CTYPE2'] = header_wcs['CTYPE2'] h_ext['CTYPE2'] = header_wcs['CTYPE2']
h_ext['EXTNAME'] = 'IMAGE'
h_ext.comments["XTENSION"] = "image extension"
return h_ext return h_ext
......
This diff is collapsed.
...@@ -43,7 +43,7 @@ class Pointing(object): ...@@ -43,7 +43,7 @@ class Pointing(object):
return max(150., self.exp_time) # [TODO] for FGS return max(150., self.exp_time) # [TODO] for FGS
def read_pointing_columns(self, columns, id=0, t=1621915200, pointing_type='SCIE'): def read_pointing_columns(self, columns, id=0, t=1621915200, pointing_type='SCI'):
self.id = id self.id = id
col_len = len(columns) col_len = len(columns)
self.ra = float(columns[0]) self.ra = float(columns[0])
......
def get_obs_id(img_type='SCIE', project_cycle=6, run_counter=0, pointing_num=0): def get_obs_id(img_type='SCI', project_cycle=6, run_counter=0, pointing_num=0):
# obs_type = {'SCI': '01', 'BIAS': '03', 'DARK': '07', 'FLAT': '11', 'CRS': '98', 'CRD': '99'} # obs_type = {'SCI': '01', 'BIAS': '03', 'DARK': '07', 'FLAT': '11', 'CRS': '98', 'CRD': '99'}
obs_type = {'SCIE': '01', 'BIAS': '03', 'DARK': '07', 'FLAT': '11', 'CRS': '98', 'CRD': '99', 'CAL': '01'} obs_type = {'SCI': '01', 'BIAS': '03', 'DARK': '07', 'FLAT': '11', 'CRS': '98', 'CRD': '99', 'CAL': '01'}
obs_id = '1'+ obs_type[img_type] + str(int(project_cycle)).rjust(2, '0') + str(int(run_counter)) + str(pointing_num).rjust(8,'0') obs_id = '1'+ obs_type[img_type] + str(int(project_cycle)).rjust(2, '0') + str(int(run_counter)) + str(pointing_num).rjust(8,'0')
return obs_id return obs_id
......
...@@ -40,6 +40,9 @@ class Observation(object): ...@@ -40,6 +40,9 @@ class Observation(object):
# Get flat, shutter, and PRNU images # Get flat, shutter, and PRNU images
chip.flat_img, _ = chip_utils.get_flat(img=chip.img, seed=int(self.config["random_seeds"]["seed_flat"])) chip.flat_img, _ = chip_utils.get_flat(img=chip.img, seed=int(self.config["random_seeds"]["seed_flat"]))
if chip.chipID > 30:
chip.shutter_img = np.ones_like(chip.img.array)
else:
chip.shutter_img = Effects.ShutterEffectArr(chip.img, t_shutter=1.3, dist_bearing=735, dt=1E-3) chip.shutter_img = Effects.ShutterEffectArr(chip.img, t_shutter=1.3, dist_bearing=735, dt=1E-3)
chip.prnu_img = Effects.PRNU_Img(xsize=chip.npix_x, ysize=chip.npix_y, sigma=0.01, chip.prnu_img = Effects.PRNU_Img(xsize=chip.npix_x, ysize=chip.npix_y, sigma=0.01,
seed=int(self.config["random_seeds"]["seed_prnu"]+chip.chipID)) seed=int(self.config["random_seeds"]["seed_prnu"]+chip.chipID))
......
...@@ -16,6 +16,9 @@ from ObservationSim.Instrument.Chip import ChipUtils as chip_utils ...@@ -16,6 +16,9 @@ from ObservationSim.Instrument.Chip import ChipUtils as chip_utils
from ObservationSim.Instrument.Chip import Effects from ObservationSim.Instrument.Chip import Effects
from ObservationSim.Instrument.Chip.libCTI.CTI_modeling import CTI_sim from ObservationSim.Instrument.Chip.libCTI.CTI_modeling import CTI_sim
from ObservationSim.MockObject import FlatLED
from ObservationSim.Instrument.FilterParam import FilterParam
class SimSteps: class SimSteps:
def __init__(self, overall_config, chip_output, all_filters): def __init__(self, overall_config, chip_output, all_filters):
self.overall_config = overall_config self.overall_config = overall_config
...@@ -23,9 +26,7 @@ class SimSteps: ...@@ -23,9 +26,7 @@ class SimSteps:
self.all_filters = all_filters self.all_filters = all_filters
def prepare_headers(self, chip, pointing): def prepare_headers(self, chip, pointing):
datetime_obs = datetime.utcfromtimestamp(pointing.timestamp)
date_obs = datetime_obs.strftime("%y%m%d")
time_obs = datetime_obs.strftime("%H%M%S")
self.h_prim = generatePrimaryHeader( self.h_prim = generatePrimaryHeader(
xlen=chip.npix_x, xlen=chip.npix_x,
ylen=chip.npix_y, ylen=chip.npix_y,
...@@ -33,8 +34,7 @@ class SimSteps: ...@@ -33,8 +34,7 @@ class SimSteps:
ra=pointing.ra, ra=pointing.ra,
dec=pointing.dec, dec=pointing.dec,
pixel_scale=chip.pix_scale, pixel_scale=chip.pix_scale,
date=date_obs, time_pt = pointing.timestamp,
time_obs=time_obs,
exptime=pointing.exp_time, exptime=pointing.exp_time,
im_type=pointing.pointing_type, im_type=pointing.pointing_type,
sat_pos=[pointing.sat_x, pointing.sat_y, pointing.sat_z], sat_pos=[pointing.sat_x, pointing.sat_y, pointing.sat_z],
...@@ -63,7 +63,71 @@ class SimSteps: ...@@ -63,7 +63,71 @@ class SimSteps:
readoutTime = chip.readout_time) readoutTime = chip.readout_time)
return self.h_prim, self.h_ext return self.h_prim, self.h_ext
def add_sky_flat_calibration(self, chip, filt, tel, pointing, catalog, obs_param):
if not hasattr(self, 'h_ext'):
_, _ = self.prepare_headers(chip=chip, pointing=pointing)
chip_wcs = galsim.FitsWCS(header = self.h_ext)
expTime = obs_param["exptime"]
skyback_level = obs_param["flat_level"]
filter_param = FilterParam()
sky_level_filt = obs_param["flat_level_filt"]
norm_scaler = skyback_level/expTime / filter_param.param[sky_level_filt][5]
flat_normal = np.ones_like(chip.img.array)
if obs_param["flat_fielding"] == True:
flat_normal = flat_normal * chip.flat_img.array / np.mean(chip.flat_img.array)
if obs_param["shutter_effect"] == True:
flat_normal = flat_normal * chip.shutter_img
flat_normal = np.array(flat_normal, dtype='float32')
if chip.survey_type == "photometric":
sky_map = flat_normal * np.ones_like(chip.img.array) * norm_scaler * filter_param.param[chip.filter_type][5] / tel.pupil_area * expTime
elif chip.survey_type == "spectroscopic":
# flat_normal = np.ones_like(chip.img.array)
if obs_param["flat_fielding"] == True:
flat_normal = flat_normal * chip.flat_img.array / np.mean(chip.flat_img.array)
if obs_param["shutter_effect"] == True:
flat_normal = flat_normal * chip.shutter_img
flat_normal = np.array(flat_normal, dtype='float32')
sky_map = calculateSkyMap_split_g(
skyMap=flat_normal,
blueLimit=filt.blue_limit,
redLimit=filt.red_limit,
conf=chip.sls_conf,
pixelSize=chip.pix_scale,
isAlongY=0,
flat_cube=chip.flat_cube)
sky_map = sky_map * norm_scaler * expTime
chip.img += sky_map
return chip, filt, tel, pointing
def add_sky_background(self, chip, filt, tel, pointing, catalog, obs_param): def add_sky_background(self, chip, filt, tel, pointing, catalog, obs_param):
if not hasattr(self, 'h_ext'):
_, _ = self.prepare_headers(chip=chip, pointing=pointing)
chip_wcs = galsim.FitsWCS(header = self.h_ext)
if "flat_level" not in obs_param or "flat_level_filt" not in obs_param:
chip, filt, tel, pointing = self.add_sky_background_sci(chip, filt, tel, pointing, catalog, obs_param)
else:
if obs_param.get('flat_level') is None or obs_param.get('flat_level_filt')is None:
chip, filt, tel, pointing = self.add_sky_background_sci(chip, filt, tel, pointing, catalog, obs_param)
else:
chip, filt, tel, pointing = self.add_sky_flat_calibration(chip, filt, tel, pointing, catalog, obs_param)
# chip, filt, tel, pointing = self.add_sky_background_sci(chip, filt, tel, pointing, catalog, obs_param)
return chip, filt, tel, pointing
def add_sky_background_sci(self, chip, filt, tel, pointing, catalog, obs_param):
flat_normal = np.ones_like(chip.img.array) flat_normal = np.ones_like(chip.img.array)
if obs_param["flat_fielding"] == True: if obs_param["flat_fielding"] == True:
flat_normal = flat_normal * chip.flat_img.array / np.mean(chip.flat_img.array) flat_normal = flat_normal * chip.flat_img.array / np.mean(chip.flat_img.array)
...@@ -96,12 +160,29 @@ class SimSteps: ...@@ -96,12 +160,29 @@ class SimSteps:
isAlongY=0, isAlongY=0,
flat_cube=chip.flat_cube, flat_cube=chip.flat_cube,
zoldial_spec = filt.zodical_spec) zoldial_spec = filt.zodical_spec)
sky_map = sky_map + filt.sky_background sky_map = (sky_map + filt.sky_background)*obs_param["exptime"]
# sky_map = sky_map * tel.pupil_area * obs_param["exptime"] # sky_map = sky_map * tel.pupil_area * obs_param["exptime"]
chip.img += sky_map chip.img += sky_map
return chip, filt, tel, pointing return chip, filt, tel, pointing
def add_LED_Flat(self, chip, filt, tel, pointing, catalog, obs_param):
if not hasattr(self, 'h_ext'):
_, _ = self.prepare_headers(chip=chip, pointing=pointing)
chip_wcs = galsim.FitsWCS(header = self.h_ext)
pf_map = np.zeros_like(chip.img.array)
if obs_param["LED_TYPE"] is not None:
if len(obs_param["LED_TYPE"]) != 0:
print("LED OPEN--------")
led_obj = FlatLED(chip, filt)
led_flat = led_obj.drawObj_LEDFlat(led_type_list=obs_param["LED_TYPE"], exp_t_list=obs_param["LED_TIME"])
pf_map = led_flat
chip.img = chip.img + led_flat
return chip, filt, tel, pointing
def add_objects(self, chip, filt, tel, pointing, catalog, obs_param): def add_objects(self, chip, filt, tel, pointing, catalog, obs_param):
# Prepare output file(s) for this chip # Prepare output file(s) for this chip
...@@ -419,6 +500,13 @@ class SimSteps: ...@@ -419,6 +500,13 @@ class SimSteps:
return chip, filt, tel, pointing return chip, filt, tel, pointing
def quantization_and_output(self, chip, filt, tel, pointing, catalog, obs_param): def quantization_and_output(self, chip, filt, tel, pointing, catalog, obs_param):
if obs_param["format_output"] == True:
self.chip_output.Log_info(" Apply 1*16 format")
chip.img = chip_utils.formatOutput(GSImage=chip.img)
chip.nsecy = 1
chip.nsecx = 16
chip.img.array[chip.img.array > 65535] = 65535 chip.img.array[chip.img.array > 65535] = 65535
chip.img.replaceNegative(replace_value=0) chip.img.replaceNegative(replace_value=0)
chip.img.quantize() chip.img.quantize()
...@@ -432,6 +520,7 @@ class SimSteps: ...@@ -432,6 +520,7 @@ class SimSteps:
hdu2.header.comments['XTENSION'] = 'extension type' hdu2.header.comments['XTENSION'] = 'extension type'
hdu2.header.comments['CHECKSUM'] = 'HDU checksum' hdu2.header.comments['CHECKSUM'] = 'HDU checksum'
hdu2.header.comments['DATASUM'] = 'data unit checksum' hdu2.header.comments['DATASUM'] = 'data unit checksum'
hdu2.header.comments["XTENSION"] = "image extension"
hdu1 = fits.HDUList([hdu1, hdu2]) hdu1 = fits.HDUList([hdu1, hdu2])
fname = os.path.join(self.chip_output.subdir, self.h_prim['FILENAME'] + '.fits') fname = os.path.join(self.chip_output.subdir, self.h_prim['FILENAME'] + '.fits')
hdu1.writeto(fname, output_verify='ignore', overwrite=True) hdu1.writeto(fname, output_verify='ignore', overwrite=True)
...@@ -452,5 +541,7 @@ SIM_STEP_TYPES = { ...@@ -452,5 +541,7 @@ SIM_STEP_TYPES = {
"bias": "add_bias", "bias": "add_bias",
"readout_noise": "add_readout_noise", "readout_noise": "add_readout_noise",
"gain": "apply_gain", "gain": "apply_gain",
"quantization_and_output": "quantization_and_output" "quantization_and_output": "quantization_and_output",
"led_calib_model":"add_LED_Flat",
# "sky_flatField":"add_sky_flat_calibration",
} }
\ No newline at end of file
...@@ -36,10 +36,12 @@ def generate_pointing_list(config, pointing_filename=None, data_dir=None): ...@@ -36,10 +36,12 @@ def generate_pointing_list(config, pointing_filename=None, data_dir=None):
if pointing_filename and data_dir: if pointing_filename and data_dir:
pointing_file = os.path.join(data_dir, pointing_filename) pointing_file = os.path.join(data_dir, pointing_filename)
f = open(pointing_file, 'r') f = open(pointing_file, 'r')
for _ in range(1): # for _ in range(1):
header = f.readline() # header = f.readline()
iline = 0 iline = 0
for line in f: for line in f:
if len(line.strip()) == 0 or line[0]=='#':
continue
if run_pointings and iline not in run_pointings: if run_pointings and iline not in run_pointings:
iline += 1 iline += 1
ipoint += 1 ipoint += 1
......
---
###############################################
#
# Configuration file for CSST simulation
# For single exposure type:
# SCI-WIDE
# CSST-Sim Group, 2024/01/08
#
###############################################
# Observation type
obs_type: "DARK"
# Define list of chips
run_chips: [8]
# Define observation sequence
call_sequence:
# Accumulate fluxes from objects
led_calib_model:
#"LED": ['LED1','LED2','LED3','LED4','LED5','LED6','LED7','LED8','LED9','LED10','LED11','LED12','LED13','LED14'] or null
#'LED1': '275', 'LED2': '310', 'LED3': '430', 'LED4': '505', 'LED5': '545', 'LED6': '590', 'LED7': '670',
#'LED8': '760', 'LED9': '940', 'LED10': '940', 'LED11': '1050', 'LED12': '1050','LED13': '340', 'LED14': '365'
LED_TYPE: ['LED5']
LED_TIME: [1.]
# flat_level: set the total skybackground value (e-) in the exptime,if none,set null, or delete the key
# flat_level_filt: the vale of "flat_level" is in the filter "flat_level_filt", can set NUV, u, g, r, i, z, y, if
# none,set null,or delete the key
sky_background:
exptime: 150. # [s]
shutter_effect: YES
flat_fielding: YES
enable_straylight_model: YES
flat_level: 20000
flat_level_filt: g
# Apply PRNU to accumulated photons
PRNU_effect: {}
# Accumulate photons caused by cosmic rays
cosmic_rays: {}
# Add Poission noise and dark current
poisson_and_dark:
add_dark: YES
# Simulate brighter fatter effects
bright_fatter: {}
# Add detector defects: hot/warm pixels, bad columns
detector_defects:
hot_pixels: YES
dead_pixels: YES
bad_columns: YES
# Apply response nonlinearity
nonlinearity: {}
# Apply CCD Saturation & Blooming
blooming: {}
# # Run CTE simulation
CTE_effect: {}
# Add prescan and overscan
prescan_overscan: {}
# Add bias
bias:
bias_16channel: YES
# Add readout noise
readout_noise: {}
# Apply gain
gain:
gain_16channel: YES
# Output the final image
quantization_and_output:
format_output: NO
...
\ No newline at end of file
...@@ -9,11 +9,10 @@ ...@@ -9,11 +9,10 @@
############################################### ###############################################
# Observation type # Observation type
obs_type: "SCIE" obs_type: "SCI"
# Define list of chips # Define list of chips
# run_chips: [6, 7, 8, 9, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 22, 23, 24, 25] run_chips: [8]
run_chips: [6]
# Define observation sequence # Define observation sequence
call_sequence: call_sequence:
...@@ -24,11 +23,16 @@ call_sequence: ...@@ -24,11 +23,16 @@ call_sequence:
flat_fielding: YES flat_fielding: YES
field_dist: YES field_dist: YES
# Accumulate fluxes from sky background # Accumulate fluxes from sky background
# flat_level: set the total skybackground value (e-) in the exptime,if none,set null, or delete the key
# flat_level_filt: the vale of "flat_level" is in the filter "flat_level_filt", can set NUV, u, g, r, i, z, y, if
# none,set null,or delete the key
sky_background: sky_background:
exptime: 150. # [s] exptime: 150. # [s]
shutter_effect: YES shutter_effect: YES
flat_fielding: YES flat_fielding: YES
enable_straylight_model: YES enable_straylight_model: YES
flat_level: null
flat_level_filt: null
# Apply PRNU to accumulated photons # Apply PRNU to accumulated photons
PRNU_effect: {} PRNU_effect: {}
# Accumulate photons caused by cosmic rays # Accumulate photons caused by cosmic rays
...@@ -60,5 +64,6 @@ call_sequence: ...@@ -60,5 +64,6 @@ call_sequence:
gain: gain:
gain_16channel: YES gain_16channel: YES
# Output the final image # Output the final image
quantization_and_output: {} quantization_and_output:
format_output: YES
... ...
\ No newline at end of file
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