Commit 96e13f5a authored by Wei Chengliang's avatar Wei Chengliang
Browse files

update darknoise module

parent 02bd3aae
...@@ -171,22 +171,40 @@ def get_poisson(seed=0, sky_level=0.): ...@@ -171,22 +171,40 @@ def get_poisson(seed=0, sky_level=0.):
poisson_noise = galsim.PoissonNoise(rng_poisson, sky_level=sky_level) poisson_noise = galsim.PoissonNoise(rng_poisson, sky_level=sky_level)
return rng_poisson, poisson_noise return rng_poisson, poisson_noise
def get_base_img(img, read_noise, readout_time, dark_noise, exptime=150.): def get_base_img(img, chip, read_noise, readout_time, dark_noise, exptime=150., InputDark=None):
if InputDark == None:
# base_level = read_noise**2 + dark_noise*(exptime+0.5*readout_time) # base_level = read_noise**2 + dark_noise*(exptime+0.5*readout_time)
base_level = dark_noise*(exptime+0.5*readout_time) ## base_level = dark_noise*(exptime+0.5*readout_time)
base_img = base_level * np.ones_like(img.array) base_level = dark_noise*(exptime)
return base_img base_img1 = base_level * np.ones_like(img.array)
else:
def add_poisson(img, chip, exptime=150., seed=0, sky_level=0., poisson_noise=None, dark_noise=None): base_img1 = np.zeros_like(img.array)
ny = int(chip.npix_y/2)
nx = chip.npix_x
arr = np.arange(ny).reshape(ny, 1)
arr = np.broadcast_to(arr, (ny, nx))
base_img2 = np.zeros_like(img.array)
base_img2[:ny, :] = arr
base_img2[ny:, :] = arr[::-1,:]
base_img2[:,:] = base_img2[:,:]*(readout_time/ny)*dark_noise
return base_img1+base_img2
def add_poisson(img, chip, exptime=150., seed=0, sky_level=0., poisson_noise=None, dark_noise=None, InputDark=None):
if poisson_noise is None: if poisson_noise is None:
_, poisson_noise = get_poisson(seed=seed, sky_level=sky_level) _, poisson_noise = get_poisson(seed=seed, sky_level=sky_level)
read_noise = chip.read_noise read_noise = chip.read_noise
if dark_noise is None: if dark_noise is None:
dark_noise = chip.dark_noise dark_noise = chip.dark_noise
base_img = get_base_img(img=img, read_noise=read_noise, readout_time=chip.readout_time, dark_noise=dark_noise, exptime=exptime) base_img = get_base_img(img=img, chip, read_noise=read_noise, readout_time=chip.readout_time, dark_noise=dark_noise, exptime=exptime, InputDark=None)
img += base_img img += base_img
img.addNoise(poisson_noise) img.addNoise(poisson_noise)
# img -= read_noise**2 # img -= read_noise**2
if InputDark != None:
hdu = fits.open(InputDark) ##"Instrument/data/dark/dark_1000s_example_0.fits"
img += hdu[0].data/hdu[0].header['exptime']*exptime
hdu.close()
return img, base_img return img, base_img
def add_brighter_fatter(img): def add_brighter_fatter(img):
...@@ -215,7 +233,7 @@ def add_brighter_fatter(img): ...@@ -215,7 +233,7 @@ def add_brighter_fatter(img):
img.array[:, :] = np.reshape(arr_imc, [nx, ny]) img.array[:, :] = np.reshape(arr_imc, [nx, ny])
del arr_ima, arr_imc del arr_ima, arr_imc
return img return img
"""
def add_inputdark(img, chip, exptime): def add_inputdark(img, chip, exptime):
fname = "/share/home/weichengliang/CSST_git/test_new_sim/csst-simulation/ObservationSim/Instrument/data/dark/dark_1000s_example_0.fits" fname = "/share/home/weichengliang/CSST_git/test_new_sim/csst-simulation/ObservationSim/Instrument/data/dark/dark_1000s_example_0.fits"
hdu = fits.open(fname) hdu = fits.open(fname)
...@@ -225,7 +243,7 @@ def add_inputdark(img, chip, exptime): ...@@ -225,7 +243,7 @@ def add_inputdark(img, chip, exptime):
hdu.close() hdu.close()
del inputdark del inputdark
return img return img
"""
def AddPreScan(GSImage, pre1=27, pre2=4, over1=71, over2=80, nsecy = 2, nsecx=8): def AddPreScan(GSImage, pre1=27, pre2=4, over1=71, over2=80, nsecy = 2, nsecx=8):
img= GSImage.array img= GSImage.array
ny, nx = img.shape ny, nx = img.shape
......
...@@ -10,8 +10,6 @@ def apply_PRNU(self, chip, filt, tel, pointing, catalog, obs_param): ...@@ -10,8 +10,6 @@ def apply_PRNU(self, chip, filt, tel, pointing, catalog, obs_param):
def add_poisson_and_dark(self, chip, filt, tel, pointing, catalog, obs_param): def add_poisson_and_dark(self, chip, filt, tel, pointing, catalog, obs_param):
# Add dark current & Poisson noise # Add dark current & Poisson noise
InputDark = False
# Get exposure time # Get exposure time
if (obs_param) and ("exptime" in obs_param) and (obs_param["exptime"] is not None): if (obs_param) and ("exptime" in obs_param) and (obs_param["exptime"] is not None):
exptime = obs_param["exptime"] exptime = obs_param["exptime"]
...@@ -19,15 +17,11 @@ def add_poisson_and_dark(self, chip, filt, tel, pointing, catalog, obs_param): ...@@ -19,15 +17,11 @@ def add_poisson_and_dark(self, chip, filt, tel, pointing, catalog, obs_param):
exptime = pointing.exp_time exptime = pointing.exp_time
if obs_param["add_dark"] == True: if obs_param["add_dark"] == True:
if InputDark:
chip.img = chip_utils.add_inputdark(img=chip.img,
chip=chip,
exptime=exptime)
else:
chip.img, _ = chip_utils.add_poisson(img=chip.img, chip.img, _ = chip_utils.add_poisson(img=chip.img,
chip=chip, chip=chip,
exptime=exptime, exptime=pointing.exp_time,
poisson_noise=chip.poisson_noise) poisson_noise=chip.poisson_noise,
InputDark=None)
else: else:
chip.img, _ = chip_utils.add_poisson(img=chip.img, chip.img, _ = chip_utils.add_poisson(img=chip.img,
chip=self, chip=self,
......
...@@ -12,6 +12,11 @@ def add_prescan_overscan(self, chip, filt, tel, pointing, catalog, obs_param): ...@@ -12,6 +12,11 @@ def add_prescan_overscan(self, chip, filt, tel, pointing, catalog, obs_param):
pre2=chip.prescan_y, pre2=chip.prescan_y,
over1=chip.overscan_x, over1=chip.overscan_x,
over2=chip.overscan_y) over2=chip.overscan_y)
if obs_param["add_dark"] == True:
ny = int(chip.npix_y/2)
base_dark = (ny-1)*(chip.readout_time/ny)*chip.dark_noise
chip.img.array[(chip.prescan_y+ny):-(chip.prescan_y+ny),:] = bese_dark
return chip, filt, tel, pointing return chip, filt, tel, pointing
def add_readout_noise(self, chip, filt, tel, pointing, catalog, obs_param): def add_readout_noise(self, chip, filt, tel, pointing, catalog, obs_param):
......
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