From 0b24318d2a1dfc59f3fe9781decb2d2595738cbd Mon Sep 17 00:00:00 2001 From: yan Date: Mon, 28 Oct 2024 10:13:34 +0800 Subject: [PATCH] update --- csst_ifs_sim/csst_ifs_sim.py | 163 +++++++++++++++++------------------ 1 file changed, 80 insertions(+), 83 deletions(-) diff --git a/csst_ifs_sim/csst_ifs_sim.py b/csst_ifs_sim/csst_ifs_sim.py index 90d3b4d..28ea758 100644 --- a/csst_ifs_sim/csst_ifs_sim.py +++ b/csst_ifs_sim/csst_ifs_sim.py @@ -333,7 +333,7 @@ def IFSinformation(): def CCDnonLinearityModel(data, beta=6e-7): """ - The non-linearity is modelled based on the results presented. + The non-linearity is modelled based on the results presented. :param data: data to which the non-linearity model is being applied to :type data: ndarray @@ -827,8 +827,8 @@ class StrayLight(object): def caculateEarthShineFilter(self, filter='i'): """ - # - # +# +# Parameters ---------- filter : TYPE, optional @@ -1212,7 +1212,7 @@ def LSR_velocity(ra, dec, velocity, Obstime): source = SkyCoord(ra*u.deg, dec*u.deg, frame='icrs', unit=(u.hourangle, u.deg)) ll = source.galactic.l.deg - b = source.galactic.b.deg + b = source.galactic.b.deg c = SkyCoord(ll=ll*u.degree, b=b*u.degree, frame='galactic') c_icrs = c.transform_to('icrs') barycorr = c_icrs.radial_velocity_correction( @@ -1829,7 +1829,6 @@ class IFSsimulator(): ############################################################################## ############################################################################## - def zodiacal(self, ra, dec, time): """ Parameters @@ -2411,7 +2410,6 @@ class IFSsimulator(): def applyDarkCurrent(self): - """ Returns ------- @@ -2474,17 +2472,17 @@ class IFSsimulator(): 'dark4_r value error, it shoub be in [0.0001, 0.001]!') raise ValueError( 'dark4_r value error, it shoub be in [0.0001, 0.001]!') - ########################################################################### + # ################################################################# # blue zone 4 self.image_b[0:1024, 0:2048] += self.information['exptime'] * \ self.information['dark2_b'] - ########## zone 1 ################# + # ######### zone 1 ################# self.image_b[1024:2048, 0:2048] += self.information['exptime'] * \ self.information['dark3_b'] - ########## zone 3 ################### + # ######### zone 3 ################### self.image_b[0:1024, 2048:4096] += self.information['exptime'] * \ self.information['dark1_b'] @@ -2495,12 +2493,12 @@ class IFSsimulator(): # red zone 4 self.image_r[0:1536, 0:3072] += self.information['exptime'] * \ self.information['dark2_r'] - ########## zone 1 ################# + # ######### zone 1 ################# self.image_r[1536:3712, 0:3072] += self.information['exptime'] * \ self.information['dark3_r'] - ########## zone 3 ################### + # ######### zone 3 ################### self.image_r[0:1536, 3072:6144] += self.information['exptime'] * \ self.information['dark1_r'] @@ -2509,8 +2507,8 @@ class IFSsimulator(): self.information['dark4_r'] -############################################################################## -############################################################################## +# ############################################################################# +# ############################################################################# def applyPoissonNoise(self): """ @@ -2559,9 +2557,9 @@ class IFSsimulator(): """ Apply cosmetic defects described in the input file. - #Number of hot and dead pixels from MSSL/Euclid/TR/12003 Issue 2 Draft b + # Number of hot and dead pixels from MSSL/Euclid/TR/12003 Issue 2 Draft b - .. Warning:: This method does not work if the input file has exactly one line. + Warning:: This method does not work if the input file has exactly one line. """ cosmetics = np.loadtxt( self.information['dir_path']+self.information['cosmeticsfile_b']) @@ -2579,7 +2577,9 @@ class IFSsimulator(): self.log.info('Adding cosmetic defects to blue channel:') for xc, yc, val in zip(x, y, value): if 0 <= xc <= 1024 and 50 < yc % 2418 <= 2048+50: - #self.image[yc, xc] = val + # + # # + # self.image[yc, xc] = val self.image_b[xc, yc] = val # cosmetics_b[xc,yc]=val self.log.info('x=%i, y=%i, value=%f' % (xc, yc, val)) @@ -2599,12 +2599,12 @@ class IFSsimulator(): for xc, yc, val in zip(x, y, value): if 0 <= xc <= 1536 and 50 < yc % 3442 <= 3072+50: - #self.image[yc, xc] = val + # self.image[yc, xc] = val self.image_r[xc, yc] = val # cosmetics_r[yc,xc]=val self.log.info('x=%i, y=%i, value=%f' % (xc, yc, val)) - ####### save cosmetics image code #### + # ###### save cosmetics image code #### # if self.simnumber<2: # #save cosmic ray image map @@ -2618,7 +2618,7 @@ class IFSsimulator(): # #output information to a FITS file # self.log.info('Save cosmetics images fits file to calibration_Data file ') -################################################################################ +# ############################################################################ def applyRadiationDamage(self): """ @@ -2691,7 +2691,7 @@ class IFSsimulator(): """ Applies readout noise to the image being constructed. - The noise is drawn from a Normal (Gaussian) distribution with + The noise is drawn from a Normal (Gaussian) distribution with average=0.0 and std=readout noise. """ self.log.info('readnoise added in blue channel') @@ -2754,17 +2754,17 @@ class IFSsimulator(): self.image_b[0:1024+overscan, 0:2048+prescan+overscan] += np.random.normal( loc=0.0, scale=self.information['rn2_b'], size=(1344, 2418)) - ########## zone 3, OSG ################# + # ######### zone 3, OSG ################# np.random.seed() self.image_b[0:1024+overscan, 2418:2418+2048+prescan+overscan] += np.random.normal( loc=0.0, scale=self.information['rn1_b'], size=(1344, 2418)) - ########## zone 1, OSE ################### + # ######### zone 1, OSE ################### np.random.seed() self.image_b[0:1024+overscan, 2418*2:2418*2+2048+prescan+overscan] += np.random.normal( loc=0.0, scale=self.information['rn3_b'], size=(1344, 2418)) - ########## zone 2, OSF ############### + # ######### zone 2, OSF ############### np.random.seed() self.image_b[0:1024+overscan, 2418*3:2418*3+2048+prescan+overscan] += np.random.normal( loc=0.0, scale=self.information['rn4_b'], size=(1344, 2418)) @@ -2776,17 +2776,17 @@ class IFSsimulator(): self.image_r[0:1536+overscan, 0:3072+prescan+overscan] += np.random.normal( loc=0.0, scale=self.information['rn2_r'], size=(1856, 3442)) - ########## zone 3 ,OSG ################# + # ######### zone 3 ,OSG ################# np.random.seed() self.image_r[0:1536+overscan, 3442:3442+3072+prescan+overscan] += np.random.normal( loc=0.0, scale=self.information['rn1_r'], size=(1856, 3442)) - ########## zone 1 ,OSE ################### + # ######### zone 1 ,OSE ################### np.random.seed() self.image_r[0:1536+overscan, 3442*2:3442*2+3072+prescan+overscan] += np.random.normal( loc=0.0, scale=self.information['rn3_r'], size=(1856, 3442)) - ########## zone 2,OSF ########### + # ######### zone 2,OSF ########### np.random.seed() self.image_r[0:1536+overscan, 3442*3:3442*3+3072+prescan+overscan] += np.random.normal( loc=0.0, scale=self.information['rn4_r'], size=(1856, 3442)) @@ -2812,17 +2812,17 @@ class IFSsimulator(): self.image_b[0:1024+overscan, prescan:2048 + prescan] += self.frame_b_4[0:1024+overscan, 0:2048] - ########## zone 3, OSG ################# + # ######### zone 3, OSG ################# self.image_b[0:1024+overscan, prescan+2418:2418+2048 + prescan] += self.frame_b_3[0:1024+overscan, 0:2048] - ########## zone 1, OSE ################### + # ######### zone 1, OSE ################### self.image_b[0:1024+overscan, prescan+2418*2:2418*2 + 2048+prescan] += self.frame_b_1[0:1024+overscan, 0:2048] - ########## zone 2, OSF ############### + # ######### zone 2, OSF ############### self.image_b[0:1024+overscan, prescan+2418*3:2418*3 + 2048+prescan] += self.frame_b_2[0:1024+overscan, 0:2048] @@ -2836,16 +2836,16 @@ class IFSsimulator(): self.image_r[0:1536+overscan, prescan+3442*0:3442*0 + 3072+prescan] += self.frame_r_4[0:1536+overscan, 0:3072] - ########## zone 3 ,OSG ################# + # ######### zone 3 ,OSG ################# self.image_r[0:1536+overscan, prescan+3442*1:3442*1 + 3072+prescan] += self.frame_r_3[0:1536+overscan, 0:3072] - ########## zone 1 ,OSE ################### + # ######### zone 1 ,OSE ################### self.image_r[0:1536+overscan, prescan+3442*2:3442*2 + 3072+prescan] += self.frame_r_1[0:1536+overscan, 0:3072] - ########## zone 2,OSF ########### + # ######### zone 2,OSF ########### self.image_r[0:1536+overscan, prescan+3442*3:3442*3 + 3072+prescan] += self.frame_r_2[0:1536+overscan, 0:3072] @@ -2928,36 +2928,36 @@ class IFSsimulator(): # # zone 2 # self.image_b[0:1344, 2418*3:2418*4] /= self.information['gain2_b'] -################# update @2024.10.18 ### +# ################ update @2024.10.18 ### # first part, menas old blue zone 4 self.image_b[0:1344, 0:2418] /= self.information['gain1_b'] - ##########second part, means old zone 3 ################# + # #########second part, means old zone 3 ################# self.image_b[0:1344, 2418:2418*2] /= self.information['gain2_b'] - ##########third part, means old zone 1 ################### + # #########third part, means old zone 1 ################### self.image_b[0:1344, 2418*2:2418*3] /= self.information['gain3_b'] # fourth part, means old zone 2 self.image_b[0:1344, 2418*3:2418*4] /= self.information['gain4_b'] - ############################################################################ + # ################################################################### -########################## +# ######################### # red zone 4 self.image_r[0:1856, 0:3442] /= self.information['gain1_r'] - ########## zone 3 ################# + # ######### zone 3 ################# self.image_r[0:1856, 3442:3442*2] /= self.information['gain2_r'] - ########## zone 1 ################### + # ######### zone 1 ################### self.image_r[0:1856, 3442*2:3442*3] /= self.information['gain3_r'] # zone 2 self.image_r[0:1856, 3442*3:3442*4] /= self.information['gain4_r'] - # 3 +# 3 - #################################################################################### +# ############################################################################ def applyBias(self): """ @@ -2973,7 +2973,7 @@ class IFSsimulator(): The value of bias is read from the configure file and stored in the information dictionary (key bias). - +# """ if self.information['bias1_b'] > 2000 or self.information['bias1_b'] < 100: @@ -3030,16 +3030,16 @@ class IFSsimulator(): # blue zone 4 self.image_b[0:1344, 0:2418] += self.information['bias2_b'] - ########## zone 3 ################# + # ######### zone 3 ################# self.image_b[0:1344, 2418:2418*2] += self.information['bias1_b'] - ########## zone 1 ################### + # ######### zone 1 ################### self.image_b[0:1344, 2418*2:2418*3] += self.information['bias3_b'] # zone 2 self.image_b[0:1344, 2418*3:2418*4] += self.information['bias4_b'] - ############################################################################ + # ############################################################## self.log.info('Bias counts were added to the blue image') @@ -3048,16 +3048,16 @@ class IFSsimulator(): # red zone 4 self.image_r[0:1856, 0:3442] += self.information['bias2_r'] - ########## zone 3 ################# + # ######### zone 3 ################# self.image_r[0:1856, 3442:3442*2] += self.information['bias1_r'] - ########## zone 1 ################### + # ######### zone 1 ################### self.image_r[0:1856, 3442*2:3442*3] += self.information['bias3_r'] # zone 2 self.image_r[0:1856, 3442*3:3442*4] += self.information['bias4_r'] - ####################################################################### + # ################################################################### self.log.info('Bias counts were added to the red image') @@ -3097,7 +3097,7 @@ class IFSsimulator(): self.log.error( 'Cannot include pre- and overscan because of an unknown quadrant!') - ##################################################################### + # ################################################################# canvas = np.zeros((self.information['redsize'], (self.information['redsize'] + self.information['prescanx'] + self.information['ovrscanx']))) @@ -3147,7 +3147,7 @@ class IFSsimulator(): overload = value - self.information['fullwellcapacity'] if overload > 0.: overload /= 2. - #self.image[j, i] -= overload + # self.image[j, i] -= overload self.image_b[j, i] -= overload sum += overload @@ -3165,14 +3165,14 @@ class IFSsimulator(): # second round - from top to bottom (bleeding was half'd already, so now full) overload = value - self.information['fullwellcapacity'] if overload > 0.: - #self.image[-j-1, i] -= overload + # self.image[-j-1, i] -= overload self.image_b[-j-1, i] -= overload sum += overload elif sum > 0.: if -overload > sum: overload = -sum - #self.image[-j-1, i] -= overload + # self.image[-j-1, i] -= overload self.image_b[-j-1, i] -= overload sum += overload @@ -3185,14 +3185,14 @@ class IFSsimulator(): overload = value - self.information['fullwellcapacity'] if overload > 0.: overload /= 2. - #self.image[j, i] -= overload + # self.image[j, i] -= overload self.image_r[j, i] -= overload sum += overload elif sum > 0.: if -overload > sum: overload = -sum - #self.image[j, i] -= overload + # self.image[j, i] -= overload self.image_r[j, i] -= overload sum += overload @@ -3203,14 +3203,14 @@ class IFSsimulator(): # second round - from top to bottom (bleeding was half'd already, so now full) overload = value - self.information['fullwellcapacity'] if overload > 0.: - #self.image[-j-1, i] -= overload + # self.image[-j-1, i] -= overload self.image_r[-j-1, i] -= overload sum += overload elif sum > 0.: if -overload > sum: overload = -sum - #self.image[-j-1, i] -= overload + # self.image[-j-1, i] -= overload self.image_r[-j-1, i] -= overload sum += overload @@ -3260,8 +3260,7 @@ class IFSsimulator(): self.image_r = np.rint(self.image_r).astype(int) self.log.info('Maximum and total values of the image are %i and %i, respectively' % (np.max(self.image_r), np.sum(self.image_r))) - - ################################################################################################## +# ############################################################################ # def applyImageShift(self): # """ @@ -3386,14 +3385,15 @@ 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 ################### + + # ## third part, old OSE, down to up ################### x1 = 0 x2 = x1+1024 y1 = 2418*2+prescan y2 = y1+2048 temp[x1:x2, y1:y2] = np.flipud(imgb[1024:2048, 0:2048]) - ########## fourth part, old OSF part; down to yp ,left to right ####### + # ######### fourth part, old OSF part; down to yp ,left to right ####### x1 = 0 x2 = x1+1024 @@ -3446,7 +3446,7 @@ class IFSsimulator(): y1 = 0+prescan y2 = y1+3072 temp[x1:x2, y1:y2] = np.fliplr(imgr[0:1536, 3072:6144]) - ########## second part, old OSH ,no change; ################# + # ######### second part, old OSH ,no change; ################# # np.fliplr(b2) ## left to right # np.flipud(b3) ## down to up x1 = 0 @@ -3455,14 +3455,14 @@ class IFSsimulator(): y1 = 3442+prescan y2 = y1+3072 temp[x1:x2, y1:y2] = imgr[0:1536, 0:3072] - ########## third part , old OSE , down to up ############################ + # ######### third part , old OSE , down to up ############################ x1 = 0 x2 = x1+1536 y1 = 3442*2+prescan y2 = y1+3072 temp[x1:x2, y1:y2] = np.flipud(imgr[1536:3072, 0:3072]) - ########## fourth part, old OSF, down to up ,left to right ################ + # ######### fourth part, old OSF, down to up ,left to right ################ x1 = 0 x2 = x1+1536 @@ -3566,7 +3566,7 @@ class IFSsimulator(): self.file_r = self.result_path+'/calibration_Data/'+filename_r+'.fits' # create a new FITS file, using HDUList instance - ##### layer 0 #### + # #### layer 0 #### ofd_b = fits.PrimaryHDU() @@ -3575,7 +3575,7 @@ class IFSsimulator(): ofd_b.header['NAXIS'] = (0, 'number of array dimensions') ofd_b.header['NEXTEND'] = (np.int16(1), 'number of array dimensions') - ############################################################################################ + # #################################################################### temp = write_end.utcnow() data_time = temp.strftime("%Y-%m-%dT%H:%M:%S.%f") ofd_b.header['DATE'] = ( @@ -3589,7 +3589,7 @@ class IFSsimulator(): ofd_b.header['EQUINOX'] = (float(2000.0), '') ofd_b.header['FITSSWV'] = ( 'ifs_sim_0.8.03', 'FITS creating software version') - ######### Object information ############# + # ######## Object information ############# if self.source == 'SCI' or self.source == 'COMP': ofd_b.header['OBJECT'] = ( self.information['name_obj'][:30], 'object name') @@ -3640,7 +3640,7 @@ class IFSsimulator(): ####################################################################### - ######## Telescope information ############### + # ####### Telescope information ############### ofd_b.header['REFFRAME'] = ('CSSTGSC-1.0', 'guiding catalog version') ofd_b.header['DATE-OBS'] = (data_time[:21], @@ -3741,7 +3741,7 @@ class IFSsimulator(): ofd_b.header['DATASUM'] = (data_time[:19], ss2) ########## - ########## finish header for 0 layer ###################### + # ######### finish header for 0 layer ###################### ############################################################# # header # new image HDU, blue channel, layer 1 @@ -3777,7 +3777,7 @@ class IFSsimulator(): hdu_b.header['BUNIT'] = ('ADU', 'physical unit of array values') ####################################################################### - ######### instrument information ################################### + # ######## instrument information ################################### if self.source == 'SCI' or self.source == 'COMP': hdu_b.header['CMIRRPOS'] = ( @@ -3808,7 +3808,7 @@ class IFSsimulator(): ###################################################################### - #################### detector information########################## + # ################### detector information########################## hdu_b.header['CAMERA'] = ('Blue', 'camera of IFS') hdu_b.header['DETSN'] = ('CCD231-c4-00', 'detector serial number') @@ -3870,7 +3870,7 @@ class IFSsimulator(): hdu_b.header['DETTEMP1'] = (np.float32( 0.0), 'detector temperature at EXPT1_'+str(k+1)+' (K)') - #######################end revised on 2024.2.27 ### + # ######################end revised on 2024.2.27 ### hdu_b.header['BIN_X'] = ( np.int16(1), 'bin number in X (wavelength)') @@ -3927,7 +3927,7 @@ class IFSsimulator(): hdu_b.header['Hole'] = ('yes', 'apply hole to LAMP') ##################################################################### - #################### red camera ###################### + # ################### red camera ###################### # create a new FITS file, using HDUList instance ofd_r = fits.PrimaryHDU() @@ -4008,7 +4008,7 @@ class IFSsimulator(): ####################################################################### - ######## Telescope information ############### + # ####### Telescope information ############### ofd_r.header['REFFRAME'] = ('CSSTGSC-1.0', 'guiding catalog version') ofd_r.header['DATE-OBS'] = (data_time[:21], @@ -4121,7 +4121,7 @@ class IFSsimulator(): ofd_r.header['DATASUM'] = (data_time[:19], ss2) ########## - ########## finish header for 0 layer ###################### + # ######### finish header for 0 layer ###################### ############################################################# # header @@ -4156,7 +4156,7 @@ class IFSsimulator(): hdu_r.header['BZERO'] = (np.float64(32768), '') hdu_r.header['BUNIT'] = ('ADU', 'physical unit of array values') - ######### instrument information ###### + # ######## instrument information ###### if self.source == 'SCI' or self.source == 'COMP': @@ -4186,7 +4186,7 @@ class IFSsimulator(): hdu_r.header['IFSSTAT'] = ( np.int32(0), 'IFS components status parameter') - ################### detector information############################ + # ################## detector information############################ hdu_r.header['CAMERA'] = ('Red', 'camera of IFS') hdu_r.header['DETSN'] = ('CCD231-c6-00', 'detector serial number') @@ -4244,7 +4244,7 @@ class IFSsimulator(): hdu_r.header[str1] = (read_start[:21], com1) hdu_r.header[str2] = (read_end[:21], com2) - #################################################################################### + # ################################################################### hdu_r.header['DETTEMP0'] = (np.float32( 0.0), 'detector temperature at EXPT0_1 (K)') hdu_r.header['DETTEMP1'] = (np.float32( @@ -4302,7 +4302,7 @@ class IFSsimulator(): if self.source == 'LAMP' and self.information['holemask'] == 'yes': hdu_r.header['Hole'] = ('yes', 'apply hole to LAMP') - ######################### +######################### hdu1 = fits.PrimaryHDU(header=ofd_b.header) hdu2 = fits.PrimaryHDU(header=ofd_r.header) @@ -4445,11 +4445,8 @@ class IFSsimulator(): return - -######################################################################################################################################################################################################################################################## - - ################################################################################### - ################################################################################## +# ############################################################################ +# ############################################################################ def CalskyNoise(self, lam): """ -- GitLab