Skip to content

Commit

Permalink
add pixel_shape to WCS converter (#480)
Browse files Browse the repository at this point in the history
Co-authored-by: Nadia Dencheva <[email protected]>
  • Loading branch information
braingram and nden authored Nov 28, 2023
1 parent 2b571a9 commit 9d21ec0
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ other

- Replace ``pkg_resources`` with ``importlib.metadata``. [#478]

- Serialize and deserialize ``pixel_shape`` with asdf. [#480]

0.19.0 (2023-09-15)
-------------------

Expand Down
4 changes: 4 additions & 0 deletions gwcs/converters/tests/test_wcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ def assert_frame_roundtrip(frame, tmpdir, version=None):

def _assert_wcs_equal(a, b):
assert a.name == b.name # nosec
assert a.pixel_shape == b.pixel_shape
assert len(a.available_frames) == len(b.available_frames) # nosec
for a_step, b_step in zip(a.pipeline, b.pipeline):
_assert_frame_equal(a_step.frame, b_step.frame)
Expand All @@ -75,10 +76,13 @@ def test_create_wcs(tmpdir):
gw1 = wcs.WCS(output_frame='icrs', input_frame='detector', forward_transform=m1)
gw2 = wcs.WCS(output_frame='icrs', forward_transform=m1)
gw3 = wcs.WCS(output_frame=icrs, input_frame=det, forward_transform=m1)
gw4 = wcs.WCS(output_frame=icrs, input_frame=det, forward_transform=m1)
gw4.pixel_shape = (100, 200)

assert_wcs_roundtrip(gw1, tmpdir)
assert_wcs_roundtrip(gw2, tmpdir)
assert_wcs_roundtrip(gw3, tmpdir)
assert_wcs_roundtrip(gw4, tmpdir)


def test_composite_frame(tmpdir):
Expand Down
8 changes: 6 additions & 2 deletions gwcs/converters/wcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,16 @@ class WCSConverter(Converter):

def from_yaml_tree(self, node, tag, ctx):
from ..wcs import WCS
return WCS(node['steps'], name=node['name'])
gwcsobj = WCS(node['steps'], name=node['name'])
if 'pixel_shape' in node:
gwcsobj.pixel_shape = node['pixel_shape']
return gwcsobj

def to_yaml_tree(self, gwcsobj, tag, ctx):
return {
'name': gwcsobj.name,
'steps': gwcsobj.pipeline
'steps': gwcsobj.pipeline,
'pixel_shape': gwcsobj.pixel_shape,
}


Expand Down

0 comments on commit 9d21ec0

Please sign in to comment.