Commit 9811db82 authored by Yan Zhaojun's avatar Yan Zhaojun
Browse files

Edit csst_mci_sim.py

parent aa673c29
Loading
Loading
Loading
Loading
Loading
+38 −25
Original line number Diff line number Diff line
@@ -79,7 +79,8 @@ The approximate sequence of events in the simulator is as follows:
             please report any weird or inconsistent simulations to the author.

# ### update heder based on 0 data formation @ 2025.05.08;
#### update all random function code with 64bit random seed
#### update new json frmat plan file, each channel has its exptime setting @20260525
#### update all random function code with 64bit random seed @20260525

Contact Information: zhaojunyan@shao.ac.cn
########
@@ -317,7 +318,7 @@ class cosmicrays():
                            exposure time.
        """

        self.exptime = exptime
        self.exptimeC = exptime

        self.log = log
        #
@@ -473,7 +474,7 @@ class cosmicrays():
        # how many events to draw at once, too large number leads to exceeding the covering fraction
        # cr_n = int(295 * self.exptime / 565. * coveringFraction / 1.4)

        cr_n = int(5000 * self.exptime / 565. * coveringFraction)
        cr_n = int(5000 * self.exptimeC / 565. * coveringFraction)
        if cr_n < 1:
            cr_n = 1

@@ -482,7 +483,7 @@ class cosmicrays():
        while covering < coveringFraction:
            # pseudo-random numbers taken from a uniform distribution between 0 and 1
            #
            luck = self.rng_c.rand(cr_n)
            luck = self.rng_c.random(cr_n)

            # draw the length of the tracks
            ius = InterpolatedUnivariateSpline(
@@ -499,13 +500,13 @@ class cosmicrays():

            # Choose the properties such as positions and an angle from a random Uniform dist
            #
            cr_x = self.xsize * self.rng_c.rand(int(np.floor(cr_n)))
            cr_x = self.xsize * self.rng_c.random(int(np.floor(cr_n)))

            #
            cr_y = self.ysize * self.rng_c.rand(int(np.floor(cr_n)))
            cr_y = self.ysize * self.rng_c.random(int(np.floor(cr_n)))

            #
            cr_phi = np.pi * self.rng_c.rand(int(np.floor(cr_n)))
            cr_phi = np.pi * self.rng_c.random(int(np.floor(cr_n)))

            # find the intercepts
            self.cosmicrayMap += self._cosmicRayIntercepts(
@@ -2434,7 +2435,7 @@ class MCIsimulator():
                    image.setOrigin(0, 0)

                    photons.x = photons.x/image.scale
                    photonschannel.y = photons.y/image.scale
                    photons.y = photons.y/image.scale

                    # siliconsensor.accumulate(photons, image)
                    photons.addTo(image)
@@ -4321,19 +4322,19 @@ class MCIsimulator():
            (self.info['ysize'], self.info['xsize']), dtype=float)

        # cosmic ray instance
        cosmics_g = cosmicrays.cosmicrays(
            self.log, crImage, self.info['exptime'], rng, crInfo=self.cr)
        cosmics_r = cosmicrays.cosmicrays(
            self.log, crImage, self.info['exptime'], rng, crInfo=self.cr)
        cosmics_i = cosmicrays.cosmicrays(
            self.log, crImage, self.info['exptime'], rng, crInfo=self.cr)
        cosmics_g = cosmicrays(
            self.log, crImage, self.info['exptime']['g'], rng, crInfo=self.cr)
        cosmics_r = cosmicrays(
            self.log, crImage, self.info['exptime']['r'], rng, crInfo=self.cr)
        cosmics_i = cosmicrays(
            self.log, crImage, self.info['exptime']['i'], rng, crInfo=self.cr)

        CCD_cr_g = cosmics_g.addUpToFraction(
            self.info['coveringfraction']*self.info['exptime']/300.0, limit=None)
            self.info['coveringfraction']*self.info['exptime']['g']/300.0, limit=None)
        CCD_cr_r = cosmics_r.addUpToFraction(
            self.info['coveringfraction']*self.info['exptime']/300.0, limit=None)
            self.info['coveringfraction']*self.info['exptime']['r']/300.0, limit=None)
        CCD_cr_i = cosmics_i.addUpToFraction(
            self.info['coveringfraction']*self.info['exptime']/300.0, limit=None)
            self.info['coveringfraction']*self.info['exptime']['i']/300.0, limit=None)

        # paste the information
        # self.image += CCD_cr
@@ -4439,17 +4440,29 @@ class MCIsimulator():
    def addshuttereffect(self):
        ''' apply shutter effect to image'''
        #
        if self.info['exptime'] > 0:
        if self.info['exptime']['g'] > 2.6:
            self.shutter = self.ShutterEffectMat(self.image_g)

            self.shutterMat = 1-self.shutter/self.info['exptime']

            self.shutterMat = 1-self.shutter/self.info['exptime']['g']
            self.image_g *= self.shutterMat
            if self.info['simnumber'] == 1:
                fits.writeto(self.result_path+'/cali_Data/' +
                             'shutter_g.fits', self.shutter, overwrite=True)

        if self.info['exptime']['r'] > 2.6:
            self.shutter = self.ShutterEffectMat(self.image_r)
            self.shutterMat = 1-self.shutter/self.info['exptime']['r']
            self.image_r *= self.shutterMat
            if self.info['simnumber'] == 1:
                fits.writeto(self.result_path+'/cali_Data/' +
                             'shutter_r.fits', self.shutter, overwrite=True)

        if self.info['exptime']['i'] > 2.6:
            self.shutter = self.ShutterEffectMat(self.image_i)
            self.shutterMat = 1-self.shutter/self.info['exptime']['i']
            self.image_i *= self.shutterMat
            if self.info['simnumber'] == 1:
                fits.writeto(self.result_path+'/cali_Data/' +
                             'shutter.fits', self.shutter, overwrite=True)
                             'shutter_i.fits', self.shutter, overwrite=True)

        return

@@ -7384,7 +7397,7 @@ class MCIsimulator():
        if self.source in sourcelist2:
            if self.cosmicRays:

                self.addCosmicRays()
                self.addCosmicRays(self.rng)
                print('addCosmicRays finished')

        ##################################################
@@ -7403,7 +7416,7 @@ class MCIsimulator():

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

        if self.shutterEffect and self.info['exptime'] > 2.6:
        if self.shutterEffect and max(self.info['exptime']['g'], self.info['exptime']['r'], self.info['exptime']['i']) > 2.6:

            self.addshuttereffect()
            print('add shutter effect ')