Skip to content

Commit 70ad715

Browse files
committed
Some adjustments to Danny Review
1 parent ed25cac commit 70ad715

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

ndcube/ndcube.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ def _generate_world_coords(self, pixel_corners, wcs, needed_axes=None, *, units)
447447
# This will generate only the coordinates that are needed if there is no correlation within the WCS
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
450-
if needed_axes is not None and not isinstance(wcs, ExtraCoords) and np.sum(wcs.axis_correlation_matrix[needed_axes]) == 1 and len(self.data.shape) == wcs.world_n_dim:
450+
if needed_axes is not None and not isinstance(wcs, ExtraCoords) and np.sum(wcs.axis_correlation_matrix[needed_axes]) == 1:
451451
lims = (-0.5, self.data.shape[::-1][needed_axes[0]] + 1) if pixel_corners else (0, self.data.shape[::-1][needed_axes[0]])
452452
indices = [np.arange(lims[0], lims[1]) if wanted else [0] for wanted in wcs.axis_correlation_matrix[needed_axes][0]]
453453
world_coords = wcs.pixel_to_world_values(*indices)
@@ -489,7 +489,7 @@ def _generate_world_coords(self, pixel_corners, wcs, needed_axes=None, *, units)
489489
# First construct a range of pixel indices for this set of coupled dimensions
490490
pixel_ranges_subset = [pixel_ranges[idx] for idx in pixel_axes_indices]
491491
# Then get a set of non-correlated dimensions
492-
non_corr_axes = set(list(range(wcs.pixel_n_dim))) - set(pixel_axes_indices)
492+
non_corr_axes = set(range(wcs.pixel_n_dim)) - set(pixel_axes_indices)
493493
# And inject 0s for those coordinates
494494
for idx in non_corr_axes:
495495
pixel_ranges_subset.insert(idx, 0)

ndcube/tests/test_ndcube.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,11 +237,16 @@ def test_axis_world_coords_single(axes, ndcube_3d_ln_lt_l):
237237

238238
@pytest.mark.parametrize("axes", [[-1], [2], ["em"]])
239239
def test_axis_world_coords_single_pixel_corners(axes, ndcube_3d_ln_lt_l):
240+
241+
# We go from 4 pixels to 6 pixels when we add pixel corners
242+
coords = ndcube_3d_ln_lt_l.axis_world_coords_values(*axes, pixel_corners=False)
243+
assert u.allclose(coords[0], [1.02e-09, 1.04e-09, 1.06e-09, 1.08e-09] * u.m)
244+
240245
coords = ndcube_3d_ln_lt_l.axis_world_coords_values(*axes, pixel_corners=True)
241-
assert u.allclose(coords, [1.01e-09, 1.03e-09, 1.05e-09, 1.07e-09, 1.09e-09] * u.m)
246+
assert u.allclose(coords[0], [1.01e-09, 1.03e-09, 1.05e-09, 1.07e-09, 1.09e-09, 1.11e-09] * u.m)
242247

243248
coords = ndcube_3d_ln_lt_l.axis_world_coords(*axes, pixel_corners=True)
244-
assert u.allclose(coords, [1.01e-09, 1.03e-09, 1.05e-09, 1.07e-09, 1.09e-09] * u.m)
249+
assert u.allclose(coords[0], [1.01e-09, 1.03e-09, 1.05e-09, 1.07e-09, 1.09e-09, 1.11e-09] * u.m)
245250

246251

247252
@pytest.mark.parametrize(("ndc", "item"),

0 commit comments

Comments
 (0)