Commit 33dff68d authored by Yan Zhaojun's avatar Yan Zhaojun
Browse files

update

parent 7f51aaa2
Loading
Loading
Loading
Loading
Loading
+94 −80
Original line number Diff line number Diff line
@@ -260,15 +260,7 @@ class CDM03bidir():

        return np.asanyarray(CTIed)

#################################################################################################################
#################################################################################################################
"""
These functions can be used for logging information.

.. Warning:: logger is not multiprocessing safe.

:version: 0.3
"""
def lg(log_filename, loggername='logger'):
    """
    Sets up a logger.
@@ -297,7 +289,7 @@ def lg(log_filename, loggername='logger'):
    logger.addHandler(handler)

    return logger
##############################################################################


def IFSinformation():
    """
@@ -772,7 +764,8 @@ class StrayLight(object):
        self.PSTFn = os.path.join(self.path, "IFS_inputdata/refs/PST")
        self.RFn = os.path.join(self.path, "IFS_inputdata/refs/R")
        self.ZolFn = os.path.join(self.path, "IFS_inputdata/refs/Zodiacal")
        self.brightStarTabFn = os.path.join(self.path,"IFS_inputdata/refs/BrightGaia_with_csst_mag")
        self.brightStarTabFn = os.path.join(
            self.path, "IFS_inputdata/refs/BrightGaia_with_csst_mag")

        self.slcdll.Init(str.encode(self.deFn), str.encode(
            self.PSTFn), str.encode(self.RFn), str.encode(self.ZolFn))
@@ -1991,12 +1984,13 @@ class IFSsimulator():

        else:
            ss = '_'


        #
        #
        # ##create result father path;
        if os.path.isdir(self.information['result_path']) is False:
            os.mkdir(self.information['result_path'])
        self.result_path=os.path.join(self.information['result_path'], self.source+ss+result_day)
        self.result_path = os.path.join(
            self.information['result_path'], self.source+ss+result_day)
        print(self.result_path)

        if os.path.isdir(self.result_path) is False:
@@ -2036,7 +2030,8 @@ class IFSsimulator():
        self.HgArsigma = self.light_FWHM/2.35  # sigma value of the light source

        # load system optical and CCD efficiency data
        matfn0 = os.path.join(self.information['dir_path'],'IFS_inputdata/TotalQ200923.mat')
        matfn0 = os.path.join(
            self.information['dir_path'], 'IFS_inputdata/TotalQ200923.mat')
        self.log.info('Optical optical efficiency file path is: %s' % (matfn0))
        da0 = sio.loadmat(matfn0)
        # optical efficiency of blue channel
@@ -2047,7 +2042,8 @@ class IFSsimulator():

        # load all useful data;
        # load wavefront data;
        matfn2 = os.path.join(self.information['dir_path'],'IFS_inputdata/opd/opd_638nm.mat')
        matfn2 = os.path.join(
            self.information['dir_path'], 'IFS_inputdata/opd/opd_638nm.mat')
        self.log.info('OPD0 file path is: %s' % (matfn2))
        da2 = sio.loadmat(matfn2)
        opd0 = da2['opd']  # opd unit is in meter
@@ -2055,17 +2051,20 @@ class IFSsimulator():
        self.pupil = abs(opd0) > 0.0

        ####################
        matfn2 = os.path.join(self.information['dir_path'],'IFS_inputdata/opd/opd1.fits')
        matfn2 = os.path.join(
            self.information['dir_path'], 'IFS_inputdata/opd/opd1.fits')
        da = fits.open(matfn2)
        self.opd1 = da[0].data
        self.log.info('OPD1 file path is: %s' % (matfn2))

        matfn2 = os.path.join(self.information['dir_path'],'IFS_inputdata/opd/opd2.fits')
        matfn2 = os.path.join(
            self.information['dir_path'], 'IFS_inputdata/opd/opd2.fits')
        self.log.info('OPD2 file path is: %s' % (matfn2))
        da = fits.open(matfn2)
        self.opd2 = da[0].data

        matfn2 = os.path.join(self.information['dir_path'],'IFS_inputdata/opd/opd3.fits')
        matfn2 = os.path.join(
            self.information['dir_path'], 'IFS_inputdata/opd/opd3.fits')
        self.log.info('OPD3 file path is: %s' % (matfn2))
        da = fits.open(matfn2)
        self.opd3 = da[0].data
@@ -2452,7 +2451,6 @@ class IFSsimulator():
# #############################################################################

    def applyPoissonNoise(self):

        """
        Returns
        -------
@@ -3422,11 +3420,13 @@ class IFSsimulator():
            filename_b = 'CSST_IFS_B_'+self.source+'_'+exp_start_str + \
                '_'+exp_end_str+'_'+str(obsid)+'_B_L0_V'+sim_ver

            self.file_b = self.result_path+'/sky_Data/'+filename_b+'.fits'
            self.file_b = os.path.join(
                self.result_path, 'sky_Data/'+filename_b+'.fits')

            filename_r = 'CSST_IFS_R_'+self.source+'_'+exp_start_str + \
                '_'+exp_end_str+'_'+str(obsid)+'_R_L0_V'+sim_ver
            self.file_r = self.result_path+'/sky_Data/'+filename_r + '.fits'
            self.file_r = os.path.join(
                self.result_path, 'sky_Data/'+filename_r + '.fits')

        else:

@@ -3441,11 +3441,13 @@ class IFSsimulator():

            filename_b = 'CSST_IFS_B_'+self.source+'_'+exp_start_str + \
                '_'+exp_end_str+'_'+str(obsid)+'_B_L0_V'+sim_ver
            self.file_b = os.path.join(self.result_path,'calibration_Data/'+filename_b+'.fits')
            self.file_b = os.path.join(
                self.result_path, 'calibration_Data/'+filename_b+'.fits')

            filename_r = 'CSST_IFS_R_'+self.source+'_'+exp_start_str + \
                '_'+exp_end_str+'_'+str(obsid)+'_R_L0_V'+sim_ver
            self.file_r = os.path.join(self.result_path,'calibration_Data/'+filename_r+'.fits')
            self.file_r = os.path.join(
                self.result_path, 'calibration_Data/'+filename_r+'.fits')

        # create a new FITS file, using HDUList instance
        # #### layer 0  ####
@@ -4411,21 +4413,24 @@ class IFSsimulator():
        ################################################################
        # ########
        # #### load slicer_Qe1K.fits  ####
        slicerfile = os.path.join(self.information['dir_path'],'IFS_inputdata/Flatfield/slicer_QE_1K_230625.fits')
        slicerfile = os.path.join(
            self.information['dir_path'], 'IFS_inputdata/Flatfield/slicer_QE_1K_230625.fits')
        da = fits.open(slicerfile)
        self.log.info('hole Sim and slicer 1K QE file:%s' % (slicerfile))
        slicer_Qe = da[0].data

        # #### load hole mask ######
        # load hole mask matrix
        file = os.path.join(self.information['dir_path'], 'IFS_inputdata/Hole/holemask_230612.fits')
        file = os.path.join(
            self.information['dir_path'], 'IFS_inputdata/Hole/holemask_230612.fits')
        self.log.info('hole mask file is %s' % (file))
        da = fits.open(file)
        HoleMask = da[self.simnumber].data

        # load HgAr data;

        matfn3 = os.path.join(self.information['dir_path'],'IFS_inputdata/HgAr.mat')
        matfn3 = os.path.join(
            self.information['dir_path'], 'IFS_inputdata/HgAr.mat')
        self.log.info('lamp flux file is : %s' % (matfn3))
        da3 = sio.loadmat(matfn3)
        HgArst = da3['HgArst']  # opd unit is in meter
@@ -4674,10 +4679,11 @@ class IFSsimulator():
        data_time = now.strftime("%Y-%m-%d")
        # write the actual file

        bluefile = os.path.join(self.result_path,'original_Calibration/IFS_'+self.source + \
            '_'+data_time+'_'+str(self.simnumber)+'_B_original.fits')
        redfile = os.path.join(self.result_path,'original_Calibration/IFS_'+self.source + \
            '_'+data_time+'_'+str(self.simnumber)+'_R_original.fits')
        bluefile = os.path.join(self.result_path, 'original_Calibration/IFS_' +
                                self.source + '_' + d ata_time + '_' +
                                str(self.simnumber)+'_B_original.fits')
        redfile = os.path.join(self.result_path, 'original_Calibration/IFS_' +
                               self.source+'_'+data_time+'_'+str(self.simnumber)+'_R_original.fits')

        fits.writeto(bluefile, blue_img.array, overwrite=True)
        fits.writeto(redfile,  red_img.array,  overwrite=True)
@@ -4697,7 +4703,8 @@ class IFSsimulator():

        newd = fits.HDUList([hdu1, hdu2])

        filename = os.path.join(self.result_path,'calibration_Data/'+self.source+'_flux.fits')
        filename = os.path.join(
            self.result_path, 'calibration_Data/'+self.source+'_flux.fits')

        if self.simnumber == 1:
            newd.writeto(filename, overwrite=True)
@@ -4738,7 +4745,8 @@ class IFSsimulator():

        ############################################################################
        # consider the slice optical efficiency in different slicer channel
        slicer_QE_file = os.path.join(self.information['dir_path'],'IFS_inputdata/Flatfield/slicer_QE230625.fits')
        slicer_QE_file = os.path.join(
            self.information['dir_path'], 'IFS_inputdata/Flatfield/slicer_QE230625.fits')
        da = fits.open(slicer_QE_file)
        self.log.info('slicer_QE_file path is: %s' % (slicer_QE_file))
        slicer_Qe = da[0].data
@@ -4942,7 +4950,8 @@ class IFSsimulator():
            # orbit parameters are not in currenct txt file
            if self.orbit_pars[-1, 0] < t2jd:
                self.orbit_file_num = self.orbit_file_num+1
                fn = os.path.join(self.information['dir_path'] , 'IFS_inputdata/TianCe/orbit20160925/'+str(self.orbit_file_num)+'.txt')
                fn = os.path.join(
                    self.information['dir_path'], 'IFS_inputdata/TianCe/orbit20160925/'+str(self.orbit_file_num)+'.txt')
                self.orbit_pars = np.loadtxt(fn)
                self.orbit_exp_num = 0

@@ -5119,8 +5128,10 @@ class IFSsimulator():
                # PSFfilename='/media/yan//IFSsim/IFSsim Data/rot_shift_Img.fits'

                # fits.writeto('/media/yan//IFSsim/IFSsim Data/rot_shift_subImg.fits',image0.array[50-32:50+32,50-32:50+32],overwrite=True )
                hdu1.writeto(os.path.join(self.result_path,'shift_rot_sky/rot_shift_subImg_'+str(simnumber)+'.fits'), overwrite=True)
                fits.writeto(os.path.join(self.result_path,'shift_rot_sky/original_Img_'+str(simnumber)+'.fits'), Nimg, overwrite=True)
                hdu1.writeto(os.path.join(
                    self.result_path, 'shift_rot_sky/rot_shift_subImg_'+str(simnumber)+'.fits'), overwrite=True)
                fits.writeto(os.path.join(
                    self.result_path, 'shift_rot_sky/original_Img_'+str(simnumber)+'.fits'), Nimg, overwrite=True)

            #####################################################################
            # ## do convolve image0 with PSF0 from primay CSST  ###
@@ -5285,7 +5296,6 @@ class IFSsimulator():

                    ########################################################


        #####################################################################
        # stray light will cover 2% of input total light;
        if self.sky_noise:
@@ -5300,9 +5310,9 @@ class IFSsimulator():
        self.image_r = red_img.array

        obsid = simnumber
        bluefile = os.path.join(self.result_path,'original_sky/IFS_' + \
        bluefile = os.path.join(self.result_path, 'original_sky/IFS_' +
                                self.source+'_'+str(obsid)+'_B.fits')
        redfile = os.path.join(self.result_path,'original_sky/IFS_' + \
        redfile = os.path.join(self.result_path, 'original_sky/IFS_' +
                               self.source+'_'+str(obsid)+'_R.fits')

        fits.writeto(bluefile, blue_img.array, overwrite=True)
@@ -5333,13 +5343,15 @@ class IFSsimulator():

        # load HgAr data;
        if self.source == 'LAMP':
            matfn3 = os.path.join(self.information['dir_path'],'IFS_inputdata/HgAr.mat')
            matfn3 = os.path.join(
                self.information['dir_path'], 'IFS_inputdata/HgAr.mat')
            self.log.info('lamp flux file is : %s' % (matfn3))
            da3 = sio.loadmat(matfn3)
            HgArst = da3['HgArst']  # opd unit is in meter
        # load flat data
        if self.source == 'FLAT':
            matfn3 = os.path.join(self.information['dir_path'],'IFS_inputdata/flat_light.mat')
            matfn3 = os.path.join(
                self.information['dir_path'], 'IFS_inputdata/flat_light.mat')
            self.log.info('flat flux file is : %s' % (matfn3))
            da3 = sio.loadmat(matfn3)
            flat_light = da3['flat_light']  # opd unit is in meter
@@ -5622,10 +5634,10 @@ class IFSsimulator():
        data_time = now.strftime("%Y-%m-%d")
        # write the actual file

        bluefile = os.path.join(self.result_path,'original_Calibration/IFS_'+self.source + \
        bluefile = os.path.join(self.result_path, 'original_Calibration/IFS_'+self.source +
                                '_'+data_time+'_'+str(self.simnumber)+'_B_original.fits')

        redfile = os.path.join(self.result_path,'original_Calibration/IFS_'+self.source + \
        redfile = os.path.join(self.result_path, 'original_Calibration/IFS_'+self.source +
                               '_'+data_time+'_'+str(self.simnumber)+'_R_original.fits')

        fits.writeto(bluefile, blue_img.array, overwrite=True)
@@ -5646,7 +5658,8 @@ class IFSsimulator():

        newd = fits.HDUList([hdu1, hdu2])

        filename = os.path.join(self.result_path,'calibration_Data/'+self.source+'_flux.fits')
        filename = os.path.join(
            self.result_path, 'calibration_Data/'+self.source+'_flux.fits')

        if self.simnumber == 1:
            newd.writeto(filename, overwrite=True)
@@ -5715,7 +5728,8 @@ class IFSsimulator():
            if simnumber <= 200 and simnumber > 150:
                self.information['exptime'] = 1200

            self.skyfilepath = os.path.join(self.information['dir_path'],self.information['sky_fitsin'])
            self.skyfilepath = os.path.join(
                self.information['dir_path'], self.information['sky_fitsin'])

            print('self.skyfilepath = ', self.skyfilepath)