add_pattern_noise.py 3.72 KB
Newer Older
1
2
3
4
5
6
from numpy.random import Generator, PCG64
from ObservationSim.Instrument.Chip import ChipUtils as chip_utils
from ObservationSim.Instrument.Chip import Effects

def apply_PRNU(self, chip, filt, tel, pointing, catalog, obs_param):
    chip.img *= chip.prnu_img
7
    if self.overall_config["output_setting"]["prnu_output"] == True:
8
        chip.prnu_img.write("%s/FlatImg_PRNU_%s.fits" % (self.chip_output.subdir, str(chip.chipID).rjust(2, '0')))
9
10
11
12
    return chip, filt, tel, pointing

def add_poisson_and_dark(self, chip, filt, tel, pointing, catalog, obs_param):
    # Add dark current & Poisson noise
13
14
15
16
17
18
    # Get exposure time
    if (obs_param) and ("exptime" in obs_param) and (obs_param["exptime"] is not None):
        exptime = obs_param["exptime"]
    else:
        exptime = pointing.exp_time
    
19
    if obs_param["add_dark"] == True:
Wei Chengliang's avatar
Wei Chengliang committed
20
21
22
23
24
        chip.img, _ = chip_utils.add_poisson(img=chip.img,
                                            chip=chip,
                                            exptime=pointing.exp_time,
                                            poisson_noise=chip.poisson_noise,
                                            InputDark=None)
25
26
27
    else:
        chip.img, _ = chip_utils.add_poisson(img=chip.img, 
                                            chip=self, 
28
                                            exptime=exptime, 
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
                                            poisson_noise=chip.poisson_noise, 
                                            dark_noise=0.)
    return chip, filt, tel, pointing

def add_detector_defects(self, chip, filt, tel, pointing, catalog, obs_param):
    # Add Hot Pixels or/and Dead Pixels
    rgbadpix = Generator(PCG64(int(self.overall_config["random_seeds"]["seed_defective"]+chip.chipID)))
    badfraction = 5E-5*(rgbadpix.random()*0.5+0.7)
    chip.img = Effects.DefectivePixels(
        chip.img, 
        IfHotPix=obs_param["hot_pixels"], 
        IfDeadPix=obs_param["dead_pixels"],
        fraction=badfraction, 
        seed=self.overall_config["random_seeds"]["seed_defective"]+chip.chipID, biaslevel=0)
    # Apply Bad columns 
    if obs_param["bad_columns"] == True:
        chip.img = Effects.BadColumns(chip.img, 
                                     seed=self.overall_config["random_seeds"]["seed_badcolumns"],  
                                     chipid=chip.chipID)
    return chip, filt, tel, pointing

def add_nonlinearity(self, chip, filt, tel, pointing, catalog, obs_param):
    self.chip_output.Log_info("  Applying Non-Linearity on the chip image")
    chip.img = Effects.NonLinearity(GSImage=chip.img, 
                                   beta1=5.e-7, 
                                   beta2=0)
    return chip, filt, tel, pointing

def add_blooming(self, chip, filt, tel, pointing, catalog, obs_param):
    self.chip_output.Log_info("  Applying CCD Saturation & Blooming")
    chip.img = Effects.SaturBloom(GSImage=chip.img, 
                                 nsect_x=1, 
                                 nsect_y=1, 
                                 fullwell=int(chip.full_well))
    return chip, filt, tel, pointing

def add_bias(self, chip, filt, tel, pointing, catalog, obs_param):
    self.chip_output.Log_info("  Adding Bias level and 16-channel non-uniformity")
    if obs_param["bias_16channel"] == True:
        chip.img = Effects.AddBiasNonUniform16(chip.img, 
                                              bias_level=float(chip.bias_level), 
                                              nsecy = chip.nsecy, 
                                              nsecx=chip.nsecx, 
                                              seed=self.overall_config["random_seeds"]["seed_biasNonUniform"]+chip.chipID)
    elif obs_param["bias_16channel"] == False:
        chip.img += self.bias_level
Wei Chengliang's avatar
Wei Chengliang committed
75
    return chip, filt, tel, pointing