diff --git a/ObservationSim/Instrument/Chip/Chip.py b/ObservationSim/Instrument/Chip/Chip.py index bb93b0a202ad4e04f4267ed4b8b7fcf9d0b2e02c..64de35b5349d45f6e16cb153bfcd4f33bdb0e953 100755 --- a/ObservationSim/Instrument/Chip/Chip.py +++ b/ObservationSim/Instrument/Chip/Chip.py @@ -358,8 +358,12 @@ class Chip(FocalPlane): # img.addNoise(dark_noise) # Add dark current & Poisson noise + InputDark = False if config["ins_effects"]["add_dark"] == True: - img, _ = chip_utils.add_poisson(img=img, chip=self, exptime=exptime, poisson_noise=poisson_noise) + if InputDark: + img = chip_utils.add_inputdark(img=img, chip=self, exptime=exptime) + else: + img, _ = chip_utils.add_poisson(img=img, chip=self, exptime=exptime, poisson_noise=poisson_noise) else: img, _ = chip_utils.add_poisson(img=img, chip=self, exptime=exptime, poisson_noise=poisson_noise, dark_noise=0.) @@ -390,14 +394,24 @@ class Chip(FocalPlane): if config["ins_effects"]["cte_trail"] == True: chip_utils.log_info(msg=" Apply CTE Effect", logger=self.logger) img = effects.CTE_Effect(GSImage=img, threshold=27) - + + ### prescan & overscan + if config["ins_effects"]["add_prescan"] == True: + img = chip_utils.AddPreScan(GSImage=img, pre1=27, pre2=4, over1=71, over2=80) + ### 1*16 output + if config["ins_effects"]["format_output"] == True: + img = chip_utils.formatOutput(GSImage=img) + self.nsecy = 1 + self.nsecx = 16 + + # Add Bias level if config["ins_effects"]["add_bias"] == True: chip_utils.log_info(msg=" Adding Bias level and 16-channel non-uniformity", logger=self.logger) if config["ins_effects"]["bias_16channel"] == True: img = effects.AddBiasNonUniform16(img, bias_level=float(self.bias_level), - nsecy = 2, nsecx=8, + nsecy = self.nsecy, nsecx=self.nsecx, seed=SeedBiasNonuni+self.chipID, logger=self.logger) elif config["ins_effects"]["bias_16channel"] == False: @@ -415,7 +429,7 @@ class Chip(FocalPlane): if config["ins_effects"]["gain_16channel"] == True: img, self.gain_channel = effects.ApplyGainNonUniform16( img, gain=self.gain, - nsecy = 2, nsecx=8, + nsecy = self.nsecy, nsecx=self.nsecx, seed=SeedGainNonuni+self.chipID, logger=self.logger) elif config["ins_effects"]["gain_16channel"] == False: diff --git a/ObservationSim/Instrument/Chip/ChipUtils.py b/ObservationSim/Instrument/Chip/ChipUtils.py index d8e9a0aaf4cfb895f1e173599a2015bd95688a93..b77ac1420d5c477a8ff3d225ec290cff9938f8f3 100644 --- a/ObservationSim/Instrument/Chip/ChipUtils.py +++ b/ObservationSim/Instrument/Chip/ChipUtils.py @@ -171,10 +171,11 @@ def add_poisson(img, chip, exptime=150., seed=0, sky_level=0., poisson_noise=Non def add_brighter_fatter(img): #Inital dynamic lib try: - with pkg_resources.files('ObservationSim.Instrument.Chip.lib_bf').joinpath("libmoduleBF.so") as lib_path: + with pkg_resources.files('ObservationSim.Instrument.Chip.libBF').joinpath("libmoduleBF.so") as lib_path: + print('--1', lib_path) lib_bf = ctypes.CDLL(lib_path) except AttributeError: - with pkg_resources.path('ObservationSim.Instrument.Chip.lib_bf', "libmoduleBF.so") as lib_path: + with pkg_resources.path('ObservationSim.Instrument.Chip.libBF', "libmoduleBF.so") as lib_path: lib_bf = ctypes.CDLL(lib_path) lib_bf.addEffects.argtypes = [ctypes.c_int, ctypes.c_int, ctypes.POINTER(ctypes.c_float), ctypes.POINTER(ctypes.c_float), ctypes.c_int] @@ -193,4 +194,87 @@ def add_brighter_fatter(img): lib_bf.addEffects(nx, ny, arr_ima, arr_imc, bit_flag) img.array[:, :] = np.reshape(arr_imc, [nx, ny]) del arr_ima, arr_imc - return img \ No newline at end of file + return img + +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" + hdu = fits.open(fname) + #ny, nx = img.array.shape + #inputdark = np.zeros([ny, nx]) + img.array[:, :] += hdu[0].data/hdu[0].header['exptime']*exptime + hdu.close() + del inputdark + return img + +def AddPreScan(GSImage, pre1=27, pre2=4, over1=71, over2=80, nsecy = 2, nsecx=8): + img= GSImage.array + ny, nx = img.shape + dx = int(nx/nsecx) + dy = int(ny/nsecy) + + imgt=np.zeros([int(nsecy*nsecx), int(ny/nsecy+pre2+over2), int(nx/nsecx+pre1+over1)]) + for iy in range(nsecy): + for ix in range(nsecx): + if iy % 2 == 0: + tx = ix + else: + tx = (nsecx-1)-ix + ty = iy + chunkidx = int(tx+ty*nsecx) #chunk1-[1,2,3,4], chunk2-[5,6,7,8], chunk3-[9,10,11,12], chunk4-[13,14,15,16] + + imgtemp = np.zeros([int(ny/nsecy+pre2+over2), int(nx/nsecx+pre1+over1)]) + if int(chunkidx/4) == 0: + imgtemp[pre2:-over2, pre1:-over1] = img[iy*dy:(iy+1)*dy, ix*dx:(ix+1)*dx] + imgt[chunkidx, :, :] = imgtemp + if int(chunkidx/4) == 1: + imgtemp[pre2:-over2, over1:-pre1] = img[iy*dy:(iy+1)*dy, ix*dx:(ix+1)*dx] + imgt[chunkidx, :, :] = imgtemp #[:, ::-1] + if int(chunkidx/4) == 2: + imgtemp[over2:-pre2, over1:-pre1] = img[iy*dy:(iy+1)*dy, ix*dx:(ix+1)*dx] + imgt[chunkidx, :, :] = imgtemp #[::-1, ::-1] + if int(chunkidx/4) == 3: + imgtemp[over2:-pre2, pre1:-over1] = img[iy*dy:(iy+1)*dy, ix*dx:(ix+1)*dx] + imgt[chunkidx, :, :] = imgtemp #[::-1, :] + + imgtx1 = np.hstack(imgt[:nsecx:, :, :]) + imgtx2 = np.hstack(imgt[:(nsecx-1):-1, :, :]) + + newimg = galsim.Image(int(nx+(pre1+over1)*nsecx), int(ny+(pre2+over2)*nsecy), init_value=0) + newimg.array[:, :] = np.concatenate([imgtx1, imgtx2]) + + newimg.wcs = GSImage.wcs + return newimg + +def formatOutput(GSImage, nsecy = 2, nsecx=8): + img = GSImage.array + ny, nx = img.shape + dx = int(nx/nsecx) + dy = int(ny/nsecy) + + imgt = np.zeros([int(nsecx*nsecy), dy, dx]) + for iy in range(nsecy): + for ix in range(nsecx): + if iy % 2 == 0: + tx = ix + else: + tx = (nsecx-1)-ix + ty = iy + chunkidx = int(tx+ty*nsecx) + if int(chunkidx/4) == 0: + imgt[chunkidx, :, :] = img[iy*dy:(iy+1)*dy, ix*dx:(ix+1)*dx] + if int(chunkidx/4) == 1: + imgt[chunkidx, :, :] = img[iy*dy:(iy+1)*dy, ix*dx:(ix+1)*dx] + if int(chunkidx/4) == 2: + imgt[chunkidx, :, :] = img[iy*dy:(iy+1)*dy, ix*dx:(ix+1)*dx] + if int(chunkidx/4) == 3: + imgt[chunkidx, :, :] = img[iy*dy:(iy+1)*dy, ix*dx:(ix+1)*dx] + + imgttx0 = np.hstack(imgt[ 0:4:, :, :]) + imgttx1 = np.hstack(imgt[ 4:8:, :, ::-1]) + imgttx2 = np.hstack(imgt[8:12:, ::-1, ::-1]) + imgttx3 = np.hstack(imgt[12:16:,::-1, :]) + + newimg = galsim.Image(int(dx*nsecx*nsecy), dy, init_value=0) + newimg.array[:, :] = np.hstack([imgttx0, imgttx1, imgttx2, imgttx3]) + return newimg + diff --git a/config/config_50sqdeg.yaml b/config/config_50sqdeg.yaml index 955d878a8487f88e7ea9b1c2a18e2dc51fff5d7f..0ffa694c4f5991a432ea32552a40df8f0a6913b3 100644 --- a/config/config_50sqdeg.yaml +++ b/config/config_50sqdeg.yaml @@ -9,13 +9,13 @@ # Base diretories and naming setup # Can add some of the command-line arguments here as well; # OK to pass either way or both, as long as they are consistent -work_dir: "/share/home/fangyuedong/new_sim/workplace/" +work_dir: "/share/home/weichengliang/CSST_git/test_new_sim/outputs/" data_dir: "/share/simudata/CSSOSDataProductsSims/data/" -run_name: "test_new_sim" +run_name: "testRun0" # Whether to use MPI run_option: - use_mpi: NO + use_mpi: YES # NOTE: "n_threads" paramters is currently not used in the backend # simulation codes. It should be implemented later in the web frontend # in order to config the number of threads to request from NAOC cluster @@ -85,7 +85,7 @@ obs_setting: # if you just want to run default pointing: # - pointing_dir: null # - pointing_file: null - pointing_dir: "/share/home/fangyuedong/50sqdeg_pointings/" + pointing_dir: "/share/simudata/CSSOSDataProductsSims/data/" pointing_file: "pointing_50_combined.dat" # Number of calibration pointings @@ -163,6 +163,7 @@ ins_effects: add_dark: ON # Whether to add dark noise add_readout: ON # Whether to add read-out (Gaussian) noise add_bias: ON # Whether to add bias-level to images + add_prescan: OFF bias_16channel: ON # Whether to add different biases for 16 channels gain_16channel: ON # Whether to make different gains for 16 channels shutter_effect: ON # Whether to add shutter effect @@ -177,6 +178,7 @@ ins_effects: add_hotpixels: ON # Whether to add hot pixels add_deadpixels: ON # Whether to add dead(dark) pixels bright_fatter: ON # Whether to simulate Brighter-Fatter (also diffusion) effect + format_output: OFF # Values: # default values have been defined individually for each chip in: @@ -218,4 +220,4 @@ random_seeds: seed_badcolumns: 20240309 # Seed for bad columns seed_defective: 20210304 # Seed for defective (bad) pixels seed_readout: 20210601 # Seed for read-out gaussian noise -... \ No newline at end of file +...