Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
csst-sims
csst_msc_sim
Commits
2c2dac03
Commit
2c2dac03
authored
May 12, 2024
by
Fang Yuedong
Browse files
remove files
parent
4afd1181
Changes
211
Hide whitespace changes
Inline
Side-by-side
Catalog/C9_Catalog.py
deleted
100644 → 0
View file @
4afd1181
import
os
import
galsim
import
random
import
copy
import
numpy
as
np
import
h5py
as
h5
import
healpy
as
hp
import
astropy.constants
as
cons
import
traceback
from
astropy.coordinates
import
spherical_to_cartesian
from
astropy.table
import
Table
from
scipy
import
interpolate
from
datetime
import
datetime
from
ObservationSim.MockObject
import
CatalogBase
,
Star
,
Galaxy
,
Quasar
from
ObservationSim.MockObject._util
import
tag_sed
,
getObservedSED
,
getABMAG
,
integrate_sed_bandpass
,
comoving_dist
from
ObservationSim.Astrometry.Astrometry_util
import
on_orbit_obs_position
# (TEST)
from
astropy.cosmology
import
FlatLambdaCDM
from
astropy
import
constants
from
astropy
import
units
as
U
from
astropy.coordinates
import
SkyCoord
from
astropy.io
import
fits
import
astropy.constants
as
atcons
import
ctypes
try
:
import
importlib.resources
as
pkg_resources
except
ImportError
:
# Try backported to PY<37 'importlib_resources'
import
importlib_resources
as
pkg_resources
NSIDE
=
128
bundle_file_list
=
[
'galaxies_C6_bundle000199.h5'
,
'galaxies_C6_bundle000200.h5'
,
'galaxies_C6_bundle000241.h5'
,
'galaxies_C6_bundle000242.h5'
,
'galaxies_C6_bundle000287.h5'
,
'galaxies_C6_bundle000288.h5'
,
'galaxies_C6_bundle000714.h5'
,
'galaxies_C6_bundle000715.h5'
,
'galaxies_C6_bundle000778.h5'
,
'galaxies_C6_bundle000779.h5'
,
'galaxies_C6_bundle000842.h5'
,
'galaxies_C6_bundle000843.h5'
,
'galaxies_C6_bundle002046.h5'
,
'galaxies_C6_bundle002110.h5'
,
'galaxies_C6_bundle002111.h5'
,
'galaxies_C6_bundle002173.h5'
,
'galaxies_C6_bundle002174.h5'
,
'galaxies_C6_bundle002238.h5'
,
'galaxies_C6_bundle002596.h5'
,
'galaxies_C6_bundle002597.h5'
,
'galaxies_C6_bundle002656.h5'
,
'galaxies_C6_bundle002657.h5'
,
'galaxies_C6_bundle002711.h5'
,
'galaxies_C6_bundle002712.h5'
,
'galaxies_C6_bundle002844.h5'
,
'galaxies_C6_bundle002845.h5'
,
'galaxies_C6_bundle002884.h5'
,
'galaxies_C6_bundle002885.h5'
,
'galaxies_C6_bundle002921.h5'
,
'galaxies_C6_bundle002922.h5'
]
qsosed_file_list
=
[
'quickspeclib_interp1d_run1.fits'
,
'quickspeclib_interp1d_run2.fits'
,
'quickspeclib_interp1d_run3.fits'
,
'quickspeclib_interp1d_run4.fits'
,
'quickspeclib_interp1d_run5.fits'
,
'quickspeclib_interp1d_run6.fits'
,
'quickspeclib_interp1d_run7.fits'
,
'quickspeclib_interp1d_run8.fits'
,
'quickspeclib_interp1d_run9.fits'
,
'quickspeclib_interp1d_run10.fits'
,
'quickspeclib_interp1d_run11.fits'
,
'quickspeclib_interp1d_run12.fits'
,
'quickspeclib_interp1d_run13.fits'
,
'quickspeclib_interp1d_run14.fits'
,
'quickspeclib_interp1d_run15.fits'
,
'quickspeclib_interp1d_run16.fits'
,
'quickspeclib_interp1d_run17.fits'
,
'quickspeclib_interp1d_run18.fits'
,
'quickspeclib_interp1d_run19.fits'
,
'quickspeclib_interp1d_run20.fits'
,
'quickspeclib_interp1d_run21.fits'
,
'quickspeclib_interp1d_run22.fits'
,
'quickspeclib_interp1d_run23.fits'
,
'quickspeclib_interp1d_run24.fits'
,
'quickspeclib_interp1d_run25.fits'
,
'quickspeclib_interp1d_run26.fits'
,
'quickspeclib_interp1d_run27.fits'
,
'quickspeclib_interp1d_run28.fits'
,
'quickspeclib_interp1d_run29.fits'
,
'quickspeclib_interp1d_run30.fits'
]
# star_file_list = ['C7_Gaia_Galaxia_RA170DECm23_healpix.hdf5', 'C7_Gaia_Galaxia_RA180DECp60_healpix.hdf5', 'C7_Gaia_Galaxia_RA240DECp30_healpix.hdf5', 'C7_Gaia_Galaxia_RA300DECm60_healpix.hdf5', 'C7_Gaia_Galaxia_RA30DECm48_healpix.hdf5']
star_center_list
=
[(
170.
,
-
23.
),
(
180.
,
60.
),
(
240.
,
30.
),
(
300.
,
-
60.
),
(
30.
,
-
48.
),[
246.5
,
40
]]
star_file_list
=
[
'C9_RA170_DECm23_calmag_Nside_128_healpix.hdf5'
,
'C9_RA180_DECp60_calmag_Nside_128_healpix.hdf5'
,
'C9_RA240_DECp30_calmag_Nside_128_healpix.hdf5'
,
'C9_RA300_DECm60_calmag_Nside_128_healpix.hdf5'
,
'C9_RA30_DECm48_calmag_Nside_128_healpix.hdf5'
,
'trilegal_calMag_mpi_Nside_128_healpix.hdf5'
]
class
StarParm
(
ctypes
.
Structure
):
_fields_
=
[
(
'logte'
,
ctypes
.
c_float
),
(
'logg'
,
ctypes
.
c_float
),
(
'Mass'
,
ctypes
.
c_float
),
(
'Av'
,
ctypes
.
c_float
),
(
'mu0'
,
ctypes
.
c_float
),
(
'Z'
,
ctypes
.
c_float
)]
def
get_bundleIndex
(
healpixID_ring
,
bundleOrder
=
4
,
healpixOrder
=
7
):
assert
NSIDE
==
2
**
healpixOrder
shift
=
healpixOrder
-
bundleOrder
shift
=
2
*
shift
nside_bundle
=
2
**
bundleOrder
nside_healpix
=
2
**
healpixOrder
healpixID_nest
=
hp
.
ring2nest
(
nside_healpix
,
healpixID_ring
)
bundleID_nest
=
(
healpixID_nest
>>
shift
)
bundleID_ring
=
hp
.
nest2ring
(
nside_bundle
,
bundleID_nest
)
return
bundleID_ring
def
get_agnsed_file
(
bundle_file_name
):
return
qsosed_file_list
[
bundle_file_list
.
index
(
bundle_file_name
)]
def
get_star_cat
(
ra_pointing
,
dec_pointing
):
pointing_c
=
SkyCoord
(
ra
=
ra_pointing
*
U
.
deg
,
dec
=
dec_pointing
*
U
.
deg
)
max_dist
=
10
return_star_path
=
None
for
star_file
,
center
in
zip
(
star_file_list
,
star_center_list
):
center_c
=
SkyCoord
(
ra
=
center
[
0
]
*
U
.
deg
,
dec
=
center
[
1
]
*
U
.
deg
)
dist
=
pointing_c
.
separation
(
center_c
).
to
(
U
.
deg
).
value
if
dist
<
max_dist
:
return_star_path
=
star_file
max_dist
=
dist
return
return_star_path
class
Catalog
(
CatalogBase
):
def
__init__
(
self
,
config
,
chip
,
pointing
,
chip_output
,
filt
,
**
kwargs
):
super
().
__init__
()
self
.
cat_dir
=
config
[
"catalog_options"
][
"input_path"
][
"cat_dir"
]
self
.
cosmo
=
FlatLambdaCDM
(
H0
=
67.66
,
Om0
=
0.3111
)
self
.
chip_output
=
chip_output
self
.
filt
=
filt
self
.
logger
=
chip_output
.
logger
with
pkg_resources
.
path
(
'Catalog.data'
,
'SLOAN_SDSS.g.fits'
)
as
filter_path
:
self
.
normF_star
=
Table
.
read
(
str
(
filter_path
))
self
.
config
=
config
self
.
chip
=
chip
self
.
pointing
=
pointing
self
.
max_size
=
0.
if
"star_cat"
in
config
[
"catalog_options"
][
"input_path"
]
and
config
[
"catalog_options"
][
"input_path"
][
"star_cat"
]
and
not
config
[
"catalog_options"
][
"galaxy_only"
]:
# Get the cloest star catalog file
star_file_name
=
get_star_cat
(
ra_pointing
=
self
.
pointing
.
ra
,
dec_pointing
=
self
.
pointing
.
dec
)
star_path
=
os
.
path
.
join
(
config
[
"catalog_options"
][
"input_path"
][
"star_cat"
],
star_file_name
)
self
.
star_path
=
os
.
path
.
join
(
self
.
cat_dir
,
star_path
)
self
.
star_SED_path
=
config
[
"catalog_options"
][
"SED_templates_path"
][
"star_SED"
]
self
.
_load_SED_lib_star
()
if
"galaxy_cat"
in
config
[
"catalog_options"
][
"input_path"
]
and
config
[
"catalog_options"
][
"input_path"
][
"galaxy_cat"
]
and
not
config
[
"catalog_options"
][
"star_only"
]:
galaxy_dir
=
config
[
"catalog_options"
][
"input_path"
][
"galaxy_cat"
]
self
.
galaxy_path
=
os
.
path
.
join
(
self
.
cat_dir
,
galaxy_dir
)
self
.
galaxy_SED_path
=
config
[
"catalog_options"
][
"SED_templates_path"
][
"galaxy_SED"
]
self
.
_load_SED_lib_gals
()
self
.
agn_seds
=
{}
if
"AGN_SED"
in
config
[
"catalog_options"
][
"SED_templates_path"
]
and
not
config
[
"catalog_options"
][
"star_only"
]:
self
.
AGN_SED_path
=
config
[
"catalog_options"
][
"SED_templates_path"
][
"AGN_SED"
]
if
"rotateEll"
in
config
[
"catalog_options"
]:
self
.
rotation
=
np
.
radians
(
float
(
config
[
"catalog_options"
][
"rotateEll"
]))
else
:
self
.
rotation
=
0.
# Update output .cat header with catalog specific output columns
self
.
_add_output_columns_header
()
self
.
_get_healpix_list
()
self
.
_load
()
def
_add_output_columns_header
(
self
):
self
.
add_hdr
=
" av stellarmass dm teff logg feh"
self
.
add_hdr
+=
" bulgemass diskmass detA e1 e2 kappa g1 g2 size galType veldisp "
self
.
add_fmt
=
"%8.4f %8.4f %8.4f %8.4f %8.4f %8.4f"
self
.
add_fmt
+=
" %8.4f %8.4f %8.4f %8.4f %8.4f %8.4f %8.4f %8.4f %8.4f %4d %8.4f "
self
.
chip_output
.
update_output_header
(
additional_column_names
=
self
.
add_hdr
)
def
_get_healpix_list
(
self
):
self
.
sky_coverage
=
self
.
chip
.
getSkyCoverageEnlarged
(
self
.
chip
.
img
.
wcs
,
margin
=
0.2
)
ra_min
,
ra_max
,
dec_min
,
dec_max
=
self
.
sky_coverage
.
xmin
,
self
.
sky_coverage
.
xmax
,
self
.
sky_coverage
.
ymin
,
self
.
sky_coverage
.
ymax
ra
=
np
.
deg2rad
(
np
.
array
([
ra_min
,
ra_max
,
ra_max
,
ra_min
]))
dec
=
np
.
deg2rad
(
np
.
array
([
dec_max
,
dec_max
,
dec_min
,
dec_min
]))
self
.
pix_list
=
hp
.
query_polygon
(
NSIDE
,
hp
.
ang2vec
(
np
.
radians
(
90.
)
-
dec
,
ra
),
inclusive
=
True
)
if
self
.
logger
is
not
None
:
msg
=
str
((
"HEALPix List: "
,
self
.
pix_list
))
self
.
logger
.
info
(
msg
)
else
:
print
(
"HEALPix List: "
,
self
.
pix_list
)
def
load_norm_filt
(
self
,
obj
):
if
obj
.
type
==
"star"
:
return
self
.
normF_star
elif
obj
.
type
==
"galaxy"
or
obj
.
type
==
"quasar"
:
# return self.normF_galaxy
return
None
else
:
return
None
# def _load_SED_lib_star(self):
# self.tempSED_star = h5.File(self.star_SED_path,'r')
def
_load_SED_lib_star
(
self
):
# self.tempSED_star = h5.File(self.star_SED_path,'r')
with
pkg_resources
.
path
(
'Catalog.data'
,
'starSpecInterp.so'
)
as
ddl_path
:
self
.
starDDL
=
ctypes
.
CDLL
(
str
(
ddl_path
))
self
.
starDDL
.
loadSpecLibs
.
argtypes
=
[
ctypes
.
c_char_p
,
ctypes
.
c_char_p
]
self
.
starDDL
.
loadExts
.
argtypes
=
[
ctypes
.
c_char_p
]
nwv
=
self
.
starDDL
.
loadSpecLibs
(
str
.
encode
(
os
.
path
.
join
(
self
.
star_SED_path
,
'file_BT-Settl_CSST_wl1000-24000_R1000.par'
)),
str
.
encode
(
self
.
star_SED_path
))
self
.
starDDL
.
loadExts
(
str
.
encode
(
os
.
path
.
join
(
self
.
star_SED_path
,
"Ext_odonnell94_R3.1_CSST_wl1000-24000_R1000.fits"
)))
self
.
star_spec_len
=
nwv
def
_interp_star_sed
(
self
,
obj
):
spec
=
(
ctypes
.
c_float
*
self
.
star_spec_len
)()
wave
=
(
ctypes
.
c_float
*
self
.
star_spec_len
)()
self
.
starDDL
.
interpSingleStar
.
argtypes
=
[
ctypes
.
Structure
,
ctypes
.
POINTER
(
ctypes
.
c_float
)]
# s=Star(obj.param['teff'], obj.param['grav''], obj.paramstar['mwmsc_mass'], obj.param['AV'], obj.param['DM'], obj.param['z_met'])
s
=
StarParm
(
obj
.
param
[
'teff'
],
obj
.
param
[
'logg'
],
obj
.
param
[
'stellarMass'
],
obj
.
param
[
'av'
],
obj
.
param
[
'DM'
],
obj
.
param
[
'feh'
])
self
.
starDDL
.
interpSingleStar
(
s
,
spec
,
wave
)
rv_c
=
obj
.
param
[
'rv'
]
/
(
atcons
.
c
.
value
/
1000.
)
Doppler_factor
=
np
.
sqrt
((
1
+
rv_c
)
/
(
1
-
rv_c
))
wave_RV
=
wave
*
Doppler_factor
return
wave_RV
,
np
.
power
(
10
,
spec
[:])
def
_load_SED_lib_gals
(
self
):
pcs
=
h5
.
File
(
os
.
path
.
join
(
self
.
galaxy_SED_path
,
"pcs.h5"
),
"r"
)
lamb
=
h5
.
File
(
os
.
path
.
join
(
self
.
galaxy_SED_path
,
"lamb.h5"
),
"r"
)
self
.
lamb_gal
=
lamb
[
'lamb'
][()]
self
.
pcs
=
pcs
[
'pcs'
][()]
def
_load_gals
(
self
,
gals
,
pix_id
=
None
,
cat_id
=
0
,
agnsed_file
=
""
):
ngals
=
len
(
gals
[
'ra'
])
# Apply astrometric modeling
ra_arr
=
gals
[
'ra'
][:]
dec_arr
=
gals
[
'dec'
][:]
if
self
.
config
[
"obs_setting"
][
"enable_astrometric_model"
]:
ra_list
=
ra_arr
.
tolist
()
dec_list
=
dec_arr
.
tolist
()
pmra_list
=
np
.
zeros
(
ngals
).
tolist
()
pmdec_list
=
np
.
zeros
(
ngals
).
tolist
()
rv_list
=
np
.
zeros
(
ngals
).
tolist
()
parallax_list
=
[
1e-9
]
*
ngals
dt
=
datetime
.
utcfromtimestamp
(
self
.
pointing
.
timestamp
)
date_str
=
dt
.
date
().
isoformat
()
time_str
=
dt
.
time
().
isoformat
()
ra_arr
,
dec_arr
=
on_orbit_obs_position
(
input_ra_list
=
ra_list
,
input_dec_list
=
dec_list
,
input_pmra_list
=
pmra_list
,
input_pmdec_list
=
pmdec_list
,
input_rv_list
=
rv_list
,
input_parallax_list
=
parallax_list
,
input_nstars
=
ngals
,
input_x
=
self
.
pointing
.
sat_x
,
input_y
=
self
.
pointing
.
sat_y
,
input_z
=
self
.
pointing
.
sat_z
,
input_vx
=
self
.
pointing
.
sat_vx
,
input_vy
=
self
.
pointing
.
sat_vy
,
input_vz
=
self
.
pointing
.
sat_vz
,
input_epoch
=
"J2000"
,
input_date_str
=
date_str
,
input_time_str
=
time_str
)
for
igals
in
range
(
ngals
):
# # (TEST)
# if igals > 100:
# break
param
=
self
.
initialize_param
()
param
[
'ra'
]
=
ra_arr
[
igals
]
param
[
'dec'
]
=
dec_arr
[
igals
]
param
[
'ra_orig'
]
=
gals
[
'ra'
][
igals
]
param
[
'dec_orig'
]
=
gals
[
'dec'
][
igals
]
if
not
self
.
chip
.
isContainObj
(
ra_obj
=
param
[
'ra'
],
dec_obj
=
param
[
'dec'
],
margin
=
200
):
continue
# param['mag_use_normal'] = gals['mag_csst_%s'%(self.filt.filter_type)][igals]
if
self
.
filt
.
filter_type
==
'NUV'
:
param
[
'mag_use_normal'
]
=
gals
[
'mag_csst_nuv'
][
igals
]
else
:
param
[
'mag_use_normal'
]
=
gals
[
'mag_csst_%s'
%
(
self
.
filt
.
filter_type
)][
igals
]
if
self
.
filt
.
is_too_dim
(
mag
=
param
[
'mag_use_normal'
],
margin
=
self
.
config
[
"obs_setting"
][
"mag_lim_margin"
]):
continue
param
[
'z'
]
=
gals
[
'redshift'
][
igals
]
param
[
'model_tag'
]
=
'None'
param
[
'g1'
]
=
gals
[
'shear'
][
igals
][
0
]
param
[
'g2'
]
=
gals
[
'shear'
][
igals
][
1
]
param
[
'kappa'
]
=
gals
[
'kappa'
][
igals
]
param
[
'e1'
]
=
gals
[
'ellipticity_true'
][
igals
][
0
]
param
[
'e2'
]
=
gals
[
'ellipticity_true'
][
igals
][
1
]
# For shape calculation
param
[
'e1'
],
param
[
'e2'
],
param
[
'ell_total'
]
=
self
.
rotate_ellipticity
(
e1
=
gals
[
'ellipticity_true'
][
igals
][
0
],
e2
=
gals
[
'ellipticity_true'
][
igals
][
1
],
rotation
=
self
.
rotation
,
unit
=
'radians'
)
# param['ell_total'] = np.sqrt(param['e1']**2 + param['e2']**2)
if
param
[
'ell_total'
]
>
0.9
:
continue
# phi_e = cmath.phase(complex(param['e1'], param['e2']))
# param['e1'] = param['ell_total'] * np.cos(phi_e + 2*self.rotation)
# param['e2'] = param['ell_total'] * np.sin(phi_e + 2*self.rotation)
param
[
'e1_disk'
]
=
param
[
'e1'
]
param
[
'e2_disk'
]
=
param
[
'e2'
]
param
[
'e1_bulge'
]
=
param
[
'e1'
]
param
[
'e2_bulge'
]
=
param
[
'e2'
]
param
[
'delta_ra'
]
=
0
param
[
'delta_dec'
]
=
0
# Masses
param
[
'bulgemass'
]
=
gals
[
'bulgemass'
][
igals
]
param
[
'diskmass'
]
=
gals
[
'diskmass'
][
igals
]
param
[
'size'
]
=
gals
[
'size'
][
igals
]
if
param
[
'size'
]
>
self
.
max_size
:
self
.
max_size
=
param
[
'size'
]
# Sersic index
param
[
'disk_sersic_idx'
]
=
1.
param
[
'bulge_sersic_idx'
]
=
4.
# Sizes
param
[
'bfrac'
]
=
param
[
'bulgemass'
]
/
(
param
[
'bulgemass'
]
+
param
[
'diskmass'
])
if
param
[
'bfrac'
]
>=
0.6
:
param
[
'hlr_bulge'
]
=
param
[
'size'
]
param
[
'hlr_disk'
]
=
param
[
'size'
]
*
(
1.
-
param
[
'bfrac'
])
else
:
param
[
'hlr_disk'
]
=
param
[
'size'
]
param
[
'hlr_bulge'
]
=
param
[
'size'
]
*
param
[
'bfrac'
]
# SED coefficients
param
[
'coeff'
]
=
gals
[
'coeff'
][
igals
]
param
[
'detA'
]
=
gals
[
'detA'
][
igals
]
# Others
param
[
'galType'
]
=
gals
[
'type'
][
igals
]
param
[
'veldisp'
]
=
gals
[
'veldisp'
][
igals
]
# TEST no redening and no extinction
param
[
'av'
]
=
0.0
param
[
'redden'
]
=
0
# TEMP
self
.
ids
+=
1
param
[
'id'
]
=
'%06d'
%
(
int
(
pix_id
))
+
'%06d'
%
(
cat_id
)
+
'%08d'
%
(
igals
)
# Is this an Quasar?
param
[
'qsoindex'
]
=
gals
[
'qsoindex'
][
igals
]
if
param
[
'qsoindex'
]
==
-
1
:
param
[
'star'
]
=
0
# Galaxy
param
[
'agnsed_file'
]
=
""
obj
=
Galaxy
(
param
,
logger
=
self
.
logger
)
else
:
param_qso
=
copy
.
deepcopy
(
param
)
param_qso
[
'star'
]
=
2
# Quasar
param_qso
[
'agnsed_file'
]
=
agnsed_file
# First add QSO model
obj
=
Quasar
(
param_qso
,
logger
=
self
.
logger
)
# Need to deal with additional output columns
obj
.
additional_output_str
=
self
.
add_fmt
%
(
0.
,
0.
,
0.
,
0.
,
0.
,
0.
,
0.
,
0.
,
0.
,
0.
,
0.
,
0.
,
0.
,
0.
,
0.
,
0
,
0.
)
self
.
objs
.
append
(
obj
)
# Then add host galaxy model
param
[
'star'
]
=
0
# Galaxy
param
[
'agnsed_file'
]
=
""
obj
=
Galaxy
(
param
,
logger
=
self
.
logger
)
# Need to deal with additional output columns for (host) galaxy
obj
.
additional_output_str
=
self
.
add_fmt
%
(
0.
,
0.
,
0.
,
0.
,
0.
,
0.
,
param
[
'bulgemass'
],
param
[
'diskmass'
],
param
[
'detA'
],
param
[
'e1'
],
param
[
'e2'
],
param
[
'kappa'
],
param
[
'g1'
],
param
[
'g2'
],
param
[
'size'
],
param
[
'galType'
],
param
[
'veldisp'
])
self
.
objs
.
append
(
obj
)
def
_load_stars
(
self
,
stars
,
pix_id
=
None
):
nstars
=
len
(
stars
[
'RA'
])
# Apply astrometric modeling
ra_arr
=
stars
[
"RA"
][:]
dec_arr
=
stars
[
"DEC"
][:]
pmra_arr
=
stars
[
'pmra'
][:]
pmdec_arr
=
stars
[
'pmdec'
][:]
rv_arr
=
stars
[
'RV'
][:]
parallax_arr
=
stars
[
'parallax'
][:]
if
self
.
config
[
"obs_setting"
][
"enable_astrometric_model"
]:
ra_list
=
ra_arr
.
tolist
()
dec_list
=
dec_arr
.
tolist
()
pmra_list
=
pmra_arr
.
tolist
()
pmdec_list
=
pmdec_arr
.
tolist
()
rv_list
=
rv_arr
.
tolist
()
parallax_list
=
parallax_arr
.
tolist
()
dt
=
datetime
.
utcfromtimestamp
(
self
.
pointing
.
timestamp
)
date_str
=
dt
.
date
().
isoformat
()
time_str
=
dt
.
time
().
isoformat
()
ra_arr
,
dec_arr
=
on_orbit_obs_position
(
input_ra_list
=
ra_list
,
input_dec_list
=
dec_list
,
input_pmra_list
=
pmra_list
,
input_pmdec_list
=
pmdec_list
,
input_rv_list
=
rv_list
,
input_parallax_list
=
parallax_list
,
input_nstars
=
nstars
,
input_x
=
self
.
pointing
.
sat_x
,
input_y
=
self
.
pointing
.
sat_y
,
input_z
=
self
.
pointing
.
sat_z
,
input_vx
=
self
.
pointing
.
sat_vx
,
input_vy
=
self
.
pointing
.
sat_vy
,
input_vz
=
self
.
pointing
.
sat_vz
,
input_epoch
=
"J2000"
,
input_date_str
=
date_str
,
input_time_str
=
time_str
)
for
istars
in
range
(
nstars
):
# (TEST)
# if istars > 100:
# break
param
=
self
.
initialize_param
()
param
[
'ra'
]
=
ra_arr
[
istars
]
param
[
'dec'
]
=
dec_arr
[
istars
]
param
[
'ra_orig'
]
=
stars
[
"RA"
][
istars
]
param
[
'dec_orig'
]
=
stars
[
"DEC"
][
istars
]
param
[
'pmra'
]
=
pmra_arr
[
istars
]
param
[
'pmdec'
]
=
pmdec_arr
[
istars
]
param
[
'rv'
]
=
rv_arr
[
istars
]
param
[
'parallax'
]
=
parallax_arr
[
istars
]
if
not
self
.
chip
.
isContainObj
(
ra_obj
=
param
[
'ra'
],
dec_obj
=
param
[
'dec'
],
margin
=
200
):
continue
param
[
'mag_use_normal'
]
=
stars
[
'app_sdss_g'
][
istars
]
self
.
ids
+=
1
param
[
'id'
]
=
'%06d'
%
(
int
(
pix_id
))
+
'%08d'
%
(
istars
)
# param['sed_type'] = istars
# param['model_tag'] = ''
param
[
'teff'
]
=
stars
[
'teff'
][
istars
]
param
[
'logg'
]
=
stars
[
'grav'
][
istars
]
param
[
'feh'
]
=
stars
[
'z_met'
][
istars
]
param
[
'stellarMass'
]
=
stars
[
'mass'
][
istars
]
param
[
'av'
]
=
stars
[
'AV'
][
istars
]
param
[
'DM'
]
=
stars
[
'DM'
][
istars
]
# param['z_met'] = stars['z_met'][istars]
param
[
'z'
]
=
0.0
param
[
'star'
]
=
1
# Star
try
:
obj
=
Star
(
param
,
logger
=
self
.
logger
)
except
Exception
as
e
:
print
(
e
)
# Append additional output columns to the .cat file
obj
.
additional_output_str
=
self
.
add_fmt
%
(
param
[
"av"
],
param
[
'stellarMass'
],
param
[
'DM'
],
param
[
'teff'
],
param
[
'logg'
],
param
[
'feh'
],
0.
,
0.
,
0.
,
0.
,
0.
,
0.
,
0.
,
0.
,
0.
,
-
1
,
0.
)
self
.
objs
.
append
(
obj
)
def
_load
(
self
,
**
kwargs
):
self
.
objs
=
[]
self
.
ids
=
0
if
"star_cat"
in
self
.
config
[
"catalog_options"
][
"input_path"
]
and
self
.
config
[
"catalog_options"
][
"input_path"
][
"star_cat"
]
and
not
self
.
config
[
"catalog_options"
][
"galaxy_only"
]:
star_cat
=
h5
.
File
(
self
.
star_path
,
'r'
)[
'star_catalog'
]
for
pix
in
self
.
pix_list
:
try
:
stars
=
star_cat
[
str
(
pix
)]
self
.
_load_stars
(
stars
,
pix_id
=
pix
)
del
stars
except
Exception
as
e
:
self
.
logger
.
error
(
str
(
e
))
# print(e)
if
"galaxy_cat"
in
self
.
config
[
"catalog_options"
][
"input_path"
]
and
self
.
config
[
"catalog_options"
][
"input_path"
][
"galaxy_cat"
]
and
not
self
.
config
[
"catalog_options"
][
"star_only"
]:
for
pix
in
self
.
pix_list
:
try
:
bundleID
=
get_bundleIndex
(
pix
)
bundle_file
=
"galaxies_C6_bundle{:06}.h5"
.
format
(
bundleID
)
file_path
=
os
.
path
.
join
(
self
.
galaxy_path
,
bundle_file
)
gals_cat
=
h5
.
File
(
file_path
,
'r'
)[
'galaxies'
]
gals
=
gals_cat
[
str
(
pix
)]
# Get corresponding AGN SED file
agnsed_file
=
get_agnsed_file
(
bundle_file
)
agnsed_path
=
os
.
path
.
join
(
self
.
AGN_SED_path
,
agnsed_file
)
self
.
agn_seds
[
agnsed_file
]
=
fits
.
open
(
agnsed_path
)[
0
].
data
self
.
_load_gals
(
gals
,
pix_id
=
pix
,
cat_id
=
bundleID
,
agnsed_file
=
agnsed_file
)
del
gals
except
Exception
as
e
:
traceback
.
print_exc
()
self
.
logger
.
error
(
str
(
e
))
print
(
e
)
if
self
.
logger
is
not
None
:
self
.
logger
.
info
(
"maximum galaxy size: %.4f"
%
(
self
.
max_size
))
self
.
logger
.
info
(
"number of objects in catalog: %d"
%
(
len
(
self
.
objs
)))
else
:
print
(
"number of objects in catalog: "
,
len
(
self
.
objs
))
def
load_sed
(
self
,
obj
,
**
kwargs
):
if
obj
.
type
==
'star'
:
# _, wave, flux = tag_sed(
# h5file=self.tempSED_star,
# model_tag=obj.param['model_tag'],
# teff=obj.param['teff'],
# logg=obj.param['logg'],
# feh=obj.param['feh']
# )
wave
,
flux
=
self
.
_interp_star_sed
(
obj
)
elif
obj
.
type
==
'galaxy'
or
obj
.
type
==
'quasar'
:
factor
=
10
**
(
-
.
4
*
self
.
cosmo
.
distmod
(
obj
.
z
).
value
)
if
obj
.
type
==
'galaxy'
:
flux
=
np
.
matmul
(
self
.
pcs
,
obj
.
coeff
)
*
factor
# if np.any(flux < 0):
# raise ValueError("Glaxy %s: negative SED fluxes"%obj.id)
flux
[
flux
<
0
]
=
0.
sedcat
=
np
.
vstack
((
self
.
lamb_gal
,
flux
)).
T
sed_data
=
getObservedSED
(
sedCat
=
sedcat
,
redshift
=
obj
.
z
,
av
=
obj
.
param
[
"av"
],
redden
=
obj
.
param
[
"redden"
]
)
wave
,
flux
=
sed_data
[
0
],
sed_data
[
1
]
elif
obj
.
type
==
'quasar'
:
flux
=
self
.
agn_seds
[
obj
.
agnsed_file
][
int
(
obj
.
qsoindex
)]
*
1e-17
flux
[
flux
<
0
]
=
0.
wave
=
self
.
lamb_gal
*
(
1.0
+
obj
.
z
)
else
:
raise
ValueError
(
"Object type not known"
)
speci
=
interpolate
.
interp1d
(
wave
,
flux
)
lamb
=
np
.
arange
(
2000
,
11001
+
0.5
,
0.5
)
y
=
speci
(
lamb
)
# erg/s/cm2/A --> photon/s/m2/A
all_sed
=
y
*
lamb
/
(
cons
.
h
.
value
*
cons
.
c
.
value
)
*
1e-13
sed
=
Table
(
np
.
array
([
lamb
,
all_sed
]).
T
,
names
=
(
'WAVELENGTH'
,
'FLUX'
))
if
obj
.
type
==
'quasar'
:
# integrate to get the magnitudes
sed_photon
=
np
.
array
([
sed
[
'WAVELENGTH'
],
sed
[
'FLUX'
]]).
T
sed_photon
=
galsim
.
LookupTable
(
x
=
np
.
array
(
sed_photon
[:,
0
]),
f
=
np
.
array
(
sed_photon
[:,
1
]),
interpolant
=
'nearest'
)
sed_photon
=
galsim
.
SED
(
sed_photon
,
wave_type
=
'A'
,
flux_type
=
'1'
,
fast
=
False
)
interFlux
=
integrate_sed_bandpass
(
sed
=
sed_photon
,
bandpass
=
self
.
filt
.
bandpass_full
)
obj
.
param
[
'mag_use_normal'
]
=
getABMAG
(
interFlux
,
self
.
filt
.
bandpass_full
)
# mag = getABMAG(interFlux, self.filt.bandpass_full)
# print("mag diff = %.3f"%(mag - obj.param['mag_use_normal']))
del
wave
del
flux
return
sed
Catalog/Catalog_example.py
deleted
100644 → 0
View file @
4afd1181
import
os
import
numpy
as
np
import
astropy.constants
as
cons
from
astropy.table
import
Table
from
scipy
import
interpolate
from
ObservationSim.MockObject
import
CatalogBase
,
Star
,
Galaxy
,
Quasar
class
Catalog
(
CatalogBase
):
"""An user customizable class for reading in catalog(s) of objects and SEDs.
NOTE: must inherit the "CatalogBase" abstract class
...
Attributes
----------
cat_dir : str
a directory that contains the catalog file(s)
star_path : str
path to the star catalog file
star_SED_path : str
path to the star SED data
objs : list
a list of ObservationSim.MockObject (Star, Galaxy, or Quasar)
NOTE: must have "obj" list when implement your own Catalog
Methods
----------
load_sed(obj, **kwargs):
load the corresponding SED data for one object
load_norm_filt(obj):
load the filter throughput for the input catalog's photometric system.
"""
def
__init__
(
self
,
config
,
chip
,
**
kwargs
):
"""Constructor method.
Parameters
----------
config : dict
configuration dictionary which is parsed from the input YAML file
chip: ObservationSim.Instrument.Chip
an ObservationSim.Instrument.Chip instance, can be used to identify the band etc.
**kwargs : dict
other needed input parameters (in key-value pairs), please modify corresponding
initialization call in "ObservationSim.py" as you need.
Returns
----------
None
"""
super
().
__init__
()
self
.
cat_dir
=
os
.
path
.
join
(
config
[
"data_dir"
],
config
[
"catalog_options"
][
"input_path"
][
"cat_dir"
])
self
.
chip
=
chip
if
"star_cat"
in
config
[
"catalog_options"
][
"input_path"
]
and
config
[
"catalog_options"
][
"input_path"
][
"star_cat"
]:
star_file
=
config
[
"catalog_options"
][
"input_path"
][
"star_cat"
]
star_SED_file
=
config
[
"catalog_options"
][
"SED_templates_path"
][
"star_SED"
]
self
.
star_path
=
os
.
path
.
join
(
self
.
cat_dir
,
star_file
)
self
.
star_SED_path
=
os
.
path
.
join
(
config
[
"data_dir"
],
star_SED_file
)
# NOTE: must call _load() method here to read in all objects
self
.
objs
=
[]
self
.
_load
()
def
_load
(
self
,
**
kwargs
):
"""Read in all objects in from the catalog file(s).
This is a must implemented method which is used to read in all objects, and
then convert them to ObservationSim.MockObject (Star, Galaxy, or Quasar).
Currently,
the model of ObservationSim.MockObject.Star class requires:
param["star"] : int
specify the object type: 0: galaxy, 1: star, 2: quasar
param["id"] : int
ID number of the object
param["ra"] : float
Right ascension (in degrees)
param["dec"] : float
Declination (in degrees)
param["mag_use_normal"]: float
the absolute magnitude in a particular filter
NOTE: if that filter is not the corresponding CSST filter, the
load_norm_filt(obj) function must be implemented to load the filter
throughput of that particular photometric system
the model of ObservationSim.MockObject.Galaxy class requires:
param["star"] : int
specify the object type: 0: galaxy, 1: star, 2: quasar
param["id"] : int
ID number of the object
param["ra"] : float
Right ascension (in degrees)
param["dec"] : float
Declination (in degrees)
param["mag_use_normal"]: float
the absolute magnitude in a particular filter
NOTE: if that filter is not the corresponding CSST filter, the
load_norm_filt(obj) function must be implemented to load the filter
throughput of that particular photometric system
param["bfrac"] : float
the bulge fraction
param["hlr_bulge"] : float
the half-light-radius of the bulge
param["hlr_disk"] : float
the half-light-radius of the disk
param["e1_bulge"], param["e2_bulge"] : float
the ellipticity of the bulge components
param["e1_disk"], param["e2_disk"] : float
the ellipticity of the disk components
(Optional parameters):
param['disk_sersic_idx']: float
Sersic index for galaxy disk component
param['bulge_sersic_idx']: float
Sersic index for galaxy bulge component
param['g1'], param['g2']: float
Reduced weak lensing shear components (valid for shear type: catalog)
the model of ObservationSim.MockObject.Galaxy class requires:
Currently a Quasar is modeled as a point source, just like a Star.
NOTE: To construct an object, according to its type, just call:
Star(param), Galaxy(param), or Quasar(param)
NOTE: All constructed objects should be appened to "self.objs".
NOTE: Any other parameters can also be set within "param" dict:
Used to calculate required quantities and/or SEDs etc.
Parameters
----------
**kwargs : dict
other needed input parameters (in key-value pairs), please modify corresponding
initialization call in "ObservationSim.py" as you need.
Returns
----------
None
"""
stars
=
Table
.
read
(
self
.
star_path
)
nstars
=
stars
[
'sourceID'
].
size
for
istars
in
range
(
nstars
):
param
=
self
.
initialize_param
()
param
[
'id'
]
=
istars
+
1
param
[
'ra'
]
=
stars
[
'RA'
][
istars
]
param
[
'dec'
]
=
stars
[
'Dec'
][
istars
]
param
[
'sed_type'
]
=
stars
[
'sourceID'
][
istars
]
param
[
'model_tag'
]
=
stars
[
'model_tag'
][
istars
]
param
[
'z'
]
=
0.0
param
[
'star'
]
=
1
# Star
param
[
'mag_use_normal'
]
=
stars
[
'app_sdss_g'
][
istars
]
obj
=
Star
(
param
)
self
.
objs
.
append
(
obj
)
def
load_sed
(
self
,
obj
,
**
kwargs
):
"""Load the corresponding SED data for a particular obj.
Parameters
----------
obj : ObservationSim.MockObject
the object to get SED data for
**kwargs : dict
other needed input parameters (in key-value pairs), please modify corresponding
initialization call in "ObservationSim.py" as you need.
Returns
----------
sed : Astropy.Table
the SED Table with two columns (namely, "WAVELENGTH", "FLUX"):
sed["WAVELENGTH"] : wavelength in Angstroms
sed["FLUX"] : fluxes in photons/s/m^2/A
NOTE: the range of wavelengthes must at least cover [2450 - 11000] Angstorms
"""
if
obj
.
type
==
'star'
:
wave
=
Table
.
read
(
self
.
star_SED_path
,
path
=
f
"/SED/wave_
{
obj
.
model_tag
}
"
)
flux
=
Table
.
read
(
self
.
star_SED_path
,
path
=
f
"/SED/
{
obj
.
sed_type
}
"
)
wave
,
flux
=
wave
[
'col0'
].
data
,
flux
[
'col0'
].
data
else
:
raise
ValueError
(
"Object type not known"
)
speci
=
interpolate
.
interp1d
(
wave
,
flux
)
lamb
=
np
.
arange
(
2400
,
11001
+
0.5
,
0.5
)
y
=
speci
(
lamb
)
# erg/s/cm^2/A --> photons/s/m^2/A
all_sed
=
y
*
lamb
/
(
cons
.
h
.
value
*
cons
.
c
.
value
)
*
1e-13
sed
=
Table
(
np
.
array
([
lamb
,
all_sed
]).
T
,
names
=
(
'WAVELENGTH'
,
'FLUX'
))
return
sed
def
load_norm_filt
(
self
,
obj
):
"""Load the corresponding thourghput for the input magnitude "param["mag_use_normal"]".
NOTE: if the input magnitude is already in CSST magnitude, simply return None
Parameters
----------
obj : ObservationSim.MockObject
the object to get thourghput data for
Returns
----------
norm_filt : Astropy.Table
the throughput Table with two columns (namely, "WAVELENGTH", "SENSITIVITY"):
norm_filt["WAVELENGTH"] : wavelengthes in Angstroms
norm_filt["SENSITIVITY"] : efficiencies
"""
return
None
\ No newline at end of file
Catalog/data/SLOAN_SDSS.g.fits
deleted
100644 → 0
View file @
4afd1181
File deleted
Catalog/data/__init__.py
deleted
100644 → 0
View file @
4afd1181
Catalog/data/lsst_throuput_g.fits
deleted
100644 → 0
View file @
4afd1181
File deleted
Catalog/data/starSpecInterp.so
deleted
100755 → 0
View file @
4afd1181
File deleted
Catalog/testCat_fits.py
deleted
100644 → 0
View file @
4afd1181
import
os
import
galsim
import
random
import
numpy
as
np
import
h5py
as
h5
import
healpy
as
hp
import
astropy.constants
as
cons
import
traceback
from
astropy.coordinates
import
spherical_to_cartesian
from
astropy.table
import
Table
from
scipy
import
interpolate
from
datetime
import
datetime
from
ObservationSim.MockObject
import
CatalogBase
,
Star
,
Galaxy
,
Quasar
,
Stamp
from
ObservationSim.MockObject._util
import
tag_sed
,
getObservedSED
,
getABMAG
,
integrate_sed_bandpass
,
comoving_dist
from
ObservationSim.Astrometry.Astrometry_util
import
on_orbit_obs_position
import
astropy.io.fits
as
fitsio
from
ObservationSim.MockObject._util
import
seds
,
sed_assign
,
extAv
# (TEST)
from
astropy.cosmology
import
FlatLambdaCDM
from
astropy
import
constants
from
astropy
import
units
as
U
try
:
import
importlib.resources
as
pkg_resources
except
ImportError
:
# Try backported to PY<37 'importlib_resources'
import
importlib_resources
as
pkg_resources
NSIDE
=
128
class
Catalog
(
CatalogBase
):
def
__init__
(
self
,
config
,
chip
,
pointing
,
chip_output
,
filt
,
**
kwargs
):
super
().
__init__
()
self
.
cat_dir
=
config
[
"catalog_options"
][
"input_path"
][
"cat_dir"
]
self
.
seed_Av
=
121212
#config["catalog_options"]["seed_Av"]
# (TEST)
self
.
cosmo
=
FlatLambdaCDM
(
H0
=
67.66
,
Om0
=
0.3111
)
self
.
chip_output
=
chip_output
self
.
filt
=
filt
self
.
logger
=
chip_output
.
logger
with
pkg_resources
.
path
(
'Catalog.data'
,
'SLOAN_SDSS.g.fits'
)
as
filter_path
:
self
.
normF_star
=
Table
.
read
(
str
(
filter_path
))
with
pkg_resources
.
path
(
'Catalog.data'
,
'lsst_throuput_g.fits'
)
as
filter_path
:
self
.
normF_galaxy
=
Table
.
read
(
str
(
filter_path
))
self
.
config
=
config
self
.
chip
=
chip
self
.
pointing
=
pointing
self
.
max_size
=
0.
if
"stamp_cat"
in
config
[
"catalog_options"
][
"input_path"
]
and
config
[
"catalog_options"
][
"input_path"
][
"stamp_cat"
]
and
config
[
"catalog_options"
][
"stamp_yes"
]:
stamp_file
=
config
[
"catalog_options"
][
"input_path"
][
"stamp_cat"
]
self
.
stamp_path
=
os
.
path
.
join
(
self
.
cat_dir
,
stamp_file
)
#self.stamp_SED_path = os.path.join(config["data_dir"], config["SED_templates_path"]["stamp_SED"]) ###shoule be stamp-SED
#self._load_SED_lib_stamps() ###shoule be stamp-SED
self
.
tempSed_gal
,
self
.
tempRed_gal
=
seds
(
"galaxy.list"
,
seddir
=
"/public/home/chengliang/CSSOSDataProductsSims/testCats/Templates/Galaxy/"
)
#only for test
self
.
_add_output_columns_header
()
self
.
_get_healpix_list
()
self
.
_load
()
def
_add_output_columns_header
(
self
):
self
.
add_hdr
=
" model_tag teff logg feh"
self
.
add_hdr
+=
" bulgemass diskmass detA e1 e2 kappa g1 g2 size galType veldisp "
self
.
add_fmt
=
" %10s %8.4f %8.4f %8.4f"
self
.
add_fmt
+=
" %8.4f %8.4f %8.4f %8.4f %8.4f %8.4f %8.4f %8.4f %8.4f %4d %8.4f "
self
.
chip_output
.
update_output_header
(
additional_column_names
=
self
.
add_hdr
)
def
_get_healpix_list
(
self
):
self
.
sky_coverage
=
self
.
chip
.
getSkyCoverageEnlarged
(
self
.
chip
.
img
.
wcs
,
margin
=
0.2
)
ra_min
,
ra_max
,
dec_min
,
dec_max
=
self
.
sky_coverage
.
xmin
,
self
.
sky_coverage
.
xmax
,
self
.
sky_coverage
.
ymin
,
self
.
sky_coverage
.
ymax
ra
=
np
.
deg2rad
(
np
.
array
([
ra_min
,
ra_max
,
ra_max
,
ra_min
]))
dec
=
np
.
deg2rad
(
np
.
array
([
dec_max
,
dec_max
,
dec_min
,
dec_min
]))
# vertices = spherical_to_cartesian(1., dec, ra)
self
.
pix_list
=
hp
.
query_polygon
(
NSIDE
,
hp
.
ang2vec
(
np
.
radians
(
90.
)
-
dec
,
ra
),
inclusive
=
True
)
# self.pix_list = hp.query_polygon(NSIDE, np.array(vertices).T, inclusive=True)
if
self
.
logger
is
not
None
:
msg
=
str
((
"HEALPix List: "
,
self
.
pix_list
))
self
.
logger
.
info
(
msg
)
else
:
print
(
"HEALPix List: "
,
self
.
pix_list
)
def
load_norm_filt
(
self
,
obj
):
if
obj
.
type
==
"stamp"
:
return
self
.
normF_galaxy
###normalize_filter for stamp
else
:
return
None
def
_load_stamps
(
self
,
stamps
,
pix_id
=
None
):
print
(
"debug:: load_stamps"
)
nstamps
=
len
(
stamps
[
'filename'
])
self
.
rng_sedGal
=
random
.
Random
()
self
.
rng_sedGal
.
seed
(
float
(
pix_id
))
# Use healpix index as the random seed
self
.
ud
=
galsim
.
UniformDeviate
(
pix_id
)
for
istamp
in
range
(
nstamps
):
print
(
"debug::"
,
istamp
)
fitsfile
=
os
.
path
.
join
(
self
.
cat_dir
,
"stampCats/"
+
stamps
[
'filename'
][
istamp
].
decode
(
'utf-8'
))
print
(
"debug::"
,
istamp
,
fitsfile
)
hdu
=
fitsio
.
open
(
fitsfile
)
param
=
self
.
initialize_param
()
param
[
'id'
]
=
hdu
[
0
].
header
[
'index'
]
#istamp
param
[
'star'
]
=
3
# Stamp type in .cat file
param
[
'ra'
]
=
hdu
[
0
].
header
[
'ra'
]
param
[
'dec'
]
=
hdu
[
0
].
header
[
'dec'
]
param
[
'pixScale'
]
=
hdu
[
0
].
header
[
'pixScale'
]
#param['srcGalaxyID'] = hdu[0].header['srcGID']
#param['mu']= hdu[0].header['mu']
#param['PA']= hdu[0].header['PA']
#param['bfrac']= hdu[0].header['bfrac']
#param['z']= hdu[0].header['z']
param
[
'mag_use_normal'
]
=
hdu
[
0
].
header
[
'mag_g'
]
#gals['mag_true_g_lsst']
# Apply astrometric modeling
# in C3 case only aberration
param
[
'ra_orig'
]
=
param
[
'ra'
]
param
[
'dec_orig'
]
=
param
[
'dec'
]
if
self
.
config
[
"obs_setting"
][
"enable_astrometric_model"
]:
ra_list
=
[
param
[
'ra'
]]
#ra_arr.tolist()
dec_list
=
[
param
[
'dec'
]]
#dec_arr.tolist()
pmra_list
=
np
.
zeros
(
1
).
tolist
()
pmdec_list
=
np
.
zeros
(
1
).
tolist
()
rv_list
=
np
.
zeros
(
1
).
tolist
()
parallax_list
=
[
1e-9
]
*
1
dt
=
datetime
.
fromtimestamp
(
self
.
pointing
.
timestamp
)
date_str
=
dt
.
date
().
isoformat
()
time_str
=
dt
.
time
().
isoformat
()
ra_arr
,
dec_arr
=
on_orbit_obs_position
(
input_ra_list
=
ra_list
,
input_dec_list
=
dec_list
,
input_pmra_list
=
pmra_list
,
input_pmdec_list
=
pmdec_list
,
input_rv_list
=
rv_list
,
input_parallax_list
=
parallax_list
,
input_nstars
=
1
,
input_x
=
self
.
pointing
.
sat_x
,
input_y
=
self
.
pointing
.
sat_y
,
input_z
=
self
.
pointing
.
sat_z
,
input_vx
=
self
.
pointing
.
sat_vx
,
input_vy
=
self
.
pointing
.
sat_vy
,
input_vz
=
self
.
pointing
.
sat_vz
,
input_epoch
=
"J2015.5"
,
input_date_str
=
date_str
,
input_time_str
=
time_str
)
param
[
'ra'
]
=
ra_arr
[
0
]
param
[
'dec'
]
=
dec_arr
[
0
]
# Assign each galaxy a template SED
param
[
'sed_type'
]
=
sed_assign
(
phz
=
param
[
'z'
],
btt
=
param
[
'bfrac'
],
rng
=
self
.
rng_sedGal
)
param
[
'redden'
]
=
self
.
tempRed_gal
[
param
[
'sed_type'
]]
param
[
'av'
]
=
0.0
param
[
'redden'
]
=
0
param
[
'mu'
]
=
1
#param["CSSTmag"]= True
#param["mag_r"] = 20.
#param['']
###more keywords for stamp###
param
[
'image'
]
=
hdu
[
0
].
data
param
[
'image'
]
=
param
[
'image'
]
/
(
np
.
sum
(
param
[
'image'
]))
obj
=
Stamp
(
param
)
self
.
objs
.
append
(
obj
)
def
_load
(
self
,
**
kwargs
):
self
.
objs
=
[]
self
.
ids
=
0
if
"stamp_cat"
in
self
.
config
[
"catalog_options"
][
"input_path"
]
and
self
.
config
[
"catalog_options"
][
"input_path"
][
"stamp_cat"
]
and
self
.
config
[
"catalog_options"
][
"stamp_yes"
]:
stamps_cat
=
h5
.
File
(
self
.
stamp_path
,
'r'
)[
'Stamps'
]
print
(
"debug::"
,
stamps_cat
.
keys
())
for
pix
in
self
.
pix_list
:
try
:
stamps
=
stamps_cat
[
str
(
pix
)]
print
(
"debug::"
,
stamps
.
keys
())
self
.
_load_stamps
(
stamps
,
pix_id
=
pix
)
del
stamps
except
Exception
as
e
:
self
.
logger
.
error
(
str
(
e
))
print
(
e
)
if
self
.
logger
is
not
None
:
self
.
logger
.
info
(
"maximum galaxy size: %.4f"
%
(
self
.
max_size
))
self
.
logger
.
info
(
"number of objects in catalog: %d"
%
(
len
(
self
.
objs
)))
else
:
print
(
"number of objects in catalog: "
,
len
(
self
.
objs
))
def
load_sed
(
self
,
obj
,
**
kwargs
):
if
obj
.
type
==
'stamp'
:
sed_data
=
getObservedSED
(
sedCat
=
self
.
tempSed_gal
[
obj
.
sed_type
],
redshift
=
obj
.
z
,
av
=
obj
.
param
[
"av"
],
redden
=
obj
.
param
[
"redden"
]
)
wave
,
flux
=
sed_data
[
0
],
sed_data
[
1
]
else
:
raise
ValueError
(
"Object type not known"
)
speci
=
interpolate
.
interp1d
(
wave
,
flux
)
lamb
=
np
.
arange
(
2000
,
11001
+
0.5
,
0.5
)
y
=
speci
(
lamb
)
# erg/s/cm2/A --> photon/s/m2/A
all_sed
=
y
*
lamb
/
(
cons
.
h
.
value
*
cons
.
c
.
value
)
*
1e-13
sed
=
Table
(
np
.
array
([
lamb
,
all_sed
]).
T
,
names
=
(
'WAVELENGTH'
,
'FLUX'
))
del
wave
del
flux
return
sed
ObservationSim/Astrometry/Astrometry_util.py
deleted
100644 → 0
View file @
4afd1181
from
ctypes
import
*
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
def
checkInputList
(
input_list
,
n
):
if
not
isinstance
(
input_list
,
list
):
raise
TypeError
(
"Input type is not list!"
,
input_list
)
for
i
in
input_list
:
if
type
(
i
)
!=
type
(
1.1
):
if
type
(
i
)
!=
type
(
1
):
raise
TypeError
(
"Input list's element is not float or int!"
,
input_list
)
if
len
(
input_list
)
!=
n
:
raise
RuntimeError
(
"Length of input list is not equal to stars' number!"
,
input_list
)
def
on_orbit_obs_position
(
input_ra_list
,
input_dec_list
,
input_pmra_list
,
input_pmdec_list
,
input_rv_list
,
input_parallax_list
,
input_nstars
,
input_x
,
input_y
,
input_z
,
input_vx
,
input_vy
,
input_vz
,
input_epoch
,
input_date_str
,
input_time_str
,
lib_path
=
None
):
#Check input parameters
if
not
isinstance
(
input_nstars
,
int
):
raise
TypeError
(
"Parameter 7 is not int!"
,
input_nstars
)
checkInputList
(
input_ra_list
,
input_nstars
)
checkInputList
(
input_dec_list
,
input_nstars
)
checkInputList
(
input_pmra_list
,
input_nstars
)
checkInputList
(
input_pmdec_list
,
input_nstars
)
checkInputList
(
input_rv_list
,
input_nstars
)
checkInputList
(
input_parallax_list
,
input_nstars
)
if
not
isinstance
(
input_x
,
float
):
raise
TypeError
(
"Parameter 8 is not double!"
,
input_x
)
if
not
isinstance
(
input_y
,
float
):
raise
TypeError
(
"Parameter 9 is not double!"
,
input_y
)
if
not
isinstance
(
input_z
,
float
):
raise
TypeError
(
"Parameter 10 is not double!"
,
input_z
)
if
not
isinstance
(
input_vx
,
float
):
raise
TypeError
(
"Parameter 11 is not double!"
,
input_vx
)
if
not
isinstance
(
input_vy
,
float
):
raise
TypeError
(
"Parameter 12 is not double!"
,
input_vy
)
if
not
isinstance
(
input_vz
,
float
):
raise
TypeError
(
"Parameter 13 is not double!"
,
input_vz
)
#Convert km -> m
input_x
=
input_x
*
1000.0
input_y
=
input_y
*
1000.0
input_z
=
input_z
*
1000.0
input_vx
=
input_vx
*
1000.0
input_vy
=
input_vy
*
1000.0
input_vz
=
input_vz
*
1000.0
if
not
isinstance
(
input_date_str
,
str
):
raise
TypeError
(
"Parameter 15 is not string!"
,
input_date_str
)
else
:
input_date_str
=
input_date_str
.
strip
()
if
not
(
input_date_str
[
4
]
==
"-"
and
input_date_str
[
7
]
==
"-"
):
raise
TypeError
(
"Parameter 15 format error (1)!"
,
input_date_str
)
else
:
tmp
=
input_date_str
.
split
(
"-"
)
if
len
(
tmp
)
!=
3
:
raise
TypeError
(
"Parameter 15 format error (2)!"
,
input_date_str
)
input_year
=
int
(
tmp
[
0
])
input_month
=
int
(
tmp
[
1
])
input_day
=
int
(
tmp
[
2
])
if
not
(
input_year
>=
1900
and
input_year
<=
2100
):
raise
TypeError
(
"Parameter 15 year range error [1900 ~ 2100]!"
,
input_year
)
if
not
(
input_month
>=
1
and
input_month
<=
12
):
raise
TypeError
(
"Parameter 15 month range error [1 ~ 12]!"
,
input_month
)
if
not
(
input_day
>=
1
and
input_day
<=
31
):
raise
TypeError
(
"Parameter 15 day range error [1 ~ 31]!"
,
input_day
)
if
not
isinstance
(
input_time_str
,
str
):
raise
TypeError
(
"Parameter 16 is not string!"
,
input_time_str
)
else
:
input_time_str
=
input_time_str
.
strip
()
if
not
(
input_time_str
[
2
]
==
":"
and
input_time_str
[
5
]
==
":"
):
raise
TypeError
(
"Parameter 16 format error (1)!"
,
input_time_str
)
else
:
tmp
=
input_time_str
.
split
(
":"
)
if
len
(
tmp
)
!=
3
:
raise
TypeError
(
"Parameter 16 format error (2)!"
,
input_time_str
)
input_hour
=
int
(
tmp
[
0
])
input_minute
=
int
(
tmp
[
1
])
input_second
=
float
(
tmp
[
2
])
if
not
(
input_hour
>=
0
and
input_hour
<=
23
):
raise
TypeError
(
"Parameter 16 hour range error [0 ~ 23]!"
,
input_hour
)
if
not
(
input_minute
>=
0
and
input_minute
<=
59
):
raise
TypeError
(
"Parameter 16 minute range error [0 ~ 59]!"
,
input_minute
)
if
not
(
input_second
>=
0
and
input_second
<
60.0
):
raise
TypeError
(
"Parameter 16 second range error [0 ~ 60)!"
,
input_second
)
#Inital dynamic lib
try
:
with
pkg_resources
.
files
(
'ObservationSim.Astrometry.lib'
).
joinpath
(
"libshao.so"
)
as
lib_path
:
shao
=
cdll
.
LoadLibrary
(
lib_path
)
except
AttributeError
:
with
pkg_resources
.
path
(
'ObservationSim.Astrometry.lib'
,
"libshao.so"
)
as
lib_path
:
shao
=
cdll
.
LoadLibrary
(
lib_path
)
shao
.
onOrbitObs
.
restype
=
c_int
d3
=
c_double
*
3
shao
.
onOrbitObs
.
argtypes
=
[
c_double
,
c_double
,
c_double
,
c_double
,
c_double
,
c_double
,
\
c_int
,
c_int
,
c_int
,
c_int
,
c_int
,
c_double
,
\
c_double
,
POINTER
(
d3
),
POINTER
(
d3
),
\
c_int
,
c_int
,
c_int
,
c_int
,
c_int
,
c_double
,
\
POINTER
(
c_double
),
POINTER
(
c_double
)
]
output_ra_list
=
list
()
output_dec_list
=
list
()
for
i
in
range
(
input_nstars
):
input_ra
=
c_double
(
input_ra_list
[
i
])
input_dec
=
c_double
(
input_dec_list
[
i
])
input_pmra
=
c_double
(
input_pmra_list
[
i
])
input_pmdec
=
c_double
(
input_pmdec_list
[
i
])
# input_rv = c_double(input_rv_list[i] * 3600.) # Convert from km/s to km/h
input_rv
=
c_double
(
input_rv_list
[
i
])
input_parallax
=
c_double
(
input_parallax_list
[
i
])
p3
=
d3
(
input_x
,
input_y
,
input_z
)
v3
=
d3
(
input_vx
,
input_vy
,
input_vz
)
input_year_c
=
c_int
(
input_year
)
input_month_c
=
c_int
(
input_month
)
input_day_c
=
c_int
(
input_day
)
input_hour_c
=
c_int
(
input_hour
)
input_minute_c
=
c_int
(
input_minute
)
input_second_c
=
c_double
(
input_second
)
DAT
=
c_double
(
37.0
)
output_ra
=
c_double
(
0.0
)
output_dec
=
c_double
(
0.0
)
rs
=
shao
.
onOrbitObs
(
input_ra
,
input_dec
,
input_parallax
,
input_pmra
,
input_pmdec
,
input_rv
,
\
input_year_c
,
input_month_c
,
input_day_c
,
input_hour_c
,
input_minute_c
,
input_second_c
,
\
DAT
,
byref
(
p3
),
byref
(
v3
),
\
input_year_c
,
input_month_c
,
input_day_c
,
input_hour_c
,
input_minute_c
,
input_second_c
,
\
byref
(
output_ra
),
byref
(
output_dec
))
if
rs
!=
0
:
raise
RuntimeError
(
"Calculate error!"
)
output_ra_list
.
append
(
output_ra
.
value
)
output_dec_list
.
append
(
output_dec
.
value
)
return
np
.
array
(
output_ra_list
),
np
.
array
(
output_dec_list
)
ObservationSim/Astrometry/__init__.py
deleted
100644 → 0
View file @
4afd1181
ObservationSim/Astrometry/lib/__init__.py
deleted
100644 → 0
View file @
4afd1181
ObservationSim/Astrometry/lib/libshao.so
deleted
100644 → 0
View file @
4afd1181
File deleted
ObservationSim/Config/ChipOutput.py
deleted
100755 → 0
View file @
4afd1181
import
os
import
logging
import
ObservationSim.Config._util
as
_util
from
ObservationSim.Config.Header
import
generatePrimaryHeader
class
ChipOutput
(
object
):
def
__init__
(
self
,
config
,
chip
,
filt
,
pointing
,
logger_filename
=
None
):
self
.
config
=
config
self
.
chip
=
chip
self
.
filt
=
filt
self
.
pointing_type
=
pointing
.
pointing_type
self
.
chip_label
=
str
(
chip
.
chipID
).
rjust
(
2
,
'0'
)
# Get primary header based on chip and pointing
self
.
h_prim
=
generatePrimaryHeader
(
xlen
=
chip
.
npix_x
,
ylen
=
chip
.
npix_y
,
pointing_id
=
pointing
.
obs_id
,
pointing_type_code
=
pointing
.
pointing_type_code
,
ra
=
pointing
.
ra
,
dec
=
pointing
.
dec
,
pixel_scale
=
chip
.
pix_scale
,
time_pt
=
pointing
.
timestamp
,
exptime
=
pointing
.
exp_time
,
im_type
=
pointing
.
pointing_type
,
sat_pos
=
[
pointing
.
sat_x
,
pointing
.
sat_y
,
pointing
.
sat_z
],
sat_vel
=
[
pointing
.
sat_vx
,
pointing
.
sat_vy
,
pointing
.
sat_vz
],
project_cycle
=
self
.
config
[
"project_cycle"
],
run_counter
=
self
.
config
[
"run_counter"
],
chip_name
=
self
.
chip_label
)
obs_id
=
_util
.
get_obs_id
(
img_type
=
self
.
pointing_type
,
project_cycle
=
config
[
"project_cycle"
],
run_counter
=
config
[
"run_counter"
],
pointing_id
=
pointing
.
obs_id
,
pointing_type_code
=
pointing
.
pointing_type_code
)
self
.
subdir
=
pointing
.
output_dir
self
.
cat_name
=
self
.
h_prim
[
'FILENAME'
]
+
'.cat'
if
logger_filename
is
None
:
logger_filename
=
self
.
h_prim
[
'FILENAME'
]
+
'.log'
self
.
logger
=
logging
.
getLogger
()
fh
=
logging
.
FileHandler
(
os
.
path
.
join
(
self
.
subdir
,
logger_filename
),
mode
=
'w+'
,
encoding
=
'utf-8'
)
fh
.
setLevel
(
logging
.
DEBUG
)
self
.
logger
.
setLevel
(
logging
.
DEBUG
)
logging
.
getLogger
(
'numba'
).
setLevel
(
logging
.
WARNING
)
formatter
=
logging
.
Formatter
(
'%(asctime)s - %(msecs)d - %(levelname)-8s - [%(filename)s:%(lineno)d] - %(message)s'
)
fh
.
setFormatter
(
formatter
)
self
.
logger
.
addHandler
(
fh
)
hdr1
=
"# obj_ID ID_chip filter xImage yImage ra dec ra_orig dec_orig z mag obj_type "
hdr2
=
"pm_ra pm_dec RV parallax"
fmt1
=
"%20s %4d %5s %10.3f %10.3f %15.8f %15.8f %15.8f %15.8f %7.4f %8.4f %15s "
fmt2
=
"%15.8f %15.8f %15.8f %15.8f"
self
.
hdr
=
hdr1
+
hdr2
self
.
fmt
=
fmt1
+
fmt2
self
.
logger
.
info
(
"pointing_type = %s
\n
"
%
(
self
.
pointing_type
))
def
Log_info
(
self
,
message
):
print
(
message
)
self
.
logger
.
info
(
message
)
def
Log_error
(
self
,
message
):
print
(
message
)
self
.
logger
.
error
(
message
)
def
update_output_header
(
self
,
additional_column_names
=
""
):
self
.
hdr
+=
additional_column_names
def
create_output_file
(
self
):
if
self
.
pointing_type
==
'SCI'
:
self
.
cat
=
open
(
os
.
path
.
join
(
self
.
subdir
,
self
.
cat_name
),
"w"
)
self
.
logger
.
info
(
"Creating catalog file %s ...
\n
"
%
(
os
.
path
.
join
(
self
.
subdir
,
self
.
cat_name
)))
if
not
self
.
hdr
.
endswith
(
"
\n
"
):
self
.
hdr
+=
"
\n
"
self
.
cat
.
write
(
self
.
hdr
)
def
cat_add_obj
(
self
,
obj
,
pos_img
,
pos_shear
):
ximg
=
obj
.
real_pos
.
x
+
1.0
yimg
=
obj
.
real_pos
.
y
+
1.0
line
=
self
.
fmt
%
(
obj
.
id
,
int
(
self
.
chip_label
),
self
.
filt
.
filter_type
,
ximg
,
yimg
,
obj
.
ra
,
obj
.
dec
,
obj
.
ra_orig
,
obj
.
dec_orig
,
obj
.
z
,
obj
.
getMagFilter
(
self
.
filt
),
obj
.
type
,
obj
.
pmra
,
obj
.
pmdec
,
obj
.
rv
,
obj
.
parallax
)
line
+=
obj
.
additional_output_str
if
not
line
.
endswith
(
"
\n
"
):
line
+=
"
\n
"
self
.
cat
.
write
(
line
)
ObservationSim/Config/Header/ImageHeader.py
deleted
100644 → 0
View file @
4afd1181
"""
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
ObservationSim.Config._util
import
get_obs_id
,
get_file_type
from
datetime
import
datetime
,
timezone
# import socket
import
platform
import
toml
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
=
rotate_chip
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
,
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
# k = (row_num-1)*6+col_num
# ccdnum = str(k)
datetime_obs
=
datetime
.
utcfromtimestamp
(
time_pt
)
datetime_obs
=
datetime_obs
.
replace
(
tzinfo
=
timezone
.
utc
)
# print(datetime_obs.strftime("%Y-%m-%dT%H:%M:%S.%f")[:-5])
datetime_obs
=
datetime
.
utcfromtimestamp
(
np
.
round
(
datetime_obs
.
timestamp
(),
1
))
# print(datetime_obs.strftime("%Y-%m-%dT%H:%M:%S.%f")[:-5])
# date_obs = datetime_obs.strftime("%y%m%d")
# 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'
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
()
# h_prim = fits.Header()
# h_prim = fits.Header.fromfile(g_header_fn)
header_fits
=
fits
.
open
(
g_header_fn
)
h_prim
=
header_fits
[
0
].
header
# h_prim = fits.Header()
# with open(g_header_fn, 'r') as file:
# header_toml = toml.load(file)
# h_key='HDU0'
# for key, value in header_toml[h_key].items():
# 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['PIXSIZE1'] = xlen
# h_prim['PIXSIZE2'] = ylen
h_prim
[
'DATE'
]
=
datetime_obs
.
strftime
(
"%Y-%m-%dT%H:%M:%S.%f"
)[:
-
5
]
h_prim
[
'DATE-OBS'
]
=
datetime_obs
.
strftime
(
"%Y-%m-%dT%H:%M:%S.%f"
)[:
-
5
]
# 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
[
'RA_OBJ'
]
=
ra
h_prim
[
'DEC_OBJ'
]
=
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_id
=
pointing_id
,
pointing_type_code
=
pointing_type_code
)
# h_prim['OBJECT'] = str(int(project_cycle)) + pointNum.rjust(7, '0')
h_prim
[
'OBJECT'
]
=
pointing_id
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)
h_prim
[
'FILETYPE'
]
=
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.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
:
h_prim
[
'TARGET'
]
=
ra_hms
+
'+'
+
dec_hms
else
:
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]
file_start_time
=
datetime_obs
.
strftime
(
"%Y%m%d%H%M%S"
)
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
[
'FITSSWV'
]
=
get_distribution
(
"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
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'
)
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)
header_fits
=
fits
.
open
(
e_header_fn
)
h_ext
=
header_fits
[
1
].
header
# h_ext = fits.Header()
# with open(e_header_fn, 'r') as file:
# header_toml = toml.load(file)
# h_key='HDU1'
# for key, value in header_toml[h_key].items():
# h_card = fits.card.Card(header_toml[h_key][key]['key'],header_toml[h_key][key]['example'],header_toml[h_key][key]['comment'])
# h_ext.append(h_card)
# 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
[
'CHIPLABL'
]
=
chip
.
chip_name
h_ext
[
'FILTER'
]
=
chip
.
filter_type
h_ext
[
'NAXIS1'
]
=
xlen
h_ext
[
'NAXIS2'
]
=
ylen
h_ext
[
'EXTNAME'
]
=
extName
h_ext
[
'GAIN01'
]
=
chip
.
gain_channel
[
0
]
h_ext
[
'GAIN02'
]
=
chip
.
gain_channel
[
1
]
h_ext
[
'GAIN03'
]
=
chip
.
gain_channel
[
2
]
h_ext
[
'GAIN04'
]
=
chip
.
gain_channel
[
3
]
h_ext
[
'GAIN05'
]
=
chip
.
gain_channel
[
4
]
h_ext
[
'GAIN06'
]
=
chip
.
gain_channel
[
5
]
h_ext
[
'GAIN07'
]
=
chip
.
gain_channel
[
6
]
h_ext
[
'GAIN08'
]
=
chip
.
gain_channel
[
7
]
h_ext
[
'GAIN09'
]
=
chip
.
gain_channel
[
8
]
h_ext
[
'GAIN10'
]
=
chip
.
gain_channel
[
9
]
h_ext
[
'GAIN11'
]
=
chip
.
gain_channel
[
10
]
h_ext
[
'GAIN12'
]
=
chip
.
gain_channel
[
11
]
h_ext
[
'GAIN13'
]
=
chip
.
gain_channel
[
12
]
h_ext
[
'GAIN14'
]
=
chip
.
gain_channel
[
13
]
h_ext
[
'GAIN15'
]
=
chip
.
gain_channel
[
14
]
h_ext
[
'GAIN16'
]
=
chip
.
gain_channel
[
15
]
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
datetime_obs
=
datetime
.
utcfromtimestamp
(
timestamp
)
datetime_obs
=
datetime_obs
.
replace
(
tzinfo
=
timezone
.
utc
)
tstart
=
Time
(
datetime_obs
)
t_shutter_os
=
tstart
t_shutter_oe
=
Time
(
tstart
.
mjd
+
t_shutter_open
/
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_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
]
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
]
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
]
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
]
tstart_read
=
Time
(
tstart
.
mjd
+
exptime
/
86400.
,
format
=
"mjd"
)
tend_read
=
Time
(
tstart
.
mjd
+
(
exptime
+
readoutTime
)
/
86400.
,
format
=
"mjd"
)
# 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
))
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
=
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['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'
]
h_ext
[
'EXTNAME'
]
=
'IMAGE'
h_ext
.
comments
[
"XTENSION"
]
=
"image extension"
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)
ObservationSim/Config/Header/ImageHeader_1.py
deleted
100644 → 0
View file @
4afd1181
"""
generate image header
"""
import
numpy
as
np
from
astropy.io
import
fits
import
astropy.wcs
as
pywcs
from
scipy
import
math
import
random
import
os
import
sys
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
])
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
Header_extention
(
xlen
=
9232
,
ylen
=
9216
,
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
+
']'
name
=
[]
value
=
[]
description
=
[]
for
k
in
range
(
1
,
2
):
# f = open("extension"+str(k)+"_image.param","w")
j
=
row_num
i
=
col_num
ccdnum
=
str
((
j
-
1
)
*
5
+
i
)
name
=
[
'EXTNAME'
,
'BSCALE'
,
'BZERO'
,
'OBSID'
,
'CCDNAME'
,
'AMPNAME'
,
'GAIN'
,
'RDNOISE'
,
'DARK'
,
'SATURATE'
,
'RSPEED'
,
'CHIPTEMP'
,
'CCDCHIP'
,
'DATASEC'
,
'CCDSUM'
,
'NSUM'
,
'LTM1_1'
,
'LTM2_2'
,
'LTV1'
,
'LTV2'
,
'ATM1_1'
,
'ATM2_2'
,
'ATV1'
,
'ATV2'
,
'DTV1'
,
'DTV2'
,
'DTM1_1'
,
'DTM2_2'
]
value
=
[
'IM'
+
str
(
k
),
1.0
,
0.0
,
'CSST.20200101T000000'
,
'ccd'
+
ccdnum
.
rjust
(
2
,
'0'
),
'ccd'
+
ccdnum
.
rjust
(
2
,
'0'
)
+
':'
+
str
(
k
),
gain
,
readout
,
dark
,
saturation
,
10.0
,
-
100.0
,
'ccd'
+
ccdnum
.
rjust
(
2
,
'0'
),
data_sec
,
'1 1'
,
'1 1'
,
flag_ltm_x
[
k
],
flag_ltm_y
[
k
],
flag_ltv_x
[
k
]
*
(
detector_size_x
-
20
*
2
+
1
),
flag_ltv_y
[
k
]
*
(
detector_size_y
+
1
),
flag_ltm_x
[
k
],
flag_ltm_y
[
k
],
flag_ltv_x
[
k
]
*
(
detector_size_x
-
20
*
2
+
1
),
flag_ltv_y
[
k
]
*
(
detector_size_y
+
1
),
0
,
0
,
1
,
1
]
description
=
[
'Extension name'
,
' '
,
' '
,
'Observation ID'
,
'CCD name'
,
'Amplifier name'
,
'Gain (e-/ADU)'
,
'Readout noise (e-/pixel)'
,
'Dark noise (e-/pixel/s)'
,
'Saturation (e-)'
,
'Read speed'
,
'Chip temperature'
,
'CCD chip ID'
,
'Data section'
,
'CCD pixel summing'
,
'CCD pixel summing'
,
'CCD to image transformation'
,
'CCD to image transformation'
,
'CCD to image transformation'
,
'CCD to image transformation'
,
'CCD to amplifier transformation'
,
'CCD to amplifier transformation'
,
'CCD to amplifier transformation'
,
'CCD to amplifier transformation'
,
'CCD to detector transformatio'
,
'CCD to detector transformatio'
,
'CCD to detector transformatio'
,
'CCD to detector transformatio'
]
return
name
,
value
,
description
##9232 9216 898 534 1309 60 -40 -23.4333
def
WCS_def
(
xlen
=
9232
,
ylen
=
9216
,
gapx
=
898.0
,
gapy1
=
534
,
gapy2
=
1309
,
ra
=
60
,
dec
=
-
40
,
pa
=
-
23.433
,
psize
=
0.074
,
row_num
=
1
,
col_num
=
1
):
""" Creat a wcs frame for CCST with multiple extensions
Parameters
----------
"""
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
]
x_num
=
5
y_num
=
6
detector_num
=
x_num
*
y_num
detector_size_x
=
xlen
detector_size_y
=
ylen
gap_x
=
gapx
gap_y
=
[
gapy1
,
gapy2
]
ra_ref
=
ra
dec_ref
=
dec
pa_aper
=
pa
pixel_size
=
psize
gap_y1_num
=
3
gap_y2_num
=
2
x_center
=
(
detector_size_x
*
x_num
+
gap_x
*
(
x_num
-
1
))
/
2
y_center
=
(
detector_size_y
*
y_num
+
gap_y
[
0
]
*
gap_y1_num
+
gap_y
[
1
]
*
gap_y2_num
)
/
2
gap_y_map
=
np
.
array
([[
0
,
0
,
0
,
0
,
0
],[
gap_y
[
0
],
gap_y
[
1
],
gap_y
[
1
],
gap_y
[
1
],
gap_y
[
1
]],[
gap_y
[
1
],
gap_y
[
0
],
gap_y
[
0
],
gap_y
[
0
],
gap_y
[
0
]],[
gap_y
[
0
],
gap_y
[
0
],
gap_y
[
0
],
gap_y
[
0
],
gap_y
[
0
]],[
gap_y
[
0
],
gap_y
[
0
],
gap_y
[
0
],
gap_y
[
0
],
gap_y
[
1
]],[
gap_y
[
1
],
gap_y
[
1
],
gap_y
[
1
],
gap_y
[
1
],
gap_y
[
0
]]])
frame_array
=
np
.
empty
((
5
,
6
),
dtype
=
np
.
float64
)
# print(x_center,y_center)
j
=
row_num
i
=
col_num
ccdnum
=
str
((
j
-
1
)
*
5
+
i
)
x_ref
,
y_ref
=
(
detector_size_x
+
gap_x
)
*
i
-
gap_x
-
detector_size_x
/
2
,
detector_size_y
*
j
+
sum
(
gap_y_map
[
0
:
j
,
i
-
1
])
-
detector_size_y
/
2
# print(i,j,x_ref,y_ref,ra_ref,dec_ref)
name
=
[]
value
=
[]
description
=
[]
for
k
in
range
(
1
,
2
):
cd
=
np
.
array
([[
pixel_size
,
0
],
[
0
,
pixel_size
]])
/
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")
name
=
[
'EQUINOX'
,
'WCSDIM'
,
'CTYPE1'
,
'CTYPE2'
,
'CRVAL1'
,
'CRVAL2'
,
'CRPIX1'
,
'CRPIX2'
,
'CD1_1'
,
'CD1_2'
,
'CD2_1'
,
'CD2_2'
]
value
=
[
2000.0
,
2.0
,
'RA---TAN'
,
'DEC--TAN'
,
ra_ref
,
dec_ref
,
flag_ext_x
[
k
]
*
((
x_ref
+
flag_ext_x
[
k
]
*
detector_size_x
/
2
)
-
x_center
),
flag_ext_y
[
k
]
*
((
y_ref
+
flag_ext_y
[
k
]
*
detector_size_y
/
2
)
-
y_center
),
cd_rot
[
0
,
0
],
cd_rot
[
0
,
1
],
cd_rot
[
1
,
0
],
cd_rot
[
1
,
1
]]
description
=
[
'Equinox of WCS'
,
'WCS Dimensionality'
,
'Coordinate type'
,
'Coordinate typ'
,
'Coordinate reference value'
,
'Coordinate reference value'
,
'Coordinate reference pixel'
,
'Coordinate reference pixel'
,
'Coordinate matrix'
,
'Coordinate matrix'
,
'Coordinate matrix'
,
'Coordinate matrix'
]
return
name
,
value
,
description
def
generatePrimaryHeader
(
xlen
=
9232
,
ylen
=
9216
,
pointNum
=
'1'
,
ra
=
60
,
dec
=
-
40
,
psize
=
0.074
,
row_num
=
1
,
col_num
=
1
):
# array_size1, array_size2, flux, sigma = int(argv[1]), int(argv[2]), 1000.0, 5.0
filerParm_fn
=
os
.
path
.
split
(
os
.
path
.
realpath
(
__file__
))[
0
]
+
'/filter.lst'
f
=
open
(
filerParm_fn
)
s
=
f
.
readline
()
s
=
s
.
strip
(
"
\n
"
)
filter
=
s
.
split
(
' '
)
k
=
(
row_num
-
1
)
*
5
+
col_num
ccdnum
=
str
(
k
)
g_header_fn
=
os
.
path
.
split
(
os
.
path
.
realpath
(
__file__
))[
0
]
+
'/global_header.param'
name
,
value
,
description
=
read_header_parameter
(
g_header_fn
)
h_prim
=
fits
.
Header
()
date
=
'200930'
time_obs
=
'120000'
for
i
in
range
(
len
(
name
)):
if
(
name
[
i
]
==
'FILTER'
):
value
[
i
]
=
filter
[
k
-
1
]
if
(
name
[
i
]
==
'FILENAME'
):
value
[
i
]
=
'CSST_'
+
date
+
'_'
+
time_obs
+
'_'
+
pointNum
.
rjust
(
6
,
'0'
)
+
'_'
+
ccdnum
.
rjust
(
2
,
'0'
)
+
'_raw'
if
(
name
[
i
]
==
'DETSIZE'
):
value
[
i
]
=
'[1:'
+
str
(
int
(
xlen
))
+
',1:'
+
str
(
int
(
ylen
))
+
']'
if
(
name
[
i
]
==
'PIXSCAL1'
):
value
[
i
]
=
str
(
psize
)
if
(
name
[
i
]
==
'PIXSCAL2'
):
value
[
i
]
=
str
(
psize
)
h_prim
[
name
[
i
]]
=
(
value
[
i
],
description
[
i
])
h_prim
.
add_comment
(
'=================================================================='
,
after
=
'FILETYPE'
)
h_prim
.
add_comment
(
'Target information'
)
h_prim
.
add_comment
(
'=================================================================='
)
h_prim
.
add_comment
(
'=================================================================='
,
after
=
'EQUINOX'
)
h_prim
.
add_comment
(
'Exposure information'
)
h_prim
.
add_comment
(
'=================================================================='
)
h_prim
.
add_comment
(
'=================================================================='
,
after
=
'MJDEND'
)
h_prim
.
add_comment
(
'Telescope information'
)
h_prim
.
add_comment
(
'=================================================================='
)
h_prim
.
add_comment
(
'=================================================================='
,
after
=
'REFFRAME'
)
h_prim
.
add_comment
(
'Detector information'
)
h_prim
.
add_comment
(
'=================================================================='
)
h_prim
.
add_comment
(
'=================================================================='
,
after
=
'FILTER'
)
h_prim
.
add_comment
(
'Other information'
)
h_prim
.
add_comment
(
'=================================================================='
)
return
h_prim
def
generateExtensionHeader
(
xlen
=
9232
,
ylen
=
9216
,
ra
=
60
,
dec
=
-
40
,
pa
=
-
23.433
,
gain
=
1.0
,
readout
=
5.0
,
dark
=
0.02
,
saturation
=
90000
,
psize
=
0.074
,
row_num
=
1
,
col_num
=
1
):
h_ext
=
fits
.
Header
()
for
i
in
range
(
1
,
2
):
# NAXIS1:Number of pixels per row; NAXIS2:Number of rows
h_ext
[
'NAXIS1'
]
=
xlen
h_ext
[
'NAXIS2'
]
=
ylen
name
,
value
,
description
=
Header_extention
(
xlen
=
xlen
,
ylen
=
ylen
,
gain
=
gain
,
readout
=
readout
,
dark
=
dark
,
saturation
=
saturation
,
row_num
=
row_num
,
col_num
=
col_num
)
for
j
in
range
(
len
(
name
)):
h_ext
[
name
[
j
]]
=
(
value
[
j
],
description
[
j
])
name
,
value
,
description
=
WCS_def
(
xlen
=
xlen
,
ylen
=
ylen
,
gapx
=
898.0
,
gapy1
=
534
,
gapy2
=
1309
,
ra
=
ra
,
dec
=
dec
,
pa
=
pa
,
psize
=
psize
,
row_num
=
row_num
,
col_num
=
col_num
)
for
j
in
range
(
len
(
name
)):
h_ext
[
name
[
j
]]
=
(
value
[
j
],
description
[
j
])
h_ext
.
add_comment
(
'=================================================================='
,
after
=
'OBSID'
)
h_ext
.
add_comment
(
'Readout information'
)
h_ext
.
add_comment
(
'=================================================================='
)
h_ext
.
add_comment
(
'=================================================================='
,
after
=
'CHIPTEMP'
)
h_ext
.
add_comment
(
'Chip information'
)
h_ext
.
add_comment
(
'=================================================================='
)
h_ext
.
add_comment
(
'=================================================================='
,
after
=
'DTM2_2'
)
h_ext
.
add_comment
(
'WCS information'
)
h_ext
.
add_comment
(
'=================================================================='
)
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)
ObservationSim/Config/Header/Readme.pdf
deleted
100644 → 0
View file @
4afd1181
File deleted
ObservationSim/Config/Header/__init__.py
deleted
100755 → 0
View file @
4afd1181
from
.ImageHeader
import
generatePrimaryHeader
from
.ImageHeader
import
generateExtensionHeader
\ No newline at end of file
ObservationSim/Config/Header/csst_msc_l0_ms.fits
deleted
100644 → 0
View file @
4afd1181
This source diff could not be displayed because it is too large. You can
view the blob
instead.
ObservationSim/Config/Header/extension_header.header
deleted
100644 → 0
View file @
4afd1181
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
ObservationSim/Config/Header/extension_header.param
deleted
100644 → 0
View file @
4afd1181
EXTNAME|IM1|Extension name
EXTVER|1|The ID number
BSCALE|1|
BZERO|8|
OBSID|CSST.20200101T000000|Observation ID
CCDNAME|CCD02|CCD name
AMPNAME|ccd02:B|Amplifier name
GAIN|1.00|Gain (e/ADU)
RDNOISE|5.00|Readout noise (e)
SATURATE|90000.0|Saturation (ADU)
RSPEED|10.0|Read speed (in MHz)
CHIPTEMP|-100.0|Chip temperature (in K)
CCDCHIP|1|CCD chip ID
CCDLABEL|GI-1|CCD chip label
HOSCAN|2000|Horizontal overscan width, per readout channel
VOSCAN|2000|Virtical overscan height, per readout channel
CCDSUM|1 1|CCD pixel summing
CCDSEC|[1:9216:9232]|CCD section
AMPSEC|[1:9216:9232]|Amplifier section
DATASEC|[1:9216,1: 9232]|Data section
DETSEC|[1:9216,1:9232]|Detector section
BIASSEC|[9216:9217,9232:9234]|Bias section
TRIMSEC|[1:9216,1:9232]|Trim section
WCSDIM|2|WCS dimensionality
EQUINOX|2000|Epoch (year)
CTYPE1|RA---TPV|Coordinate type
CTYPE2|DEC---TPV|Coordinate type
CRVAL1|1.00|Coordinate reference value
CRVAL2|1.00|Coordinate reference value
CRPIX1|1.00|Coordinate reference pixel
CRPIX2|1.00|Coordinate reference pixel
CD1_1|1|Coordinate matrix
CD2_1|0|Coordinate matrix
CD1_2|0|Coordinate matrix
CD2_2|1|Coordinate matrix
CHECKSUM|C65|SHA256 checksum of global headers
\ No newline at end of file
ObservationSim/Config/Header/filter.lst
deleted
100644 → 0
View file @
4afd1181
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
Prev
1
2
3
4
5
…
11
Next
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment