Commit 8918310a authored by Zhang Xin's avatar Zhang Xin
Browse files

add flat with shutter Effect

parent c4412855
......@@ -268,7 +268,7 @@ class Chip(FocalPlane):
noise = self.dark_noise * exptime + self.read_noise**2
return noise
def addEffects(self, config, img, chip_output, filt, ra_cen, dec_cen, img_rot, exptime=150., pointing_ID=0, timestamp_obs=1621915200, pointing_type='SCI', sky_map=None, tel=None, logger=None):
def addEffects(self, config, img, chip_output, filt, ra_cen, dec_cen, img_rot, exptime=150., pointing_ID=0, timestamp_obs=1621915200, pointing_type='SCI', sky_map=None, post_flash_map=None, tel=None, logger=None):
# Set random seeds
SeedGainNonuni=int(config["random_seeds"]["seed_gainNonUniform"])
SeedBiasNonuni=int(config["random_seeds"]["seed_biasNonUniform"])
......@@ -307,6 +307,9 @@ class Chip(FocalPlane):
if config["output_setting"]["flat_output"] == False:
del flat_img
if post_flash_map is not None:
img = img + post_flash_map
# Apply Shutter-effect for one chip
if config["ins_effects"]["shutter_effect"] == True:
chip_utils.log_info(msg=" Apply shutter effect", logger=self.logger)
......@@ -318,7 +321,6 @@ class Chip(FocalPlane):
shutt_gsimg.write("%s/ShutterEffect_%s_1.fits" % (chip_output.subdir, self.chipID))
del shutt_gsimg
del shuttimg
# # Add Poisson noise to the resulting images
# # (NOTE): this can only applied to the slitless image
# # since it dose not use photon shooting to draw stamps
......
......@@ -415,7 +415,7 @@ class Observation(object):
chip_output.Log_info("check running:2: pointing-%d chip-%d pid-%d memory-%6.2fGB"%(pointing.id, chip.chipID, os.getpid(), (psutil.Process(os.getpid()).memory_info().rss / 1024 / 1024 / 1024) ))
def run_one_chip_LEDlight(self, chip, filt, pointing, chip_output, wcs_fp=None, psf_model=None, cat_dir=None, sed_dir=None):
def run_one_chip_calibration(self, chip, filt, pointing, chip_output, skyback_level = 20000, sky_level_filt = 'g', wcs_fp=None, psf_model=None, cat_dir=None, sed_dir=None):
......@@ -428,18 +428,51 @@ class Observation(object):
chip.img = galsim.ImageF(chip.npix_x, chip.npix_y)
chip.img.setOrigin(chip.bound.xmin, chip.bound.ymin)
# chip.img.wcs = wcs_fp
pf_map = np.zeros_like(chip.img.array)
if self.config["obs_setting"]["LED_TYPE"] is not None:
if len(self.config["obs_setting"]["LED_TYPE"]) != 0:
print("LED OPEN--------")
led_obj = FlatLED(chip, filt)
led_flat = led_obj.drawObj_LEDFlat(led_type_list=self.config["obs_setting"]["LED_TYPE"], exp_t_list=self.config["obs_setting"]["LED_TIME"])
chip.img = chip.img + galsim.ImageF(led_flat)
pf_map = led_flat
# whether to output zero, dark, flat calibration images.
sky_map = np.zeros_like(chip.img.array)
expTime = self.config["obs_setting"]["exp_time"]
skybg_unit = self.filter_param.param[sky_level_filt][5]
norm_scaler = skyback_level/expTime/skybg_unit
if skyback_level == 0:
self.config["ins_effects"]["shutter_effect"] = False
if chip.survey_type == "photometric":
sky_map = np.ones_like(chip.img.array) * skybg_unit * norm_scaler / self.tel.pupil_area
elif chip.survey_type == "spectroscopic":
flat_normal = np.ones_like(chip.img.array)
if self.config["ins_effects"]["flat_fielding"] == True:
chip_output.Log_info("SLS flat preprocess,CHIP %d : Creating and applying Flat-Fielding" % chip.chipID)
msg = str(chip.img.bounds)
chip_output.Log_info(msg)
flat_img = Effects.MakeFlatSmooth(
chip.img.bounds,
int(self.config["random_seeds"]["seed_flat"]))
flat_normal = flat_normal * flat_img.array / np.mean(flat_img.array)
if self.config["ins_effects"]["shutter_effect"] == True:
chip_output.Log_info("SLS flat preprocess,CHIP %d : Apply shutter effect" % chip.chipID)
shuttimg = Effects.ShutterEffectArr(chip.img, t_shutter=1.3, dist_bearing=735,
dt=1E-3) # shutter effect normalized image for this chip
flat_normal = flat_normal * shuttimg
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
chip.img = chip.addEffects(
config=self.config,
img=chip.img,
......@@ -453,6 +486,7 @@ class Observation(object):
timestamp_obs=pointing.timestamp,
pointing_type=pointing.pointing_type,
sky_map=sky_map, tel=self.tel,
post_flash_map=pf_map,
logger=chip_output.logger)
datetime_obs = datetime.utcfromtimestamp(pointing.timestamp)
......@@ -564,11 +598,13 @@ class Observation(object):
subdir=sub_img_dir,
prefix=prefix)
chip_output.Log_info("running pointing#%d, chip#%d, at PID#%d..."%(pointing_ID, chip.chipID, pid))
if self.config["obs_setting"]["survey_type"] == "LED":
self.run_one_chip_LEDlight(chip=chip,
if self.config["obs_setting"]["survey_type"] == "CALIBRATION":
self.run_one_chip_calibration(chip=chip,
filt=filt,
chip_output=chip_output,
pointing=pointing)
pointing=pointing,
skyback_level = self.config["obs_setting"]["FLAT_LEVEL"],
sky_level_filt = self.config["obs_setting"]["FLAT_LEVEL_FIL"])
else:
self.run_one_chip(
chip=chip,
......
......@@ -66,11 +66,16 @@ obs_setting:
# "Spectroscopic": simulate slitless spectroscopic chips only
# "FGS": simulate FGS chips only (31-42)
# "All": simulate full focal plane
# "LED":
survey_type: "LED"
LED_TYPE: ["LED5"]
LED_TIME: [10.]
# "CALIBRATION": falt, bias, dark with or without postflash
survey_type: "CALIBRATION"
#"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.]
# unit e- ,flat level
FLAT_LEVEL: 20000
FLAT_LEVEL_FIL: 'g'
# Exposure time [seconds]
exp_time: 150.
......@@ -106,7 +111,7 @@ obs_setting:
# - give a list of indexes of chips: [ip_1, ip_2...]
# - run all chips: null
# Note: for all pointings
run_chips: [8]
run_chips: [5]
# Whether to enable astrometric modeling
enable_astrometric_model: False
......
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