Skip to content

Commit

Permalink
first draft of fully labeled inputs and outputs
Browse files Browse the repository at this point in the history
  • Loading branch information
emolter committed May 30, 2024
1 parent 09be0a7 commit 6d077e6
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 31 deletions.
6 changes: 3 additions & 3 deletions jwst/assign_wcs/nirspec.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ def ifu(input_model, reference_files, slit_y_range=[-.55, .55]):
# in the whole pipeline) to microns (which is the expected output)
#
# "detector", "gwa", "slit_frame", "msa_frame", "oteip", "v2v3", "world"
breakpoint()

pipeline = [(det, dms2detector),
(sca, det2gwa),
(gwa, gwa2slit),
Expand Down Expand Up @@ -854,7 +854,7 @@ def ifuslit_to_slicer(slits, reference_files):
msa_transform = slitdata_model | ifuslicer_model
msa_transform.name = "ifuslit_to_slicer"
msa_transform.inputs = ('x_slit', 'y_slit')
msa_transform.outputs = ('x_slicer', 'y_slicer')
msa_transform.outputs = ('x_msa', 'y_msa')
models.append(msa_transform)
ifuslicer.close()

Expand All @@ -878,7 +878,7 @@ def slicer_to_msa(reference_files):
ifufore2fore_mapping.inverse = Mapping((0, 1, 2, 2))
ifu_fore_transform = slicer2fore_mapping | ifufore & Identity(1)
ifu_fore_transform.name = "slicer_to_msa"
ifu_fore_transform.inputs = ('x_slicer', 'y_slicer', 'lam')
ifu_fore_transform.inputs = ('x_msa', 'y_msa', 'lam')
ifu_fore_transform.outputs = ('x_msa', 'y_msa', 'lam')
return ifu_fore_transform

Expand Down
4 changes: 2 additions & 2 deletions jwst/assign_wcs/tests/test_nircam.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,9 +258,9 @@ def test_transform_metadata_imaging(create_imaging_wcs):


@pytest.mark.parametrize('exptype', ['tso', 'wfss'])
def test_transform_metadata_grism(exptype):
def test_transform_metadata_grism(exptype, create_tso_wcs):
if exptype == "tso":
wcsobj = create_tso_wcs()
wcsobj = create_tso_wcs
assert wcsobj.get_transform("grism_detector", "detector").inputs == ('x_grism', 'y_grism', 'order')
elif exptype == "wfss":
wcsobj = create_wfss_wcs('GRISMR')
Expand Down
43 changes: 17 additions & 26 deletions jwst/assign_wcs/tests/test_nirspec.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from math import cos, sin
import os.path

import asdf
import pytest
import numpy as np
from numpy.testing import assert_allclose
Expand Down Expand Up @@ -785,30 +786,8 @@ def test_functional_ifu_grating(wcs_ifu_grating):
assert_allclose(v2, ins_tab['xV2V3'])
assert_allclose(v3, ins_tab['yV2V3'])

# test transform metadata for slit_wcs
# available frames ['detector', 'sca', 'gwa', 'slit_frame', 'slicer', 'msa_frame', 'oteip', 'v2v3', 'v2v3vacorr', 'world']
assert slit_wcs.get_transform('detector', 'sca').inputs == ('x_detector', 'y_detector')
assert slit_wcs.get_transform('detector', 'sca').outputs == ('x_sca', 'y_sca')
assert slit_wcs.get_transform('sca', 'gwa').inputs == ('x_sca', 'y_sca')
assert slit_wcs.get_transform('sca', 'gwa').outputs == ('alpha', 'beta', 'gamma')
assert slit_wcs.get_transform('gwa', 'slit_frame').inputs == ('alpha', 'beta', 'gamma')
assert slit_wcs.get_transform('gwa', 'slit_frame').outputs == ('x_slit', 'y_slit', 'lam')
assert slit_wcs.get_transform('slit_frame', 'slicer').inputs == ('name', 'x_slit', 'y_slit')
assert slit_wcs.get_transform('slit_frame', 'slicer').outputs == ('name', 'x_slicer', 'y_slicer')
assert slit_wcs.get_transform('slicer', 'msa_frame').inputs == ('name', 'x_slicer', 'y_slicer')
assert slit_wcs.get_transform('slicer', 'msa_frame').outputs == ('x_msa', 'y_msa', 'lam')
assert slit_wcs.get_transform('msa_frame', 'oteip').inputs == ('x_msa', 'y_msa', 'lam')
assert slit_wcs.get_transform('msa_frame', 'oteip').outputs == ('xan', 'yan', 'lam')
assert slit_wcs.get_transform('oteip', 'v2v3').inputs == ('xan', 'yan', 'lam')
assert slit_wcs.get_transform('oteip', 'v2v3').outputs == ("v2", "v3", 'lam')
assert slit_wcs.get_transform('v2v3', 'v2v3vacorr').inputs == ("v2", "v3", 'lam')
assert slit_wcs.get_transform('v2v3', 'v2v3vacorr').outputs == ("v2", "v3", 'lam')
assert slit_wcs.get_transform('v2v3vacorr', 'world').inputs == ("v2", "v3", 'lam')
assert slit_wcs.get_transform('v2v3vacorr', 'world').outputs == ("ra", "dec", 'lam')



def test_functional_ifu_prism():

def test_functional_ifu_prism(tmp_cwd):
"""Compare Nirspec instrument model with IDT model for IFU prism."""
# setup test
model_file = 'ifu_prism_functional_ESA_v1_20180619.txt'
Expand Down Expand Up @@ -933,7 +912,7 @@ def test_functional_ifu_prism():
assert w.get_transform('gwa', 'slit_frame').outputs == ('name', 'x_slit', 'y_slit', 'lam')
assert w.get_transform('slit_frame', 'slicer').inputs == ('name', 'x_slit', 'y_slit')
assert w.get_transform('slit_frame', 'slicer').outputs == ('x_msa', 'y_msa')
assert w.get_transform('slicer', 'msa_frame').inputs == ('x_msa', 'y_msa')
assert w.get_transform('slicer', 'msa_frame').inputs == ('x_msa', 'y_msa', 'lam')
assert w.get_transform('slicer', 'msa_frame').outputs == ('x_msa', 'y_msa', 'lam')
assert w.get_transform('msa_frame', 'oteip').inputs == ('x_msa', 'y_msa', 'lam')
assert w.get_transform('msa_frame', 'oteip').outputs == ('xan', 'yan', 'lam')
Expand All @@ -944,7 +923,19 @@ def test_functional_ifu_prism():
assert w.get_transform('v2v3vacorr', 'world').inputs == ("v2", "v3", 'lam')
assert w.get_transform('v2v3vacorr', 'world').outputs == ("ra", "dec", 'lam')

# can they be serialized? when this is done are the names restored?

# test these can be serialized and that names are restored when this is done
outfile = 'w_asdf.asdf'
tree = {"wcs": w}
af = asdf.AsdfFile(tree)
af.write_to(outfile)
with asdf.open(outfile) as af:
w = af.tree['wcs']
print(w)
assert True
assert w.get_transform('detector', 'sca').inputs == ('x_detector', 'y_detector')
assert w.get_transform('detector', 'sca').outputs == ('x_sca', 'y_sca')
assert w.get_transform('detector', 'sca').name == "dms_to_sca"


def test_ifu_bbox():
Expand Down

0 comments on commit 6d077e6

Please sign in to comment.