Initial version
This commit is contained in:
parent
bdef2d1c2a
commit
90256d8ced
53
esbo-etc_defaults.xml
Normal file
53
esbo-etc_defaults.xml
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
<root>
|
||||||
|
<common>
|
||||||
|
<wl_min val="400" units="nanometer" comment="Shortest wavelength used for binning input spectra"/>
|
||||||
|
<wl_max val="5" units="micron" comment="Shortest wavelength used for binning input spectra"/>
|
||||||
|
<logbinres val="1000" units="" comment="Resolving power for common spectral binning. A linear binning wavelength integral is estimated as wl_min/R"/>
|
||||||
|
<d_aperture val="5" units="m" comment="Diameter of the telescope aperture"/>
|
||||||
|
<jitter_rms val="0.1" units="arcsec" comment="Sigma RMS of the telescope jitter"/>
|
||||||
|
<output_path val="../output" comment="Output directory to store output files"/>
|
||||||
|
<config_path val="__path__"/>
|
||||||
|
</common>
|
||||||
|
|
||||||
|
<!-- <noise>-->
|
||||||
|
<!-- <EnableJitter val="False"/>-->
|
||||||
|
<!-- <EnableShotNoise val="True"/>-->
|
||||||
|
<!-- <EnableReadoutNoise val="True"/>-->
|
||||||
|
<!-- </noise>-->
|
||||||
|
|
||||||
|
<astroscene>
|
||||||
|
<target type="BlackBodyTarget" val="5778" units="K" mag="10" band="G" comment="Modeling the sun as mag 10 star"/>
|
||||||
|
<medium type="Atmosphere" transmissivity="__base__/data/atmosphere/transmittance.csv"
|
||||||
|
emission="__base__/data/atmosphere/emission.csv" comment="Including the atmosphere"/>
|
||||||
|
<medium type="StrayLight" emission="__base__/data/strayLight/emission.csv"
|
||||||
|
comment="Including arbitrary noise sources"/>
|
||||||
|
</astroscene>
|
||||||
|
|
||||||
|
<common_optics>
|
||||||
|
<optical_component type="Mirror" reflectivity="__path__/data/mirror/reflectivity.csv"
|
||||||
|
emissivity="__path__/data/mirror/emissivity.csv" val="70" units="K" comment="M1"/>
|
||||||
|
<optical_component type="Mirror" reflectivity="__path__/data/mirror/reflectivity.csv"
|
||||||
|
emissivity="__path__/data/mirror/emissivity.csv" val="70" units="K" comment="M2"/>
|
||||||
|
<optical_component type="Mirror" reflectivity="__path__/data/mirror/reflectivity.csv"
|
||||||
|
emissivity="__path__/data/mirror/emissivity.csv" val="70" units="K" comment="M3"/>
|
||||||
|
<optical_component type="Filter" band="G"
|
||||||
|
emissivity="__path__/data/filter/emissivity.csv" val="70" units="K" comment="Filter wheel"/>
|
||||||
|
</common_optics>
|
||||||
|
|
||||||
|
<instrument>
|
||||||
|
<optical_component type="Mirror" reflectivity="__path__/data/mirror/reflectivity.csv"
|
||||||
|
emissivity="__path__/data/mirror/emissivity.csv" val="70" units="K" comment="M4"/>
|
||||||
|
<optical_component type="Filter" band="G"
|
||||||
|
emissivity="__path__/data/filter/emissivity.csv" val="70" units="K" comment="Filter wheel"/>
|
||||||
|
<sensor type="CCD">
|
||||||
|
<f_number val="18.5" units="" comment="The working f/#"/>
|
||||||
|
<pixel_geometry val="1024, 1024" units="" comment="Pixel geometry"/>
|
||||||
|
<pixel>
|
||||||
|
<quantum_efficiency val="__path__/data/ccd/qe.csv" comment="Quantum efficiency of the detector pixel"/>
|
||||||
|
<pixel_size val="15" units="micron"/>
|
||||||
|
<dark_current val="20" units="1/s" comment="Detector dark current"/>
|
||||||
|
<sigma_read_out val="10.0" units="" comment="Detector readout noise in e-rms"/>
|
||||||
|
</pixel>
|
||||||
|
</sensor>
|
||||||
|
</instrument>
|
||||||
|
</root>
|
4
esbo_etc/__init__.py
Normal file
4
esbo_etc/__init__.py
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
from esbo_etc.classes import *
|
||||||
|
from esbo_etc.modules import *
|
||||||
|
|
||||||
|
# __root__ = "."
|
1
esbo_etc/classes/__init__.py
Normal file
1
esbo_etc/classes/__init__.py
Normal file
@ -0,0 +1 @@
|
|||||||
|
from esbo_etc.classes.config import *
|
146
esbo_etc/classes/config.py
Normal file
146
esbo_etc/classes/config.py
Normal file
@ -0,0 +1,146 @@
|
|||||||
|
import xml.etree.ElementTree as eT
|
||||||
|
import numpy as np
|
||||||
|
import quantities as pq
|
||||||
|
import os
|
||||||
|
import logging
|
||||||
|
import sys
|
||||||
|
|
||||||
|
|
||||||
|
class Entry(object):
|
||||||
|
"""
|
||||||
|
A class used to represent a configuration entry.
|
||||||
|
"""
|
||||||
|
|
||||||
|
val = None
|
||||||
|
attrib = None
|
||||||
|
xml_entry = None
|
||||||
|
|
||||||
|
def __call__(self):
|
||||||
|
return self.val
|
||||||
|
|
||||||
|
def parse(self, xml):
|
||||||
|
"""
|
||||||
|
Parse a XML tree element
|
||||||
|
|
||||||
|
:param xml: XML element tree to parse
|
||||||
|
"""
|
||||||
|
self.attrib = xml.attrib
|
||||||
|
for attr in self.attrib.keys():
|
||||||
|
setattr(self, attr, self.attrib[attr])
|
||||||
|
|
||||||
|
if hasattr(self, 'units'):
|
||||||
|
try:
|
||||||
|
self.val = pq.Quantity(list(map(float, self.val.split(','))),
|
||||||
|
self.units).simplified
|
||||||
|
if self.units == 'deg':
|
||||||
|
self.val = [x * pq.rad for x in self.val] # workaround for qt unit conversion
|
||||||
|
if len(self.val) == 1:
|
||||||
|
self.val = self.val[0]
|
||||||
|
except (ValueError, LookupError):
|
||||||
|
logging.error('unable to convert units in entry [tag, units, value]: ',
|
||||||
|
xml.tag, self.units, self.val)
|
||||||
|
|
||||||
|
|
||||||
|
class Configuration(object):
|
||||||
|
"""
|
||||||
|
A Class to parse the XML configuration file.
|
||||||
|
|
||||||
|
Attributes
|
||||||
|
----------
|
||||||
|
conf : str
|
||||||
|
Parsed XML tree
|
||||||
|
"""
|
||||||
|
conf = None
|
||||||
|
|
||||||
|
def __init__(self, filename="esbo-etc_defaults.xml", default_path=None):
|
||||||
|
"""
|
||||||
|
Parse a XML configuration file.
|
||||||
|
|
||||||
|
Parameters
|
||||||
|
----------
|
||||||
|
filename : str
|
||||||
|
configuration file to parse
|
||||||
|
default_path : str
|
||||||
|
default path to use for relative paths
|
||||||
|
"""
|
||||||
|
if not os.path.exists(filename):
|
||||||
|
logging.error("Configuration file '" + filename + "' doesn't exist.")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
logging.info("Reading configuration from file '" + filename + "'.")
|
||||||
|
self.conf = self.parser(eT.parse(filename).getroot())
|
||||||
|
|
||||||
|
if default_path:
|
||||||
|
setattr(self.conf, "__path__", default_path)
|
||||||
|
elif hasattr(self.conf.common, "ConfigPath"):
|
||||||
|
setattr(self.conf, "__path__",
|
||||||
|
os.path.expanduser(self.conf.common.ConfigPath().replace('__path__', os.getcwd())))
|
||||||
|
else:
|
||||||
|
logging.error("Path to config files not defined")
|
||||||
|
|
||||||
|
self.validate_options()
|
||||||
|
self.calc_metaoptions()
|
||||||
|
|
||||||
|
def parser(self, root):
|
||||||
|
"""
|
||||||
|
Parse a XML configuration file.
|
||||||
|
|
||||||
|
Parameters
|
||||||
|
----------
|
||||||
|
root : ElementTree
|
||||||
|
The XML tree to be parsed
|
||||||
|
|
||||||
|
Returns
|
||||||
|
-------
|
||||||
|
obj : Entry
|
||||||
|
The parsed XML tree
|
||||||
|
"""
|
||||||
|
obj = Entry()
|
||||||
|
|
||||||
|
for ch in root:
|
||||||
|
retval = self.parser(ch)
|
||||||
|
retval.parse(ch)
|
||||||
|
|
||||||
|
if hasattr(obj, ch.tag):
|
||||||
|
if isinstance(getattr(obj, ch.tag), list):
|
||||||
|
getattr(obj, ch.tag).append(retval)
|
||||||
|
else:
|
||||||
|
setattr(obj, ch.tag, [getattr(obj, ch.tag), retval])
|
||||||
|
else:
|
||||||
|
setattr(obj, ch.tag, retval)
|
||||||
|
return obj
|
||||||
|
|
||||||
|
def validate_options(self):
|
||||||
|
self.validate_is_list()
|
||||||
|
self.validate_True_False_spelling()
|
||||||
|
|
||||||
|
def validate_is_list(self):
|
||||||
|
if not isinstance(self.conf.common_optics.optical_component, list):
|
||||||
|
self.conf.common_optics.optical_component = [self.conf.common_optics.optical_component]
|
||||||
|
if not isinstance(self.conf.instrument, list):
|
||||||
|
self.conf.instrument = [self.conf.instrument]
|
||||||
|
|
||||||
|
def validate_True_False_spelling(self):
|
||||||
|
accepted_values = ['True', 'False']
|
||||||
|
test_cases = [
|
||||||
|
'noise/EnableJitter',
|
||||||
|
'noise/EnableShotNoise',
|
||||||
|
'noise/EnableReadoutNoise',
|
||||||
|
]
|
||||||
|
for item in test_cases:
|
||||||
|
if hasattr(self.conf, item.split('/')[0]):
|
||||||
|
if not self.conf.__getattribute__(item.split('/')[0]).__dict__[item.split('/')[1]]() in accepted_values:
|
||||||
|
raise ValueError("Accepted values for [%s] are 'True' or 'False'" % item)
|
||||||
|
|
||||||
|
def calc_metaoptions(self):
|
||||||
|
self.calc_metaoption_wl_delta()
|
||||||
|
|
||||||
|
def calc_metaoption_wl_delta(self):
|
||||||
|
wl_delta = self.conf.common.wl_min() / self.conf.common.logbinres()
|
||||||
|
setattr(self.conf.common, 'common_wl', (np.arange(self.conf.common.wl_min(),
|
||||||
|
self.conf.common.wl_max(),
|
||||||
|
wl_delta) * wl_delta.units).rescale(pq.um))
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
conf = Configuration()
|
47
esbo_etc/esbo-etc.py
Normal file
47
esbo_etc/esbo-etc.py
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
import esbo_etc
|
||||||
|
import argparse
|
||||||
|
import logging
|
||||||
|
import sys
|
||||||
|
import os
|
||||||
|
|
||||||
|
|
||||||
|
def run_exosim(opt=None):
|
||||||
|
pass
|
||||||
|
# star, planet = exosim.modules.astroscene.run(opt)
|
||||||
|
#
|
||||||
|
# exosim_msg(' Stellar SED: {:s}\n'.format(os.path.basename(star.ph_filename)))
|
||||||
|
# exosim_msg(' Star luminosity {:f}\n'.format(star.luminosity))
|
||||||
|
#
|
||||||
|
# # Instanciate Zodi
|
||||||
|
# zodi = exosim.classes.zodiacal_light(opt.common.common_wl, level=1.0)
|
||||||
|
#
|
||||||
|
# exosim.exolib.sed_propagation(star.sed, zodi.transmission)
|
||||||
|
# # Run Instrument Model
|
||||||
|
# channel = exosim.modules.instrument.run(opt, star, planet, zodi)
|
||||||
|
# # Create Signal timelines
|
||||||
|
# frame_time, total_observing_time, exposure_time = exosim.modules.timeline_generator.run(opt, channel, planet)
|
||||||
|
# # Generate noise timelines
|
||||||
|
# exosim.modules.noise.run(opt, channel, frame_time, total_observing_time, exposure_time)
|
||||||
|
# # Save
|
||||||
|
# exosim.modules.output.run(opt, channel, planet)
|
||||||
|
#
|
||||||
|
# return star, planet, zodi, channel
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
parser = argparse.ArgumentParser(prog="esbo_etc/esbo-etc.py", description='Exposure time calculator for ESBO-DS')
|
||||||
|
parser.add_argument("-c", "--config", dest='config', default="esbo-etc_defaults.xml",
|
||||||
|
metavar="config.xml", help="path to the configuration file")
|
||||||
|
parser.add_argument("-d", "--debug", action="store_true", dest="debug", help="print debug information")
|
||||||
|
parser.add_argument("-o", "--output-dir", dest="output_dir", help="path to the output directory",
|
||||||
|
default="output")
|
||||||
|
parser.add_argument("-v", "--version", action="version", version="ESBO-ETC version 1.0.0",
|
||||||
|
help="show version information")
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.DEBUG if args.debug else logging.WARNING,
|
||||||
|
stream=sys.stdout)
|
||||||
|
|
||||||
|
conf = esbo_etc.Configuration(filename=args.config).conf
|
||||||
|
|
||||||
|
# run_exosim(opt)
|
1
esbo_etc/lib/__init__.py
Normal file
1
esbo_etc/lib/__init__.py
Normal file
@ -0,0 +1 @@
|
|||||||
|
from esbo_etc.lib.helpers import *
|
0
esbo_etc/lib/helpers.py
Normal file
0
esbo_etc/lib/helpers.py
Normal file
Loading…
Reference in New Issue
Block a user