Skip to content

Commit 72d8859

Browse files
committed
Added coupled WCS from Will
1 parent 2e1fb0b commit 72d8859

File tree

2 files changed

+94
-0
lines changed

2 files changed

+94
-0
lines changed

ndcube/conftest.py

+60
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,47 @@ def wcs_3d_ln_lt_t_rotated():
292292
return WCS(header=h_rotated)
293293

294294

295+
@pytest.fixture
296+
def wcs_3d_ln_lt_l_coupled():
297+
# WCS for a 3D data cube with two celestial axes and one wavelength axis.
298+
# The latitudinal dimension is coupled to the third pixel dimension through
299+
# a single off diagonal element in the PCij matrix
300+
header = {
301+
'CTYPE1': 'HPLN-TAN',
302+
'CRPIX1': 5,
303+
'CDELT1': 5,
304+
'CUNIT1': 'arcsec',
305+
'CRVAL1': 0.0,
306+
307+
'CTYPE2': 'HPLT-TAN',
308+
'CRPIX2': 5,
309+
'CDELT2': 5,
310+
'CUNIT2': 'arcsec',
311+
'CRVAL2': 0.0,
312+
313+
'CTYPE3': 'WAVE',
314+
'CRPIX3': 1.0,
315+
'CDELT3': 1,
316+
'CUNIT3': 'Angstrom',
317+
'CRVAL3': 1.0,
318+
319+
'PC1_1': 1,
320+
'PC1_2': 0,
321+
'PC1_3': 0,
322+
'PC2_1': 0,
323+
'PC2_2': 1,
324+
'PC2_3': -1.0,
325+
'PC3_1': 0.0,
326+
'PC3_2': 0.0,
327+
'PC3_3': 1.0,
328+
329+
'WCSAXES': 3,
330+
331+
'DATEREF': "2020-01-01T00:00:00"
332+
}
333+
return WCS(header=header)
334+
335+
295336
################################################################################
296337
# Extra and Global Coords Fixtures
297338
################################################################################
@@ -519,6 +560,25 @@ def ndcube_3d_rotated(wcs_3d_ln_lt_t_rotated, simple_extra_coords_3d):
519560
return cube
520561

521562

563+
564+
@pytest.fixture
565+
def ndcube_3d_coupled(wcs_3d_ln_lt_l_coupled):
566+
shape = (10, 10, 5)
567+
wcs_3d_ln_lt_l_coupled.array_shape = shape
568+
data = data_nd(shape)
569+
mask = data > 0
570+
cube = NDCube(
571+
data,
572+
wcs_3d_ln_lt_l_coupled,
573+
mask=mask,
574+
uncertainty=data,
575+
)
576+
base_time = Time('2000-01-01', format='fits', scale='utc')
577+
timestamps = Time([base_time + TimeDelta(60 * i, format='sec') for i in range(data.shape[0])])
578+
cube.extra_coords.add('time', 0, timestamps)
579+
return cube
580+
581+
522582
@pytest.fixture
523583
def ndcube_3d_l_ln_lt_ectime(wcs_3d_lt_ln_l):
524584
return gen_ndcube_3d_l_ln_lt_ectime(wcs_3d_lt_ln_l,

ndcube/tests/test_ndcube.py

+34
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,40 @@ def test_axis_world_coords_wave_ec(ndcube_3d_l_ln_lt_ectime):
230230
assert coords[0].shape == (5,)
231231

232232

233+
def test_axis_world_coords_wave_coupled_dims(ndcube_3d_coupled):
234+
cube = ndcube_3d_coupled
235+
236+
coords = cube.axis_world_coords('em.wl')
237+
assert u.allclose(coords, [1.e-10, 2.e-10, 3.e-10, 4.e-10, 5.e-10,
238+
6.e-10, 7.e-10, 8.e-10, 9.e-10, 1.e-09] * u.m)
239+
240+
coords = cube.axis_world_coords()
241+
assert len(coords) == 2
242+
assert isinstance(coords[0], SkyCoord)
243+
assert coords[0].shape == (10, 10, 5)
244+
assert isinstance(coords[1], SpectralCoord)
245+
assert coords[1].shape == (10,)
246+
247+
coords = cube.axis_world_coords(wcs=cube.combined_wcs)
248+
assert len(coords) == 3
249+
assert isinstance(coords[0], SkyCoord)
250+
assert coords[0].shape == (10, 10, 5)
251+
assert isinstance(coords[1], SpectralCoord)
252+
assert coords[1].shape == (10,)
253+
assert isinstance(coords[2], Time)
254+
assert coords[2].shape == (10,)
255+
256+
coords = cube.axis_world_coords(wcs=cube.extra_coords)
257+
assert len(coords) == 1
258+
assert isinstance(coords[0], Time)
259+
assert coords[0].shape == (10,)
260+
261+
coords = cube.axis_world_coords_values(wcs=cube.extra_coords)
262+
assert len(coords) == 1
263+
assert isinstance(coords[0], u.Quantity)
264+
assert coords[0].shape == (10,)
265+
266+
233267
def test_axis_world_coords_empty_ec(ndcube_3d_l_ln_lt_ectime):
234268
cube = ndcube_3d_l_ln_lt_ectime
235269
sub_cube = cube[:, 0]

0 commit comments

Comments
 (0)