Loading csst_ifs_sim/csst_ifs_sim.py +94 −94 Original line number Diff line number Diff line Loading @@ -2407,8 +2407,8 @@ class IFSsimulator(): ########################################################## ######################################################################### # # def applyDarkCurrent(self): """ Returns Loading Loading @@ -2507,13 +2507,12 @@ class IFSsimulator(): self.information['dark4_r'] # ############################################################################# # ############################################################################# def applyPoissonNoise(self): """ def applyPoissonNoise(self): """ Returns ------- None. Loading Loading @@ -2542,8 +2541,8 @@ class IFSsimulator(): self.log.info('Added Poisson noise on channel red') self.image_r += residual ############################################################################## # ############################################################################ # def applyCosmetics(self): """ Loading Loading @@ -3096,7 +3095,8 @@ class IFSsimulator(): else: self.log.error( 'Cannot include pre- and overscan because of an unknown quadrant!') # # # ################################################################# canvas = np.zeros((self.information['redsize'], Loading Loading @@ -3324,14 +3324,11 @@ class IFSsimulator(): def CCDreadout(self): """ Returns ------- None. """ imgb = self.image_b.copy() prescan = int(self.information['prescan']) overscan = int(self.information['overscan']) Loading Loading @@ -3385,7 +3382,9 @@ class IFSsimulator(): y1 = 2418+prescan y2 = y1+2048 temp[x1:x2, y1:y2] = imgb[0:1024, 0:2048] # # # # ## third part, old OSE, down to up ################### x1 = 0 x2 = x1+1024 Loading Loading @@ -4362,7 +4361,7 @@ class IFSsimulator(): '========================================================================', before='EXPT0_1') hdulist_b.writeto(self.file_b, output_verify='ignore', checksum=True) ######################################################################### # ################################################################## hdulist_r = fits.HDUList([hdu2, hdu_r]) hdu_r.header.add_comment( Loading Loading @@ -4399,7 +4398,7 @@ class IFSsimulator(): """ # read solar template solar_template = pd.read_csv(self.information['dir_path']+'IFS_inputdata/refs/solar_spec.dat', sep='\s+', solar_template = pd.read_csv(self.information['dir_path']+'IFS_inputdata/refs/solar_spec.dat', sep='\\s+', header=None, comment='#') template_wave = solar_template[0].values template_flux = solar_template[1].values Loading @@ -4411,7 +4410,7 @@ class IFSsimulator(): surface_brightness = earthshine_curve[1].values # read V-band throughtput cat_filter_V = pd.read_csv(self.information['dir_path']+'IFS_inputdata/refs/filter_Bessell_V.dat', sep='\s+', cat_filter_V = pd.read_csv(self.information['dir_path']+'IFS_inputdata/refs/filter_Bessell_V.dat', sep='\\s+', header=None, comment='#') filter_wave = cat_filter_V[0].values filter_response = cat_filter_V[1].values Loading Loading @@ -4510,7 +4509,7 @@ class IFSsimulator(): """ sizeout = 1000 # here image has the pixelscale =0.01 arcsec ################# create the slicer and slit file for high resolution 0.01arcsec simulation ################### # create the slicer and slit file for high resolution 0.01arcsec simulation ################### maskSlice = dict() maskSlit = dict() Loading @@ -4526,7 +4525,8 @@ class IFSsimulator(): self.maskSliceHole = maskSlice self.maskSlitHole = maskSlit ######################################################################### ################################################################ # ######## # #### load slicer_Qe1K.fits #### slicerfile = self.information['dir_path'] + \ 'IFS_inputdata/Flatfield/slicer_QE_1K_230625.fits' Loading Loading @@ -4822,7 +4822,7 @@ class IFSsimulator(): newd.writeto(filename, overwrite=True) return ################################################################################## # ######################################################################## def sim_sky_img(self, skyfitsfilename, skyRa, skyDec, sky_rot, telRa, telDec, exposuretime, simnumber): """ Loading Loading @@ -4885,7 +4885,7 @@ class IFSsimulator(): self.information['dec_pnt0'] = a[0].header['DEC'] + disDec ############### calculate the earthshine and zodiacal noise ,new code 2023.11.1 ############ # calculate the earthshine and zodiacal noise ,new code 2023.11.1 ############ ############### self.log.info('Real telescope pointing in Ra = %f, Dec = %f' % ( Loading Loading @@ -4959,7 +4959,7 @@ class IFSsimulator(): Wave = 0.1*a[2].data # print('Wave data header', hdr) ###################################################################################### # ##################################################################### exptime = self.information['exptime'] # exposure time Loading Loading @@ -5340,7 +5340,7 @@ class IFSsimulator(): # print('covtime =', t2-t1) ######################## get subimage ##################### # ### get subimage ##################### subimage = galsim.Image(80, 80) subimage.array[:, :] = img3[int( sizeout/2)-40:int(sizeout/2)+40, int(sizeout/2)-40:int(sizeout/2)+40] Loading @@ -5355,17 +5355,17 @@ class IFSsimulator(): photons = galsim.PhotonArray.makeFromImage( subimage, max_flux=max(img3.max()/10000.0, 1)) ############################################################################# ############################################################ # do something for each photons; ############################################################################## ############################################################# idx0 = np.where(photons.flux > 1e-3) # totla energy for slice image energy = energy+sum(photons.flux[idx0]) p_num = len(idx0[0]) ############################################################################################### ####################### code for test slice is right or not ################################### ############################################################################################### ############################################################## # ######### code for test slice is right or not ############## ############################################################## # photons_2=galsim.PhotonArray(N=p_num, x=photons.x[idx0], y=photons.y[idx0], flux = photons.flux[idx0], wavelength=lam) # if k==0: # sliceimage = galsim.Image(100,100) Loading Loading @@ -5425,8 +5425,8 @@ class IFSsimulator(): ######################################################## ########################### test code ################################ ###################################################################### # ##################### test code ################################ # ################################################################ # fits.writeto('originalImg.fits',Nimg,overwrite=True) # fits.writeto('PSFedImg.fits',temp,overwrite=True) # fits.writeto('rotedphotonsImg.fits',image.array,overwrite=True) Loading @@ -5434,10 +5434,10 @@ class IFSsimulator(): # fits.writeto('slicephotonsImg.fits',sliceimage.array,overwrite=True) # pause() ###################################################################### ###################### finish test code ########################### # ############################################################# # ############## finish test code ########################### #################################################################################### ##################################################################### # stray light will cover 2% of input total light; if self.sky_noise: Loading Loading @@ -5696,14 +5696,14 @@ class IFSsimulator(): img3 = conv ######################## get subimage ##################### # # ## get subimage ##################### subimage = galsim.Image(80, 80) subimage.array[:, :] = img3[int( sizeout/2)-40:int(sizeout/2)+40, int(sizeout/2)-40:int(sizeout/2)+40] # fits.writeto('subimage.fits',subimage.array,overwrite=True) ######################## get photons from sub-image ##################### # ##### get photons from sub-image ##################### subimage.scale = self.pixelscale subimage.setOrigin(0, 0) Loading @@ -5711,16 +5711,16 @@ class IFSsimulator(): photons = galsim.PhotonArray.makeFromImage( subimage, max_flux=max(img3.max()/10000.0, 1)) ############################################################################# # ########################################################### # do something for each photons; ############################################################################## # ############################################################ idx0 = np.where(photons.flux > 1e-2) # energy=energy+sum(photons.flux[idx0]) ### totla energy for slice image p_num = len(idx0[0]) ############################################################################################### ####################### code for test slice is right or not ################################### ############################################################################################### # ############################################################# # ##### code for test slice is right or not ################## ######################################################### # photons_2=galsim.PhotonArray(N=p_num, x=photons.x[idx0], y=photons.y[idx0], flux = photons.flux[idx0], wavelength=lam) # if k==0: # sliceimage = galsim.Image(100,100) Loading Loading @@ -5829,7 +5829,7 @@ class IFSsimulator(): # fits.writeto(bluefile, self.image_b, overwrite=True) # fits.writeto(redfile, self.image_r, overwrite=True) ################################################################################################# # ############################################################################# def simulate(self, sourcein, simnumber): """ Loading Loading @@ -5902,7 +5902,7 @@ class IFSsimulator(): df = pd.read_csv( self.information['dir_path']+'IFS_inputdata/TianCe/'+starcat) ################################################################### ############################################################## sn = self.simnumber-1 arr = np.array(df['time'][sn*5:sn*5+5]) self.exptime_start_jd, self.exptime_start_index = find_min(arr) Loading @@ -5911,7 +5911,7 @@ class IFSsimulator(): # self.earthshine_theta=df['earth_angle'][sn*5+index] # in degree self.dt = jd2time(self.exptime_start_jd) self.bianpai_data = df ################################################################## # ############################################################ else: # ### load orbit parameters ##### Loading @@ -5937,7 +5937,7 @@ class IFSsimulator(): if flag == 1: break ################################################################## # ############################################################ if kk + self.dt_num < len(d[:, 0]): Loading Loading @@ -6040,7 +6040,7 @@ class IFSsimulator(): else: print('Souce is not correct and programe will return') raise ValueError('Souce is not correct and programe will return') ############################################################################### # ######################################################################## # save the original image firstly; self.image_b_ori = self.image_b+10.0 self.image_r_ori = self.image_r+10.0 Loading @@ -6066,7 +6066,7 @@ class IFSsimulator(): for idk in range(exptimes): ############ add some effect to images ####################################### # ### add some effect to images ################################# self.image_b = self.image_b_ori-10.0 self.image_r = self.image_r_ori-10.0 Loading Loading @@ -6203,4 +6203,4 @@ def runIFSsim(sourcein, configfile, dir_path, result_path, iLoop, debug, applyho return 1 ############################## end ########################################## # ######################### end ########################################## tests/test_ifs_sim.py +6 −6 File changed.Contains only whitespace changes. Show changes Loading
csst_ifs_sim/csst_ifs_sim.py +94 −94 Original line number Diff line number Diff line Loading @@ -2407,8 +2407,8 @@ class IFSsimulator(): ########################################################## ######################################################################### # # def applyDarkCurrent(self): """ Returns Loading Loading @@ -2507,13 +2507,12 @@ class IFSsimulator(): self.information['dark4_r'] # ############################################################################# # ############################################################################# def applyPoissonNoise(self): """ def applyPoissonNoise(self): """ Returns ------- None. Loading Loading @@ -2542,8 +2541,8 @@ class IFSsimulator(): self.log.info('Added Poisson noise on channel red') self.image_r += residual ############################################################################## # ############################################################################ # def applyCosmetics(self): """ Loading Loading @@ -3096,7 +3095,8 @@ class IFSsimulator(): else: self.log.error( 'Cannot include pre- and overscan because of an unknown quadrant!') # # # ################################################################# canvas = np.zeros((self.information['redsize'], Loading Loading @@ -3324,14 +3324,11 @@ class IFSsimulator(): def CCDreadout(self): """ Returns ------- None. """ imgb = self.image_b.copy() prescan = int(self.information['prescan']) overscan = int(self.information['overscan']) Loading Loading @@ -3385,7 +3382,9 @@ class IFSsimulator(): y1 = 2418+prescan y2 = y1+2048 temp[x1:x2, y1:y2] = imgb[0:1024, 0:2048] # # # # ## third part, old OSE, down to up ################### x1 = 0 x2 = x1+1024 Loading Loading @@ -4362,7 +4361,7 @@ class IFSsimulator(): '========================================================================', before='EXPT0_1') hdulist_b.writeto(self.file_b, output_verify='ignore', checksum=True) ######################################################################### # ################################################################## hdulist_r = fits.HDUList([hdu2, hdu_r]) hdu_r.header.add_comment( Loading Loading @@ -4399,7 +4398,7 @@ class IFSsimulator(): """ # read solar template solar_template = pd.read_csv(self.information['dir_path']+'IFS_inputdata/refs/solar_spec.dat', sep='\s+', solar_template = pd.read_csv(self.information['dir_path']+'IFS_inputdata/refs/solar_spec.dat', sep='\\s+', header=None, comment='#') template_wave = solar_template[0].values template_flux = solar_template[1].values Loading @@ -4411,7 +4410,7 @@ class IFSsimulator(): surface_brightness = earthshine_curve[1].values # read V-band throughtput cat_filter_V = pd.read_csv(self.information['dir_path']+'IFS_inputdata/refs/filter_Bessell_V.dat', sep='\s+', cat_filter_V = pd.read_csv(self.information['dir_path']+'IFS_inputdata/refs/filter_Bessell_V.dat', sep='\\s+', header=None, comment='#') filter_wave = cat_filter_V[0].values filter_response = cat_filter_V[1].values Loading Loading @@ -4510,7 +4509,7 @@ class IFSsimulator(): """ sizeout = 1000 # here image has the pixelscale =0.01 arcsec ################# create the slicer and slit file for high resolution 0.01arcsec simulation ################### # create the slicer and slit file for high resolution 0.01arcsec simulation ################### maskSlice = dict() maskSlit = dict() Loading @@ -4526,7 +4525,8 @@ class IFSsimulator(): self.maskSliceHole = maskSlice self.maskSlitHole = maskSlit ######################################################################### ################################################################ # ######## # #### load slicer_Qe1K.fits #### slicerfile = self.information['dir_path'] + \ 'IFS_inputdata/Flatfield/slicer_QE_1K_230625.fits' Loading Loading @@ -4822,7 +4822,7 @@ class IFSsimulator(): newd.writeto(filename, overwrite=True) return ################################################################################## # ######################################################################## def sim_sky_img(self, skyfitsfilename, skyRa, skyDec, sky_rot, telRa, telDec, exposuretime, simnumber): """ Loading Loading @@ -4885,7 +4885,7 @@ class IFSsimulator(): self.information['dec_pnt0'] = a[0].header['DEC'] + disDec ############### calculate the earthshine and zodiacal noise ,new code 2023.11.1 ############ # calculate the earthshine and zodiacal noise ,new code 2023.11.1 ############ ############### self.log.info('Real telescope pointing in Ra = %f, Dec = %f' % ( Loading Loading @@ -4959,7 +4959,7 @@ class IFSsimulator(): Wave = 0.1*a[2].data # print('Wave data header', hdr) ###################################################################################### # ##################################################################### exptime = self.information['exptime'] # exposure time Loading Loading @@ -5340,7 +5340,7 @@ class IFSsimulator(): # print('covtime =', t2-t1) ######################## get subimage ##################### # ### get subimage ##################### subimage = galsim.Image(80, 80) subimage.array[:, :] = img3[int( sizeout/2)-40:int(sizeout/2)+40, int(sizeout/2)-40:int(sizeout/2)+40] Loading @@ -5355,17 +5355,17 @@ class IFSsimulator(): photons = galsim.PhotonArray.makeFromImage( subimage, max_flux=max(img3.max()/10000.0, 1)) ############################################################################# ############################################################ # do something for each photons; ############################################################################## ############################################################# idx0 = np.where(photons.flux > 1e-3) # totla energy for slice image energy = energy+sum(photons.flux[idx0]) p_num = len(idx0[0]) ############################################################################################### ####################### code for test slice is right or not ################################### ############################################################################################### ############################################################## # ######### code for test slice is right or not ############## ############################################################## # photons_2=galsim.PhotonArray(N=p_num, x=photons.x[idx0], y=photons.y[idx0], flux = photons.flux[idx0], wavelength=lam) # if k==0: # sliceimage = galsim.Image(100,100) Loading Loading @@ -5425,8 +5425,8 @@ class IFSsimulator(): ######################################################## ########################### test code ################################ ###################################################################### # ##################### test code ################################ # ################################################################ # fits.writeto('originalImg.fits',Nimg,overwrite=True) # fits.writeto('PSFedImg.fits',temp,overwrite=True) # fits.writeto('rotedphotonsImg.fits',image.array,overwrite=True) Loading @@ -5434,10 +5434,10 @@ class IFSsimulator(): # fits.writeto('slicephotonsImg.fits',sliceimage.array,overwrite=True) # pause() ###################################################################### ###################### finish test code ########################### # ############################################################# # ############## finish test code ########################### #################################################################################### ##################################################################### # stray light will cover 2% of input total light; if self.sky_noise: Loading Loading @@ -5696,14 +5696,14 @@ class IFSsimulator(): img3 = conv ######################## get subimage ##################### # # ## get subimage ##################### subimage = galsim.Image(80, 80) subimage.array[:, :] = img3[int( sizeout/2)-40:int(sizeout/2)+40, int(sizeout/2)-40:int(sizeout/2)+40] # fits.writeto('subimage.fits',subimage.array,overwrite=True) ######################## get photons from sub-image ##################### # ##### get photons from sub-image ##################### subimage.scale = self.pixelscale subimage.setOrigin(0, 0) Loading @@ -5711,16 +5711,16 @@ class IFSsimulator(): photons = galsim.PhotonArray.makeFromImage( subimage, max_flux=max(img3.max()/10000.0, 1)) ############################################################################# # ########################################################### # do something for each photons; ############################################################################## # ############################################################ idx0 = np.where(photons.flux > 1e-2) # energy=energy+sum(photons.flux[idx0]) ### totla energy for slice image p_num = len(idx0[0]) ############################################################################################### ####################### code for test slice is right or not ################################### ############################################################################################### # ############################################################# # ##### code for test slice is right or not ################## ######################################################### # photons_2=galsim.PhotonArray(N=p_num, x=photons.x[idx0], y=photons.y[idx0], flux = photons.flux[idx0], wavelength=lam) # if k==0: # sliceimage = galsim.Image(100,100) Loading Loading @@ -5829,7 +5829,7 @@ class IFSsimulator(): # fits.writeto(bluefile, self.image_b, overwrite=True) # fits.writeto(redfile, self.image_r, overwrite=True) ################################################################################################# # ############################################################################# def simulate(self, sourcein, simnumber): """ Loading Loading @@ -5902,7 +5902,7 @@ class IFSsimulator(): df = pd.read_csv( self.information['dir_path']+'IFS_inputdata/TianCe/'+starcat) ################################################################### ############################################################## sn = self.simnumber-1 arr = np.array(df['time'][sn*5:sn*5+5]) self.exptime_start_jd, self.exptime_start_index = find_min(arr) Loading @@ -5911,7 +5911,7 @@ class IFSsimulator(): # self.earthshine_theta=df['earth_angle'][sn*5+index] # in degree self.dt = jd2time(self.exptime_start_jd) self.bianpai_data = df ################################################################## # ############################################################ else: # ### load orbit parameters ##### Loading @@ -5937,7 +5937,7 @@ class IFSsimulator(): if flag == 1: break ################################################################## # ############################################################ if kk + self.dt_num < len(d[:, 0]): Loading Loading @@ -6040,7 +6040,7 @@ class IFSsimulator(): else: print('Souce is not correct and programe will return') raise ValueError('Souce is not correct and programe will return') ############################################################################### # ######################################################################## # save the original image firstly; self.image_b_ori = self.image_b+10.0 self.image_r_ori = self.image_r+10.0 Loading @@ -6066,7 +6066,7 @@ class IFSsimulator(): for idk in range(exptimes): ############ add some effect to images ####################################### # ### add some effect to images ################################# self.image_b = self.image_b_ori-10.0 self.image_r = self.image_r_ori-10.0 Loading Loading @@ -6203,4 +6203,4 @@ def runIFSsim(sourcein, configfile, dir_path, result_path, iLoop, debug, applyho return 1 ############################## end ########################################## # ######################### end ##########################################