Commit 88aea0d6 authored by Fang Yuedong's avatar Fang Yuedong
Browse files

split sim steps into multiple files

parent 3d7404e7
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -14,7 +14,7 @@ from ObservationSim.Instrument.Chip import Effects
from ObservationSim.Instrument.Chip import ChipUtils as chip_utils
from ObservationSim._util import makeSubDir_PointingList
from ObservationSim.Astrometry.Astrometry_util import on_orbit_obs_position
from ObservationSim.SimSteps import SimSteps, SIM_STEP_TYPES
from ObservationSim.sim_steps import SimSteps, SIM_STEP_TYPES

class Observation(object):
    def __init__(self, config, Catalog, work_dir=None, data_dir=None):

ObservationSim/SimSteps.py

deleted100644 → 0
+0 −547

File deleted.

Preview size limit exceeded, changes collapsed.

+35 −0
Original line number Diff line number Diff line
import os

class SimSteps:
    def __init__(self, overall_config, chip_output, all_filters):
        self.overall_config = overall_config
        self.chip_output = chip_output
        self.all_filters = all_filters

    from .prepare_headers import prepare_headers
    from .add_sky_background import add_sky_background_sci, add_sky_flat_calibration, add_sky_background
    from .add_objects import add_objects
    from .add_cosmic_rays import add_cosmic_rays
    from .add_pattern_noise import apply_PRNU, add_poisson_and_dark, add_detector_defects, add_nonlinearity, add_blooming, add_bias
    from .add_brighter_fatter_CTE import add_brighter_fatter, apply_CTE
    from .readout_output import add_prescan_overscan, add_readout_noise, apply_gain, quantization_and_output

SIM_STEP_TYPES = {
    "scie_obs": "add_objects",
    "sky_background": "add_sky_background",
    "cosmic_rays": "add_cosmic_rays",
    "PRNU_effect": "apply_PRNU",
    "poisson_and_dark": "add_poisson_and_dark",
    "bright_fatter": "add_brighter_fatter",
    "detector_defects": "add_detector_defects",
    "nonlinearity": "add_nonlinearity",
    "blooming": "add_blooming",
    "CTE_effect": "apply_CTE",
    "prescan_overscan": "add_prescan_overscan",
    "bias": "add_bias",
    "readout_noise": "add_readout_noise",
    "gain": "apply_gain",
    "quantization_and_output": "quantization_and_output",
    "led_calib_model":"add_LED_Flat",
    "sky_flatField":"add_sky_flat_calibration",
}
 No newline at end of file
+19 −0
Original line number Diff line number Diff line
import numpy as np
from ObservationSim.MockObject import FlatLED

def add_LED_Flat(self, chip, filt, tel, pointing, catalog, obs_param):
        
    if not hasattr(self, 'h_ext'):
        _, _ = self.prepare_headers(chip=chip, pointing=pointing)
    chip_wcs = galsim.FitsWCS(header = self.h_ext)
    pf_map = np.zeros_like(chip.img.array)
    if obs_param["LED_TYPE"] is not None:
        if len(obs_param["LED_TYPE"]) != 0:
            print("LED OPEN--------")

            led_obj = FlatLED(chip, filt)

            led_flat = led_obj.drawObj_LEDFlat(led_type_list=obs_param["LED_TYPE"], exp_t_list=obs_param["LED_TIME"])
            pf_map = led_flat
    chip.img = chip.img + led_flat
    return chip, filt, tel, pointing
 No newline at end of file
+42 −0
Original line number Diff line number Diff line
import numpy as np
import galsim
from ObservationSim.Instrument.Chip import ChipUtils as chip_utils
from ObservationSim.Instrument.Chip.libCTI.CTI_modeling import CTI_sim

def add_brighter_fatter(self, chip, filt, tel, pointing, catalog, obs_param):
    chip.img = chip_utils.add_brighter_fatter(img=chip.img)
    return chip, filt, tel, pointing

def apply_CTE(self, chip, filt, tel, pointing, catalog, obs_param):
    self.chip_output.Log_info("  Apply CTE Effect")
    ### 2*8 -> 1*16 img-layout
    img = chip_utils.formatOutput(GSImage=chip.img)
    chip.nsecy = 1
    chip.nsecx = 16

    img_arr = img.array
    ny, nx = img_arr.shape
    dx = int(nx/chip.nsecx)
    dy = int(ny/chip.nsecy)
    newimg = galsim.Image(nx, int(ny+chip.overscan_y), init_value=0)
    for ichannel in range(16):
        print('\n***add CTI effects: pointing-{:} chip-{:} channel-{:}***'.format(pointing.id, chip.chipID, ichannel+1))
        noverscan, nsp, nmax = chip.overscan_y, 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 + chip.chipID*16
        release_seed = 50 + ichannel + pointing.id*30  + chip.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
    chip.img = chip_utils.formatRevert(GSImage=img)
    chip.nsecy = 2
    chip.nsecx = 8
    
    # [TODO] make overscan_y == 0
    chip.overscan_y = 0
    return chip, filt, tel, pointing
 No newline at end of file
Loading