Commit b4f212dc authored by Zhang Xin's avatar Zhang Xin
Browse files

issue17:fix led model memory bug; issue19:header time is not utc bug;...

issue17:fix led model memory bug; issue19:header time is not utc bug; issue18:header data-obs\darktime\exposure time fix by shaoli's chart;add new star catalog:C6_50sqdeg_ns.py
parent 90a73995
Loading
Loading
Loading
Loading
+526 −0

File added.

Preview size limit exceeded, changes collapsed.

+28.6 KiB

File added.

No diff preview for this file type.

+13 −8
Original line number Original line Diff line number Diff line
@@ -19,7 +19,7 @@ from astropy.time import Time
from astropy import wcs
from astropy import wcs
from ObservationSim.Config._util import get_obs_id, get_file_type
from ObservationSim.Config._util import get_obs_id, get_file_type


from datetime import datetime
from datetime import datetime, timezone
# import socket
# import socket
import platform
import platform
import toml
import toml
@@ -352,7 +352,10 @@ def generatePrimaryHeader(xlen = 9216, ylen = 9232, pointing_id = '00000001', po
    # ccdnum = str(k)
    # ccdnum = str(k)


    datetime_obs = datetime.utcfromtimestamp(time_pt)
    datetime_obs = datetime.utcfromtimestamp(time_pt)
    datetime_obs = datetime_obs.replace(tzinfo=timezone.utc)
    # print(datetime_obs.strftime("%Y-%m-%dT%H:%M:%S.%f")[:-5])
    datetime_obs = datetime.utcfromtimestamp(np.round(datetime_obs.timestamp(), 1))
    datetime_obs = datetime.utcfromtimestamp(np.round(datetime_obs.timestamp(), 1))
    # print(datetime_obs.strftime("%Y-%m-%dT%H:%M:%S.%f")[:-5])
    # date_obs = datetime_obs.strftime("%y%m%d")
    # date_obs = datetime_obs.strftime("%y%m%d")
    # time_obs = datetime_obs.strftime("%H%M%S%f")[:-5]
    # time_obs = datetime_obs.strftime("%H%M%S%f")[:-5]


@@ -551,30 +554,32 @@ def generateExtensionHeader(chip, xlen = 9216, ylen = 9232,ra = 60, dec = -40, p
    h_ext['PIXSCAL1'] = pixel_scale
    h_ext['PIXSCAL1'] = pixel_scale
    h_ext['PIXSCAL2'] = pixel_scale
    h_ext['PIXSCAL2'] = pixel_scale
    h_ext['EXPTIME'] = exptime
    h_ext['EXPTIME'] = exptime
    h_ext['DARKTIME'] = exptime + readoutTime
    h_ext['DARKTIME'] = exptime


    datetime_obs = datetime.utcfromtimestamp(timestamp)
    datetime_obs = datetime.utcfromtimestamp(timestamp)
    datetime_obs = datetime_obs.replace(tzinfo=timezone.utc)
    tstart = Time(datetime_obs)
    tstart = Time(datetime_obs)
    t_shutter_os = tstart
    t_shutter_os = tstart
    t_shutter_oe = Time(tstart.mjd + t_shutter_open / 86400., format="mjd")
    t_shutter_oe = Time(tstart.mjd + t_shutter_open / 86400., format="mjd")
    t_shutter_co = Time(tstart.mjd + exptime / 86400., format="mjd")
    t_shutter_co = Time(tstart.mjd + exptime / 86400., format="mjd")
    t_shutter_ce = Time(tstart.mjd + (exptime + t_shutter_close) / 86400., format="mjd")
    t_shutter_ce = Time(tstart.mjd + (exptime + t_shutter_close) / 86400., format="mjd")
    t_shutter_os1 = datetime.utcfromtimestamp(np.round(datetime.utcfromtimestamp(t_shutter_os.unix).timestamp(), 1))
    t_shutter_os1 = datetime.utcfromtimestamp(np.round(datetime.utcfromtimestamp(t_shutter_os.unix).replace(tzinfo=timezone.utc).timestamp(), 1))
    h_ext['SHTOPEN0'] = t_shutter_os1.strftime("%Y-%m-%dT%H:%M:%S.%f")[:-5]
    h_ext['SHTOPEN0'] = t_shutter_os1.strftime("%Y-%m-%dT%H:%M:%S.%f")[:-5]
    t_shutter_oe1 = datetime.utcfromtimestamp(np.round(datetime.utcfromtimestamp(t_shutter_oe.unix).timestamp(), 1))
    t_shutter_oe1 = datetime.utcfromtimestamp(np.round(datetime.utcfromtimestamp(t_shutter_oe.unix).replace(tzinfo=timezone.utc).timestamp(), 1))
    h_ext['SHTOPEN1'] = t_shutter_oe1.strftime("%Y-%m-%dT%H:%M:%S.%f")[:-5]
    h_ext['SHTOPEN1'] = t_shutter_oe1.strftime("%Y-%m-%dT%H:%M:%S.%f")[:-5]
    t_shutter_co1 = datetime.utcfromtimestamp(np.round(datetime.utcfromtimestamp(t_shutter_co.unix).timestamp(), 1))
    t_shutter_co1 = datetime.utcfromtimestamp(np.round(datetime.utcfromtimestamp(t_shutter_co.unix).replace(tzinfo=timezone.utc).timestamp(), 1))
    h_ext['SHTCLOS0'] = t_shutter_co1.strftime("%Y-%m-%dT%H:%M:%S.%f")[:-5]
    h_ext['SHTCLOS0'] = t_shutter_co1.strftime("%Y-%m-%dT%H:%M:%S.%f")[:-5]
    t_shutter_ce1 = datetime.utcfromtimestamp(np.round(datetime.utcfromtimestamp(t_shutter_ce.unix).timestamp(), 1))
    t_shutter_ce1 = datetime.utcfromtimestamp(np.round(datetime.utcfromtimestamp(t_shutter_ce.unix).replace(tzinfo=timezone.utc).timestamp(), 1))
    h_ext['SHTCLOS1'] = t_shutter_ce1.strftime("%Y-%m-%dT%H:%M:%S.%f")[:-5]
    h_ext['SHTCLOS1'] = t_shutter_ce1.strftime("%Y-%m-%dT%H:%M:%S.%f")[:-5]
    
    

    tstart_read = Time(tstart.mjd + exptime / 86400., format="mjd")
    tstart_read = Time(tstart.mjd + exptime / 86400., format="mjd")
    tend_read = Time(tstart.mjd + (exptime + readoutTime) / 86400., format="mjd")
    tend_read = Time(tstart.mjd + (exptime + readoutTime) / 86400., format="mjd")
    # tstart1=tstart.datetime.replace(microsecond=round(tstart.datetime.microsecond, -5))
    # tstart1=tstart.datetime.replace(microsecond=round(tstart.datetime.microsecond, -5))
    tstart1 = datetime.utcfromtimestamp(np.round(datetime.utcfromtimestamp(tstart_read.unix).timestamp(), 1))
    tstart1 = datetime.utcfromtimestamp(np.round(datetime.utcfromtimestamp(tstart_read.unix).replace(tzinfo=timezone.utc).timestamp(), 1))
    h_ext['ROTIME0'] = tstart1.strftime("%Y-%m-%dT%H:%M:%S.%f")[:-5]
    h_ext['ROTIME0'] = tstart1.strftime("%Y-%m-%dT%H:%M:%S.%f")[:-5]
    # tend_read1 = tend_read.datetime.replace(microsecond=round(tend_read.datetime.microsecond, -5))
    # tend_read1 = tend_read.datetime.replace(microsecond=round(tend_read.datetime.microsecond, -5))
    tend_read1 = datetime.utcfromtimestamp(np.round(datetime.utcfromtimestamp(tend_read.unix).timestamp(), 1))
    tend_read1 = datetime.utcfromtimestamp(np.round(datetime.utcfromtimestamp(tend_read.unix).replace(tzinfo=timezone.utc).timestamp(), 1))
    h_ext['ROTIME1'] = tend_read1.strftime("%Y-%m-%dT%H:%M:%S.%f")[:-5]
    h_ext['ROTIME1'] = tend_read1.strftime("%Y-%m-%dT%H:%M:%S.%f")[:-5]
    # h_ext['POS_ANG'] = pa
    # h_ext['POS_ANG'] = pa
    header_wcs = WCS_def(xlen=xlen, ylen=ylen, gapy=898.0, gapx1=534, gapx2=1309, ra_ref=ra, dec_ref=dec, pa=pa, pixel_scale=pixel_scale, pixel_size=pixel_size, 
    header_wcs = WCS_def(xlen=xlen, ylen=ylen, gapy=898.0, gapx1=534, gapx2=1309, ra_ref=ra, dec_ref=dec, pa=pa, pixel_scale=pixel_scale, pixel_size=pixel_size, 
+2 −0
Original line number Original line Diff line number Diff line
@@ -56,6 +56,8 @@ class CatalogBase(metaclass=ABCMeta):
            "teff":0.,
            "teff":0.,
            "logg":0.,
            "logg":0.,
            "feh":0.,
            "feh":0.,
            "DM":0.,
            "stellarMass":1.,
            # C6 galaxies parameters
            # C6 galaxies parameters
            "e1":0.,
            "e1":0.,
            "e2":0.,
            "e2":0.,
+48 −3
Original line number Original line Diff line number Diff line
@@ -11,6 +11,7 @@ from scipy.interpolate import griddata
from astropy.table import Table
from astropy.table import Table
from ObservationSim.MockObject.SpecDisperser import SpecDisperser
from ObservationSim.MockObject.SpecDisperser import SpecDisperser
from scipy import interpolate
from scipy import interpolate
import gc


from ObservationSim.MockObject.MockObject import MockObject
from ObservationSim.MockObject.MockObject import MockObject
# from ObservationSim.Straylight import calculateSkyMap_split_g
# from ObservationSim.Straylight import calculateSkyMap_split_g
@@ -96,9 +97,48 @@ class FlatLED(object):
        U = griddata(X_, Z_, (
        U = griddata(X_, Z_, (
            M[self.chip.npix_y * i:self.chip.npix_y * (i + 1), self.chip.npix_x * j:self.chip.npix_x * (j + 1)],
            M[self.chip.npix_y * i:self.chip.npix_y * (i + 1), self.chip.npix_x * j:self.chip.npix_x * (j + 1)],
            N[self.chip.npix_y * i:self.chip.npix_y * (i + 1), self.chip.npix_x * j:self.chip.npix_x * (j + 1)]),
            N[self.chip.npix_y * i:self.chip.npix_y * (i + 1), self.chip.npix_x * j:self.chip.npix_x * (j + 1)]),
                     method='cubic')
                     method='linear')
        U = U/np.mean(U)
        U = U/np.mean(U)
        flatImage = U*fluxLED[led_type]*1000
        flatImage = U*fluxLED[led_type]*1000
        gc.collect()
        return flatImage


        ###
    ### return LED flat, e/s
    ###
    def getLEDImage1(self, led_type='LED1'):
        # cwave = cwaves[led_type]
        flat = fits.open(os.path.join(self.flatDir, 'model_' + cwaves_name[led_type] + 'nm.fits'))
        xlen = flat[0].header['NAXIS1']
        ylen = 601

        i = self.chip.rowID - 1
        j = self.chip.colID - 1

        x = np.linspace(0, self.chip.npix_x, int(xlen/6.))
        y = np.linspace(0, self.chip.npix_y, int(ylen/5.))
        xx, yy = np.meshgrid(x, y)

        a1 = flat[0].data[int(ylen*i/5.):int(ylen*i/5.)+int(ylen/5.), int(xlen*j/6.):int(xlen*j/6.)+int(xlen/6.)]
        # z = np.sin((xx+yy+xx**2+yy**2))
        # fInterp = interp2d(xx, yy, z, kind='linear')

        X_ = np.hstack((xx.flatten()[:, None], yy.flatten()[:, None]))
        Z_ = a1.flatten()

        n_x = np.arange(0, self.chip.npix_x , 1)
        n_y = np.arange(0, self.chip.npix_y, 1)

        M, N = np.meshgrid(n_x, n_y)

        U = griddata(X_, Z_, (
            M[0:self.chip.npix_y, 0:self.chip.npix_x],
            N[0:self.chip.npix_y, 0:self.chip.npix_x ]),
                     method='linear')
        U = U/np.mean(U)
        flatImage = U*fluxLED[led_type]*1000
        gc.collect()
        return flatImage
        return flatImage


    def drawObj_LEDFlat_img(self, led_type_list=['LED1'], exp_t_list=[0.1]):
    def drawObj_LEDFlat_img(self, led_type_list=['LED1'], exp_t_list=[0.1]):
@@ -114,7 +154,9 @@ class FlatLED(object):
        for i in np.arange(len(led_type_list)):
        for i in np.arange(len(led_type_list)):
            led_type = led_type_list[i]
            led_type = led_type_list[i]
            exp_t = exp_t_list[i]
            exp_t = exp_t_list[i]
            unitFlatImg = self.getLEDImage(led_type=led_type)
            # unitFlatImg = self.getLEDImage(led_type=led_type)
            unitFlatImg = self.getLEDImage1(led_type=led_type)
            # print("---------------TEST mem:",np.mean(unitFlatImg))
            led_wave = cwaves[led_type]
            led_wave = cwaves[led_type]
            led_fwhm = cwaves_fwhm[led_type]
            led_fwhm = cwaves_fwhm[led_type]
            led_spec = self.gaussian1d_profile_led(led_wave, led_fwhm)
            led_spec = self.gaussian1d_profile_led(led_wave, led_fwhm)
@@ -134,6 +176,7 @@ class FlatLED(object):


            ledStat = ledStat[0:int(led_type[3:])-1]+nledStat+ledStat[int(led_type[3:]):]
            ledStat = ledStat[0:int(led_type[3:])-1]+nledStat+ledStat[int(led_type[3:]):]
            ledTimes[int(led_type[3:])-1] = exp_t * 1000
            ledTimes[int(led_type[3:])-1] = exp_t * 1000
            gc.collect()
        return ledFlat, ledStat, ledTimes
        return ledFlat, ledStat, ledTimes


    def drawObj_LEDFlat_slitless(self, led_type_list=['LED1'], exp_t_list=[0.1]):
    def drawObj_LEDFlat_slitless(self, led_type_list=['LED1'], exp_t_list=[0.1]):
@@ -150,7 +193,9 @@ class FlatLED(object):
        for i in np.arange(len(led_type_list)):
        for i in np.arange(len(led_type_list)):
            led_type = led_type_list[i]
            led_type = led_type_list[i]
            exp_t = exp_t_list[i]
            exp_t = exp_t_list[i]
            unitFlatImg = self.getLEDImage(led_type=led_type)
            # unitFlatImg = self.getLEDImage(led_type=led_type)
            unitFlatImg = self.getLEDImage1(led_type=led_type)
            # print("---------------TEST mem:",np.mean(unitFlatImg))
            ledFlat_ = unitFlatImg*exp_t
            ledFlat_ = unitFlatImg*exp_t
            ledFlat_ = ledFlat_ / mirro_eff[self.filt.filter_type]
            ledFlat_ = ledFlat_ / mirro_eff[self.filt.filter_type]
            ledFlat_.astype(np.float32)
            ledFlat_.astype(np.float32)
Loading