Commit c9468014 authored by Wei Chengliang's avatar Wei Chengliang
Browse files

add CTI/1*16/prescan/overscan

parent d84594ad
Loading
Loading
Loading
Loading
+47 −2
Original line number Diff line number Diff line
@@ -15,6 +15,8 @@ from ObservationSim.Config.Header import generatePrimaryHeader, generateExtensio
from ObservationSim.Instrument._util import rotate_conterclockwise
from ObservationSim.Instrument.Chip import ChipUtils as chip_utils

from ObservationSim.Instrument.Chip.libCTI.CTI_modeling import CTI_sim

try:
    import importlib.resources as pkg_resources
except ImportError:
@@ -394,15 +396,58 @@ class Chip(FocalPlane):
            img = effects.SaturBloom(GSImage=img, nsect_x=1, nsect_y=1, fullwell=fullwell)

        # Apply CTE Effect
        ###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)

        pre1 = self.prescan_x  #27
        over1= self.overscan_x #71
        pre2 = self.prescan_y  #0 #4
        over2= self.overscan_y #84 #80

        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)
            ###img = effects.CTE_Effect(GSImage=img, threshold=27)
            ###CTI_modeling
            ### 2*8 -> 1*16 img-layout
            img = chip_utils.formatOutput(GSImage=img)
            self.nsecy = 1
            self.nsecx = 16

            img_arr = img.array
            ny, nx = img_arr.shape
            dx = int(nx/self.nsecx)
            dy = int(ny/self.nsecy)
            newimg = galsim.Image(nx, int(ny+over2), init_value=0)
            for ichannel in range(16):
                #nx,ny,noverscan,nsp,nmax = 4608,4616,84,3,10
                noverscan,nsp,nmax = over2,3,10
                beta,w,c = 0.478,84700,0
                t = np.array([0.74,7.7,37],dtype=np.float32)
                rho_trap = np.array([0.6,1.6,1.4],dtype=np.float32)
                trap_seeds = np.array([0,1000,10000],dtype=np.int32) + ichannel + self.chipID*16
                release_seed = 50 + ichannel + pointing_ID*30  + self.chipID*16
                newimg.array[:, 0+ichannel*dx:dx+ichannel*dx] = CTI_sim(img_arr[:, 0+ichannel*dx:dx+ichannel*dx],dx,dy,noverscan,nsp,nmax,beta,w,c,t,rho_trap,trap_seeds,release_seed)
            newimg.wcs = img.wcs
            del img
            img = newimg

            ### 1*16 -> 2*8 img-layout
            img = chip_utils.formatRevert(GSImage=img)
            self.nsecy = 2
            self.nsecx = 8

        ### prescan & overscan
        if config["ins_effects"]["add_prescan"] == True:
            img = chip_utils.AddPreScan(GSImage=img, pre1=27, pre2=4, over1=71, over2=80)
            chip_utils.log_info(msg="  Apply pre/over-scan", logger=self.logger)
            if config["ins_effects"]["cte_trail"] == False:
                img = chip_utils.AddPreScan(GSImage=img, pre1=pre1, pre2=pre2, over1=over1, over2=over2)
            if config["ins_effects"]["cte_trail"] == True:
                img = chip_utils.AddPreScan(GSImage=img, pre1=pre1, pre2=pre2, over1=over1, over2=0)

        ### 1*16 output
        if config["ins_effects"]["format_output"] == True:
            chip_utils.log_info(msg="  Apply 1*16 format", logger=self.logger)
            img = chip_utils.formatOutput(GSImage=img)
            self.nsecy = 1
            self.nsecx = 16
+45 −10
Original line number Diff line number Diff line
@@ -192,11 +192,10 @@ 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:
            print('--1', lib_path)
        with pkg_resources.files('ObservationSim.Instrument.Chip.libBF').joinpath("libmoduleBF.so") as 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]
    
@@ -245,27 +244,41 @@ def AddPreScan(GSImage, pre1=27, pre2=4, over1=71, over2=80, nsecy = 2, nsecx=8)

            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]
                imgtemp[pre2:pre2+dy, pre1:pre1+dx] = 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]
                imgtemp[pre2:pre2+dy, over1:over1+dx] = 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]
                imgtemp[over2:over2+dy, over1:over1+dx] = 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]
                imgtemp[over2:over2+dy, pre1:pre1+dx] = 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, :, :])
    imgtx1 = np.hstack(imgt[:nsecx:,       :, :])  #hstack chunk(1,2)-[1,2,3,4,5,6,7,8]
    imgtx2 = np.hstack(imgt[:(nsecx-1):-1, :, :])  #hstack chunk(4,3)-[16,15,14,13,12,11,,10,9]

    newimg = galsim.Image(int(nx+(pre1+over1)*nsecx), int(ny+(pre2+over2)*nsecy), init_value=0)
    newimg.array[:, :] = np.concatenate([imgtx1, imgtx2])
    newimg.array[:, :] = np.concatenate([imgtx1, imgtx2]) #vstack chunk(1,2) & chunk(4,3)

    newimg.wcs = GSImage.wcs
    return newimg

def AddPreScanFO(GSImage, pre1=27, pre2=4, over1=71, over2=80, nsecy = 1, nsecx=16):
    img= GSImage.array
    ny, nx = img.shape
    dx = int(nx/nsecx)
    dy = int(ny/nsecy)

    newimg = galsim.Image(int(nx+(pre1+over1)*nsecx), int(ny+(pre2+over2)*nsecy), init_value=0)
    for ix in range(nsecx):
        newimg.array[pre2:pre2+dy, pre1+ix*(dx+pre1+over1):pre1+dx+ix*(dx+pre1+over1)] = img[0:dy, 0+ix*dx:dx+ix*dx]

    newimg.wcs = GSImage.wcs
    return newimg


def formatOutput(GSImage, nsecy = 2, nsecx=8):
    img = GSImage.array
    ny, nx = img.shape
@@ -299,3 +312,25 @@ def formatOutput(GSImage, nsecy = 2, nsecx=8):
    newimg.array[:, :] = np.hstack([imgttx0, imgttx1, imgttx2, imgttx3])
    return newimg

def formatRevert(GSImage, nsecy = 1, nsecx=16):
    img = GSImage.array
    ny, nx = img.shape
    dx = int(nx/nsecx)
    dy = int(ny/nsecy)

    newimg = galsim.Image(int(dx*8), int(dy*2), init_value=0)

    for ix in range(0,4):
        tx = ix
        newimg.array[0:dy, 0+tx*dx:dx+tx*dx] = img[:, 0+ix*dx:dx+ix*dx]
    for ix in range(4,8):
        tx = ix
        newimg.array[0:dy, 0+tx*dx:dx+tx*dx] = img[:, 0+ix*dx:dx+ix*dx][:, ::-1]
    for ix in range(8,12):
        tx = 7-(ix-8)
        newimg.array[0+dy:dy+dy, 0+tx*dx:dx+tx*dx] = img[:, 0+ix*dx:dx+ix*dx][::-1, ::-1]
    for ix in range(12,16):
        tx = 7-(ix-8)
        newimg.array[0+dy:dy+dy, 0+tx*dx:dx+tx*dx] = img[:, 0+ix*dx:dx+ix*dx][::-1, :]

    return newimg
+18.1 KiB

File added.

No diff preview for this file type.

+10.5 KiB

File added.

No diff preview for this file type.

+19.1 KiB

File added.

No diff preview for this file type.

Loading