@@ -448,11 +448,17 @@ def _generate_world_coords(self, pixel_corners, wcs, needed_axes=None, *, units)
448448 # This bypasses the entire rest of the function below which works out the full set of coordinates
449449 # This only works for WCS that have the same number of world and pixel dimensions
450450 if needed_axes is not None and not isinstance (wcs , ExtraCoords ) and np .sum (wcs .axis_correlation_matrix [needed_axes ]) == 1 :
451- lims = (- 0.5 , self .data .shape [::- 1 ][needed_axes [0 ]] + 1 ) if pixel_corners else (0 , self .data .shape [::- 1 ][needed_axes [0 ]])
452- indices = [np .arange (lims [0 ], lims [1 ]) if wanted else [0 ] for wanted in wcs .axis_correlation_matrix [needed_axes ][0 ]]
451+ # Account for non-pixel axes affecting the value of needed_axes
452+ # Only works for one axis
453+ if np .max (wcs .axis_correlation_matrix [needed_axes ][0 ].shape ) == needed_axes [0 ]:
454+ needed_axis = needed_axes [0 ] - 1
455+ else :
456+ needed_axis = needed_axes [0 ]
457+ lims = (- 0.5 , self .data .shape [::- 1 ][needed_axis ] + 1 ) if pixel_corners else (0 , self .data .shape [::- 1 ][needed_axis ])
458+ indices = [np .arange (lims [0 ], lims [1 ]) if wanted else [0 ] for wanted in wcs .axis_correlation_matrix [needed_axis ]]
453459 world_coords = wcs .pixel_to_world_values (* indices )
454460 if units :
455- world_coords = world_coords << u .Unit (wcs .world_axis_units [needed_axes [ 0 ] ])
461+ world_coords = world_coords << u .Unit (wcs .world_axis_units [needed_axis ])
456462 return world_coords
457463
458464 # Create a meshgrid of all pixel coordinates.
@@ -546,23 +552,19 @@ def axis_world_coords_values(self, *axes, pixel_corners=False, wcs=None):
546552 # Docstring in NDCubeABC.
547553 if isinstance (wcs , BaseHighLevelWCS ):
548554 wcs = wcs .low_level_wcs
549-
550555 orig_wcs = wcs
551556 if isinstance (wcs , ExtraCoords ):
552557 wcs = wcs .wcs
553-
558+ if not wcs :
559+ return ()
554560 world_indices = utils .wcs .calculate_world_indices_from_axes (wcs , axes )
555-
556561 axes_coords = self ._generate_world_coords (pixel_corners , orig_wcs , world_indices , units = True )
557-
558562 world_axis_physical_types = wcs .world_axis_physical_types
559-
560563 # If user has supplied axes, extract only the
561564 # world coords that correspond to those axes.
562565 if axes :
563566 axes_coords = [axes_coords [i ] for i in world_indices ]
564567 world_axis_physical_types = tuple (np .array (world_axis_physical_types )[world_indices ])
565-
566568 # Return in array order.
567569 # First replace characters in physical types forbidden for namedtuple identifiers.
568570 identifiers = []
0 commit comments