Commit 35ff7caa authored by Fang Yuedong's avatar Fang Yuedong
Browse files

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

parents 0a868f42 72f70d57
......@@ -529,12 +529,26 @@ class Chip(FocalPlane):
print(" Applying Non-Linearity on the Bias image", flush=True)
BiasCombImg = effects.NonLinearity(GSImage=BiasCombImg, beta1=5.e-7, beta2=0)
###########################START
### prescan & overscan
if config["ins_effects"]["add_prescan"] == True:
chip_utils.log_info(msg=" Apply pre/over-scan", logger=self.logger)
BiasCombImg = chip_utils.AddPreScan(GSImage=BiasCombImg, pre1=pre1, pre2=pre2, over1=over1, over2=over2)
### 1*16 output
if config["ins_effects"]["format_output"] == True:
chip_utils.log_info(msg=" Apply 1*16 format", logger=self.logger)
BiasCombImg = chip_utils.formatOutput(GSImage=BiasCombImg)
self.nsecy = 1
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
BiasCombImg, self.gain_channel = effects.ApplyGainNonUniform16(BiasCombImg, gain=self.gain,
nsecy = 2, nsecx=8,
nsecy = self.nsecy, nsecx=self.nsecx,
seed=SeedGainNonuni+self.chipID,
logger=self.logger)
# BiasCombImg = effects.AddOverscan(
......@@ -606,8 +620,61 @@ class Chip(FocalPlane):
print(" Applying Non-Linearity on the Flat image", flush=True)
FlatCombImg = effects.NonLinearity(GSImage=FlatCombImg, beta1=5.e-7, beta2=0)
###if config["ins_effects"]["cte_trail"] == True:
### FlatCombImg = effects.CTE_Effect(GSImage=FlatCombImg, threshold=3)
###########################START
pre1 = self.prescan_x #27
over1= self.overscan_x #71
pre2 = self.prescan_y #0 #4
over2= self.overscan_y #84 #80
if config["ins_effects"]["cte_trail"] == True:
FlatCombImg = effects.CTE_Effect(GSImage=FlatCombImg, threshold=3)
chip_utils.log_info(msg=" Apply CTE Effect", logger=self.logger)
###img = effects.CTE_Effect(GSImage=img, threshold=27)
###CTI_modeling
### 2*8 -> 1*16 img-layout
FlatCombImg = chip_utils.formatOutput(GSImage=FlatCombImg)
self.nsecy = 1
self.nsecx = 16
img_arr = FlatCombImg.array
ny, nx = img_arr.shape
dx = int(nx/self.nsecx)
dy = int(ny/self.nsecy)
newimg = galsim.Image(nx, int(ny+over2), init_value=0)
for ichannel in range(16):
print('\n***add CTI effects: pointing-{:} chip-{:} channel-{:}***'.format(pointing_ID, self.chipID, ichannel+1))
#nx,ny,noverscan,nsp,nmax = 4608,4616,84,3,10
noverscan,nsp,nmax = over2,3,10
beta,w,c = 0.478,84700,0
t = np.array([0.74,7.7,37],dtype=np.float32)
rho_trap = np.array([0.6,1.6,1.4],dtype=np.float32)
trap_seeds = np.array([0,1000,10000],dtype=np.int32) + ichannel + self.chipID*16
release_seed = 50 + ichannel + pointing_ID*30 + self.chipID*16
newimg.array[:, 0+ichannel*dx:dx+ichannel*dx] = CTI_sim(img_arr[:, 0+ichannel*dx:dx+ichannel*dx],dx,dy,noverscan,nsp,nmax,beta,w,c,t,rho_trap,trap_seeds,release_seed)
newimg.wcs = FlatCombImg.wcs
del FlatCombImg
FlatCombImg = newimg
### 1*16 -> 2*8 img-layout
img = chip_utils.formatRevert(GSImage=FlatCombImg)
self.nsecy = 2
self.nsecx = 8
### prescan & overscan
if config["ins_effects"]["add_prescan"] == True:
chip_utils.log_info(msg=" Apply pre/over-scan", logger=self.logger)
if config["ins_effects"]["cte_trail"] == False:
FlatCombImg = chip_utils.AddPreScan(GSImage=FlatCombImg, pre1=pre1, pre2=pre2, over1=over1, over2=over2)
if config["ins_effects"]["cte_trail"] == True:
FlatCombImg = chip_utils.AddPreScan(GSImage=FlatCombImg, pre1=pre1, pre2=pre2, over1=over1, over2=0)
### 1*16 output
if config["ins_effects"]["format_output"] == True:
chip_utils.log_info(msg=" Apply 1*16 format", logger=self.logger)
FlatCombImg = chip_utils.formatOutput(GSImage=FlatCombImg)
self.nsecy = 1
self.nsecx = 16
###########################END
# Add Hot Pixels or/and Dead Pixels
rgbadpix = Generator(PCG64(int(SeedDefective+self.chipID)))
......@@ -627,7 +694,7 @@ class Chip(FocalPlane):
# img += float(config["ins_effects"]["bias_level"])
FlatCombImg = effects.AddBiasNonUniform16(FlatCombImg,
bias_level=biaslevel,
nsecy = 2, nsecx=8,
nsecy = self.nsecy, nsecx=self.nsecx,
seed=SeedBiasNonuni+self.chipID,
logger=self.logger)
......@@ -639,7 +706,7 @@ class Chip(FocalPlane):
FlatCombImg.addNoise(readout_noise)
FlatCombImg, self.gain_channel = effects.ApplyGainNonUniform16(FlatCombImg, gain=self.gain,
nsecy = 2, nsecx=8,
nsecy = self.nsecy, nsecx=self.nsecx,
seed=SeedGainNonuni+self.chipID,
logger=self.logger)
# FlatCombImg = effects.AddOverscan(FlatCombImg, overscan=overscan, gain=self.gain, widthl=27, widthr=27, widtht=8, widthb=8)
......@@ -702,6 +769,19 @@ class Chip(FocalPlane):
cr_map[cr_map < 0] = 0
crmap_gsimg = galsim.Image(cr_map, dtype=np.uint16)
del cr_map
###########################START
### prescan & overscan
if config["ins_effects"]["add_prescan"] == True:
chip_utils.log_info(msg=" Apply pre/over-scan", logger=self.logger)
crmap_gsimg = chip_utils.AddPreScan(GSImage=crmap_gsimg, pre1=pre1, pre2=pre2, over1=over1, over2=over2)
### 1*16 output
if config["ins_effects"]["format_output"] == True:
chip_utils.log_info(msg=" Apply 1*16 format", logger=self.logger)
crmap_gsimg = chip_utils.formatOutput(GSImage=crmap_gsimg)
self.nsecy = 1
self.nsecx = 16
###########################END
chip_utils.outputCal(
chip=self,
img=crmap_gsimg,
......@@ -725,8 +805,61 @@ class Chip(FocalPlane):
print(" Applying Non-Linearity on the Dark image", flush=True)
DarkCombImg = effects.NonLinearity(GSImage=DarkCombImg, beta1=5.e-7, beta2=0)
###if config["ins_effects"]["cte_trail"] == True:
### DarkCombImg = effects.CTE_Effect(GSImage=DarkCombImg, threshold=3)
###########################START
pre1 = self.prescan_x #27
over1= self.overscan_x #71
pre2 = self.prescan_y #0 #4
over2= self.overscan_y #84 #80
if config["ins_effects"]["cte_trail"] == True:
DarkCombImg = effects.CTE_Effect(GSImage=DarkCombImg, threshold=3)
chip_utils.log_info(msg=" Apply CTE Effect", logger=self.logger)
###img = effects.CTE_Effect(GSImage=img, threshold=27)
###CTI_modeling
### 2*8 -> 1*16 img-layout
DarkCombImg = chip_utils.formatOutput(GSImage=DarkCombImg)
self.nsecy = 1
self.nsecx = 16
img_arr = DarkCombImg.array
ny, nx = img_arr.shape
dx = int(nx/self.nsecx)
dy = int(ny/self.nsecy)
newimg = galsim.Image(nx, int(ny+over2), init_value=0)
for ichannel in range(16):
print('\n***add CTI effects: pointing-{:} chip-{:} channel-{:}***'.format(pointing_ID, self.chipID, ichannel+1))
#nx,ny,noverscan,nsp,nmax = 4608,4616,84,3,10
noverscan,nsp,nmax = over2,3,10
beta,w,c = 0.478,84700,0
t = np.array([0.74,7.7,37],dtype=np.float32)
rho_trap = np.array([0.6,1.6,1.4],dtype=np.float32)
trap_seeds = np.array([0,1000,10000],dtype=np.int32) + ichannel + self.chipID*16
release_seed = 50 + ichannel + pointing_ID*30 + self.chipID*16
newimg.array[:, 0+ichannel*dx:dx+ichannel*dx] = CTI_sim(img_arr[:, 0+ichannel*dx:dx+ichannel*dx],dx,dy,noverscan,nsp,nmax,beta,w,c,t,rho_trap,trap_seeds,release_seed)
newimg.wcs = DarkCombImg.wcs
del DarkCombImg
DarkCombImg = newimg
### 1*16 -> 2*8 img-layout
DarkCombImg = chip_utils.formatRevert(GSImage=DarkCombImg)
self.nsecy = 2
self.nsecx = 8
### prescan & overscan
if config["ins_effects"]["add_prescan"] == True:
chip_utils.log_info(msg=" Apply pre/over-scan", logger=self.logger)
if config["ins_effects"]["cte_trail"] == False:
DarkCombImg = chip_utils.AddPreScan(GSImage=DarkCombImg, pre1=pre1, pre2=pre2, over1=over1, over2=over2)
if config["ins_effects"]["cte_trail"] == True:
DarkCombImg = chip_utils.AddPreScan(GSImage=DarkCombImg, pre1=pre1, pre2=pre2, over1=over1, over2=0)
### 1*16 output
if config["ins_effects"]["format_output"] == True:
chip_utils.log_info(msg=" Apply 1*16 format", logger=self.logger)
DarkCombImg = chip_utils.formatOutput(GSImage=DarkCombImg)
self.nsecy = 1
self.nsecx = 16
###########################END
# Add Hot Pixels or/and Dead Pixels
rgbadpix = Generator(PCG64(int(SeedDefective+self.chipID)))
......@@ -746,7 +879,7 @@ class Chip(FocalPlane):
# img += float(config["ins_effects"]["bias_level"])
DarkCombImg = effects.AddBiasNonUniform16(DarkCombImg,
bias_level=biaslevel,
nsecy = 2, nsecx=8,
nsecy = self.nsecy, nsecx=self.nsecx,
seed=SeedBiasNonuni+self.chipID,
logger=self.logger)
......@@ -759,7 +892,7 @@ class Chip(FocalPlane):
DarkCombImg, self.gain_channel = effects.ApplyGainNonUniform16(
DarkCombImg, gain=self.gain,
nsecy = 2, nsecx=8,
nsecy = self.nsecy, nsecx=self.nsecx,
seed=SeedGainNonuni+self.chipID,
logger=self.logger)
# DarkCombImg = effects.AddOverscan(
......
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