Skip to content

Commit

Permalink
chore(dragons update): 📦 Add wcs tabular1d
Browse files Browse the repository at this point in the history
Covers commit f9145214996e3f0be4966b5293e948b5181af4ba to
19282848a5180fcc52a90c30fc15fbb413a85feb.
  • Loading branch information
teald committed Sep 10, 2024
1 parent d67ea39 commit 385cc39
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
7 changes: 6 additions & 1 deletion astrodata/wcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -1052,18 +1052,23 @@ def fitswcs_other(header, other=None):
if other is not None:
table_name = header.get(f"PS{ax + 1}_0")
table = other.get(table_name)

if table is None:
raise ValueError(
f"Cannot read table for {ctype} for axis {ax}"
)

if isinstance(table, Table):
other_model = models.Tabular1D(
lookup_table=table[f"PS{ax + 1}_1"]
lookup_table=table[header[f"PS{ax + 1}_1"]]
)
else:
other_model = models.Tabular2D(lookup_table=table.T)

other_model.name = model_name_mapping.get(ctype[:4], ctype[:4])

del other[table_name]

elif len(pixel_axes) == 1:
pixel_axis = pixel_axes[0]
m1 = models.Shift(
Expand Down
13 changes: 13 additions & 0 deletions tests/unit/test_wcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,3 +263,16 @@ def test_loglinear_axis(NIRI_IMAGE):
ad.write("test.fits", overwrite=True)
ad2 = astrodata.from_file("test.fits")
assert_allclose(ad2[0].wcs(2, 200, 300), new_coords)

@pytest.mark.preprocessed_data
def test_tabular1D_axis(path_to_inputs, change_working_dir):
"""Check a FITS file with a tabular 1D axis is read correctly and
then rewritten to disk and read back in"""
ad = astrodata.open(Path(path_to_inputs) / "tab1dtest.fits")
assert ad[0].wcs(0) == pytest.approx(3017.51065254)
assert ad[0].wcs(1021) == pytest.approx(4012.89510727)
with change_working_dir():
ad.write("test.fits", overwrite=True)
ad2 = astrodata.open("test.fits")
assert ad2[0].wcs(0) == pytest.approx(3017.51065254)
assert ad2[0].wcs(1021) == pytest.approx(4012.89510727)

0 comments on commit 385cc39

Please sign in to comment.