Commit 38e2c452 authored by Fang Yuedong's avatar Fang Yuedong
Browse files

Merge branch 'master' into 'current_stable_for_tests'

for tests before release

See merge request !23
parents e0f2b9f7 1c35c0e2
import os import os
import logging import logging
import ObservationSim.Config._util as _util import observation_sim.config._util as _util
from ObservationSim.Config.Header import generatePrimaryHeader from observation_sim.config.header import generatePrimaryHeader
class ChipOutput(object): class ChipOutput(object):
......
...@@ -5,11 +5,12 @@ import galsim ...@@ -5,11 +5,12 @@ import galsim
import numpy as np import numpy as np
from astropy.time import Time from astropy.time import Time
from ObservationSim.Config._util import get_obs_id from observation_sim.config._util import get_obs_id
import ObservationSim.Instrument._util as _util import observation_sim.instruments._util as _util
class Pointing(object): class Pointing(object):
def __init__(self, id=0, ra=0., dec=0., img_pa=0., timestamp=1621915200, sat_x=0., sat_y=0., sat_z=0., sun_x=0., sun_y=0., sun_z=0., sat_vx=0., sat_vy=0., sat_vz=0., exp_time=150., pointing_type='SCI', pointing_type_code='101', pointing_id = '00000001', obs_config_file=None, t_shutter_open = 1.3, t_shutter_close = 1.3): def __init__(self, id=0, ra=0., dec=0., img_pa=0., timestamp=1621915200, sat_x=0., sat_y=0., sat_z=0., sun_x=0., sun_y=0., sun_z=0., sat_vx=0., sat_vy=0., sat_vz=0., exp_time=150., pointing_type='SCI', pointing_type_code='101', pointing_id='00000001', obs_config_file=None, t_shutter_open=1.3, t_shutter_close=1.3):
self.id = id self.id = id
self.ra = ra self.ra = ra
self.dec = dec self.dec = dec
...@@ -23,7 +24,7 @@ class Pointing(object): ...@@ -23,7 +24,7 @@ class Pointing(object):
self.pointing_type_code = pointing_type_code self.pointing_type_code = pointing_type_code
self.obs_id = pointing_id self.obs_id = pointing_id
self.survey_field_type = 'WIDE' self.survey_field_type = 'WIDE'
self.jdt = 0. self.jdt = 0.
self.obs_config_file = obs_config_file self.obs_config_file = obs_config_file
self.t_shutter_open = t_shutter_open self.t_shutter_open = t_shutter_open
self.t_shutter_close = t_shutter_close self.t_shutter_close = t_shutter_close
...@@ -41,7 +42,6 @@ class Pointing(object): ...@@ -41,7 +42,6 @@ class Pointing(object):
if self.obs_param["obs_id"]: if self.obs_param["obs_id"]:
self.obs_id = str(self.obs_param["obs_id"]) self.obs_id = str(self.obs_param["obs_id"])
def get_full_depth_exptime(self, filter_type): def get_full_depth_exptime(self, filter_type):
if self.survey_field_type == 'WIDE': if self.survey_field_type == 'WIDE':
if filter_type in _util.SPEC_FILTERS: if filter_type in _util.SPEC_FILTERS:
...@@ -52,7 +52,7 @@ class Pointing(object): ...@@ -52,7 +52,7 @@ class Pointing(object):
elif filter_type.lower() in ['u', 'g', 'r', 'i', 'z']: elif filter_type.lower() in ['u', 'g', 'r', 'i', 'z']:
return 150. * 2 return 150. * 2
else: else:
return max(150., self.exp_time) # [TODO] for FGS return max(150., self.exp_time) # [TODO] for FGS
elif self.survey_field_type == 'DEEP': elif self.survey_field_type == 'DEEP':
if filter_type in _util.SPEC_FILTERS: if filter_type in _util.SPEC_FILTERS:
return 250. * 4 * 4 return 250. * 4 * 4
...@@ -62,8 +62,7 @@ class Pointing(object): ...@@ -62,8 +62,7 @@ class Pointing(object):
elif filter_type.lower() in ['u', 'g', 'r', 'i', 'z']: elif filter_type.lower() in ['u', 'g', 'r', 'i', 'z']:
return 250. * 2 * 4 return 250. * 2 * 4
else: else:
return max(150., self.exp_time) # [TODO] for FGS return max(150., self.exp_time) # [TODO] for FGS
def read_pointing_columns(self, columns, id=0, t=1621915200, pointing_type='SCI'): def read_pointing_columns(self, columns, id=0, t=1621915200, pointing_type='SCI'):
self.id = id self.id = id
...@@ -91,7 +90,7 @@ class Pointing(object): ...@@ -91,7 +90,7 @@ class Pointing(object):
# [TODO] Can also define other survey types # [TODO] Can also define other survey types
if is_deep != -1.0: if is_deep != -1.0:
self.survey_field_type = "DEEP" self.survey_field_type = "DEEP"
if not self.obs_config_file: if not self.obs_config_file:
self.obs_config_file = str(columns[20]) self.obs_config_file = str(columns[20])
with open(self.obs_config_file, "r") as stream: with open(self.obs_config_file, "r") as stream:
...@@ -99,7 +98,7 @@ class Pointing(object): ...@@ -99,7 +98,7 @@ class Pointing(object):
self.obs_param = yaml.safe_load(stream) self.obs_param = yaml.safe_load(stream)
except yaml.YAMLError as exc: except yaml.YAMLError as exc:
print(exc) print(exc)
self.pointing_type_code = columns[21][0:3] self.pointing_type_code = columns[21][0:3]
self.obs_id = columns[21][3:] self.obs_id = columns[21][3:]
...@@ -108,18 +107,19 @@ class Pointing(object): ...@@ -108,18 +107,19 @@ class Pointing(object):
self.timestamp = t self.timestamp = t
def make_output_pointing_dir(self, overall_config, copy_obs_config=False): def make_output_pointing_dir(self, overall_config, copy_obs_config=False):
run_dir = os.path.join(overall_config["work_dir"], overall_config["run_name"]) run_dir = os.path.join(
overall_config["work_dir"], overall_config["run_name"])
if not os.path.exists(run_dir): if not os.path.exists(run_dir):
try: try:
os.makedirs(run_dir, exist_ok=True) os.makedirs(run_dir, exist_ok=True)
except OSError: except OSError:
pass pass
self.output_prefix = get_obs_id( self.output_prefix = get_obs_id(
img_type=self.pointing_type, img_type=self.pointing_type,
project_cycle=overall_config["project_cycle"], project_cycle=overall_config["project_cycle"],
run_counter=overall_config["run_counter"], run_counter=overall_config["run_counter"],
pointing_id=self.obs_id, pointing_id=self.obs_id,
pointing_type_code = self.pointing_type_code) pointing_type_code=self.pointing_type_code)
self.output_dir = os.path.join(run_dir, self.output_prefix) self.output_dir = os.path.join(run_dir, self.output_prefix)
if not os.path.exists(self.output_dir): if not os.path.exists(self.output_dir):
try: try:
...@@ -127,10 +127,10 @@ class Pointing(object): ...@@ -127,10 +127,10 @@ class Pointing(object):
except OSError: except OSError:
pass pass
if copy_obs_config and self.obs_config_file: if copy_obs_config and self.obs_config_file:
obs_config_output_path = os.path.join(self.output_dir, os.path.basename(self.obs_config_file)) obs_config_output_path = os.path.join(
self.output_dir, os.path.basename(self.obs_config_file))
if not os.path.exists(obs_config_output_path): if not os.path.exists(obs_config_output_path):
try: try:
shutil.copy(self.obs_config_file, self.output_dir) shutil.copy(self.obs_config_file, self.output_dir)
except OSError: except OSError:
pass pass
def get_obs_id(img_type='SCI', project_cycle=6, run_counter=0, pointing_id='00000001',pointing_type_code='101'): def get_obs_id(img_type='SCI', project_cycle=6, run_counter=0, pointing_id='00000001', pointing_type_code='101'):
# obs_type = {'SCI': '01', 'BIAS': '03', 'DARK': '07', 'FLAT': '11', 'CRS': '98', 'CRD': '99'} # obs_type = {'SCI': '01', 'BIAS': '03', 'DARK': '07', 'FLAT': '11', 'CRS': '98', 'CRD': '99'}
# obs_type = {'SCIE': '01', 'BIAS': '03', 'DARK': '07', 'FLAT': '11', 'CRS': '98', 'CRD': '99', 'CAL': '01'} # obs_type = {'SCIE': '01', 'BIAS': '03', 'DARK': '07', 'FLAT': '11', 'CRS': '98', 'CRD': '99', 'CAL': '01'}
obs_id = pointing_type_code + str(int(project_cycle)).rjust(2, '0') + str(int(run_counter)) + pointing_id obs_id = pointing_type_code + \
str(int(project_cycle)).rjust(2, '0') + \
str(int(run_counter)) + pointing_id
return obs_id return obs_id
# def get_obs_id(img_type='SCI', project_cycle=6, run_counter=0, pointing_num=0):
# # obs_type = {'SCI': '01', 'BIAS': '03', 'DARK': '07', 'FLAT': '11', 'CRS': '98', 'CRD': '99'}
# obs_type = {'SCIE': '01', 'BIAS': '03', 'DARK': '07', 'FLAT': '11', 'CRS': '98', 'CRD': '99', 'CAL': '01'}
# obs_id = '1'+ obs_type[img_type] + str(int(project_cycle)).rjust(2, '0') + str(int(run_counter)) + str(pointing_num).rjust(8,'0')
# return obs_id
def get_file_type(img_type='SCI'): def get_file_type(img_type='SCI'):
file_type = {'SCI':'SCI', 'BIAS':'BIAS', 'DARK':'DARK', 'FLAT':'FLAT', 'CRS':'CRS', 'CRD':'CRD','CALS':'CALS','CALF':'CALF'} file_type = {'SCI': 'SCI', 'BIAS': 'BIAS', 'DARK': 'DARK', 'FLAT': 'FLAT',
return file_type[img_type] 'CRS': 'CRS', 'CRD': 'CRD', 'CALS': 'CALS', 'CALF': 'CALF'}
\ No newline at end of file return file_type[img_type]
...@@ -17,13 +17,14 @@ from astropy.coordinates import SkyCoord ...@@ -17,13 +17,14 @@ from astropy.coordinates import SkyCoord
from astropy.wcs.utils import fit_wcs_from_points from astropy.wcs.utils import fit_wcs_from_points
from astropy.time import Time 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 observation_sim.config._util import get_obs_id, get_file_type
from datetime import datetime, timezone from datetime import datetime, timezone
# import socket # import socket
import platform import platform
import toml import toml
def chara2digit(char): def chara2digit(char):
""" Function to judge and convert characters to digitals """ Function to judge and convert characters to digitals
...@@ -33,7 +34,7 @@ def chara2digit(char): ...@@ -33,7 +34,7 @@ def chara2digit(char):
""" """
try: try:
float(char) # for int, long and float float(char) # for int, long and float
except ValueError: except ValueError:
pass pass
return char return char
...@@ -66,41 +67,43 @@ def read_header_parameter(filename='global_header.param'): ...@@ -66,41 +67,43 @@ def read_header_parameter(filename='global_header.param'):
# print(value) # print(value)
return name, value, description return name, value, description
def rotate_CD_matrix(cd, pa_aper): def rotate_CD_matrix(cd, pa_aper):
"""Rotate CD matrix """Rotate CD matrix
Parameters Parameters
---------- ----------
cd: (2,2) array cd: (2,2) array
CD matrix CD matrix
pa_aper: float pa_aper: float
Position angle, in degrees E from N, of y axis of the detector Position angle, in degrees E from N, of y axis of the detector
Returns Returns
------- -------
cd_rot: (2,2) array cd_rot: (2,2) array
Rotated CD matrix Rotated CD matrix
Comments Comments
-------- --------
`astropy.wcs.WCS.rotateCD` doesn't work for non-square pixels in that it `astropy.wcs.WCS.rotateCD` doesn't work for non-square pixels in that it
doesn't preserve the pixel scale! The bug seems to come from the fact doesn't preserve the pixel scale! The bug seems to come from the fact
that `rotateCD` assumes a transposed version of its own CD matrix. that `rotateCD` assumes a transposed version of its own CD matrix.
""" """
rad = np.deg2rad(-pa_aper) rad = np.deg2rad(-pa_aper)
mat = np.zeros((2,2)) mat = np.zeros((2, 2))
mat[0,:] = np.array([np.cos(rad),-np.sin(rad)]) mat[0, :] = np.array([np.cos(rad), -np.sin(rad)])
mat[1,:] = np.array([np.sin(rad),np.cos(rad)]) mat[1, :] = np.array([np.sin(rad), np.cos(rad)])
cd_rot = np.dot(mat, cd) cd_rot = np.dot(mat, cd)
return cd_rot return cd_rot
def calcaluteSLSRotSkyCoor(pix_xy = None,rot_angle = 1, xlen = 9216, ylen = 9232, w = None):
def calcaluteSLSRotSkyCoor(pix_xy=None, rot_angle=1, xlen=9216, ylen=9232, w=None):
rad = np.deg2rad(rot_angle) rad = np.deg2rad(rot_angle)
mat = np.zeros((2,2)) mat = np.zeros((2, 2))
mat[0,:] = np.array([np.cos(rad),-np.sin(rad)]) mat[0, :] = np.array([np.cos(rad), -np.sin(rad)])
mat[1,:] = np.array([np.sin(rad),np.cos(rad)]) mat[1, :] = np.array([np.sin(rad), np.cos(rad)])
center = np.array([xlen/2, ylen/2]) center = np.array([xlen/2, ylen/2])
rot_pix = np.dot(mat, pix_xy-center) + center rot_pix = np.dot(mat, pix_xy-center) + center
skyCoor = w.wcs_pix2world(np.array([rot_pix]), 1) skyCoor = w.wcs_pix2world(np.array([rot_pix]), 1)
...@@ -172,10 +175,9 @@ def calcaluteSLSRotSkyCoor(pix_xy = None,rot_angle = 1, xlen = 9216, ylen = 9232 ...@@ -172,10 +175,9 @@ def calcaluteSLSRotSkyCoor(pix_xy = None,rot_angle = 1, xlen = 9216, ylen = 9232
# return name, value, description # return name, value, description
##9232 9216 898 534 1309 60 -40 -23.4333 # 9232 9216 898 534 1309 60 -40 -23.4333
def WCS_def(xlen = 9216, ylen = 9232, gapy = 898.0, gapx1 = 534, gapx2 = 1309, ra_ref = 60, dec_ref = -40, pa = -23.433, pixel_scale = 0.074, pixel_size=1e-2, def WCS_def(xlen=9216, ylen=9232, gapy=898.0, gapx1=534, gapx2=1309, ra_ref=60, dec_ref=-40, pa=-23.433, pixel_scale=0.074, pixel_size=1e-2,
rotate_chip=0., filter = 'GI', row_num = None, col_num = None, xcen = None, ycen = None): rotate_chip=0., filter='GI', row_num=None, col_num=None, xcen=None, ycen=None):
""" Creat a wcs frame for CCST with multiple extensions """ Creat a wcs frame for CCST with multiple extensions
Parameters Parameters
...@@ -189,11 +191,11 @@ def WCS_def(xlen = 9216, ylen = 9232, gapy = 898.0, gapx1 = 534, gapx2 = 1309, r ...@@ -189,11 +191,11 @@ def WCS_def(xlen = 9216, ylen = 9232, gapy = 898.0, gapx1 = 534, gapx2 = 1309, r
r_dat['CTYPE2'] = 'DEC--TAN' r_dat['CTYPE2'] = 'DEC--TAN'
r_dat['CRVAL1'] = ra_ref r_dat['CRVAL1'] = ra_ref
r_dat['CRVAL2'] = dec_ref r_dat['CRVAL2'] = dec_ref
flag_x = [0, 1, -1, 1, -1] flag_x = [0, 1, -1, 1, -1]
flag_y = [0, 1, 1, -1, -1] flag_y = [0, 1, 1, -1, -1]
flag_ext_x = [0,-1,1,-1,1] flag_ext_x = [0, -1, 1, -1, 1]
flag_ext_y = [0,-1,-1,1,1] flag_ext_y = [0, -1, -1, 1, 1]
pa_aper = pa pa_aper = pa
if (row_num is not None) and (col_num is not None): if (row_num is not None) and (col_num is not None):
...@@ -205,35 +207,42 @@ def WCS_def(xlen = 9216, ylen = 9232, gapy = 898.0, gapx1 = 534, gapx2 = 1309, r ...@@ -205,35 +207,42 @@ def WCS_def(xlen = 9216, ylen = 9232, gapy = 898.0, gapx1 = 534, gapx2 = 1309, r
detector_size_x = xlen detector_size_x = xlen
detector_size_y = ylen detector_size_y = ylen
gap_y = gapy gap_y = gapy
gap_x = [gapx1,gapx2] gap_x = [gapx1, gapx2]
gap_x1_num = 3 gap_x1_num = 3
gap_x2_num = 2 gap_x2_num = 2
y_center = (detector_size_y*y_num+gap_y*(y_num-1))/2 y_center = (detector_size_y*y_num+gap_y*(y_num-1))/2
x_center = (detector_size_x*x_num+gap_x[0]*gap_x1_num+gap_x[1]*gap_x2_num)/2 x_center = (detector_size_x*x_num +
gap_x[0]*gap_x1_num+gap_x[1]*gap_x2_num)/2
gap_x_map = np.array([[0, 0, 0, 0, 0], [gap_x[0], gap_x[1], gap_x[1], gap_x[1], gap_x[1]], [gap_x[1], gap_x[0], gap_x[0], gap_x[0], gap_x[0]], [
gap_x[0], gap_x[0], gap_x[0], gap_x[0], gap_x[0]], [gap_x[0], gap_x[0], gap_x[0], gap_x[0], gap_x[1]], [gap_x[1], gap_x[1], gap_x[1], gap_x[1], gap_x[0]]])
gap_x_map = np.array([[0,0,0,0,0],[gap_x[0],gap_x[1],gap_x[1],gap_x[1],gap_x[1]],[gap_x[1],gap_x[0],gap_x[0],gap_x[0],gap_x[0]],[gap_x[0],gap_x[0],gap_x[0],gap_x[0],gap_x[0]],[gap_x[0],gap_x[0],gap_x[0],gap_x[0],gap_x[1]],[gap_x[1],gap_x[1],gap_x[1],gap_x[1],gap_x[0]]])
j = row_num j = row_num
i = col_num i = col_num
# ccdnum = str((j-1)*5+i) # ccdnum = str((j-1)*5+i)
x_ref, y_ref = detector_size_x*i + sum(gap_x_map[0:i,j-1]) - detector_size_x/2. , (detector_size_y+gap_y)*j-gap_y-detector_size_y/2 x_ref, y_ref = detector_size_x*i + \
sum(gap_x_map[0:i, j-1]) - detector_size_x / \
for k in range(1,2): 2., (detector_size_y+gap_y)*j-gap_y-detector_size_y/2
cd = np.array([[ pixel_scale, 0], [0, pixel_scale]])/3600.*flag_x[k] for k in range(1, 2):
cd = np.array([[pixel_scale, 0], [0, pixel_scale]]) / \
3600.*flag_x[k]
cd_rot = rotate_CD_matrix(cd, pa_aper) cd_rot = rotate_CD_matrix(cd, pa_aper)
# f = open("CCD"+ccdnum.rjust(2,'0')+"_extension"+str(k)+"_wcs.param","w") # f = open("CCD"+ccdnum.rjust(2,'0')+"_extension"+str(k)+"_wcs.param","w")
r_dat['CRPIX1'] = flag_ext_x[k]*((x_ref+flag_ext_x[k]*detector_size_x/2)-x_center) r_dat['CRPIX1'] = flag_ext_x[k] * \
r_dat['CRPIX2'] = flag_ext_y[k]*((y_ref+flag_ext_y[k]*detector_size_y/2)-y_center) ((x_ref+flag_ext_x[k]*detector_size_x/2)-x_center)
r_dat['CD1_1'] = cd_rot[0,0] r_dat['CRPIX2'] = flag_ext_y[k] * \
r_dat['CD1_2'] = cd_rot[0,1] ((y_ref+flag_ext_y[k]*detector_size_y/2)-y_center)
r_dat['CD2_1'] = cd_rot[1,0] r_dat['CD1_1'] = cd_rot[0, 0]
r_dat['CD2_2'] = cd_rot[1,1] r_dat['CD1_2'] = cd_rot[0, 1]
r_dat['CD2_1'] = cd_rot[1, 0]
r_dat['CD2_2'] = cd_rot[1, 1]
if filter in ['GU', 'GV', 'GI']: if filter in ['GU', 'GV', 'GI']:
...@@ -265,12 +274,13 @@ def WCS_def(xlen = 9216, ylen = 9232, gapy = 898.0, gapx1 = 534, gapx2 = 1309, r ...@@ -265,12 +274,13 @@ def WCS_def(xlen = 9216, ylen = 9232, gapy = 898.0, gapx1 = 534, gapx2 = 1309, r
y_pixs[i_pix] = y y_pixs[i_pix] = y
pix_coor = np.array([x, y]) pix_coor = np.array([x, y])
sc1 = calcaluteSLSRotSkyCoor(pix_xy=pix_coor, rot_angle=sls_rot, xlen=xlen, ylen=ylen, w=w) sc1 = calcaluteSLSRotSkyCoor(
pix_xy=pix_coor, rot_angle=sls_rot, xlen=xlen, ylen=ylen, w=w)
# print(sc1[0,0],sc1[0,1]) # print(sc1[0,0],sc1[0,1])
sky_coors.append((sc1[0, 0], sc1[0, 1])) sky_coors.append((sc1[0, 0], sc1[0, 1]))
wcs_new = fit_wcs_from_points(xy=np.array([x_pixs, y_pixs]), wcs_new = fit_wcs_from_points(xy=np.array([x_pixs, y_pixs]),
world_coords=SkyCoord(sky_coors, frame="icrs", unit="deg"), projection='TAN') world_coords=SkyCoord(sky_coors, frame="icrs", unit="deg"), projection='TAN')
# print(wcs_new) # print(wcs_new)
# test_center = wcs_new.wcs_pix2world(np.array([[xlen / 2, ylen / 2]]), 1) # test_center = wcs_new.wcs_pix2world(np.array([[xlen / 2, ylen / 2]]), 1)
...@@ -294,12 +304,12 @@ def WCS_def(xlen = 9216, ylen = 9232, gapy = 898.0, gapx1 = 534, gapx2 = 1309, r ...@@ -294,12 +304,12 @@ def WCS_def(xlen = 9216, ylen = 9232, gapy = 898.0, gapx1 = 534, gapx2 = 1309, r
r_dat['CRPIX2'] = -y1 r_dat['CRPIX2'] = -y1
# cd = np.array([[ pixel_scale, 0], [0, pixel_scale]])/3600.*flag_x[1] # cd = np.array([[ pixel_scale, 0], [0, pixel_scale]])/3600.*flag_x[1]
cd = np.array([[ pixel_scale, 0], [0, -pixel_scale]])/3600. cd = np.array([[pixel_scale, 0], [0, -pixel_scale]])/3600.
cd_rot = rotate_CD_matrix(cd, pa_aper) cd_rot = rotate_CD_matrix(cd, pa_aper)
r_dat['CD1_1'] = cd_rot[0,0] r_dat['CD1_1'] = cd_rot[0, 0]
r_dat['CD1_2'] = cd_rot[0,1] r_dat['CD1_2'] = cd_rot[0, 1]
r_dat['CD2_1'] = cd_rot[1,0] r_dat['CD2_1'] = cd_rot[1, 0]
r_dat['CD2_2'] = cd_rot[1,1] r_dat['CD2_2'] = cd_rot[1, 1]
w = wcs.WCS(naxis=2) w = wcs.WCS(naxis=2)
w.wcs.crpix = [r_dat['CRPIX1'], r_dat['CRPIX2']] w.wcs.crpix = [r_dat['CRPIX1'], r_dat['CRPIX2']]
...@@ -320,10 +330,12 @@ def WCS_def(xlen = 9216, ylen = 9232, gapy = 898.0, gapx1 = 534, gapx2 = 1309, r ...@@ -320,10 +330,12 @@ def WCS_def(xlen = 9216, ylen = 9232, gapy = 898.0, gapx1 = 534, gapx2 = 1309, r
x_pixs[i_pix] = x x_pixs[i_pix] = x
y_pixs[i_pix] = y y_pixs[i_pix] = y
pix_coor = np.array([x, y]) pix_coor = np.array([x, y])
sc1 = calcaluteSLSRotSkyCoor(pix_xy=pix_coor, rot_angle=rotate_chip, xlen=xlen, ylen=ylen, w=w) sc1 = calcaluteSLSRotSkyCoor(
pix_xy=pix_coor, rot_angle=rotate_chip, xlen=xlen, ylen=ylen, w=w)
sky_coors.append((sc1[0, 0], sc1[0, 1])) sky_coors.append((sc1[0, 0], sc1[0, 1]))
wcs_new = fit_wcs_from_points(xy=np.array([x_pixs, y_pixs]), wcs_new = fit_wcs_from_points(xy=np.array([x_pixs, y_pixs]),
world_coords=SkyCoord(sky_coors, frame="icrs", unit="deg"), world_coords=SkyCoord(
sky_coors, frame="icrs", unit="deg"),
projection='TAN') projection='TAN')
r_dat['CD1_1'] = wcs_new.wcs.cd[0, 0] r_dat['CD1_1'] = wcs_new.wcs.cd[0, 0]
r_dat['CD1_2'] = wcs_new.wcs.cd[0, 1] r_dat['CD1_2'] = wcs_new.wcs.cd[0, 1]
...@@ -336,30 +348,31 @@ def WCS_def(xlen = 9216, ylen = 9232, gapy = 898.0, gapx1 = 534, gapx2 = 1309, r ...@@ -336,30 +348,31 @@ def WCS_def(xlen = 9216, ylen = 9232, gapy = 898.0, gapx1 = 534, gapx2 = 1309, r
r_dat['CRVAL2'] = wcs_new.wcs.crval[1] r_dat['CRVAL2'] = wcs_new.wcs.crval[1]
else: else:
raise ValueError('In function WCS_def(): Either (row_num, col_num) or (xcen, ycen, pixel_size) should be given') raise ValueError(
'In function WCS_def(): Either (row_num, col_num) or (xcen, ycen, pixel_size) should be given')
return r_dat
return r_dat
#TODO project_cycle is temporary, is not in header defined, delete in future # TODO project_cycle is temporary, is not in header defined, delete in future
def generatePrimaryHeader(xlen = 9216, ylen = 9232, pointing_id = '00000001', pointing_type_code='101', ra = 60, dec = -40, pixel_scale = 0.074, time_pt = None, im_type = 'SCI', exptime=150., sat_pos = [0.,0.,0.], sat_vel = [0., 0., 0.], project_cycle=6, run_counter=0, chip_name="01"): def generatePrimaryHeader(xlen=9216, ylen=9232, pointing_id='00000001', pointing_type_code='101', ra=60, dec=-40, pixel_scale=0.074, time_pt=None, im_type='SCI', exptime=150., sat_pos=[0., 0., 0.], sat_vel=[0., 0., 0.], project_cycle=6, run_counter=0, chip_name="01"):
# array_size1, array_size2, flux, sigma = int(argv[1]), int(argv[2]), 1000.0, 5.0 # array_size1, array_size2, flux, sigma = int(argv[1]), int(argv[2]), 1000.0, 5.0
# k = (row_num-1)*6+col_num # k = (row_num-1)*6+col_num
# 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) datetime_obs = datetime_obs.replace(tzinfo=timezone.utc)
# print(datetime_obs.strftime("%Y-%m-%dT%H:%M:%S.%f")[:-5]) # 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]) # 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]
g_header_fn = os.path.split(os.path.realpath(__file__))[0] + '/csst_msc_l0_ms.fits' g_header_fn = os.path.split(os.path.realpath(__file__))[
0] + '/csst_msc_l0_ms.fits'
f = open(os.path.split(os.path.realpath(__file__))[0] + '/filter.lst') f = open(os.path.split(os.path.realpath(__file__))[0] + '/filter.lst')
s = f.readline() s = f.readline()
s = s.strip("\n") s = s.strip("\n")
...@@ -386,7 +399,6 @@ def generatePrimaryHeader(xlen = 9216, ylen = 9232, pointing_id = '00000001', po ...@@ -386,7 +399,6 @@ def generatePrimaryHeader(xlen = 9216, ylen = 9232, pointing_id = '00000001', po
# h_card = fits.card.Card(header_toml[h_key][key]['key'],header_toml[h_key][key]['example'],header_toml[h_key][key]['comment']) # h_card = fits.card.Card(header_toml[h_key][key]['key'],header_toml[h_key][key]['example'],header_toml[h_key][key]['comment'])
# h_prim.append(h_card) # h_prim.append(h_card)
# h_prim['PIXSIZE1'] = xlen # h_prim['PIXSIZE1'] = xlen
# h_prim['PIXSIZE2'] = ylen # h_prim['PIXSIZE2'] = ylen
...@@ -404,14 +416,15 @@ def generatePrimaryHeader(xlen = 9216, ylen = 9232, pointing_id = '00000001', po ...@@ -404,14 +416,15 @@ def generatePrimaryHeader(xlen = 9216, ylen = 9232, pointing_id = '00000001', po
# # OBS_id = '1'+ obs_type[im_type] + str(int(project_cycle)) + pointNum.rjust(7,'0') # # OBS_id = '1'+ obs_type[im_type] + str(int(project_cycle)) + pointNum.rjust(7,'0')
# OBS_id = '1'+ obs_type[im_type] + str(int(project_cycle)) + str(int(run_counter)).rjust(2, '0') + pointNum.rjust(5,'0') # OBS_id = '1'+ obs_type[im_type] + str(int(project_cycle)) + str(int(run_counter)).rjust(2, '0') + pointNum.rjust(5,'0')
OBS_id = get_obs_id(img_type=im_type, project_cycle=project_cycle, run_counter=run_counter, pointing_id=pointing_id, pointing_type_code = pointing_type_code) OBS_id = get_obs_id(img_type=im_type, project_cycle=project_cycle, run_counter=run_counter,
pointing_id=pointing_id, pointing_type_code=pointing_type_code)
# h_prim['OBJECT'] = str(int(project_cycle)) + pointNum.rjust(7, '0') # h_prim['OBJECT'] = str(int(project_cycle)) + pointNum.rjust(7, '0')
h_prim['OBJECT'] = pointing_id h_prim['OBJECT'] = pointing_id
h_prim['OBSID'] = OBS_id h_prim['OBSID'] = OBS_id
# h_prim['TELFOCUS'] = 'f/14' # h_prim['TELFOCUS'] = 'f/14'
h_prim['EXPTIME'] = exptime h_prim['EXPTIME'] = exptime
# # Define file types # # Define file types
# file_type = {'SCI':'SCIE', 'BIAS':'BIAS', 'DARK':'DARK', 'FLAT':'FLAT', 'CRS':'CRS', 'CRD':'CRD','CALS':'CALS','CALF':'CALF'} # file_type = {'SCI':'SCIE', 'BIAS':'BIAS', 'DARK':'DARK', 'FLAT':'FLAT', 'CRS':'CRS', 'CRD':'CRD','CALS':'CALS','CALF':'CALF'}
# h_prim['FILETYPE'] = file_type[im_type] # h_prim['FILETYPE'] = file_type[im_type]
...@@ -420,8 +433,10 @@ def generatePrimaryHeader(xlen = 9216, ylen = 9232, pointing_id = '00000001', po ...@@ -420,8 +433,10 @@ def generatePrimaryHeader(xlen = 9216, ylen = 9232, pointing_id = '00000001', po
co = coord.SkyCoord(ra, dec, unit='deg') co = coord.SkyCoord(ra, dec, unit='deg')
ra_hms = format(co.ra.hms.h, '02.0f') + format(co.ra.hms.m, '02.0f') + format(co.ra.hms.s, '02.1f') ra_hms = format(co.ra.hms.h, '02.0f') + format(co.ra.hms.m,
dec_hms = format(co.dec.dms.d, '02.0f') + format(abs(co.dec.dms.m), '02.0f') + format(abs(co.dec.dms.s), '02.0f') '02.0f') + format(co.ra.hms.s, '02.1f')
dec_hms = format(co.dec.dms.d, '02.0f') + format(abs(co.dec.dms.m),
'02.0f') + format(abs(co.dec.dms.s), '02.0f')
if dec >= 0: if dec >= 0:
h_prim['TARGET'] = ra_hms + '+' + dec_hms h_prim['TARGET'] = ra_hms + '+' + dec_hms
else: else:
...@@ -435,8 +450,6 @@ def generatePrimaryHeader(xlen = 9216, ylen = 9232, pointing_id = '00000001', po ...@@ -435,8 +450,6 @@ def generatePrimaryHeader(xlen = 9216, ylen = 9232, pointing_id = '00000001', po
h_prim['RA_PNT1'] = ra h_prim['RA_PNT1'] = ra
h_prim['DEC_PNT1'] = dec h_prim['DEC_PNT1'] = dec
# h_prim['PIXSCAL1'] = pixel_scale # h_prim['PIXSCAL1'] = pixel_scale
# h_prim['PIXSCAL2'] = pixel_scale # h_prim['PIXSCAL2'] = pixel_scale
...@@ -452,11 +465,13 @@ def generatePrimaryHeader(xlen = 9216, ylen = 9232, pointing_id = '00000001', po ...@@ -452,11 +465,13 @@ def generatePrimaryHeader(xlen = 9216, ylen = 9232, pointing_id = '00000001', po
# file_start_time = '20' + date[0:6] + time_obs[0:6] # file_start_time = '20' + date[0:6] + time_obs[0:6]
file_start_time = datetime_obs.strftime("%Y%m%d%H%M%S") file_start_time = datetime_obs.strftime("%Y%m%d%H%M%S")
end_time_str = str(tend.datetime) end_time_str = str(tend.datetime)
file_end_time = end_time_str[0:4] + end_time_str[5:7]+end_time_str[8:10] + end_time_str[11:13] + end_time_str[14:16] + end_time_str[17:19] file_end_time = end_time_str[0:4] + end_time_str[5:7]+end_time_str[8:10] + \
end_time_str[11:13] + end_time_str[14:16] + end_time_str[17:19]
# h_prim['FILENAME'] = 'CSST_MSC_MS_' + im_type + '_' + file_start_time + '_' + file_end_time + '_' + OBS_id + '_' + CCDID[ # h_prim['FILENAME'] = 'CSST_MSC_MS_' + im_type + '_' + file_start_time + '_' + file_end_time + '_' + OBS_id + '_' + CCDID[
# k - 1].rjust(2, '0') + '_L0_V01' # k - 1].rjust(2, '0') + '_L0_V01'
h_prim['FILENAME'] = 'CSST_MSC_MS_' + h_prim['FILETYPE'] + '_' + file_start_time + '_' + file_end_time + '_' + OBS_id + '_' + chip_name + '_L0_V01' h_prim['FILENAME'] = 'CSST_MSC_MS_' + h_prim['FILETYPE'] + '_' + \
file_start_time + '_' + file_end_time + \
'_' + OBS_id + '_' + chip_name + '_L0_V01'
h_prim['POSI0_X'] = sat_pos[0] h_prim['POSI0_X'] = sat_pos[0]
h_prim['POSI0_Y'] = sat_pos[1] h_prim['POSI0_Y'] = sat_pos[1]
...@@ -467,21 +482,25 @@ def generatePrimaryHeader(xlen = 9216, ylen = 9232, pointing_id = '00000001', po ...@@ -467,21 +482,25 @@ def generatePrimaryHeader(xlen = 9216, ylen = 9232, pointing_id = '00000001', po
h_prim['VELO0_Z'] = sat_vel[2] h_prim['VELO0_Z'] = sat_vel[2]
# h_prim['RA_PNT0'] = ra_hms # h_prim['RA_PNT0'] = ra_hms
# h_prim['DEC_PNT0'] = dec_hms # h_prim['DEC_PNT0'] = dec_hms
# Get version of CSSTSim Package # Get version of CSSTSim Package
from pkg_resources import get_distribution from pkg_resources import get_distribution
# h_prim['SIM_VER'] = (get_distribution("CSSTSim").version, "Version of CSST MSC simulation software") # h_prim['SIM_VER'] = (get_distribution("CSSTSim").version, "Version of CSST MSC simulation software")
currentDateAndTime = datetime.now() currentDateAndTime = datetime.now()
compute_name = platform.node() compute_name = platform.node()
h_prim['FITSSWV'] = get_distribution("csst_msc_sim").version +'_' + currentDateAndTime.strftime("%Y%m%d") + '_' +compute_name h_prim['FITSSWV'] = get_distribution(
h_prim['EPOCH'] = round((Time(h_prim['EXPSTART'], format='mjd', scale='tcb')).jyear, 1) "csst_msc_sim").version + '_' + currentDateAndTime.strftime("%Y%m%d") + '_' + compute_name
h_prim['EPOCH'] = round(
(Time(h_prim['EXPSTART'], format='mjd', scale='tcb')).jyear, 1)
return h_prim return h_prim
def generateExtensionHeader(chip, xlen = 9216, ylen = 9232,ra = 60, dec = -40, pa = -23.433, gain = 1.0, readout = 5.0, dark = 0.02, saturation=90000, pixel_scale = 0.074, pixel_size=1e-2,
extName='SCIE', row_num = None, col_num = None, xcen=None, ycen=None, timestamp = 1621915200,exptime = 150., readoutTime = 40., t_shutter_open = 1.3, t_shutter_close = 1.3):
e_header_fn = os.path.split(os.path.realpath(__file__))[0] + '/csst_msc_l0_ms.fits' def generateExtensionHeader(chip, xlen=9216, ylen=9232, ra=60, dec=-40, pa=-23.433, gain=1.0, readout=5.0, dark=0.02, saturation=90000, pixel_scale=0.074, pixel_size=1e-2,
extName='SCIE', row_num=None, col_num=None, xcen=None, ycen=None, timestamp=1621915200, exptime=150., readoutTime=40., t_shutter_open=1.3, t_shutter_close=1.3):
e_header_fn = os.path.split(os.path.realpath(__file__))[
0] + '/csst_msc_l0_ms.fits'
f = open(os.path.split(os.path.realpath(__file__))[0] + '/filter.lst') f = open(os.path.split(os.path.realpath(__file__))[0] + '/filter.lst')
s = f.readline() s = f.readline()
s = s.strip("\n") s = s.strip("\n")
...@@ -562,28 +581,35 @@ def generateExtensionHeader(chip, xlen = 9216, ylen = 9232,ra = 60, dec = -40, p ...@@ -562,28 +581,35 @@ def generateExtensionHeader(chip, xlen = 9216, ylen = 9232,ra = 60, dec = -40, p
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(
t_shutter_os1 = datetime.utcfromtimestamp(np.round(datetime.utcfromtimestamp(t_shutter_os.unix).replace(tzinfo=timezone.utc).timestamp(), 1)) tstart.mjd + (exptime + t_shutter_close) / 86400., format="mjd")
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).replace(tzinfo=timezone.utc).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).replace(tzinfo=timezone.utc).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).replace(tzinfo=timezone.utc).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).replace(tzinfo=timezone.utc).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).replace(tzinfo=timezone.utc).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,
rotate_chip=chip.rotate_angle, filter = h_ext['FILTER'], row_num=row_num, col_num=col_num, xcen = xcen, ycen = ycen) rotate_chip=chip.rotate_angle, filter=h_ext['FILTER'], row_num=row_num, col_num=col_num, xcen=xcen, ycen=ycen)
h_ext['CRPIX1'] = header_wcs['CRPIX1'] h_ext['CRPIX1'] = header_wcs['CRPIX1']
h_ext['CRPIX2'] = header_wcs['CRPIX2'] h_ext['CRPIX2'] = header_wcs['CRPIX2']
...@@ -604,7 +630,6 @@ def generateExtensionHeader(chip, xlen = 9216, ylen = 9232,ra = 60, dec = -40, p ...@@ -604,7 +630,6 @@ def generateExtensionHeader(chip, xlen = 9216, ylen = 9232,ra = 60, dec = -40, p
return h_ext return h_ext
def main(argv): def main(argv):
xlen = int(argv[1]) xlen = int(argv[1])
...@@ -621,17 +646,17 @@ def main(argv): ...@@ -621,17 +646,17 @@ def main(argv):
dark = float(argv[12]) dark = float(argv[12])
fw = float(argv[13]) fw = float(argv[13])
h_prim = generatePrimaryHeader(xlen=xlen, ylen=ylen, ra=ra, dec=dec, psize=pSize,
row_num=ccd_row_num, col_num=ccd_col_num, pointNum=pointingNum)
h_ext = generateExtensionHeader(xlen=xlen, ylen=ylen, ra=ra, dec=dec, pa=pa_aper, gain=gain,
h_prim = generatePrimaryHeader(xlen = xlen, ylen = ylen,ra = ra, dec = dec, psize = pSize, row_num = ccd_row_num, col_num = ccd_col_num, pointNum = pointingNum) readout=readout, dark=dark, saturation=fw, psize=pSize, row_num=ccd_row_num, col_num=ccd_col_num)
h_ext = generateExtensionHeader(xlen = xlen, ylen = ylen,ra = ra, dec = dec, pa = pa_aper, gain = gain, readout = readout, dark = dark, saturation=fw, psize = pSize, row_num = ccd_row_num, col_num = ccd_col_num)
hdu1 = fits.PrimaryHDU(header=h_prim) hdu1 = fits.PrimaryHDU(header=h_prim)
hdu2 = fits.ImageHDU(np.zeros([ylen,xlen]),header = h_ext) hdu2 = fits.ImageHDU(np.zeros([ylen, xlen]), header=h_ext)
hdul = fits.HDUList([hdu1,hdu2]) hdul = fits.HDUList([hdu1, hdu2])
hdul.writeto(h_prim['FILENAME']+'.fits',output_verify='ignore') hdul.writeto(h_prim['FILENAME']+'.fits', output_verify='ignore')
# if __name__ == "__main__": # if __name__ == "__main__":
# main(sys.argv) # main(sys.argv)
...@@ -4,9 +4,9 @@ import os ...@@ -4,9 +4,9 @@ import os
import numpy as np import numpy as np
import gc import gc
import ObservationSim.Instrument._util as _util import observation_sim.instruments._util as _util
from ObservationSim.Instrument.FilterParam import FilterParam from observation_sim.instruments.FilterParam import FilterParam
from ObservationSim.Straylight import Straylight from observation_sim.sky_background import Straylight
try: try:
import importlib.resources as pkg_resources import importlib.resources as pkg_resources
...@@ -14,6 +14,7 @@ except ImportError: ...@@ -14,6 +14,7 @@ except ImportError:
# Try backported to PY<37 'importlib_resources' # Try backported to PY<37 'importlib_resources'
import importlib_resources as pkg_resources import importlib_resources as pkg_resources
class Filter(object): class Filter(object):
def __init__(self, filter_id, filter_type, filter_param, ccd_bandpass=None): def __init__(self, filter_id, filter_type, filter_param, ccd_bandpass=None):
self.filter_id = filter_id self.filter_id = filter_id
...@@ -52,57 +53,67 @@ class Filter(object): ...@@ -52,57 +53,67 @@ class Filter(object):
def _get_bandpasses(self, filter_dir=None, unit='A'): def _get_bandpasses(self, filter_dir=None, unit='A'):
if self.filter_id < 7: # Photometric if self.filter_id < 7: # Photometric
try: try:
with pkg_resources.files('ObservationSim.Instrument.data.filters').joinpath(self.filter_type.lower() + '.txt') as filter_file: with pkg_resources.files('observation_sim.instruments.data.filters').joinpath(self.filter_type.lower() + '.txt') as filter_file:
self.filter_bandpass = galsim.Bandpass(str(filter_file), wave_type=unit) self.filter_bandpass = galsim.Bandpass(
str(filter_file), wave_type=unit)
except AttributeError: except AttributeError:
with pkg_resources.path('ObservationSim.Instrument.data.filters', self.filter_type.lower() + '.txt') as filter_file: with pkg_resources.path('observation_sim.instruments.data.filters', self.filter_type.lower() + '.txt') as filter_file:
self.filter_bandpass = galsim.Bandpass(str(filter_file), wave_type=unit) self.filter_bandpass = galsim.Bandpass(
str(filter_file), wave_type=unit)
try: try:
with pkg_resources.files('ObservationSim.Instrument.data.throughputs').joinpath(self.filter_type.lower() + '_throughput.txt') as filter_file: with pkg_resources.files('observation_sim.instruments.data.throughputs').joinpath(self.filter_type.lower() + '_throughput.txt') as filter_file:
bandpass_full = galsim.Bandpass(str(filter_file), wave_type=unit) bandpass_full = galsim.Bandpass(
str(filter_file), wave_type=unit)
except AttributeError: except AttributeError:
with pkg_resources.path('ObservationSim.Instrument.data.throughputs', self.filter_type.lower() + '_throughput.txt') as filter_file: with pkg_resources.path('observation_sim.instruments.data.throughputs', self.filter_type.lower() + '_throughput.txt') as filter_file:
bandpass_full = galsim.Bandpass(str(filter_file), wave_type=unit) bandpass_full = galsim.Bandpass(
str(filter_file), wave_type=unit)
# bandpass_full = bandpass_full * self.ccd_bandpass # bandpass_full = bandpass_full * self.ccd_bandpass
# Get sub-bandpasses # Get sub-bandpasses
bandpass_sub_list = [] bandpass_sub_list = []
try: try:
with pkg_resources.files('ObservationSim.Instrument.data.filters').joinpath(self.filter_type.lower() + "_sub.list") as wave_bin_file: with pkg_resources.files('observation_sim.instruments.data.filters').joinpath(self.filter_type.lower() + "_sub.list") as wave_bin_file:
wave_points = open(wave_bin_file).read().splitlines() wave_points = open(wave_bin_file).read().splitlines()
except AttributeError: except AttributeError:
with pkg_resources.path('ObservationSim.Instrument.data.filters', self.filter_type.lower() + "_sub.list") as wave_bin_file: with pkg_resources.path('observation_sim.instruments.data.filters', self.filter_type.lower() + "_sub.list") as wave_bin_file:
wave_points = open(wave_bin_file).read().splitlines() wave_points = open(wave_bin_file).read().splitlines()
for i in range(2, len(wave_points), 2): for i in range(2, len(wave_points), 2):
blim = max(float(wave_points[i-2])*0.1, bandpass_full.blue_limit) blim = max(float(wave_points[i-2])
* 0.1, bandpass_full.blue_limit)
rlim = min(float(wave_points[i])*0.1, bandpass_full.red_limit) rlim = min(float(wave_points[i])*0.1, bandpass_full.red_limit)
if blim >= rlim: if blim >= rlim:
continue continue
bandpass = bandpass_full.truncate(blue_limit=blim, red_limit=rlim) bandpass = bandpass_full.truncate(
blue_limit=blim, red_limit=rlim)
bandpass_sub_list.append(bandpass) bandpass_sub_list.append(bandpass)
# print("num of sub-bandpasses for filter#%d(%s) = "%(self.filter_id, self.filter_type), len(bandpass_sub_list), flush=True) # print("num of sub-bandpasses for filter#%d(%s) = "%(self.filter_id, self.filter_type), len(bandpass_sub_list), flush=True)
else: # Spectroscopic else: # Spectroscopic
sls_lamb = np.linspace(self.blue_limit, self.red_limit, 100) sls_lamb = np.linspace(self.blue_limit, self.red_limit, 100)
sls_flux = np.ones_like(sls_lamb) sls_flux = np.ones_like(sls_lamb)
con_spec = galsim.LookupTable(sls_lamb, sls_flux, interpolant='nearest') con_spec = galsim.LookupTable(
sls_lamb, sls_flux, interpolant='nearest')
bandpass_full = galsim.Bandpass(con_spec, wave_type=unit) bandpass_full = galsim.Bandpass(con_spec, wave_type=unit)
bandpass_sub_list = [] bandpass_sub_list = []
try: try:
with pkg_resources.files('ObservationSim.Instrument.data.filters').joinpath(self.filter_type.lower() + "_sub.list") as wave_bin_file: with pkg_resources.files('observation_sim.instruments.data.filters').joinpath(self.filter_type.lower() + "_sub.list") as wave_bin_file:
wave_points = open(wave_bin_file).read().splitlines() wave_points = open(wave_bin_file).read().splitlines()
except AttributeError: except AttributeError:
with pkg_resources.path('ObservationSim.Instrument.data.filters', self.filter_type.lower() + "_sub.list") as wave_bin_file: with pkg_resources.path('observation_sim.instruments.data.filters', self.filter_type.lower() + "_sub.list") as wave_bin_file:
wave_points = open(wave_bin_file).read().splitlines() wave_points = open(wave_bin_file).read().splitlines()
for i in range(2, len(wave_points), 2): for i in range(2, len(wave_points), 2):
blim = max(float(wave_points[i - 2]) * 0.1, bandpass_full.blue_limit) blim = max(float(wave_points[i - 2])
rlim = min(float(wave_points[i]) * 0.1, bandpass_full.red_limit) * 0.1, bandpass_full.blue_limit)
rlim = min(float(wave_points[i])
* 0.1, bandpass_full.red_limit)
if blim >= rlim: if blim >= rlim:
continue continue
bandpass = bandpass_full.truncate(blue_limit=blim, red_limit=rlim) bandpass = bandpass_full.truncate(
blue_limit=blim, red_limit=rlim)
bandpass_sub_list.append(bandpass) bandpass_sub_list.append(bandpass)
# print("num of sub-bandpasses for filter#%d(%s) = " % (self.filter_id, self.filter_type), len(bandpass_sub_list), flush=True) # print("num of sub-bandpasses for filter#%d(%s) = " % (self.filter_id, self.filter_type), len(bandpass_sub_list), flush=True)
return bandpass_full, bandpass_sub_list return bandpass_full, bandpass_sub_list
def getPhotonE(self): def getPhotonE(self):
...@@ -111,17 +122,20 @@ class Filter(object): ...@@ -111,17 +122,20 @@ class Filter(object):
def getSkyNoise(self, exptime, gain=1.): def getSkyNoise(self, exptime, gain=1.):
return self.sky_background * exptime / gain return self.sky_background * exptime / gain
def setFilterStrayLightPixel(self,jtime = 2460843., sat_pos = np.array([0,0,0]), pointing_radec = np.array([0,0]), sun_pos = np.array([0,0,0])): def setFilterStrayLightPixel(self, jtime=2460843., sat_pos=np.array([0, 0, 0]), pointing_radec=np.array([0, 0]), sun_pos=np.array([0, 0, 0])):
sl = Straylight(jtime=jtime, sat_pos=sat_pos, pointing_radec=pointing_radec,sun_pos=sun_pos) sl = Straylight(jtime=jtime, sat_pos=sat_pos,
pointing_radec=pointing_radec, sun_pos=sun_pos)
if self.filter_type in _util.SPEC_FILTERS: if self.filter_type in _util.SPEC_FILTERS:
s_pix, spec = sl.calculateStrayLightGrating(grating = self.filter_type.upper()) s_pix, spec = sl.calculateStrayLightGrating(
if s_pix>0.8: grating=self.filter_type.upper())
if s_pix > 0.8:
s_pix = 0.8 s_pix = 0.8
self.sky_background = s_pix self.sky_background = s_pix
self.zodical_spec = spec self.zodical_spec = spec
elif self.filter_type.lower() in [x.lower for x in _util.PHOT_FILTERS]: elif self.filter_type.lower() in [x.lower for x in _util.PHOT_FILTERS]:
s_pix = sl.calculateStrayLightFilter(filter=self.filter_type.lower()) s_pix = sl.calculateStrayLightFilter(
if s_pix>1: filter=self.filter_type.lower())
if s_pix > 1:
s_pix = 1 s_pix = 1
self.sky_background = s_pix self.sky_background = s_pix
self.zodical_spec = None self.zodical_spec = None
...@@ -144,6 +158,8 @@ class Filter(object): ...@@ -144,6 +158,8 @@ class Filter(object):
full_well = 90000 full_well = 90000
throughput_file = self.filter_type.lower() + '_throughput.txt' throughput_file = self.filter_type.lower() + '_throughput.txt'
self.mag_limiting, self.mag_saturation = _util.calculateLimitMag(psf_fwhm=psf_fwhm, pixelSize=pix_scale, throughputFn=throughput_file, readout=5.0, skyFn=skyFn, darknoise=dark_noise, exTime=exptime, fw=full_well) self.mag_limiting, self.mag_saturation = _util.calculateLimitMag(
psf_fwhm=psf_fwhm, pixelSize=pix_scale, throughputFn=throughput_file, readout=5.0, skyFn=skyFn, darknoise=dark_noise, exTime=exptime, fw=full_well)
print("for filter %s: mag_limiting: %.3f, mag_saturation: %.3f"%(self.filter_type, self.mag_limiting, self.mag_saturation)) print("for filter %s: mag_limiting: %.3f, mag_saturation: %.3f" %
(self.filter_type, self.mag_limiting, self.mag_saturation))
import galsim import galsim
import numpy as np import numpy as np
class FilterParam(object): class FilterParam(object):
def __init__(self, filter_dir=None, filter_param=None): def __init__(self, filter_dir=None, filter_param=None):
self.param = self._filtParam(filter_param) self.param = self._filtParam(filter_param)
...@@ -14,7 +15,7 @@ class FilterParam(object): ...@@ -14,7 +15,7 @@ class FilterParam(object):
TODO: subject to change TODO: subject to change
Basic parameters of the CSSOS filters. Basic parameters of the CSSOS filters.
""" """
# filter parameters: name: # filter parameters: name:
# 1) effective wavelength # 1) effective wavelength
# 2) effective width # 2) effective width
# 3) blue end # 3) blue end
...@@ -26,19 +27,20 @@ class FilterParam(object): ...@@ -26,19 +27,20 @@ class FilterParam(object):
# 8) dim end magnitude # 8) dim end magnitude
if filter_param == None: if filter_param == None:
filtP = { filtP = {
"NUV": [2867.7, 705.4, 2470.0, 3270.0, 0.1404, 0.004, 15.7, 25.4], "NUV": [2867.7, 705.4, 2470.0, 3270.0, 0.1404, 0.004, 15.7, 25.4],
"u": [3601.1, 852.1, 3120.0, 4090.0, 0.2176, 0.021, 16.1, 25.4], "u": [3601.1, 852.1, 3120.0, 4090.0, 0.2176, 0.021, 16.1, 25.4],
"g": [4754.5, 1569.8, 3900.0, 5620.0, 0.4640, 0.164, 17.2, 26.3], "g": [4754.5, 1569.8, 3900.0, 5620.0, 0.4640, 0.164, 17.2, 26.3],
"r": [6199.8, 1481.2, 5370.0, 7030.0, 0.5040, 0.207, 17.0, 26.0], "r": [6199.8, 1481.2, 5370.0, 7030.0, 0.5040, 0.207, 17.0, 26.0],
"i": [7653.2, 1588.1, 6760.0, 8550.0, 0.4960, 0.212, 16.7, 25.9], "i": [7653.2, 1588.1, 6760.0, 8550.0, 0.4960, 0.212, 16.7, 25.9],
"z": [9600.6, 2490.5, 8240.0, 11000.0, 0.2000, 0.123, 15.7, 25.2], "z": [9600.6, 2490.5, 8240.0, 11000.0, 0.2000, 0.123, 15.7, 25.2],
"y": [10051.0, 1590.6, 9130.0, 11000.0, 0.0960, 0.037, 14.4, 24.4], "y": [10051.0, 1590.6, 9130.0, 11000.0, 0.0960, 0.037, 14.4, 24.4],
"FGS": [5000.0, 8000.0, 3000.0, 11000.0, 0.6500, 0.164, 0., 30.], # [TODO] # [TODO]
"FGS": [5000.0, 8000.0, 3000.0, 11000.0, 0.6500, 0.164, 0., 30.],
"GU": [0.0, 0.0, 2550.0, 4200.0, 1.0, 0.037, 14.0, 26.0],
"GV": [0.0, 0.0, 4000.0, 6500.0, 1.0, 0.037, 14.0, 26.0], "GU": [0.0, 0.0, 2550.0, 4200.0, 1.0, 0.037, 14.0, 26.0],
"GI": [0.0, 0.0, 6200.0, 10000.0, 1.0, 0.037, 14.0, 26.0], "GV": [0.0, 0.0, 4000.0, 6500.0, 1.0, 0.037, 14.0, 26.0],
} "GI": [0.0, 0.0, 6200.0, 10000.0, 1.0, 0.037, 14.0, 26.0],
}
else: else:
filtP = filter_param filtP = filter_param
...@@ -48,10 +50,10 @@ class FilterParam(object): ...@@ -48,10 +50,10 @@ class FilterParam(object):
""" """
read filters and save into Python dictionary read filters and save into Python dictionary
NOTE: the wavelength unit must be in "Angstrom" NOTE: the wavelength unit must be in "Angstrom"
Parameters: Parameters:
Same as function 'seds' Same as function 'seds'
Return: Return:
Same as function 'seds' Same as function 'seds'
""" """
...@@ -65,9 +67,10 @@ class FilterParam(object): ...@@ -65,9 +67,10 @@ class FilterParam(object):
ifiltn = filtdir+itype+".dat" ifiltn = filtdir+itype+".dat"
iblim = filtParams[itype][2] iblim = filtParams[itype][2]
irlim = filtParams[itype][3] irlim = filtParams[itype][3]
ifilt = galsim.Bandpass(ifiltn,wave_type=unit,blue_limit=iblim,red_limit=irlim) ifilt = galsim.Bandpass(
wave = ifilt.wave_list ifiltn, wave_type=unit, blue_limit=iblim, red_limit=irlim)
wave = ifilt.wave_list
ifilt = ifilt.func(wave) ifilt = ifilt.func(wave)
filts[itype] = np.transpose(np.array([wave*10.0,ifilt])) filts[itype] = np.transpose(np.array([wave*10.0, ifilt]))
return filtype, filts return filtype, filts
\ No newline at end of file
...@@ -40,18 +40,6 @@ class FocalPlane(object): ...@@ -40,18 +40,6 @@ class FocalPlane(object):
for i in range(1, 31): for i in range(1, 31):
self.ignore_chips.append(i) self.ignore_chips.append(i)
# if config is not None:
# self.nchip_x = config["nchip_x"]
# self.nchip_y = config["nchip_y"]
# self.npix_tot_x = config["npix_tot_x"]
# self.npix_tot_y = config["npix_tot_y"]
# self.npix_gap_x = config["npix_gap_x"]
# self.npix_gap_y = config["npix_gap_y"]
# if "chipLabelIDs" in config:
# self.chipLabelIDs = config["chipLabelIDs"]
# if "bad_chips" in config:
# self.bad_chips = config["bad_chips"]
# else:
self.nchip_x = 6 self.nchip_x = 6
self.nchip_y = 5 self.nchip_y = 5
self.npix_tot_x = 59516 self.npix_tot_x = 59516
...@@ -95,10 +83,6 @@ class FocalPlane(object): ...@@ -95,10 +83,6 @@ class FocalPlane(object):
if (xcen == None) or (ycen == None): if (xcen == None) or (ycen == None):
xcen = self.cen_pix_x xcen = self.cen_pix_x
ycen = self.cen_pix_y ycen = self.cen_pix_y
# dudx = -np.cos(img_rot.rad) * pix_scale
# dudy = -np.sin(img_rot.rad) * pix_scale
# dvdx = -np.sin(img_rot.rad) * pix_scale
# dvdy = +np.cos(img_rot.rad) * pix_scale
dudx = -np.cos(img_rot.rad) * pix_scale dudx = -np.cos(img_rot.rad) * pix_scale
dudy = +np.sin(img_rot.rad) * pix_scale dudy = +np.sin(img_rot.rad) * pix_scale
......
import numpy as np
try:
import importlib.resources as pkg_resources
except ImportError:
# Try backported to PY<37 'importlib_resources'
import importlib_resources as pkg_resources
class Telescope(object):
def __init__(self, param=None, optEffCurve_path=None):
self.diameter = 2.0 # in unit of meter
if param is not None:
self.diameter = param["diameter"]
self.pupil_area = np.pi * (0.5 * self.diameter)**2
if optEffCurve_path is not None:
self.efficiency = self._get_efficiency(optEffCurve_path)
else:
try:
with pkg_resources.files('observation_sim.instruments.data').joinpath('mirror_ccdnote.txt') as optEffCurve_path:
self.efficiency = self._get_efficiency(optEffCurve_path)
except AttributeError:
with pkg_resources.path('observation_sim.instruments.data', 'mirror_ccdnote.txt') as optEffCurve_path:
self.efficiency = self._get_efficiency(optEffCurve_path)
def _get_efficiency(self, effCurve_path):
""" Read in the efficiency of optics
for each band
Parameters:
effCurve_path: the path for efficiency file
Returns:
opticsEff: a dictionary of efficiency (a scalar) for each band
"""
f = open(effCurve_path, 'r')
for _ in range(2):
header = f.readline()
iline = 0
opticsEff = {}
for line in f:
line = line.strip()
columns = line.split()
opticsEff[str(columns[0])] = float(columns[2])
f.close()
return opticsEff
...@@ -2,4 +2,4 @@ from .Telescope import Telescope ...@@ -2,4 +2,4 @@ from .Telescope import Telescope
from .Filter import Filter from .Filter import Filter
from .FilterParam import FilterParam from .FilterParam import FilterParam
from .FocalPlane import FocalPlane from .FocalPlane import FocalPlane
from .Chip import Chip from .chip import Chip
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment