Commit bbf88615 authored by Wei Chengliang's avatar Wei Chengliang
Browse files

update calibration in Chip.py

parent 6db8a942
......@@ -501,12 +501,14 @@ class Chip(FocalPlane):
print(" Output N frame Bias files", flush=True)
NBias = int(config["output_setting"]["NBias"])
for i in range(NBias):
BiasCombImg, BiasTag = effects.MakeBiasNcomb(
self.npix_x, self.npix_y,
bias_level=float(self.bias_level),
ncombine=1, read_noise=self.read_noise, gain=1,
seed=SeedBiasNonuni+self.chipID,
logger=self.logger)
### BiasCombImg, BiasTag = effects.MakeBiasNcomb(
### self.npix_x, self.npix_y,
### bias_level=float(self.bias_level),
### ncombine=1, read_noise=self.read_noise, gain=1,
### seed=SeedBiasNonuni+self.chipID,
### logger=self.logger)
BiasCombImg = galsim.Image(self.npix_x, self.npix_y, init_value=0) ###
# Readout noise for Biases is not generated with random seeds. So readout noise for bias images can't be reproduced.
if config["ins_effects"]["cosmic_ray"] == True:
if config["ins_effects"]["cray_differ"] == True:
......@@ -521,6 +523,11 @@ class Chip(FocalPlane):
BiasCombImg += cr_map
del cr_map
# Apply Bad lines
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
# Non-Linearity for Bias
if config["ins_effects"]["non_linear"] == True:
if self.logger is not None:
......@@ -530,6 +537,11 @@ class Chip(FocalPlane):
BiasCombImg = effects.NonLinearity(GSImage=BiasCombImg, beta1=5.e-7, beta2=0)
###########################START
pre1 = self.prescan_x #27
over1= self.overscan_x #71
pre2 = self.prescan_y #0 #4
over2= self.overscan_y #84 #80
### prescan & overscan
if config["ins_effects"]["add_prescan"] == True:
chip_utils.log_info(msg=" Apply pre/over-scan", logger=self.logger)
......@@ -543,9 +555,21 @@ class Chip(FocalPlane):
self.nsecx = 16
###########################END
# Apply Bad lines
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
### 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")
BiasCombImg = effects.AddBiasNonUniform16(BiasCombImg,
bias_level=biaslevel,
nsecy = self.nsecy, nsecx=self.nsecx,
seed=SeedBiasNonuni+self.chipID,
logger=self.logger)
rng = galsim.UniformDeviate()
ncombine = 1
NoiseBias = galsim.GaussianNoise(rng=rng, sigma=self.read_noise*ncombine**0.5)
BiasCombImg.addNoise(NoiseBias)
BiasCombImg, self.gain_channel = effects.ApplyGainNonUniform16(BiasCombImg, gain=self.gain,
nsecy = self.nsecy, nsecx=self.nsecx,
......@@ -613,6 +637,16 @@ class Chip(FocalPlane):
FlatCombImg += cr_map
del cr_map
# Add Hot Pixels or/and Dead Pixels
rgbadpix = Generator(PCG64(int(SeedDefective+self.chipID)))
badfraction = 5E-5*(rgbadpix.random()*0.5+0.7)
FlatCombImg = effects.DefectivePixels(FlatCombImg, IfHotPix=BoolHotPix, IfDeadPix=BoolDeadPix, fraction=badfraction, seed=SeedDefective+self.chipID, biaslevel=0)
# Apply Bad lines
if config["ins_effects"]["add_badcolumns"] == True:
FlatCombImg = effects.BadColumns(FlatCombImg, seed=SeedBadColumns, chipid=self.chipID, logger=self.logger)
if config["ins_effects"]["non_linear"] == True:
if self.logger is not None:
self.logger.info(" Applying Non-Linearity on the Flat image")
......@@ -676,15 +710,6 @@ class Chip(FocalPlane):
self.nsecx = 16
###########################END
# Add Hot Pixels or/and Dead Pixels
rgbadpix = Generator(PCG64(int(SeedDefective+self.chipID)))
badfraction = 5E-5*(rgbadpix.random()*0.5+0.7)
FlatCombImg = effects.DefectivePixels(FlatCombImg, IfHotPix=BoolHotPix, IfDeadPix=BoolDeadPix, fraction=badfraction, seed=SeedDefective+self.chipID, biaslevel=0)
# Apply Bad lines
if config["ins_effects"]["add_badcolumns"] == True:
FlatCombImg = effects.BadColumns(FlatCombImg, seed=SeedBadColumns, chipid=self.chipID, logger=self.logger)
# Add Bias level
if config["ins_effects"]["add_bias"] == True:
if self.logger is not None:
......@@ -797,6 +822,16 @@ class Chip(FocalPlane):
timestamp=timestamp_obs)
del crmap_gsimg
# Add Hot Pixels or/and Dead Pixels
rgbadpix = Generator(PCG64(int(SeedDefective+self.chipID)))
badfraction = 5E-5*(rgbadpix.random()*0.5+0.7)
DarkCombImg = effects.DefectivePixels(DarkCombImg, IfHotPix=BoolHotPix, IfDeadPix=BoolDeadPix, fraction=badfraction, seed=SeedDefective+self.chipID, biaslevel=0)
# Apply Bad lines
if config["ins_effects"]["add_badcolumns"] == True:
DarkCombImg = effects.BadColumns(DarkCombImg, seed=SeedBadColumns, chipid=self.chipID, logger=self.logger)
# Non-Linearity for Dark
if config["ins_effects"]["non_linear"] == True:
if self.logger is not None:
......@@ -861,15 +896,6 @@ class Chip(FocalPlane):
self.nsecx = 16
###########################END
# Add Hot Pixels or/and Dead Pixels
rgbadpix = Generator(PCG64(int(SeedDefective+self.chipID)))
badfraction = 5E-5*(rgbadpix.random()*0.5+0.7)
DarkCombImg = effects.DefectivePixels(DarkCombImg, IfHotPix=BoolHotPix, IfDeadPix=BoolDeadPix, fraction=badfraction, seed=SeedDefective+self.chipID, biaslevel=0)
# Apply Bad lines
if config["ins_effects"]["add_badcolumns"] == True:
DarkCombImg = effects.BadColumns(DarkCombImg, seed=SeedBadColumns, chipid=self.chipID, logger=self.logger)
# Add Bias level
if config["ins_effects"]["add_bias"] == True:
if self.logger is not None:
......
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