Skip to content

Commit 5bfc57b

Browse files
authored
Merge pull request #2552 from dhomeier/more-wcs-autolink
Fix incorrect autolinking of axes of unknown physical types in presence of celestial axes
2 parents 6af300c + fe03d80 commit 5bfc57b

File tree

2 files changed

+21
-19
lines changed

2 files changed

+21
-19
lines changed

glue/plugins/wcs_autolinking/tests/test_wcs_autolinking.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ def test_wcs_autolink_emptywcs():
4040
links = wcs_autolink(dc)
4141
assert len(links) == 0
4242

43+
4344
def test_wcs_autolink_2D_emptywcs():
4445

4546
# No links should be found because the WCS don't actually have well defined
@@ -57,6 +58,7 @@ def test_wcs_autolink_2D_emptywcs():
5758
links = wcs_autolink(dc)
5859
assert len(links) == 0
5960

61+
6062
def test_wcs_autolink_spectral_cube():
6163

6264
# This should link all coordinates
@@ -196,14 +198,17 @@ def test_link_editor():
196198
assert link2.data2.label == 'Data 2'
197199

198200

199-
def test_celestial_with_unknown_axes():
201+
@pytest.mark.parametrize('physical_types',
202+
[['SPAM', 'FREQ'], ['SPAM', 'EGGS'], ['WAVE', ''], ['', '']])
203+
def test_celestial_with_unknown_axes(physical_types):
200204

201205
# Regression test for a bug that caused n-d datasets with celestial axes
202206
# and axes with unknown physical types to not even be linked by celestial
203-
# axes.
207+
# axes. Also testing various corner cases with one or both datasets having
208+
# unknown or no physical type.
204209

205210
wcs1 = WCS(naxis=3)
206-
wcs1.wcs.ctype = 'DEC--TAN', 'RA---TAN', 'SPAM'
211+
wcs1.wcs.ctype = 'DEC--TAN', 'RA---TAN', physical_types[0]
207212
wcs1.wcs.set()
208213

209214
data1 = Data()
@@ -212,7 +217,7 @@ def test_celestial_with_unknown_axes():
212217
pz1, py1, px1 = data1.pixel_component_ids
213218

214219
wcs2 = WCS(naxis=3)
215-
wcs2.wcs.ctype = 'GLON-CAR', 'FREQ', 'GLAT-CAR'
220+
wcs2.wcs.ctype = 'GLON-CAR', physical_types[1], 'GLAT-CAR'
216221
wcs2.wcs.set()
217222

218223
data2 = Data()

glue/plugins/wcs_autolinking/wcs_autolinking.py

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,7 @@ def __init__(self, data1=None, data2=None, cids1=None, cids2=None):
113113

114114
if (wcs1.world_axis_physical_types.count(None) == wcs1.world_n_dim or
115115
wcs2.world_axis_physical_types.count(None) == wcs2.world_n_dim):
116-
raise IncompatibleWCS("Can't create WCS link between {0} and {1}".format(data1.label, data2.label))
117-
116+
raise IncompatibleWCS(f"Can't create WCS link between {data1.label} and {data2.label}")
118117

119118
forwards = backwards = None
120119
if wcs1.pixel_n_dim == wcs2.pixel_n_dim and wcs1.world_n_dim == wcs2.world_n_dim:
@@ -133,8 +132,6 @@ def __init__(self, data1=None, data2=None, cids1=None, cids2=None):
133132
self._physical_types_1 = wcs1.world_axis_physical_types
134133
self._physical_types_2 = wcs2.world_axis_physical_types
135134

136-
137-
138135
if not forwards or not backwards:
139136
# A generalized APE 14-compatible way
140137
# Handle also the extra-spatial axes such as those of the time and wavelength dimensions
@@ -173,14 +170,15 @@ def __init__(self, data1=None, data2=None, cids1=None, cids2=None):
173170
wcs2_sliced_physical_types = wcs2_celestial_physical_types
174171

175172
for i, physical_type1 in enumerate(wcs1.world_axis_physical_types):
176-
for j, physical_type2 in enumerate(wcs2.world_axis_physical_types):
177-
if physical_type1 == physical_type2:
178-
if physical_type1 not in wcs1_sliced_physical_types:
179-
slicing_axes1.append(wcs1.world_n_dim - i - 1)
180-
wcs1_sliced_physical_types.append(physical_type1)
181-
if physical_type2 not in wcs2_sliced_physical_types:
182-
slicing_axes2.append(wcs2.world_n_dim - j - 1)
183-
wcs2_sliced_physical_types.append(physical_type2)
173+
if physical_type1 is not None:
174+
for j, physical_type2 in enumerate(wcs2.world_axis_physical_types):
175+
if physical_type1 == physical_type2:
176+
if physical_type1 not in wcs1_sliced_physical_types:
177+
slicing_axes1.append(wcs1.world_n_dim - i - 1)
178+
wcs1_sliced_physical_types.append(physical_type1)
179+
if physical_type2 not in wcs2_sliced_physical_types:
180+
slicing_axes2.append(wcs2.world_n_dim - j - 1)
181+
wcs2_sliced_physical_types.append(physical_type2)
184182

185183
slicing_axes1 = sorted(slicing_axes1, key=str, reverse=True)
186184
slicing_axes2 = sorted(slicing_axes2, key=str, reverse=True)
@@ -215,7 +213,7 @@ def __init__(self, data1=None, data2=None, cids1=None, cids2=None):
215213
self._physical_types_2 = wcs2_sliced_physical_types
216214

217215
if pixel_cids1 is None:
218-
raise IncompatibleWCS("Can't create WCS link between {0} and {1}".format(data1.label, data2.label))
216+
raise IncompatibleWCS(f"Can't create WCS link between {data1.label} and {data2.label}")
219217

220218
super(WCSLink, self).__init__(pixel_cids1, pixel_cids2,
221219
forwards=forwards, backwards=backwards)
@@ -243,8 +241,7 @@ def description(self):
243241
'two datasets using the World Coordinate System (WCS) '
244242
'coordinates defined in the files.<br><br>The physical types '
245243
'of the coordinates linked in the first dataset are: '
246-
'<ul>{0}</ul>and in the second dataset:<ul>{1}</ul>'
247-
.format(types1, types2))
244+
f'<ul>{types1}</ul>and in the second dataset:<ul>{types2}</ul>')
248245

249246
def as_affine_link(self, n_samples=1000, tolerance=1):
250247
"""

0 commit comments

Comments
 (0)