Commit 663e096c authored by Zhang Xin's avatar Zhang Xin
Browse files

Initial commit

parents
File added
"""
generate image header
"""
import numpy as np
from astropy.io import fits
import astropy.wcs as pywcs
from collections import OrderedDict
# from scipy import math
import random
import os
import sys
import astropy.coordinates as coord
from astropy.coordinates import SkyCoord
from astropy.wcs.utils import fit_wcs_from_points
from astropy.time import Time
from astropy import wcs
from datetime import datetime
# import socket
import platform
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 = {'SCI': '01', 'BIAS': '03', 'DARK': '07', 'FLAT': '11', 'CRS': '98', 'CRD': '99', 'CAL': '01'}
# obs_id = '1'+ obs_type[img_type] + str(int(project_cycle)) + str(int(run_counter)).rjust(2, '0') + str(pointing_num).rjust(5,'0')
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'):
file_type = {'SCI':'SCIE', 'BIAS':'BIAS', 'DARK':'DARK', 'FLAT':'FLAT', 'CRS':'CRS', 'CRD':'CRD','CALS':'CALS','CALF':'CALF'}
return file_type[img_type]
def chara2digit(char):
""" Function to judge and convert characters to digitals
Parameters
----------
"""
try:
float(char) # for int, long and float
except ValueError:
pass
return char
else:
data = float(char)
return data
def read_header_parameter(filename='global_header.param'):
""" Function to read the header parameters
Parameters
----------
"""
name = []
value = []
description = []
for line in open(filename):
line = line.strip("\n")
arr = line.split('|')
# csvReader = csv.reader(csvDataFile)
# for arr in csvReader:
name.append(arr[0])
# print(arr[0],arr[1])
value.append(chara2digit(arr[1]))
description.append(arr[2])
# print(value)
return name, value, description
def rotate_CD_matrix(cd, pa_aper):
"""Rotate CD matrix
Parameters
----------
cd: (2,2) array
CD matrix
pa_aper: float
Position angle, in degrees E from N, of y axis of the detector
Returns
-------
cd_rot: (2,2) array
Rotated CD matrix
Comments
--------
`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
that `rotateCD` assumes a transposed version of its own CD matrix.
"""
rad = np.deg2rad(-pa_aper)
mat = np.zeros((2,2))
mat[0,:] = np.array([np.cos(rad),-np.sin(rad)])
mat[1,:] = np.array([np.sin(rad),np.cos(rad)])
cd_rot = np.dot(mat, cd)
return cd_rot
def calcaluteSLSRotSkyCoor(pix_xy = None,rot_angle = 1, xlen = 9216, ylen = 9232, w = None):
rad = np.deg2rad(rot_angle)
mat = np.zeros((2,2))
mat[0,:] = np.array([np.cos(rad),-np.sin(rad)])
mat[1,:] = np.array([np.sin(rad),np.cos(rad)])
center = np.array([xlen/2, ylen/2])
rot_pix = np.dot(mat, pix_xy-center) + center
skyCoor = w.wcs_pix2world(np.array([rot_pix]), 1)
return skyCoor
# def Header_extention(xlen = 9216, ylen = 9232, gain = 1.0, readout = 5.0, dark = 0.02,saturation=90000, row_num = 1, col_num = 1):
#
# """ Creat an image frame for CCST with multiple extensions
#
# Parameters
# ----------
#
# """
#
# flag_ltm_x = [0,1,-1,1,-1]
# flag_ltm_y = [0,1,1,-1,-1]
# flag_ltv_x = [0,0,1,0,1]
# flag_ltv_y = [0,0,0,1,1]
#
# detector_size_x = int(xlen)
# detector_size_y = int(ylen)
#
# data_x = str(int(detector_size_x))
# data_y = str(int(detector_size_y))
#
# data_sec = '[1:'+data_x+',1:'+data_y+']'
# e_header_fn = os.path.split(os.path.realpath(__file__))[0] + '/extension_header.param'
# name, value, description = read_header_parameter(e_header_fn)
# f = open(os.path.split(os.path.realpath(__file__))[0] + '/filter.lst')
# s = f.readline()
# s = s.strip("\n")
# filters = s.split(' ')
# s = f.readline()
# s = s.strip("\n")
# filterID = s.split()
#
# s = f.readline()
# s = s.strip("\n")
# CCDID = s.split()
#
# k = (row_num-1)*6+col_num
#
# h_iter = 0
# for n1,v1,d1 in zip(name, value, description):
# if n1=='EXTNAME':
# value[h_iter] = 'RAW,'+CCDID[k-1].rjust(2,'0')
# if n1=='CCDNAME':
# value[h_iter] = 'ccd' + CCDID[k-1].rjust(2,'0')
# if n1=='AMPNAME':
# value[h_iter] = 'ccd' + CCDID[k-1].rjust(2,'0') + ':A'
# if n1=='GAIN':
# value[h_iter] = gain
# if n1=='RDNOISE':
# value[h_iter] = readout
# if n1=='SATURATE':
# value[h_iter] = saturation
# if n1=='CCDCHIP':
# value[h_iter] = 'ccd' + CCDID[k-1].rjust(2,'0')
# if n1=='CCDLABEL':
# value[h_iter] = filters[k-1] + '-' + filterID[k-1]
# if n1=='DATASEC':
# value[h_iter] = data_sec
#
# h_iter = h_iter + 1
#
#
# return name, value, description
##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,
rotate_chip=0., filter = 'GI', row_num = None, col_num = None, xcen = None, ycen = None):
""" Creat a wcs frame for CCST with multiple extensions
Parameters
----------
"""
r_dat = OrderedDict()
r_dat['EQUINOX'] = 2000.0
r_dat['WCSDIM'] = 2.0
r_dat['CTYPE1'] = 'RA---TAN'
r_dat['CTYPE2'] = 'DEC--TAN'
r_dat['CRVAL1'] = ra_ref
r_dat['CRVAL2'] = dec_ref
flag_x = [0, 1, -1, 1, -1]
flag_y = [0, 1, 1, -1, -1]
flag_ext_x = [0,-1,1,-1,1]
flag_ext_y = [0,-1,-1,1,1]
pa_aper = pa
if (row_num is not None) and (col_num is not None):
x_num = 6
y_num = 5
detector_num = x_num*y_num
detector_size_x = xlen
detector_size_y = ylen
gap_y = gapy
gap_x = [gapx1,gapx2]
gap_x1_num = 3
gap_x2_num = 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
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
i = col_num
# 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
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)
# 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['CRPIX2'] = flag_ext_y[k]*((y_ref+flag_ext_y[k]*detector_size_y/2)-y_center)
r_dat['CD1_1'] = cd_rot[0,0]
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']:
w = wcs.WCS(naxis=2)
w.wcs.crpix = [r_dat['CRPIX1'], r_dat['CRPIX2']]
w.wcs.cd = cd_rot
w.wcs.crval = [ra_ref, dec_ref]
w.wcs.ctype = [r_dat['CTYPE1'], r_dat['CTYPE2']]
# test_center_o = w.wcs_pix2world(np.array([[xlen / 2, ylen / 2]]), 1)
sls_rot = 1
if i > 2:
sls_rot = -sls_rot
sn_x = 30
sn_y = 30
x_pixs = np.zeros(sn_y * sn_x)
y_pixs = np.zeros(sn_y * sn_x)
xpixs_line = np.linspace(1, xlen, sn_x)
ypixs_line = np.linspace(1, ylen, sn_y)
sky_coors = []
for n1, y in enumerate(ypixs_line):
for n2, x in enumerate(xpixs_line):
i_pix = n1 * sn_x + n2
x_pixs[i_pix] = x
y_pixs[i_pix] = y
pix_coor = np.array([x, y])
sc1 = calcaluteSLSRotSkyCoor(pix_xy=pix_coor, rot_angle=sls_rot, xlen=xlen, ylen=ylen, w=w)
# print(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]),
world_coords=SkyCoord(sky_coors, frame="icrs", unit="deg"), projection='TAN')
# print(wcs_new)
# test_center = wcs_new.wcs_pix2world(np.array([[xlen / 2, ylen / 2]]), 1)
#
# print(test_center - test_center_o)
r_dat['CD1_1'] = wcs_new.wcs.cd[0, 0]
r_dat['CD1_2'] = wcs_new.wcs.cd[0, 1]
r_dat['CD2_1'] = wcs_new.wcs.cd[1, 0]
r_dat['CD2_2'] = wcs_new.wcs.cd[1, 1]
r_dat['CRPIX1'] = wcs_new.wcs.crpix[0]
r_dat['CRPIX2'] = wcs_new.wcs.crpix[1]
r_dat['CRVAL1'] = wcs_new.wcs.crval[0]
r_dat['CRVAL2'] = wcs_new.wcs.crval[1]
elif (xcen is not None) and (ycen is not None):
xcen, ycen = xcen/pixel_size, ycen/pixel_size
x1, y1 = xcen - xlen/2., ycen - ylen/2.
r_dat['CRPIX1'] = -x1
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.
cd_rot = rotate_CD_matrix(cd, pa_aper)
r_dat['CD1_1'] = cd_rot[0,0]
r_dat['CD1_2'] = cd_rot[0,1]
r_dat['CD2_1'] = cd_rot[1,0]
r_dat['CD2_2'] = cd_rot[1,1]
w = wcs.WCS(naxis=2)
w.wcs.crpix = [r_dat['CRPIX1'], r_dat['CRPIX2']]
w.wcs.cd = cd_rot
w.wcs.crval = [ra_ref, dec_ref]
w.wcs.ctype = [r_dat['CTYPE1'], r_dat['CTYPE2']]
sn_x = 30
sn_y = 30
x_pixs = np.zeros(sn_y * sn_x)
y_pixs = np.zeros(sn_y * sn_x)
xpixs_line = np.linspace(1, xlen, sn_x)
ypixs_line = np.linspace(1, ylen, sn_y)
sky_coors = []
for n1, y in enumerate(ypixs_line):
for n2, x in enumerate(xpixs_line):
i_pix = n1 * sn_x + n2
x_pixs[i_pix] = x
y_pixs[i_pix] = y
pix_coor = np.array([x, y])
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]))
wcs_new = fit_wcs_from_points(xy=np.array([x_pixs, y_pixs]),
world_coords=SkyCoord(sky_coors, frame="icrs", unit="deg"),
projection='TAN')
r_dat['CD1_1'] = wcs_new.wcs.cd[0, 0]
r_dat['CD1_2'] = wcs_new.wcs.cd[0, 1]
r_dat['CD2_1'] = wcs_new.wcs.cd[1, 0]
r_dat['CD2_2'] = wcs_new.wcs.cd[1, 1]
r_dat['CRPIX1'] = wcs_new.wcs.crpix[0]
r_dat['CRPIX2'] = wcs_new.wcs.crpix[1]
r_dat['CRVAL1'] = wcs_new.wcs.crval[0]
r_dat['CRVAL2'] = wcs_new.wcs.crval[1]
else:
raise ValueError('In function WCS_def(): Either (row_num, col_num) or (xcen, ycen, pixel_size) should be given')
return r_dat
#TODO project_cycle is temporary, is not in header defined, delete in future
def generatePrimaryHeader(xlen = 9216, ylen = 9232, pointNum = '1', ra = 60, dec = -40, pixel_scale = 0.074, date='200930', time_obs='120000', im_type = 'MS', 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
# k = (row_num-1)*6+col_num
# ccdnum = str(k)
g_header_fn = 'global_header.header'
f = open('filter.lst')
s = f.readline()
s = s.strip("\n")
filters = s.split(' ')
s = f.readline()
s = s.strip("\n")
filterID = s.split()
s = f.readline()
s = s.strip("\n")
CCDID = s.split()
h_prim = fits.Header()
h_prim = fits.Header.fromfile(g_header_fn)
# h_prim['PIXSIZE1'] = xlen
# h_prim['PIXSIZE2'] = ylen
h_prim['DATE'] = '20'+date[0:2]+'-' + date[2:4]+'-'+date[4:6] + 'T' + time_obs[0:2]+':'+time_obs[2:4]+':'+time_obs[4:6]
# h_prim['TIME'] = time_obs[0:2]+':'+time_obs[2:4]+':'+time_obs[4:6]
h_prim['DATE-OBS'] = '20'+date[0:2]+'-' + date[2:4]+'-'+date[4:6] + 'T' + time_obs[0:2]+':'+time_obs[2:4]+':'+time_obs[4:6]
# h_prim['TIME-OBS'] = time_obs[0:2]+':'+time_obs[2:4]+':'+time_obs[4:6]
# h_prim['DETECTOR'] = 'CHIP'+CCDID[k-1].rjust(2,'0')
h_prim['OBJ_RA'] = ra
h_prim['OBJ_DEC'] = dec
# obs_type = {'SCI': '01', 'BIAS': '03', 'DARK': '07', 'FLAT': '11', 'CRS': '98', 'CRD': '99'}
# # 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 = get_obs_id(img_type=im_type, project_cycle=project_cycle, run_counter=run_counter, pointing_num=pointNum)
h_prim['OBJECT'] = str(int(project_cycle)) + pointNum.rjust(7, '0')
h_prim['OBSID'] = OBS_id
# h_prim['TELFOCUS'] = 'f/14'
h_prim['EXPTIME'] = exptime
# # Define file types
# 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'] = get_file_type(img_type=im_type)
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.0f')
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')
h_prim['TARGET'] = ra_hms + '+' + dec_hms
#
# h_prim['RA_NOM'] = ra_hms
# h_prim['DEC_NOM'] = dec_hms
h_prim['RA_PNT0'] = ra
h_prim['DEC_PNT0'] = dec
h_prim['RA_PNT1'] = ra
h_prim['DEC_PNT1'] = dec
# h_prim['PIXSCAL1'] = pixel_scale
# h_prim['PIXSCAL2'] = pixel_scale
ttt = h_prim['DATE']
tstart = Time(ttt)
h_prim['EXPSTART'] = round(tstart.mjd, 5)
h_prim['CABSTART'] = h_prim['EXPSTART']
# tend = Time(tstart.cxcsec + h_prim['EXPTIME'], format="cxcsec")
tend = Time(tstart.mjd + h_prim['EXPTIME']/86400., format="mjd")
h_prim['EXPEND'] = round(tend.mjd, 5)
h_prim['CABEND'] = h_prim['EXPEND']
file_start_time = '20' + date[0:6] + time_obs[0:6]
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]
# h_prim['FILENAME'] = 'CSST_MSC_MS_' + im_type + '_' + file_start_time + '_' + file_end_time + '_' + OBS_id + '_' + CCDID[
# 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['POSI0_X'] = sat_pos[0]
h_prim['POSI0_Y'] = sat_pos[1]
h_prim['POSI0_Z'] = sat_pos[2]
h_prim['VELO0_X'] = sat_vel[0]
h_prim['VELO0_Y'] = sat_vel[1]
h_prim['VELO0_Z'] = sat_vel[2]
# h_prim['RA_PNT0'] = ra_hms
# h_prim['DEC_PNT0'] = dec_hms
# Get version of CSSTSim Package
from pkg_resources import get_distribution
# h_prim['SIM_VER'] = (get_distribution("CSSTSim").version, "Version of CSST MSC simulation software")
currentDateAndTime = datetime.now()
compute_name = platform.node()
h_prim['FITSCREA'] = get_distribution("CSSTSim").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
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='SCI', row_num = None, col_num = None, xcen=None, ycen=None, timestamp = 1621915200,exptime = 150., readoutTime = 40.):
e_header_fn = 'extension_header.header'
f = open('filter.lst')
s = f.readline()
s = s.strip("\n")
filters = s.split(' ')
s = f.readline()
s = s.strip("\n")
filterID = s.split()
s = f.readline()
s = s.strip("\n")
CCDID = s.split()
# k = (row_num - 1) * 6 + col_num
h_ext = fits.Header.fromfile(e_header_fn)
# h_ext['CCDCHIP'] = CCDID[k - 1].rjust(2, '0')
# h_ext['CCDLABEL'] = filters[k-1] + '-' + filterID[k-1]
# h_ext['FILTER'] = filters[k-1]
h_ext['CHIPID'] = str(chip.chipID).rjust(2, '0')
h_ext['CHIPLAB'] = chip.chip_name
h_ext['FILTER'] = chip.filter_type
h_ext['NAXIS1'] = xlen
h_ext['NAXIS2'] = ylen
h_ext['EXTNAME'] = extName
h_ext['GAIN01'] = 1
h_ext['GAIN02'] = 1
h_ext['GAIN03'] = 1
h_ext['GAIN04'] = 1
h_ext['GAIN05'] = 1
h_ext['GAIN06'] = 1
h_ext['GAIN07'] = 1
h_ext['GAIN08'] = 1
h_ext['GAIN09'] = 1
h_ext['GAIN10'] = 1
h_ext['GAIN11'] = 1
h_ext['GAIN12'] = 1
h_ext['GAIN13'] = 1
h_ext['GAIN14'] = 1
h_ext['GAIN15'] = 1
h_ext['GAIN16'] = 1
h_ext['RON01'] = readout
h_ext['RON02'] = readout
h_ext['RON03'] = readout
h_ext['RON04'] = readout
h_ext['RON05'] = readout
h_ext['RON06'] = readout
h_ext['RON07'] = readout
h_ext['RON08'] = readout
h_ext['RON09'] = readout
h_ext['RON10'] = readout
h_ext['RON11'] = readout
h_ext['RON12'] = readout
h_ext['RON13'] = readout
h_ext['RON14'] = readout
h_ext['RON15'] = readout
h_ext['RON16'] = readout
h_ext['PIXSCAL1'] = pixel_scale
h_ext['PIXSCAL2'] = pixel_scale
h_ext['EXPTIME'] = exptime
h_ext['DARKTIME'] = exptime + 2
datetime_obs = datetime.utcfromtimestamp(timestamp)
tstart = Time(datetime_obs)
tstart_read = Time(tstart.mjd + exptime / 86400., format="mjd")
tend_read = Time(tstart.mjd + (exptime + readoutTime) / 86400., format="mjd")
t_s1 = str(tstart_read.datetime).split()
h_ext['READT0'] = t_s1[0]+'T'+t_s1[1]
t_s2 = str(tend_read.datetime).split()
h_ext['READT1'] = t_s2[0] + 'T' + t_s2[1]
# 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,
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['CRPIX2'] = header_wcs['CRPIX2']
h_ext['CRVAL1'] = header_wcs['CRVAL1']
h_ext['CRVAL2'] = header_wcs['CRVAL2']
h_ext['CD1_1'] = header_wcs['CD1_1']
h_ext['CD1_2'] = header_wcs['CD1_2']
h_ext['CD2_1'] = header_wcs['CD2_1']
h_ext['CD2_2'] = header_wcs['CD2_2']
# h_ext['EQUINOX'] = header_wcs['EQUINOX']
# h_ext['WCSDIM'] = header_wcs['WCSDIM']
h_ext['CTYPE1'] = header_wcs['CTYPE1']
h_ext['CTYPE2'] = header_wcs['CTYPE2']
return h_ext
def main(argv):
xlen = int(argv[1])
ylen = int(argv[2])
pointingNum = argv[3]
ra = float(argv[4])
dec = float(argv[5])
pSize = float(argv[6])
ccd_row_num = int(argv[7])
ccd_col_num = int(argv[8])
pa_aper = float(argv[9])
gain = float(argv[10])
readout = float(argv[11])
dark = float(argv[12])
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, readout = readout, dark = dark, saturation=fw, psize = pSize, row_num = ccd_row_num, col_num = ccd_col_num)
hdu1 = fits.PrimaryHDU(header=h_prim)
hdu2 = fits.ImageHDU(np.zeros([ylen,xlen]),header = h_ext)
hdul = fits.HDUList([hdu1,hdu2])
hdul.writeto(h_prim['FILENAME']+'.fits',output_verify='ignore')
# if __name__ == "__main__":
# main(sys.argv)
{
"31": {
"chip_name": "FGS1A-D1",
"pix_size": 0.0075,
"pix_scale": 0.0555,
"npix_x": 11264,
"npix_y": 7680,
"x_cen": -325.395,
"y_cen": -47.82,
"rotate_angle": 0.0,
"n_psf_samples": 900,
"dark_exptime": 300.0,
"falt_exptime": 150.0,
"readout_time": 0.01,
"df_strength": 2.3,
"bias_level": 2000.0,
"gain": 1.0,
"full_well": 90000,
"prescan_x": 27,
"overscan_x": 71,
"prescan_y": 0,
"overscan_y": 84
},
"32": {
"chip_name": "FGS1A-D2",
"pix_size": 0.0075,
"pix_scale": 0.0555,
"npix_x": 11264,
"npix_y": 7680,
"x_cen": -325.395,
"y_cen": 22.7,
"rotate_angle": 0.0,
"n_psf_samples": 900,
"dark_exptime": 300.0,
"falt_exptime": 150.0,
"readout_time": 0.01,
"df_strength": 2.3,
"bias_level": 2000.0,
"gain": 1.0,
"full_well": 90000,
"prescan_x": 27,
"overscan_x": 71,
"prescan_y": 0,
"overscan_y": 84
},
"33": {
"chip_name": "FGS1B-D1",
"pix_size": 0.0075,
"pix_scale": 0.0555,
"npix_x": 11264,
"npix_y": 7680,
"x_cen": -325.395,
"y_cen": 93.195,
"rotate_angle": 0.0,
"n_psf_samples": 900,
"dark_exptime": 300.0,
"falt_exptime": 150.0,
"readout_time": 0.01,
"df_strength": 2.3,
"bias_level": 2000.0,
"gain": 1.0,
"full_well": 90000,
"prescan_x": 27,
"overscan_x": 71,
"prescan_y": 0,
"overscan_y": 84
},
"34": {
"chip_name": "FGS1B-D2",
"pix_size": 0.0075,
"pix_scale": 0.0555,
"npix_x": 11264,
"npix_y": 7680,
"x_cen": -325.395,
"y_cen": 163.69,
"rotate_angle": 0.0,
"n_psf_samples": 900,
"dark_exptime": 300.0,
"falt_exptime": 150.0,
"readout_time": 0.01,
"df_strength": 2.3,
"bias_level": 2000.0,
"gain": 1.0,
"full_well": 90000,
"prescan_x": 27,
"overscan_x": 71,
"prescan_y": 0,
"overscan_y": 84
},
"35": {
"chip_name": "FGS2A-D1",
"pix_size": 0.0075,
"pix_scale": 0.0555,
"npix_x": 11264,
"npix_y": 7680,
"x_cen": 325.395,
"y_cen": 47.82,
"rotate_angle": 0.0,
"n_psf_samples": 900,
"dark_exptime": 300.0,
"falt_exptime": 150.0,
"readout_time": 0.01,
"df_strength": 2.3,
"bias_level": 2000.0,
"gain": 1.0,
"full_well": 90000,
"prescan_x": 27,
"overscan_x": 71,
"prescan_y": 0,
"overscan_y": 84
},
"36": {
"chip_name": "FGS2A-D2",
"pix_size": 0.0075,
"pix_scale": 0.0555,
"npix_x": 11264,
"npix_y": 7680,
"x_cen": 325.395,
"y_cen": -22.7,
"rotate_angle": 0.0,
"n_psf_samples": 900,
"dark_exptime": 300.0,
"falt_exptime": 150.0,
"readout_time": 0.01,
"df_strength": 2.3,
"bias_level": 2000.0,
"gain": 1.0,
"full_well": 90000,
"prescan_x": 27,
"overscan_x": 71,
"prescan_y": 0,
"overscan_y": 84
},
"37": {
"chip_name": "FGS2B-D1",
"pix_size": 0.0075,
"pix_scale": 0.0555,
"npix_x": 11264,
"npix_y": 7680,
"x_cen": 325.395,
"y_cen": -93.195,
"rotate_angle": 0.0,
"n_psf_samples": 900,
"dark_exptime": 300.0,
"falt_exptime": 150.0,
"readout_time": 0.01,
"df_strength": 2.3,
"bias_level": 2000.0,
"gain": 1.0,
"full_well": 90000,
"prescan_x": 27,
"overscan_x": 71,
"prescan_y": 0,
"overscan_y": 84
},
"38": {
"chip_name": "FGS2B-D2",
"pix_size": 0.0075,
"pix_scale": 0.0555,
"npix_x": 11264,
"npix_y": 7680,
"x_cen": 325.395,
"y_cen": -163.69,
"rotate_angle": 0.0,
"n_psf_samples": 900,
"dark_exptime": 300.0,
"falt_exptime": 150.0,
"readout_time": 0.01,
"df_strength": 2.3,
"bias_level": 2000.0,
"gain": 1.0,
"full_well": 90000,
"prescan_x": 27,
"overscan_x": 71,
"prescan_y": 0,
"overscan_y": 84
},
"39": {
"chip_name": "FGS3-D1",
"pix_size": 0.0075,
"pix_scale": 0.0555,
"npix_x": 11264,
"npix_y": 7680,
"x_cen": -273.35,
"y_cen": 211.36,
"rotate_angle": 90.0,
"n_psf_samples": 100,
"dark_exptime": 300.0,
"falt_exptime": 150.0,
"readout_time": 0.01,
"df_strength": 2.3,
"bias_level": 2000.0,
"gain": 1.0,
"full_well": 90000,
"prescan_x": 27,
"overscan_x": 71,
"prescan_y": 0,
"overscan_y": 84
},
"40": {
"chip_name": "FGS3-D2",
"pix_size": 0.0075,
"pix_scale": 0.0555,
"npix_x": 11264,
"npix_y": 7680,
"x_cen": -202.805,
"y_cen": 211.36,
"rotate_angle": 90.0,
"n_psf_samples": 100,
"dark_exptime": 300.0,
"falt_exptime": 150.0,
"readout_time": 0.01,
"df_strength": 2.3,
"bias_level": 2000.0,
"gain": 1.0,
"full_well": 90000,
"prescan_x": 27,
"overscan_x": 71,
"prescan_y": 0,
"overscan_y": 84
},
"41": {
"chip_name": "FGS4-D1",
"pix_size": 0.0075,
"pix_scale": 0.0555,
"npix_x": 11264,
"npix_y": 7680,
"x_cen": 151.03,
"y_cen": -233.885,
"rotate_angle": 90.0,
"n_psf_samples": 100,
"dark_exptime": 300.0,
"falt_exptime": 150.0,
"readout_time": 0.01,
"df_strength": 2.3,
"bias_level": 2000.0,
"gain": 1.0,
"full_well": 90000,
"prescan_x": 27,
"overscan_x": 71,
"prescan_y": 0,
"overscan_y": 84
},
"42": {
"chip_name": "FGS4-D2",
"pix_size": 0.0075,
"pix_scale": 0.0555,
"npix_x": 11264,
"npix_y": 7680,
"x_cen": 80.51,
"y_cen": -233.885,
"rotate_angle": 90.0,
"n_psf_samples": 100,
"dark_exptime": 300.0,
"falt_exptime": 150.0,
"readout_time": 0.01,
"df_strength": 2.3,
"bias_level": 2000.0,
"gain": 1.0,
"full_well": 90000,
"prescan_x": 27,
"overscan_x": 71,
"prescan_y": 0,
"overscan_y": 84
},
"1": {
"chip_name": "GI-1",
"pix_size": 0.01,
"pix_scale": 0.074,
"npix_x": 9216,
"npix_y": 9232,
"x_cen": 251.5,
"y_cen": -202.6,
"rotate_angle": -1.0,
"n_psf_samples": 900,
"dark_exptime": 300,
"flat_exptime": 150,
"readout_time": 40,
"df_strength": 2.3,
"bias_level": 500,
"gain": 1.1,
"full_well": 90000,
"prescan_x": 27,
"overscan_x": 71,
"prescan_y": 0,
"overscan_y": 84
},
"2": {
"chip_name": "GV-1",
"pix_size": 0.01,
"pix_scale": 0.074,
"npix_x": 9216,
"npix_y": 9232,
"x_cen": 251.5,
"y_cen": -101.3,
"rotate_angle": -1.0,
"n_psf_samples": 900,
"dark_exptime": 300,
"flat_exptime": 150,
"readout_time": 40,
"df_strength": 2.3,
"bias_level": 500,
"gain": 1.1,
"full_well": 90000,
"prescan_x": 27,
"overscan_x": 71,
"prescan_y": 0,
"overscan_y": 84
},
"3": {
"chip_name": "GU-1",
"pix_size": 0.01,
"pix_scale": 0.074,
"npix_x": 9216,
"npix_y": 9232,
"x_cen": 251.5,
"y_cen": 0.0,
"rotate_angle": -1.0,
"n_psf_samples": 900,
"dark_exptime": 300,
"flat_exptime": 150,
"readout_time": 40,
"df_strength": 2.3,
"bias_level": 500,
"gain": 1.1,
"full_well": 90000,
"prescan_x": 27,
"overscan_x": 71,
"prescan_y": 0,
"overscan_y": 84
},
"4": {
"chip_name": "GU-2",
"pix_size": 0.01,
"pix_scale": 0.074,
"npix_x": 9216,
"npix_y": 9232,
"x_cen": 251.5,
"y_cen": 101.3,
"rotate_angle": -1.0,
"n_psf_samples": 900,
"dark_exptime": 300,
"flat_exptime": 150,
"readout_time": 40,
"df_strength": 2.3,
"bias_level": 500,
"gain": 1.1,
"full_well": 90000,
"prescan_x": 27,
"overscan_x": 71,
"prescan_y": 0,
"overscan_y": 84
},
"5": {
"chip_name": "GV-2",
"pix_size": 0.01,
"pix_scale": 0.074,
"npix_x": 9216,
"npix_y": 9232,
"x_cen": 251.5,
"y_cen": 202.6,
"rotate_angle": -1.0,
"n_psf_samples": 900,
"dark_exptime": 300,
"flat_exptime": 150,
"readout_time": 40,
"df_strength": 2.3,
"bias_level": 500,
"gain": 1.1,
"full_well": 90000,
"prescan_x": 27,
"overscan_x": 71,
"prescan_y": 0,
"overscan_y": 84
},
"6": {
"chip_name": "y-1",
"pix_size": 0.01,
"pix_scale": 0.074,
"npix_x": 9216,
"npix_y": 9232,
"x_cen": 146.25,
"y_cen": -202.6,
"rotate_angle": 0.0,
"n_psf_samples": 900,
"dark_exptime": 300,
"flat_exptime": 150,
"readout_time": 40,
"df_strength": 2.3,
"bias_level": 500,
"gain": 1.1,
"full_well": 90000,
"prescan_x": 27,
"overscan_x": 71,
"prescan_y": 0,
"overscan_y": 84
},
"7": {
"chip_name": "i-1",
"pix_size": 0.01,
"pix_scale": 0.074,
"npix_x": 9216,
"npix_y": 9232,
"x_cen": 146.25,
"y_cen": -101.3,
"rotate_angle": 0.0,
"n_psf_samples": 900,
"dark_exptime": 300,
"flat_exptime": 150,
"readout_time": 40,
"df_strength": 2.3,
"bias_level": 500,
"gain": 1.1,
"full_well": 90000,
"prescan_x": 27,
"overscan_x": 71,
"prescan_y": 0,
"overscan_y": 84
},
"8": {
"chip_name": "g-1",
"pix_size": 0.01,
"pix_scale": 0.074,
"npix_x": 9216,
"npix_y": 9232,
"x_cen": 146.25,
"y_cen": 0.0,
"rotate_angle": 0.0,
"n_psf_samples": 900,
"dark_exptime": 300,
"flat_exptime": 150,
"readout_time": 40,
"df_strength": 2.3,
"bias_level": 500,
"gain": 1.1,
"full_well": 90000,
"prescan_x": 27,
"overscan_x": 71,
"prescan_y": 0,
"overscan_y": 84
},
"9": {
"chip_name": "r-1",
"pix_size": 0.01,
"pix_scale": 0.074,
"npix_x": 9216,
"npix_y": 9232,
"x_cen": 146.25,
"y_cen": 101.3,
"rotate_angle": 0.0,
"n_psf_samples": 900,
"dark_exptime": 300,
"flat_exptime": 150,
"readout_time": 40,
"df_strength": 2.3,
"bias_level": 500,
"gain": 1.1,
"full_well": 90000,
"prescan_x": 27,
"overscan_x": 71,
"prescan_y": 0,
"overscan_y": 84
},
"10": {
"chip_name": "GI-2",
"pix_size": 0.01,
"pix_scale": 0.074,
"npix_x": 9216,
"npix_y": 9232,
"x_cen": 154.0,
"y_cen": 202.6,
"rotate_angle": -1.0,
"n_psf_samples": 900,
"dark_exptime": 300,
"flat_exptime": 150,
"readout_time": 40,
"df_strength": 2.3,
"bias_level": 500,
"gain": 1.1,
"full_well": 90000,
"prescan_x": 27,
"overscan_x": 71,
"prescan_y": 0,
"overscan_y": 84
},
"11": {
"chip_name": "z-1",
"pix_size": 0.01,
"pix_scale": 0.074,
"npix_x": 9216,
"npix_y": 9232,
"x_cen": 48.75,
"y_cen": -202.6,
"rotate_angle": 0.0,
"n_psf_samples": 900,
"dark_exptime": 300,
"flat_exptime": 150,
"readout_time": 40,
"df_strength": 2.3,
"bias_level": 500,
"gain": 1.1,
"full_well": 90000,
"prescan_x": 27,
"overscan_x": 71,
"prescan_y": 0,
"overscan_y": 84
},
"12": {
"chip_name": "NUV-1",
"pix_size": 0.01,
"pix_scale": 0.074,
"npix_x": 9216,
"npix_y": 9232,
"x_cen": 48.75,
"y_cen": -101.3,
"rotate_angle": 0.0,
"n_psf_samples": 900,
"dark_exptime": 300,
"flat_exptime": 150,
"readout_time": 40,
"df_strength": 2.3,
"bias_level": 500,
"gain": 1.1,
"full_well": 90000,
"prescan_x": 27,
"overscan_x": 71,
"prescan_y": 0,
"overscan_y": 84
},
"13": {
"chip_name": "NUV-2",
"pix_size": 0.01,
"pix_scale": 0.074,
"npix_x": 9216,
"npix_y": 9232,
"x_cen": 48.75,
"y_cen": 0.0,
"rotate_angle": 0.0,
"n_psf_samples": 900,
"dark_exptime": 300,
"flat_exptime": 150,
"readout_time": 40,
"df_strength": 2.3,
"bias_level": 500,
"gain": 1.1,
"full_well": 90000,
"prescan_x": 27,
"overscan_x": 71,
"prescan_y": 0,
"overscan_y": 84
},
"14": {
"chip_name": "u-1",
"pix_size": 0.01,
"pix_scale": 0.074,
"npix_x": 9216,
"npix_y": 9232,
"x_cen": 48.75,
"y_cen": 101.3,
"rotate_angle": 0.0,
"n_psf_samples": 900,
"dark_exptime": 300,
"flat_exptime": 150,
"readout_time": 40,
"df_strength": 2.3,
"bias_level": 500,
"gain": 1.1,
"full_well": 90000,
"prescan_x": 27,
"overscan_x": 71,
"prescan_y": 0,
"overscan_y": 84
},
"15": {
"chip_name": "y-2",
"pix_size": 0.01,
"pix_scale": 0.074,
"npix_x": 9216,
"npix_y": 9232,
"x_cen": 48.75,
"y_cen": 202.6,
"rotate_angle": 0.0,
"n_psf_samples": 900,
"dark_exptime": 300,
"flat_exptime": 150,
"readout_time": 40,
"df_strength": 2.3,
"bias_level": 500,
"gain": 1.1,
"full_well": 90000,
"prescan_x": 27,
"overscan_x": 71,
"prescan_y": 0,
"overscan_y": 84
},
"16": {
"chip_name": "y-3",
"pix_size": 0.01,
"pix_scale": 0.074,
"npix_x": 9216,
"npix_y": 9232,
"x_cen": -48.75,
"y_cen": -202.6,
"rotate_angle": 0.0,
"n_psf_samples": 900,
"dark_exptime": 300,
"flat_exptime": 150,
"readout_time": 40,
"df_strength": 2.3,
"bias_level": 500,
"gain": 1.1,
"full_well": 90000,
"prescan_x": 27,
"overscan_x": 71,
"prescan_y": 0,
"overscan_y": 84
},
"17": {
"chip_name": "u-2",
"pix_size": 0.01,
"pix_scale": 0.074,
"npix_x": 9216,
"npix_y": 9232,
"x_cen": -48.75,
"y_cen": -101.3,
"rotate_angle": 0.0,
"n_psf_samples": 900,
"dark_exptime": 300,
"flat_exptime": 150,
"readout_time": 40,
"df_strength": 2.3,
"bias_level": 500,
"gain": 1.1,
"full_well": 90000,
"prescan_x": 27,
"overscan_x": 71,
"prescan_y": 0,
"overscan_y": 84
},
"18": {
"chip_name": "NUV-3",
"pix_size": 0.01,
"pix_scale": 0.074,
"npix_x": 9216,
"npix_y": 9232,
"x_cen": -48.75,
"y_cen": 0.0,
"rotate_angle": 0.0,
"n_psf_samples": 900,
"dark_exptime": 300,
"flat_exptime": 150,
"readout_time": 40,
"df_strength": 2.3,
"bias_level": 500,
"gain": 1.1,
"full_well": 90000,
"prescan_x": 27,
"overscan_x": 71,
"prescan_y": 0,
"overscan_y": 84
},
"19": {
"chip_name": "NUV-4",
"pix_size": 0.01,
"pix_scale": 0.074,
"npix_x": 9216,
"npix_y": 9232,
"x_cen": -48.75,
"y_cen": 101.3,
"rotate_angle": 0.0,
"n_psf_samples": 900,
"dark_exptime": 300,
"flat_exptime": 150,
"readout_time": 40,
"df_strength": 2.3,
"bias_level": 500,
"gain": 1.1,
"full_well": 90000,
"prescan_x": 27,
"overscan_x": 71,
"prescan_y": 0,
"overscan_y": 84
},
"20": {
"chip_name": "z-2",
"pix_size": 0.01,
"pix_scale": 0.074,
"npix_x": 9216,
"npix_y": 9232,
"x_cen": -48.75,
"y_cen": 202.6,
"rotate_angle": 0.0,
"n_psf_samples": 900,
"dark_exptime": 300,
"flat_exptime": 150,
"readout_time": 40,
"df_strength": 2.3,
"bias_level": 500,
"gain": 1.1,
"full_well": 90000,
"prescan_x": 27,
"overscan_x": 71,
"prescan_y": 0,
"overscan_y": 84
},
"21": {
"chip_name": "GI-3",
"pix_size": 0.01,
"pix_scale": 0.074,
"npix_x": 9216,
"npix_y": 9232,
"x_cen": -154.0,
"y_cen": -202.6,
"rotate_angle": 1.0,
"n_psf_samples": 900,
"dark_exptime": 300,
"flat_exptime": 150,
"readout_time": 40,
"df_strength": 2.3,
"bias_level": 500,
"gain": 1.1,
"full_well": 90000,
"prescan_x": 27,
"overscan_x": 71,
"prescan_y": 0,
"overscan_y": 84
},
"22": {
"chip_name": "r-2",
"pix_size": 0.01,
"pix_scale": 0.074,
"npix_x": 9216,
"npix_y": 9232,
"x_cen": -146.25,
"y_cen": -101.3,
"rotate_angle": 0.0,
"n_psf_samples": 900,
"dark_exptime": 300,
"flat_exptime": 150,
"readout_time": 40,
"df_strength": 2.3,
"bias_level": 500,
"gain": 1.1,
"full_well": 90000,
"prescan_x": 27,
"overscan_x": 71,
"prescan_y": 0,
"overscan_y": 84
},
"23": {
"chip_name": "g-2",
"pix_size": 0.01,
"pix_scale": 0.074,
"npix_x": 9216,
"npix_y": 9232,
"x_cen": -146.25,
"y_cen": 0.0,
"rotate_angle": 0.0,
"n_psf_samples": 900,
"dark_exptime": 300,
"flat_exptime": 150,
"readout_time": 40,
"df_strength": 2.3,
"bias_level": 500,
"gain": 1.1,
"full_well": 90000,
"prescan_x": 27,
"overscan_x": 71,
"prescan_y": 0,
"overscan_y": 84
},
"24": {
"chip_name": "i-2",
"pix_size": 0.01,
"pix_scale": 0.074,
"npix_x": 9216,
"npix_y": 9232,
"x_cen": -146.25,
"y_cen": 101.3,
"rotate_angle": 0.0,
"n_psf_samples": 900,
"dark_exptime": 300,
"flat_exptime": 150,
"readout_time": 40,
"df_strength": 2.3,
"bias_level": 500,
"gain": 1.1,
"full_well": 90000,
"prescan_x": 27,
"overscan_x": 71,
"prescan_y": 0,
"overscan_y": 84
},
"25": {
"chip_name": "y-4",
"pix_size": 0.01,
"pix_scale": 0.074,
"npix_x": 9216,
"npix_y": 9232,
"x_cen": -146.25,
"y_cen": 202.6,
"rotate_angle": 0.0,
"n_psf_samples": 900,
"dark_exptime": 300,
"flat_exptime": 150,
"readout_time": 40,
"df_strength": 2.3,
"bias_level": 500,
"gain": 1.1,
"full_well": 90000,
"prescan_x": 27,
"overscan_x": 71,
"prescan_y": 0,
"overscan_y": 84
},
"26": {
"chip_name": "GV-3",
"pix_size": 0.01,
"pix_scale": 0.074,
"npix_x": 9216,
"npix_y": 9232,
"x_cen": -251.5,
"y_cen": -202.6,
"rotate_angle": 1.0,
"n_psf_samples": 900,
"dark_exptime": 300,
"flat_exptime": 150,
"readout_time": 40,
"df_strength": 2.3,
"bias_level": 500,
"gain": 1.1,
"full_well": 90000,
"prescan_x": 27,
"overscan_x": 71,
"prescan_y": 0,
"overscan_y": 84
},
"27": {
"chip_name": "GU-3",
"pix_size": 0.01,
"pix_scale": 0.074,
"npix_x": 9216,
"npix_y": 9232,
"x_cen": -251.5,
"y_cen": -101.3,
"rotate_angle": 1.0,
"n_psf_samples": 900,
"dark_exptime": 300,
"flat_exptime": 150,
"readout_time": 40,
"df_strength": 2.3,
"bias_level": 500,
"gain": 1.1,
"full_well": 90000,
"prescan_x": 27,
"overscan_x": 71,
"prescan_y": 0,
"overscan_y": 84
},
"28": {
"chip_name": "GU-4",
"pix_size": 0.01,
"pix_scale": 0.074,
"npix_x": 9216,
"npix_y": 9232,
"x_cen": -251.5,
"y_cen": 0.0,
"rotate_angle": 1.0,
"n_psf_samples": 900,
"dark_exptime": 300,
"flat_exptime": 150,
"readout_time": 40,
"df_strength": 2.3,
"bias_level": 500,
"gain": 1.1,
"full_well": 90000,
"prescan_x": 27,
"overscan_x": 71,
"prescan_y": 0,
"overscan_y": 84
},
"29": {
"chip_name": "GV-4",
"pix_size": 0.01,
"pix_scale": 0.074,
"npix_x": 9216,
"npix_y": 9232,
"x_cen": -251.5,
"y_cen": 101.3,
"rotate_angle": 1.0,
"n_psf_samples": 900,
"dark_exptime": 300,
"flat_exptime": 150,
"readout_time": 40,
"df_strength": 2.3,
"bias_level": 500,
"gain": 1.1,
"full_well": 90000,
"prescan_x": 27,
"overscan_x": 71,
"prescan_y": 0,
"overscan_y": 84
},
"30": {
"chip_name": "GI-4",
"pix_size": 0.01,
"pix_scale": 0.074,
"npix_x": 9216,
"npix_y": 9232,
"x_cen": -251.5,
"y_cen": 202.6,
"rotate_angle": 1.0,
"n_psf_samples": 900,
"dark_exptime": 300,
"flat_exptime": 150,
"readout_time": 40,
"df_strength": 2.3,
"bias_level": 500,
"gain": 1.1,
"full_well": 90000,
"prescan_x": 27,
"overscan_x": 71,
"prescan_y": 0,
"overscan_y": 84
}
}
XTENSION= 'IMAGE ' / extension type BITPIX = 16 / bits per data value NAXIS = 2 / number of data axes NAXIS1 = 9216 / length of first array axis NAXIS2 = 9232 / length of second array axis PCOUNT = 0 GCOUNT = 1 EXTNAME = 'SCI ' EXTVER = 1 BSCALE = 1 BZERO = 32768 BUNIT = 'ADU ' / physical unit of array values COMMENT ================================================================== COMMENT Detector information COMMENT ================================================================== CAMERA = 'MS' / camera of main survey DETSN = '12345678' / detector serial number DETNAME = 'CCD' / detector type DETTEMP1= 173.0 / detector temperature at EXPSTART(in Kelvin) DETTEMP2= 173.0 / detector temperature at EXPEND(in Kelvin) DETTEMP3= 173.0 / detector temperature at READT1(in Kelvin) DETSIZE = '9560x9264' / detector size DATASECT= '9216x9232' / data section PIXSCAL1= 0.074 / pixel scale for axis 1 PIXSCAL2= 0.074 / pixel scale for axis 2 PIXSIZE1= 10 / pixel size for axis 1 (in um) PIXSIZE2= 10 / pixel size for axis 2 (in um) COMMENT ================================================================== COMMENT CCD chip information COMMENT ================================================================== CHIPID = '08' / chip ID CHIPLAB = 'y-1' / chip label FILTER = 'y' / filter name NCHAN = 16 / number of readout channels PSCAN1 = 27 / horizontal prescan width, per readout channel PSCAN2 = 8 / vertical prescan width, per readout channel OSCAN1 = 16 / horizontal overscan width,per readout channel OSCAN2 = 16 / vertical overscan width,per readout channel COMMENT ================================================================== COMMENT WORLD COORDINATE SYSTEM AND RELATED PARAMETERS COMMENT ================================================================== WCSAXES = 2 / number of World Coordinate System axes CRPIX1 = -10017.0 / x-coordinate of reference pixel CRPIX2 = 24876.0 / y-coordinate of reference pixel CRVAL1 = 62.228226 / first axis value at reference pixel CRVAL2 = -42.316932 / second axis value at reference pixel CTYPE1 = 'RA---TAN' / the coordinate type for the first axis CTYPE2 = 'DEC--TAN' / the coordinate type for the second axis CD1_1 = 1.88602083707394E-05 / partial of first axis coordinate w.r.t.x CD1_2 = 8.17455836176000E-06 / partial of first axis coordinate w.r.t.y CD2_1 = -8.1745583617600E-06 / partial of second axis coordinate w.r.t.x CD2_2 = 1.88602083707394E-05 / partial of second axis coordinate w.r.t.y OTHERS = '' / COMMENT ================================================================== COMMENT Readout information COMMENT ================================================================== GAINLVL = '01' / gain level GAIN01 = 1.1 / gain (channel 01) GAIN02 = 1.1 / gain (channel 02) GAIN03 = 1.1 / gain (channel 03) GAIN04 = 1.1 / gain (channel 04) GAIN05 = 1.1 / gain (channel 05) GAIN06 = 1.1 / gain (channel 06) GAIN07 = 1.1 / gain (channel 07) GAIN08 = 1.1 / gain (channel 08) GAIN09 = 1.1 / gain (channel 09) GAIN10 = 1.1 / gain (channel 10) GAIN11 = 1.1 / gain (channel 11) GAIN12 = 1.1 / gain (channel 12) GAIN13 = 1.1 / gain (channel 13) GAIN14 = 1.1 / gain (channel 14) GAIN15 = 1.1 / gain (channel 15) GAIN16 = 1.1 / gain (channel 16) RON01 = 5.0 / read noise (channel 01) RON02 = 5.0 / read noise (channel 02) RON03 = 5.0 / read noise (channel 03) RON04 = 5.0 / read noise (channel 04) RON05 = 5.0 / read noise (channel 05) RON06 = 5.0 / read noise (channel 06) RON07 = 5.0 / read noise (channel 07) RON08 = 5.0 / read noise (channel 08) RON09 = 5.0 / read noise (channel 09) RON10 = 5.0 / read noise (channel 10) RON11 = 5.0 / read noise (channel 11) RON12 = 5.0 / read noise (channel 12) RON13 = 5.0 / read noise (channel 13) RON14 = 5.0 / read noise (channel 14) RON15 = 5.0 / read noise (channel 15) RON16 = 5.0 / read noise (channel 16) READT0 = '2024-00-00T00:00:00'/ readout start time(UTC) READT1 = '2024-00-00T00:00:00'/ readout end time(UTC) ROSPEED = 10.0 / readout speed (in MHz) EXPTIME = 150.0 / exposure duration DARKTIME= 150.0 / dark current time COMMENT ================================================================== COMMENT Shutter information COMMENT ================================================================== SHTSTAT = T / shutter status SHTOPEN0= 0.0 / shutter open time (begin) SHTOPEN1= 0.0 / shutter open time (end) SHTCLOS0= 0.0 / shutter close time (begin) SHTCLOS1= 0.0 / shutter close time (end) COMMENT ================================================================== COMMENT LED information COMMENT ================================================================== LEDFLAG = 0 / main/backup LED LEDSTAT = '00000000000000' / LED status LEDEXPT = 0.0 / LED flash time (s) LEDTEMP = 173.0 / LED temperature (in K) COMMENT ================================================================== COMMENT Other information COMMENT ================================================================== CHECKSUM= '''abcde''' / HDU checksum updated yyyy-mm-ddTHH:MM:SS DATASUM = '''abcde''' / data unit checksum updated yyyy-mm-ddTHH:MM:SS END
GV GI y z y GI GU r u NUV i GV GU g NUV NUV g GU GV i NUV u r GU GI y z y GI GV
3 3 3 1 1 1 3 2 2 1 1 1 4 2 3 2 1 1 4 2 4 1 1 2 4 2 2 4 2 2
26 21 16 11 6 1 27 22 17 12 7 2 28 23 18 13 8 3 29 24 19 14 9 4 30 25 20 15 10 5
from cgitb import reset
from tkinter.tix import INTEGER
import astropy.coordinates as coord
from astropy import units as u
from pylab import *
import numpy as np
import galsim
import math
from astropy.table import Table, vstack
from astropy.io import fits
from astropy.wcs import WCS
import os
import json
import ImageHeader
# from numba import jit
ALL_FILTERS = ["NUV", "u", "g", "r", "i", "z", "y", "GU", "GV", "GI", "FGS"]
class Chip(object):
def __init__(self, chipID):
self.chipID = chipID
self.nchip_x = 6
self.nchip_y = 5
self.npix_tot_x = 59516
self.npix_tot_y = 49752
self.npix_gap_x = (534, 1309)
self.npix_gap_y = 898
self.cen_pix_x = 0
self.cen_pix_y = 0
self.npix_x = 9216
self.npix_y = 9232
self.pix_scale = 0.074
chip_dict = json.load(open("chip_definition.json", "r"))[str(self.chipID)]
for key in chip_dict:
setattr(self, key, chip_dict[key])
self.filter_id, self.filter_type = self.getChipFilter()
def getTanWCS(
self, ra, dec, img_rot, pix_scale=None, xcen=None, ycen=None, logger=None
):
"""Get the WCS of the image mosaic using Gnomonic/TAN projection
Parameter:
ra, dec: float
(RA, Dec) of pointing of optical axis
img_rot: galsim Angle object
Rotation of image
pix_scale: float
Pixel size in unit of as/pix
Returns:
WCS of the focal plane
"""
if logger is not None:
logger.info(
" Construct the wcs of the entire image mosaic using Gnomonic/TAN projection"
)
if (xcen == None) or (ycen == None):
xcen = self.cen_pix_x
ycen = self.cen_pix_y
if pix_scale == None:
pix_scale = self.pix_scale
# 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
dudy = +np.sin(img_rot.rad) * pix_scale
dvdx = -np.sin(img_rot.rad) * pix_scale
dvdy = -np.cos(img_rot.rad) * pix_scale
moscen = galsim.PositionD(x=xcen, y=ycen)
sky_center = galsim.CelestialCoord(
ra=ra * galsim.degrees, dec=dec * galsim.degrees
)
affine = galsim.AffineTransform(dudx, dudy, dvdx, dvdy, origin=moscen)
WCS = galsim.TanWCS(affine, sky_center, units=galsim.arcsec)
return WCS
def getChipRowCol(self, chipID):
rowID = ((chipID - 1) % 5) + 1
colID = 6 - ((chipID - 1) // 5)
return rowID, colID
def getChipCenter(self):
"""Calculate the edges in pixel for a given CCD chip on the focal plane
NOTE: There are 5*4 CCD chips in the focus plane for photometric observation.
Parameters:
chipID: int
the index of the chip
Returns:
A galsim BoundsD object
"""
chipID = self.chipID
rowID, colID = self.getChipRowCol(chipID)
gx1, gx2 = self.npix_gap_x
gy = self.npix_gap_y
# xlim of a given CCD chip
xrem = 2 * (colID - 1) - (self.nchip_x - 1)
xcen = (self.npix_x // 2 + gx1 // 2) * xrem
if chipID >= 26 or chipID == 21:
xcen = (self.npix_x // 2 + gx1 // 2) * xrem - (gx2 - gx1)
if chipID <= 5 or chipID == 10:
xcen = (self.npix_x // 2 + gx1 // 2) * xrem + (gx2 - gx1)
# nx0 = xcen - self.npix_x//2 + 1
# nx1 = xcen + self.npix_x//2
# ylim of a given CCD chip
yrem = (rowID - 1) - self.nchip_y // 2
ycen = (self.npix_y + gy) * yrem
# ny0 = ycen - self.npix_y//2 + 1
# ny1 = ycen + self.npix_y//2
return galsim.PositionD(xcen, ycen)
def getChipFilter(self, chipID=None):
"""Return the filter index and type for a given chip #(chipID)"""
filter_type_list = ALL_FILTERS
if chipID == None:
chipID = self.chipID
# updated configurations
if chipID > 42 or chipID < 1:
raise ValueError("!!! Chip ID: [1,42]")
if chipID in [6, 15, 16, 25]:
filter_type = "y"
if chipID in [11, 20]:
filter_type = "z"
if chipID in [7, 24]:
filter_type = "i"
if chipID in [14, 17]:
filter_type = "u"
if chipID in [9, 22]:
filter_type = "r"
if chipID in [12, 13, 18, 19]:
filter_type = "NUV"
if chipID in [8, 23]:
filter_type = "g"
if chipID in [1, 10, 21, 30]:
filter_type = "GI"
if chipID in [2, 5, 26, 29]:
filter_type = "GV"
if chipID in [3, 4, 27, 28]:
filter_type = "GU"
if chipID in range(31, 43):
filter_type = "FGS"
filter_id = filter_type_list.index(filter_type)
return filter_id, filter_type
def transRaDec2D(ra, dec):
x1 = np.cos(dec / 57.2957795) * np.cos(ra / 57.2957795)
y1 = np.cos(dec / 57.2957795) * np.sin(ra / 57.2957795)
z1 = np.sin(dec / 57.2957795)
return np.array([x1, y1, z1])
def getobsPA(ra, dec):
l1 = np.array([0, 0, 1])
l2 = transRaDec2D(ra, dec)
polar_ec = coord.SkyCoord(
0 * u.degree, 90 * u.degree, frame="barycentrictrueecliptic"
)
polar_eq = polar_ec.transform_to("icrs")
# print(polar_eq.ra.value,polar_eq.dec.value)
polar_d = transRaDec2D(polar_eq.ra.value, polar_eq.dec.value)
l1l2cross = np.cross(l2, l1)
pdl2cross = np.cross(l2, polar_d)
angle = math.acos(
np.dot(l1l2cross, pdl2cross)
/ (np.linalg.norm(l1l2cross) * np.linalg.norm(pdl2cross))
)
angle = (angle) / math.pi * 180
# if (ra>90 and ra< 270):
# angle=-angle
return angle
def getChipRangeInfo(chipID=8, ra=60.0, dec=-40.0, pa=113.0):
"""_summary_
Args:
chipID (int, optional): Chip ID.
ra (_type_, optional): Chip center ra.
dec (_type_, optional): Chip center dec.
Returns:
_type_: [ra, dec, rotation angle]
"""
# chip_center = [ra, dec]
chip = Chip(chipID)
h_ext = ImageHeader.generateExtensionHeader(
chip=chip,
xlen=chip.npix_x,
ylen=chip.npix_y,
ra=ra,
dec=dec,
pa=pa,
gain=chip.gain,
readout=5.0,
dark=0.02,
saturation=90000,
pixel_scale=chip.pix_scale,
pixel_size=chip.pix_size,
xcen=chip.x_cen,
ycen=chip.y_cen,
extName="SCI",
timestamp=1621915200,
exptime=150,
readoutTime=chip.readout_time,
)
chip_wcs = WCS(h_ext)
return chip_wcs, chip.npix_x, chip.npix_y, chip.chipID, chip.filter_type
def formateSEDfile(inputDir, outputDir):
fileFns = os.listdir(inputDir)
for fn in fileFns:
if fn[0] == ".":
continue
if ".fits" not in fn:
continue
dfn = os.path.join(inputDir, fn)
outfn = os.path.join(outputDir, "GP_" + fn[0:-5] + ".fits")
f = fits.open(dfn)
data_tab = Table(f[1].data)
col_names = data_tab.colnames
if "loglam" in col_names:
print("1:" + fn)
w1 = pow(10, f[1].data["loglam"])
f1 = f[1].data["flux"] * 1e-17
elif "WAVELENGTH" in col_names:
print("2:" + fn)
w1 = np.array(data_tab["WAVELENGTH"].tolist()[0])
f1 = np.array(data_tab["FLUX"].tolist()[0]) * 1e-17
w = np.zeros(w1.shape[0] + 4)
w[0] = 2000
w[1] = w1[0] - 1
w[-2] = w1[-1] + 1
w[-1] = 15000
w[2:-2] = w1
fl = np.zeros(f1.shape[0] + 4)
fl[0] = 0
fl[1] = 0
fl[-2] = 0
fl[-1] = 0
fl[2:-2] = f1
t = Table([w, fl], names=["WAVELENGTH", "FLUX"])
# t = Table([pow(10,f[1].data['loglam']),f[1].data['flux']*1e-17],names=['WAVELENGTH','FLUX'])
t.write(outfn, overwrite=True)
def genOneChipCat(
ra=40.0,
dec=-40.0,
pa=23.5,
chipID=1,
pointSource_flag=True,
sersic_index=1.0,
re=0.078,
specFn="LMC-SMP-58_spectrum_csst.fits",
):
chip_wcs, chip_xlen, chip_ylen, _, filterT = getChipRangeInfo(
chipID=chipID, ra=ra, dec=dec, pa=pa
)
sppos = 3685
xSize = 15
ySize = 30
y_interval = 20
X2 = np.linspace(100, sppos - 100, xSize)
Y2 = np.linspace(100, chip_ylen - 300, ySize)
y_gap = np.arange(0, y_interval * xSize, y_interval)
x2, y2 = np.meshgrid(X2, Y2)
y2 = y2 + y_gap
x2 = x2.flatten()
y2 = y2.flatten()
X1 = np.linspace(sppos + 300, chip_xlen - 100, xSize)
Y1 = np.linspace(150, chip_ylen - 250, ySize)
y_gap = np.arange(0, y_interval * xSize, y_interval)
x1, y1 = np.meshgrid(X1, Y1)
y1 = y1 + y_gap
x1 = x1.flatten()
y1 = y1.flatten()
tab_size = x1.size + x2.size
x = np.zeros(tab_size)
y = np.zeros_like(x)
x[0 : x1.size] = x1
x[x1.size :] = x2
y[0 : x1.size] = y1
y[x1.size :] = y2
radecs = chip_wcs.pixel_to_world(x, y)
# ids = np.arange(0, tab_size, 1)
mags = np.zeros(tab_size) + -99
sns = np.zeros(tab_size) + sersic_index
res = np.zeros(tab_size) + re
namelist = []
ids = []
for i in np.arange(tab_size):
namelist.append(specFn)
ids.append(format(chipID, "02.0f") + format(i + 1, "04.0f"))
if pointSource_flag:
p_flag = np.ones(tab_size, dtype=bool) # True
else:
p_flag = np.zeros(tab_size, dtype=bool) # False
cat_t = Table(
[ids, radecs.ra.deg, radecs.dec.deg, res, sns, mags, namelist, p_flag],
names=(
"ID",
"RA",
"DEC",
"RE",
"SERSIC_N",
"MAG_g",
"SPEC_FN",
"POINTSOURCE_FLAG",
),
)
return cat_t
if __name__ == "__main__":
ra = 244.972773
dec = 39.895901
pa = 109.59452000342756
chipIDs = [1, 2, 3, 4, 5, 10, 21, 26, 27, 28, 29, 30]
cat_t = Table()
for chipID in chipIDs:
cat_one = genOneChipCat(
ra=ra,
dec=dec,
pa=pa,
chipID=chipID,
pointSource_flag=True,
specFn="LMC-SMP-58_spectrum_csst.fits",
)
cat_t = vstack([cat_t, cat_one])
cat_t.write(
"calibrationPNESPEC_CHIP_ALL_SLS.fits",
format="fits",
overwrite=True,
)
SIMPLE = T / conforms to FITS standard BITPIX = 8 / array data type NAXIS = 0 / number of array dimensions EXTEND = T NEXTEND = 1 / number of array dimensions GROUPS = F / ' ' DATE = '2021-03-04T09:30:00'/ the date on which this file was written FILENAME= 'MSC_MS_210304093000_100000000_06_raw' / file name FILETYPE= 'SCIE ' / observation type TELESCOP= 'CSST ' / telescope used to acquire data INSTRUME= 'MSC ' / instrument used to acquire data RADECSYS= 'ICRS ' / reference coordinates system EQUINOX = 2000.0 / FITSCREA= 'C6' / FITS create software version COMMENT ================================================================== COMMENT Object information COMMENT ================================================================== OBJECT = '00000000' / object name TARGET = '+000000000000' / target name (hhmmss+ddmmss) OBSID = '00000000' / observation ID OBJ_RA = 62.228226 / R.A. of the object (degrees) OBJ_DEC = -42.316932 / declination of the object (degrees) COMMENT ================================================================== COMMENT Telescope information COMMENT ================================================================== REFFRAME= 'CSSTGSC-1.0' / guide star catalog version DATE-OBS= '2021-03-04T09:30:00'/ date of the observation (yyyy-mm-dd hh:mm:ss) SATESWV = '0001' / software version in the satellite EXPSTART= 59130.5 / exposure start time (MJD) CABSTART= 59130.5 / (MJD) SUNANGL0= 50.0 / angle between sun and opt axis at CABSTART MOONANG0= 30.0 / angle between moon and opt axis at CABSTART TEL_ALT0= 20.0 / angle between opt axis and Elimb at CABSTART POS_ANG0= 20.0 / angle between y axis and NP at CABSTART POSI0_X = 0.0 / the orbital position in X at CABSTART POSI0_Y = 0.0 / the orbital position in Y at CABSTART POSI0_Z = 0.0 / the orbital position in Z at CABSTART VELO0_X = 0.0 / the orbital velocity in X at CABSTART VELO0_Y = 0.0 / the orbital velocity in Y at CABSTART VELO0_Z = 0.0 / the orbital velocity in Z at CABSTART EULER0_1= 0.0 / euler angle 1 at CABSTART EULER0_2= 0.0 / euler angle 2 at CABSTART EULER0_3= 0.0 / euler angle 3 at CABSTART RA_PNT0 = 0.0 / RA of the pointing (degrees) at CABSTART DEC_PNT0= 0.0 / DEC of the pointing (degrees) at CABSTART EXPEND = 0.0 / exposure end time (MJD) CABEND = 0.0 / (MJD) SUNANGL1= 50.0 / angle between sun and opt axis at CABEND MOONANG1= 30.0 / angle between moon and opt axis at CABEND TEL_ALT1= 20.0 / angle between opt axis and Elimb at CABEND POS_ANG1= 20.0 / angle between y axis and NP at CABEND POSI1_X = 0.0 / the orbital position in X at CABEND POSI1_Y = 0.0 / the orbital position in Y at CABEND POSI1_Z = 0.0 / the orbital position in Z at CABEND VELO1_X = 0.0 / the orbital velocity in X at CABEND VELO1_Y = 0.0 / the orbital velocity in Y at CABEND VELO1_Z = 0.0 / the orbital velocity in Z at CABEND EULER1_1= 0.0 / euler angle 1 at CABEND EULER1_2= 0.0 / euler angle 2 at CABEND EULER1_3= 0.0 / euler angle 3 at CABEND RA_PNT1 = 0.0 / RA of the pointing (degrees) at CABEND DEC_PNT1= 0.0 / DEC of the pointing (degrees) at CABEND EXPTIME = 150.0 / exposure duration EPOCH = 2000.0 / coordinate epoch COMMENT Other information COMMENT ================================================================== CHECKSUM= 'abcdefg ' / HDU checksum updated yyyy-mm-ddTHH:MM:SS DATASUM = 'abcdefg ' / data unit checksum updated yyyy-mm-ddTHH:MM:SS END
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