add_LED_flat.py 2.19 KB
Newer Older
1
2
import numpy as np
from ObservationSim.MockObject import FlatLED
Zhang Xin's avatar
Zhang Xin committed
3
import galsim
4

5
6
7
8
9
from astropy.time import Time
from datetime import datetime, timezone

import gc

10
11
12
13
14
15
16
17
18
19
20
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)
21
            led_flat, ledstat, letts = led_obj.drawObj_LEDFlat(led_type_list=obs_param["LED_TYPE"], exp_t_list=obs_param["LED_TIME"])
22
            pf_map = led_flat
23
24
            self.updateHeaderInfo(header_flag='ext', keys = ['LEDSTAT'], values = [ledstat])
            self.updateHeaderInfo(header_flag='ext', keys = ['LEDT01','LEDT02','LEDT03','LEDT04','LEDT05','LEDT06','LEDT07','LEDT08','LEDT09','LEDT10','LEDT11','LEDT12','LEDT13','LEDT14'], values = letts)
25
        
26
27
28
29
30
31

    if obs_param["shutter_effect"] == True:
        pf_map = pf_map * chip.shutter_img
        pf_map = np.array(pf_map, dtype='float32')
        self.updateHeaderInfo(header_flag='ext', keys = ['SHTSTAT'], values = [True])
    else:
32
        self.updateHeaderInfo(header_flag='ext', keys = ['SHTSTAT','SHTOPEN0','SHTOPEN1','SHTCLOS0','SHTCLOS1'], values = [True,'','','',''])
33
34

    chip.img = chip.img + pf_map
35
36
37
38
39
40
41

    # renew header info
    datetime_obs = datetime.utcfromtimestamp(pointing.timestamp)
    datetime_obs = datetime_obs.replace(tzinfo=timezone.utc)
    t_obs = Time(datetime_obs)
    
    ##ccd刷新2s,等待0.5s,开灯后等待0.5s,开始曝光
42
    t_obs_renew = Time(t_obs.mjd - (2.) / 86400., format="mjd")
43
44
45
46

    t_obs_utc = datetime.utcfromtimestamp(np.round(datetime.utcfromtimestamp(t_obs_renew.unix).replace(tzinfo=timezone.utc).timestamp(), 1))
    self.updateHeaderInfo(header_flag='prim', keys = ['DATE-OBS'], values = [t_obs_utc.strftime("%Y-%m-%dT%H:%M:%S.%f")[:-5]])

47
48
    #dark time : 
    self.updateHeaderInfo(header_flag='ext', keys = ['DARKTIME'], values = [pointing.exp_time])
49
50

    gc.collect()
51
    return chip, filt, tel, pointing