Skip to content

Fix slicing and axis_world_coords for extra coords that span several axes - #980

Open
nabobalis wants to merge 7 commits into
sunpy:mainfrom
nabobalis:extra-coords-axes
Open

nabobalis wants to merge 7 commits into
sunpy:mainfrom
nabobalis:extra-coords-axes

Conversation

@nabobalis

@nabobalis nabobalis commented Sep 27, 2026 •

Copy link
Copy Markdown
Member

PR Description

Fixes two bugs with extra coords that span more than one array axis:

  • Slicing raised TypeError when a lookup table's axes were a list, which is how ASDF stores them. Integer indexing gave the wrong length or NaN.
  • axis_world_coords(wcs=cube.extra_coords) returned them transposed when their array axes were ascending, e.g. (0, 1). The transpose now follows ExtraCoords.mapping; output for the cube's own WCS is unchanged.

Related to #342. Should be backported to 2.4.

AI Assistance Disclosure

AI tools were used for:

  • Code generation (e.g., when writing an implementation or fixing a bug)
  • Test/benchmark generation
  • Documentation (including examples)
  • Research and understanding
  • No AI tools were used

Regardless of AI use, the human contributor remains fully responsible for correctness, design choices, licensing compatibility, and long-term maintainability.

@nabobalis nabobalis changed the title Fix slicing and transposed world coords of multi-axis extra coords Fix slicing and axis_world_coords for extra coords that span several axes Oct 1, 2026
ExtraCoords._getitem_lookup_tables treated any axes that were not a
tuple as a single axis, and kept every axis of a table after integer
slicing. Tables added with a list of axes, and every multi-axis lookup
table loaded from ASDF (which stores the axes as a list), therefore
raised "list indices must be integers or slices" when the cube was
sliced. Integer indexing also left stale axes on the table (cube[1]
turned (0, 1) into (-1, 0)), so on a cube with more axes than the table
the extra coord was read along the wrong array axis, giving wrong or
NaN values.

Normalise the axes to a tuple and drop integer-sliced axes.
_generate_world_coords transposed each block of correlated world
coordinates with .T, which is only right when the WCS pixel inputs are
in ascending cube pixel order. That holds for the cube's own WCS, but an
ExtraCoords WCS takes its inputs in the order of its mapping, which for
lookup tables follows the order the array axes were given in. So a 2-D
SkyCoord table added on array axes (0, 1) came out of axis_world_coords
transposed, as did WCS-backed extra coords whose mapping reorders
correlated pixel axes.

Order each block by descending cube pixel axis instead. For the cube's
own WCS this is the same reversal as .T, so its output is unchanged.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant