Skip to content

Commit

Permalink
Merge pull request #808 from Cadair/more_gwcs_dev_fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
nabobalis authored Jan 14, 2025
2 parents 8eb6f12 + a2f9746 commit ace9596
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
4 changes: 2 additions & 2 deletions docs/explaining_ndcube/tabular_coordinates.rst
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ is the following temporal axis::

>>> gwcs = TimeTableCoordinate(time_axis).wcs
>>> gwcs
<WCS(output_frame=TemporalFrame, input_frame=PixelFrame, forward_transform=Model: Tabular1D
<WCS(output_frame=TemporalFrame, input_frame=Frame..., forward_transform=Model: Tabular1D
N_inputs: 1
N_outputs: 1
Parameters:
Expand Down Expand Up @@ -86,7 +86,7 @@ This keyword argument interprets the input to `.SkyCoordTableCoordinate` in a si
>>> gwcs = (TimeTableCoordinate(time_axis) & SkyCoordTableCoordinate(icrs_table, mesh=True)).wcs
>>> gwcs
<WCS(output_frame=CompositeFrame, input_frame=PixelFrame, forward_transform=Model: CompoundModel
<WCS(output_frame=CompositeFrame, input_frame=Frame..., forward_transform=Model: CompoundModel
Inputs: ('x', 'x0', 'x1')
Outputs: ('y', 'y0', 'y1')
Model set size: 1
Expand Down
9 changes: 7 additions & 2 deletions ndcube/extra_coords/table_coord.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import abc
import copy
import uuid
from numbers import Integral
from functools import partial
from collections import defaultdict
Expand Down Expand Up @@ -111,7 +112,12 @@ def _generate_generic_frame(naxes, unit, names=None, physical_types=None):
"""
axes_order = tuple(range(naxes))

name = None
if names is None:
# Ensure that the frame name is always unique
name = f"Frame-{str(uuid.uuid4()).split('-')[1]}"
else:
# If we have axes names use them as the frame name
name = "-".join(names) + " Frame"
axes_type = "CUSTOM"

if isinstance(unit, (u.Unit, u.IrreducibleUnit, u.CompositeUnit)):
Expand All @@ -121,7 +127,6 @@ def _generate_generic_frame(naxes, unit, names=None, physical_types=None):
axes_type = "SPATIAL"

if all(u.pix.is_equivalent(un) for un in unit):
name = "PixelFrame"
axes_type = "PIXEL"

axes_type = tuple([axes_type] * naxes)
Expand Down
9 changes: 4 additions & 5 deletions ndcube/extra_coords/tests/test_lookup_table_coord.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def lut_3d_distance_mesh():
def lut_2d_distance_no_mesh():
# Fixture is broken and raises: Currently all tables must be 1-D
lookup_table = np.arange(9).reshape(3, 3) * u.km, np.arange(9, 18).reshape(3, 3) * u.km
return QuantityTableCoordinate(*lookup_table)
return QuantityTableCoordinate(*lookup_table, mesh=False)


@pytest.fixture
Expand Down Expand Up @@ -213,6 +213,7 @@ def test_3d_skycoord_mesh(lut_3d_skycoord_mesh):
assert sub_ltc.delayed_models[0].lookup_table[2].shape == (6, )


@pytest.mark.xfail(reason="Two dimensional tables are not supported")
def test_2d_skycoord_no_mesh(lut_2d_skycoord_no_mesh):
ltc = lut_2d_skycoord_no_mesh

Expand All @@ -222,10 +223,8 @@ def test_2d_skycoord_no_mesh(lut_2d_skycoord_no_mesh):
pixel_coords = (0, 0)*u.pix
sc = ltc.wcs.pixel_to_world(*pixel_coords)

# TODO: Fix
with pytest.raises(u.UnitsError, match="could not be converted to required input units of pix"):
pix = ltc.wcs.world_to_pixel(sc)
assert u.allclose(pix, pixel_coords.value)
pix = ltc.wcs.world_to_pixel(sc)
assert u.allclose(pix, pixel_coords.value)


def test_1d_time(lut_1d_time):
Expand Down

0 comments on commit ace9596

Please sign in to comment.