Commit 18bdecdb authored by Fang Yuedong's avatar Fang Yuedong
Browse files

encapsulate instrumental data

parent 72f88213
......@@ -14,6 +14,12 @@ from ObservationSim.MockObject import CatalogBase, Star, Galaxy, Quasar
from ObservationSim.MockObject._util import seds, sed_assign, extAv, tag_sed, getObservedSED
from ObservationSim.Astrometry.Astrometry_util import on_orbit_obs_position
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 C3Catalog(CatalogBase):
......@@ -21,10 +27,14 @@ class C3Catalog(CatalogBase):
super().__init__()
self.cat_dir = os.path.join(config["data_dir"], config["input_path"]["cat_dir"])
self.seed_Av = config["random_seeds"]["seed_Av"]
self.normalize_dir = os.path.join(config["data_dir"], config["SLS_path"]["SLS_norm"])
self.normF_star = Table.read(os.path.join(self.normalize_dir, 'SLOAN_SDSS.g.fits'))
self.normF_galaxy = Table.read(os.path.join(self.normalize_dir, 'lsst_throuput_g.fits'))
# self.normalize_dir = os.path.join(config["data_dir"], config["SLS_path"]["SLS_norm"])
# self.normF_star = Table.read(os.path.join(self.normalize_dir, 'SLOAN_SDSS.g.fits'))
# self.normF_galaxy = Table.read(os.path.join(self.normalize_dir, 'lsst_throuput_g.fits'))
with pkg_resources.path('Catalog.data', 'SLOAN_SDSS.g.fits') as filter_path:
self.normF_star = filter_path
with pkg_resources.path('Catalog.data', 'lsst_throuput_g.fits') as filter_path:
self.normF_star = filter_path
self.config = config
self.chip = chip
......@@ -136,14 +146,15 @@ class C3Catalog(CatalogBase):
# Apply astrometric modeling
ra_arr = stars["RA"][:]
dec_arr = stars["Dec"][:]
if "astrometric_lib" in self.config["obs_setting"] and self.config["obs_setting"]["enable_astrometric_model"]:
# if "astrometric_lib" in self.config["obs_setting"] and self.config["obs_setting"]["enable_astrometric_model"]:
if self.config["obs_setting"]["enable_astrometric_model"]:
ra_list = ra_arr.tolist()
dec_list = dec_arr.tolist()
pmra_list = np.zeros(nstars).tolist()
pmdec_list = np.zeros(nstars).tolist()
rv_list = np.zeros(nstars).tolist()
parallax_list = [1e-9] * nstars
lib_path = os.path.join(self.config["data_dir"], self.config["obs_setting"]["astrometric_lib"])
# lib_path = os.path.join(self.config["data_dir"], self.config["obs_setting"]["astrometric_lib"])
dt = datetime.fromtimestamp(self.pointing.timestamp)
date_str = dt.date().isoformat()
time_str = dt.time().isoformat()
......@@ -164,7 +175,7 @@ class C3Catalog(CatalogBase):
input_epoch="J2015.5",
input_date_str=date_str,
input_time_str=time_str,
lib_path=lib_path
# lib_path=lib_path
)
for istars in range(nstars):
param = self.initialize_param()
......
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)
......@@ -11,7 +17,7 @@ def checkInputList(input_list, n):
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):
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)
......@@ -83,7 +89,9 @@ def on_orbit_obs_position(input_ra_list, input_dec_list, input_pmra_list, input_
if not (input_second>=0 and input_second<60.0):
raise TypeError("Parameter 16 second range error [0 ~ 60)!", input_second)
#Inital dynamic lib
shao = cdll.LoadLibrary(lib_path)
# shao = cdll.LoadLibrary(lib_path)
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
......
......@@ -26,18 +26,24 @@ def config_dir(config, work_dir=None, data_dir=None):
# SED catalog directory
# TODO: SED_dir is deprecated
path_dict["SED_dir"] = os.path.join(path_dict["data_dir"], "imageSims/Catalog/SEDObject")
# Directories/files for instrument parameters, e.g. efficiency curves.
path_dict["filter_dir"] = os.path.join(path_dict["data_dir"], config["Efficiency_curve_path"]["filter_eff"])
path_dict["ccd_dir"] = os.path.join(path_dict["data_dir"], config["Efficiency_curve_path"]["ccd_eff"])
path_dict["mirror_file"] = os.path.join(path_dict["data_dir"], config["Efficiency_curve_path"]["mirror_eff"])
# path_dict["filter_dir"] = os.path.join(path_dict["data_dir"], config["Efficiency_curve_path"]["filter_eff"])
# path_dict["ccd_dir"] = os.path.join(path_dict["data_dir"], config["Efficiency_curve_path"]["ccd_eff"])
# path_dict["mirror_file"] = os.path.join(path_dict["data_dir"], config["Efficiency_curve_path"]["mirror_eff"])
# Cosmic-ray data directory:
path_dict["CRdata_dir"] = os.path.join(path_dict["data_dir"], config["CR_data_path"])
path_dict["sky_file"] = os.path.join(path_dict["data_dir"], config["sky_data_path"])
# path_dict["CRdata_dir"] = os.path.join(path_dict["data_dir"], config["CR_data_path"])
# if "sky_file" in config:
# path_dict["sky_file"] = os.path.join(path_dict["data_dir"], config["sky_file"])
# else:
# path_dict["sky_file"] = 'sky_emiss_hubble_50_50_A.dat'
# path_dict["sky_file"] = os.path.join(path_dict["data_dir"], config["sky_data_path"])
# Slitless spectroscopy realted
path_dict["sls_dir"] = os.path.join(path_dict["data_dir"], config["SLS_path"]["SLS_conf"])
path_dict["normalize_dir"] = os.path.join(path_dict["data_dir"], config["SLS_path"]["SLS_norm"])
# path_dict["sls_dir"] = os.path.join(path_dict["data_dir"], config["SLS_path"]["SLS_conf"])
# path_dict["normalize_dir"] = os.path.join(path_dict["data_dir"], config["SLS_path"]["SLS_norm"])
return path_dict
......
......@@ -10,8 +10,14 @@ from ObservationSim.Instrument.Chip import Effects as effects
from ObservationSim.Instrument.FocalPlane import FocalPlane
from ObservationSim.Config.Header import generatePrimaryHeader, generateExtensionHeader
try:
import importlib.resources as pkg_resources
except ImportError:
# Try backported to PY<37 'importlib_resources'
import importlib_resources as pkg_resources
class Chip(FocalPlane):
def __init__(self, chipID, ccdEffCurve_dir, CRdata_dir, normalize_dir=None, sls_dir=None, config=None, treering_func=None):
def __init__(self, chipID, ccdEffCurve_dir=None, CRdata_dir=None, sls_dir=None, config=None, treering_func=None):
# Get focal plane (instance of paraent class) info
# TODO: use chipID to config individual chip?
super().__init__()
......@@ -40,17 +46,21 @@ class Chip(FocalPlane):
self.bound = self.getChipLim()
self.ccdEffCurve_dir = ccdEffCurve_dir
self.CRdata_dir = CRdata_dir
self.normalize_dir = normalize_dir
self.sls_dir=sls_dir
# self.sls_dir=sls_dir
# self.sls_conf = os.path.join(self.sls_dir, self.getChipSLSConf())
slsconfs = self.getChipSLSConf()
if np.size(slsconfs) == 1:
self.sls_conf = [os.path.join(self.sls_dir, slsconfs)]
# self.sls_conf = [os.path.join(self.sls_dir, slsconfs)]
with pkg_resources.path('ObservationSim.Instrument.data.sls_conf', slsconfs) as conf_path:
self.sls_conf = str(conf_path)
else:
self.sls_conf = [os.path.join(self.sls_dir, slsconfs[0]), os.path.join(self.sls_dir, slsconfs[1])]
# self.sls_conf = [os.path.join(self.sls_dir, slsconfs[0]), os.path.join(self.sls_dir, slsconfs[1])]
self.sls_conf = []
with pkg_resources.path('ObservationSim.Instrument.data.sls_conf', slsconfs[0]) as conf_path:
self.sls_conf.append(str(conf_path))
with pkg_resources.path('ObservationSim.Instrument.data.sls_conf', slsconfs[1]) as conf_path:
self.sls_conf.append(str(conf_path))
if self.normalize_dir is not None:
self._getNormF()
self.effCurve = self._getChipEffCurve(self.filter_type)
self._getCRdata()
......@@ -77,10 +87,6 @@ class Chip(FocalPlane):
else:
return "photometric"
def _getNormF(self):
self.normF_star = Table.read(os.path.join(self.normalize_dir, 'SLOAN_SDSS.g.fits'))
self.normF_galaxy = Table.read(os.path.join(self.normalize_dir, 'lsst_throuput_g.fits'))
def _getChipEffCurve(self, filter_type):
# CCD efficiency curves
if filter_type in ['nuv', 'u', 'GU']: filename = 'UV0.txt'
......@@ -92,15 +98,19 @@ class Chip(FocalPlane):
if filter_type in ['g', 'r', 'i', 'z', 'y']: mirror_eff = 0.8
if filter_type in ['GU', 'GV', 'GI']: mirror_eff = 1. # Not sure if this is right
path = os.path.join(self.ccdEffCurve_dir, filename)
table = Table.read(path, format='ascii')
# path = os.path.join(self.ccdEffCurve_dir, filename)
# table = Table.read(path, format='ascii')
with pkg_resources.path('ObservationSim.Instrument.data.ccd', filename) as ccd_path:
table = Table.read(ccd_path, format='ascii')
throughput = galsim.LookupTable(x=table['col1'], f=table['col2']*mirror_eff, interpolant='linear')
bandpass = galsim.Bandpass(throughput, wave_type='nm')
return bandpass
def _getCRdata(self):
path = os.path.join(self.CRdata_dir, 'wfc-cr-attachpixel.dat')
self.attachedSizes = np.loadtxt(path)
# path = os.path.join(self.CRdata_dir, 'wfc-cr-attachpixel.dat')
# self.attachedSizes = np.loadtxt(path)
with pkg_resources.path('ObservationSim.Instrument.data', "wfc-cr-attachpixel.dat") as cr_path:
self.attachedSizes = np.loadtxt(cr_path)
def getChipFilter(self, chipID=None, filter_layout=None):
"""Return the filter index and type for a given chip #(chipID)
......
......@@ -6,14 +6,20 @@ import numpy as np
from ObservationSim.Instrument._util import photonEnergy
from ObservationSim.Instrument.FilterParam import FilterParam
try:
import importlib.resources as pkg_resources
except ImportError:
# Try backported to PY<37 'importlib_resources'
import importlib_resources as pkg_resources
class Filter(object):
def __init__(self, filter_id, filter_type, filter_param, ccd_bandpass):
self.filter_id = filter_id
self.filter_type = filter_type
self.ccd_bandpass = ccd_bandpass
self._getParam(filter_param, filter_type)
if self.filter_dir is not None:
self.bandpass_full, self.bandpass_sub_list = self._get_bandpasses(self.filter_dir)
# if self.filter_dir is not None:
self.bandpass_full, self.bandpass_sub_list = self._get_bandpasses()
self.survey_type = self._getSurveyType()
def _getSurveyType(self):
......@@ -31,7 +37,7 @@ class Filter(object):
self.sky_background = filter_param.param[filter_type][5]
self.mag_saturation = filter_param.param[filter_type][6]
self.mag_dim = filter_param.param[filter_type][7]
self.filter_dir = filter_param.filter_dir
# self.filter_dir = filter_param.filter_dir
def is_too_bright(self, mag):
return mag <= self.mag_saturation - 1.0
......@@ -39,17 +45,21 @@ class Filter(object):
def is_too_dim(self, mag):
return mag >= self.mag_dim + 1.0
def _get_bandpasses(self, filter_dir, unit='A'):
def _get_bandpasses(self, filter_dir=None, unit='A'):
if self.filter_id < 7: # Photometric
# Get full-bandpass
filter_file = os.path.join(filter_dir, self.filter_type+".dat")
bandpass_full = galsim.Bandpass(filter_file, wave_type=unit)
# filter_file = os.path.join(filter_dir, self.filter_type+".dat")
# bandpass_full = galsim.Bandpass(filter_file, wave_type=unit)
with pkg_resources.path('ObservationSim.Instrument.data.filters', self.filter_type.lower() + '.txt') as filter_file:
bandpass_full = galsim.Bandpass(str(filter_file), wave_type=unit)
bandpass_full = bandpass_full * self.ccd_bandpass
# Get sub-bandpasses
bandpass_sub_list = []
wave_bin_file = os.path.join(filter_dir, self.filter_type.lower() + "_sub.list")
wave_points = open(wave_bin_file).read().splitlines()
# wave_bin_file = os.path.join(filter_dir, self.filter_type.lower() + "_sub.list")
# wave_points = open(wave_bin_file).read().splitlines()
with pkg_resources.path('ObservationSim.Instrument.data.filters', self.filter_type.lower() + "_sub.list") as wave_bin_file:
wave_points = open(wave_bin_file).read().splitlines()
for i in range(2, len(wave_points), 2):
blim = max(float(wave_points[i-2])*0.1, bandpass_full.blue_limit)
......@@ -65,8 +75,10 @@ class Filter(object):
con_spec = galsim.LookupTable(sls_lamb, sls_lamb, interpolant='nearest')
bandpass_full = galsim.Bandpass(con_spec, wave_type=unit)
bandpass_sub_list = []
wave_bin_file = os.path.join(filter_dir, self.filter_type.lower() + "_sub.list")
wave_points = open(wave_bin_file).read().splitlines()
# wave_bin_file = os.path.join(filter_dir, self.filter_type.lower() + "_sub.list")
# wave_points = open(wave_bin_file).read().splitlines()
with pkg_resources.path('ObservationSim.Instrument.data.filters', self.filter_type.lower() + "_sub.list") as wave_bin_file:
wave_points = open(wave_bin_file).read().splitlines()
for i in range(2, len(wave_points), 2):
blim = max(float(wave_points[i - 2]) * 0.1, bandpass_full.blue_limit)
rlim = min(float(wave_points[i]) * 0.1, bandpass_full.red_limit)
......
import numpy as np
try:
import importlib.resources as pkg_resources
except ImportError:
# Try backported to PY<37 'importlib_resources'
import importlib_resources as pkg_resources
class Telescope(object):
def __init__(self, param=None, optEffCurve_path=None):
self.diameter = 2.0 # in unit of meter
......@@ -8,6 +14,9 @@ class Telescope(object):
self.pupil_area = np.pi * (0.5 * self.diameter)**2
if optEffCurve_path is not None:
self.efficiency = self._get_efficiency(optEffCurve_path)
else:
with pkg_resources.path('ObservationSim.Instrument.data', 'mirror_ccdnote.txt') as optEffCurve_path:
self.efficiency = self._get_efficiency(optEffCurve_path)
def _get_efficiency(self, effCurve_path):
""" Read in the efficiency of optics
......
# Graph from Astro&MB, page 1
251.4 0.5285
254.2 0.4885
257.0 0.4485
259.9 0.4085
264.1 0.3428
269.8 0.2828
272.6 0.2657
276.9 0.2542
281.1 0.2542
285.3 0.2657
291.0 0.2771
299.5 0.2828
316.5 0.3028
329.2 0.3200
349.1 0.3428
366.1 0.3828
371.7 0.4142
371.7 0.4142
376.0 0.4542
383.0 0.4971
390.1 0.5485
398.6 0.6000
405.7 0.6400
412.8 0.6771
424.1 0.7171
438.3 0.7628
448.2 0.7942
448.2 0.7942
448.2 0.7942
448.2 0.7942
469.4 0.8400
490.7 0.8800
490.7 0.8800
511.9 0.9057
541.6 0.9228
565.7 0.9285
586.9 0.9285
620.9 0.9200
647.8 0.9028
680.4 0.8714
721.5 0.8114
741.3 0.7800
758.3 0.7428
771.0 0.7114
786.6 0.6685
800.7 0.6314
813.5 0.5942
822.0 0.5657
836.1 0.5228
850.3 0.4714
860.2 0.4400
860.2 0.4400
868.7 0.4114
877.2 0.3771
887.1 0.3485
901.3 0.3000
915.4 0.2571
926.8 0.2257
938.1 0.1914
955.1 0.1485
976.3 0.1000
997.6 0.06000
1016 0.03714
1033 0.02000
1040 0.01428
1050 0.01142
# Graph from Basic&NIR, page 1
250.0 0.06837
258.5 0.05973
265.6 0.05681
275.5 0.07380
281.2 0.1050
286.9 0.1363
294.0 0.1704
303.9 0.2102
313.9 0.2443
323.8 0.2641
336.6 0.2754
352.3 0.2838
367.9 0.2836
376.4 0.3091
389.2 0.3432
399.2 0.3801
413.4 0.4170
430.4 0.4539
444.6 0.4794
458.8 0.5077
477.3 0.5502
494.4 0.5871
508.6 0.6154
525.6 0.6466
539.8 0.6721
549.8 0.6891
566.8 0.7145
586.7 0.7456
603.8 0.7711
603.8 0.7711
603.8 0.7711
618.0 0.7937
639.3 0.8220
656.3 0.8418
673.4 0.8587
690.4 0.8756
701.8 0.8840
720.3 0.8924
740.2 0.9007
762.9 0.9062
792.8 0.8944
812.6 0.8743
825.4 0.8570
841.1 0.8255
841.1 0.8255
855.3 0.7855
866.6 0.7540
876.6 0.7226
889.4 0.6712
897.9 0.6341
906.4 0.5969
913.5 0.5655
919.2 0.5370
924.9 0.5084
933.4 0.4684
940.5 0.4256
949.1 0.3856
957.6 0.3428
966.1 0.3000
974.6 0.2572
983.2 0.2200
993.1 0.1772
1004 0.1343
1011 0.1058
1024 0.07149
1032 0.04861
1042 0.03141
1051 0.01992
1059 0.01128
# Graph from UV0, page 1
251.4 0.4900
264.2 0.5041
274.1 0.5268
278.4 0.5609
286.9 0.5864
296.8 0.5949
308.2 0.5919
322.4 0.5861
336.6 0.5717
352.3 0.5516
360.8 0.5401
367.9 0.5229
375.0 0.5342
383.5 0.5541
394.9 0.5767
409.1 0.6108
421.9 0.6220
433.3 0.6333
447.5 0.6389
465.9 0.6444
485.8 0.6555
504.3 0.6582
522.8 0.6552
544.1 0.6578
572.5 0.6546
592.4 0.6516
620.8 0.6484
640.7 0.6396
660.6 0.6280
680.5 0.6136
693.3 0.6021
710.3 0.5876
726.0 0.5647
738.8 0.5474
757.2 0.5216
781.4 0.4729
812.6 0.4127
828.3 0.3755
845.3 0.3355
858.1 0.3040
872.3 0.2725
892.2 0.2324
905.0 0.2009
923.5 0.1551
939.1 0.1265
970.4 0.07207
1003 0.03184
1025 0.01450
1038 0.008668
1050 0.00000
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