Skip to content

Commit

Permalink
Test and polish more ordering
Browse files Browse the repository at this point in the history
  • Loading branch information
Cadair committed Sep 27, 2024
1 parent 5b189e7 commit 8264b7e
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 11 deletions.
9 changes: 1 addition & 8 deletions gwcs/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,7 @@ def world_axis_physical_types(self):
arbitrary string. Alternatively, if the physical type is
unknown/undefined, an element can be `None`.
"""
# A CompositeFrame orders the output correctly based on axes_order.
if isinstance(self.output_frame, cf.CompositeFrame):
return self.output_frame.axis_physical_types

# If we don't have a CompositeFrame, where this is taken care of for us,
# we need to make sure we re-order the output to match the transform.
# The underlying frames don't reorder themselves because axes_order is global.
return tuple(self.output_frame.axis_physical_types[i] for i in self.output_frame.axes_order)
return self.output_frame.axis_physical_types

@property
def world_axis_units(self):
Expand Down
7 changes: 5 additions & 2 deletions gwcs/coordinate_frames.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,8 @@ def axis_physical_types(self):
These physical types are the types in frame order, not transform order.
"""
return self._prop.axis_physical_types or self._default_axis_physical_types
apt = self._prop.axis_physical_types or self._default_axis_physical_types
return self._sort_property(apt)

@property
def world_axis_object_classes(self):
Expand All @@ -500,7 +501,7 @@ class CelestialFrame(CoordinateFrame):
Representation of a Celesital coordinate system.
This class has a native order of longitude then latitude, meaning
``axes_names``, ``unit`` should be lon, lat ordered. If your transform is
``axes_names``, ``unit`` and ``axis_physical_types`` should be lon, lat ordered. If your transform is
in a different order this should be specified with ``axes_order``.
Parameters
Expand All @@ -515,6 +516,8 @@ class CelestialFrame(CoordinateFrame):
Names of the axes in this frame.
name : str
Name of this frame.
axis_physical_types : list
The UCD 1+ physical types for the axes, in frame order (lon, lat).
"""

def __init__(self, axes_order=None, reference_frame=None,
Expand Down
2 changes: 1 addition & 1 deletion gwcs/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def gwcs_2d_spatial_reordered():
A simple one step spatial WCS, in ICRS with a 1 and 2 px shift.
"""
out_frame = cf.CelestialFrame(reference_frame=coord.ICRS(),
axes_order=(1, 0))
axes_order=(1, 0))
return wcs.WCS(model_2d_shift | models.Mapping((1, 0)), input_frame=detector_2d, output_frame=out_frame)


Expand Down
26 changes: 26 additions & 0 deletions gwcs/tests/test_coordinate_systems.py
Original file line number Diff line number Diff line change
Expand Up @@ -475,3 +475,29 @@ def test_ucd1_to_ctype(caplog):
assert ctype_to_ucd[v] == k

assert inv_map['new.repeated.type'] in new_ctype_to_ucd


def test_celestial_ordering():
c1 = cf.CelestialFrame(
reference_frame=coord.ICRS(),
axes_order=(0, 1),
axes_names=("lon", "lat"),
unit=(u.deg, u.arcsec),
axis_physical_types=("custom:lon", "custom:lat"),
)
c2 = cf.CelestialFrame(
reference_frame=coord.ICRS(),
axes_order=(1, 0),
axes_names=("lon", "lat"),
unit=(u.deg, u.arcsec),
axis_physical_types=("custom:lon", "custom:lat"),
)

assert c1.axes_names == ("lon", "lat")
assert c2.axes_names == ("lat", "lon")

assert c1.unit == (u.deg, u.arcsec)
assert c2.unit == (u.arcsec, u.deg)

assert c1.axis_physical_types == ("custom:lon", "custom:lat")
assert c2.axis_physical_types == ("custom:lat", "custom:lon")

0 comments on commit 8264b7e

Please sign in to comment.