Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Roman dev - WIP #296

Merged
merged 7 commits into from
Sep 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion pysiaf/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@
# package is not installed
__version__ = 'unknown'

from .aperture import Aperture, HstAperture, JwstAperture
from .aperture import Aperture, HstAperture, JwstAperture, RomanAperture
from .constants import JWST_PRD_VERSION, JWST_PRD_DATA_ROOT, JWST_PRD_DATA_ROOT_EXCEL, HST_PRD_VERSION, \
HST_PRD_DATA_ROOT
from .iando import read, write
from .siaf import Siaf, ApertureCollection
# from .tests import test_aperture#, test_polynomial
from .utils import polynomial, rotations, tools, projection
from .specpars import SpecPars

__all__ = ['Aperture', 'HstAperture', 'JwstAperture', 'SIAF', 'JWST_PRD_VERSION', 'JWST_PRD_DATA_ROOT', 'HST_PRD_VERSION', 'HST_PRD_DATA_ROOT', '_JWST_STAGING_ROOT', 'siaf', 'iando', 'polynomial', 'rotations', 'tools', 'compare', 'JWST_PRD_DATA_ROOT_EXCEL', 'generate', 'projection']

Expand Down
13 changes: 13 additions & 0 deletions pysiaf/aperture.py
Original file line number Diff line number Diff line change
Expand Up @@ -2615,3 +2615,16 @@ def compare_apertures(reference_aperture, comparison_aperture, absolute_toleranc
print('', file=print_file)

return comparison_table

class RomanAperture(Aperture):
"""
A class that defines the accepted aperture types for
the Roman SIAF. This is built upon the pysiaf.aperture.Aperture
base class.
"""

_accepted_aperture_types = ['FULLSCA', 'COMPOUND']

def __init__(self):
super(RomanAperture, self).__init__()
self.observatory = 'Roman'
77 changes: 77 additions & 0 deletions pysiaf/iando/read.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
from astropy.time import Time
import lxml.etree as ET

# from soc_roman_tools
import importlib.resources as importlib_resources

from ..constants import HST_PRD_DATA_ROOT, JWST_PRD_DATA_ROOT, JWST_SOURCE_DATA_ROOT, HST_PRD_VERSION
from ..siaf import JWST_INSTRUMENT_NAME_MAPPING

Expand Down Expand Up @@ -616,3 +619,77 @@ def read_siaf_xml_field_format_reference_file(instrument=None):
'{}_siaf_xml_field_format.txt'.format(instrument.lower()))

return Table.read(filename, format='ascii.basic', delimiter=',')

def read_roman_siaf(siaf_file=None):
"""
Purpose
-------
Read the SIAF file.

Inputs
------
None

Returns
-------
apertures (collections.OrderedDict)
An ordered dictionary of pysiaf.aperture objects containing each
aperture from the Roman SIAF file that was read.
"""

from pysiaf import aperture # runtime import to avoid circular import on startup
from pysiaf import specpars

if not siaf_file:
with importlib_resources.path('pysiaf.prd_data.Roman',
'roman_siaf.xml') as siaf_file:
siaf_file = str(siaf_file)
else:
siaf_file = str(siaf_file)

apertures = OrderedDict()
tree = ET.parse(siaf_file)
for entry in tree.getroot().iter('SiafEntry'):
roman_aperture = aperture.RomanAperture()
apertype = None
for node in entry:
if node.tag == 'AperType':
apertype = node.text
if (node.tag in aperture.ATTRIBUTES_THAT_CAN_BE_NONE) and \
(node.text is None):
value = node.text
elif node.tag in aperture.INTEGER_ATTRIBUTES:
try:
value = int(node.text)
except (TypeError, ValueError) as e:
if node.tag == 'DetSciYAngle':
value = np.int(float(node.text))
elif not node.text:
value = None
else:
raise TypeError
elif node.tag in aperture.STRING_ATTRIBUTES:
value = node.text
elif node.tag in aperture.FLOAT_ATTRIBUTES:
value = float(node.text)
# If it has children (which we can test by a simple boolean),
# then we need to get things out of it. The only time this will
# happen is the containers for the prism and grism parameters.
# Each child will be a Position container.
elif node.tag:
if apertype == 'FULLSCA':
data = list()
for child in node:
data.append(specpars.SpecPars(child))
value = data
else:
try:
value = float(node.text)
except TypeError:
print('{}: {}'.format(node.tag, node.text))
raise TypeError
setattr(roman_aperture, node.tag, value)

apertures[roman_aperture.AperName] = roman_aperture

return apertures
Empty file.
Loading
Loading