Skip to content

Commit

Permalink
Merge branch 'main' of github.com:glue-viz/glue into add_listplugins
Browse files Browse the repository at this point in the history
  • Loading branch information
CyclingNinja committed May 24, 2024
2 parents 62ce71f + 5e92185 commit c632393
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 12 deletions.
12 changes: 6 additions & 6 deletions glue/core/units.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,19 @@ def to_unit(self, data, cid, values, target_units):
if target_units is None:
return values
original_units = self._get_units(data, cid)
if original_units:
return self.converter_helper.to_unit(data, cid, values, original_units, target_units)
else:
if original_units == target_units or not original_units:
return values
else:
return self.converter_helper.to_unit(data, cid, values, original_units, target_units)

def to_native(self, data, cid, values, original_units):
if original_units is None:
return values
target_units = self._get_units(data, cid)
if target_units:
return self.converter_helper.to_unit(data, cid, values, original_units, target_units)
else:
if original_units == target_units or not target_units:
return values
else:
return self.converter_helper.to_unit(data, cid, values, original_units, target_units)

def _get_units(self, data, cid):
data = data.data if isinstance(data, Subset) else data
Expand Down
5 changes: 3 additions & 2 deletions glue/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def load_plugins(splash=None, require_qt_plugins=False, plugins_to_load=None):
n_plugins = len(plugins_to_require)

for i_plugin, item in enumerate(list(iter_plugin_entry_points())):
if item.module in plugins_to_require:
if item.module in plugins_to_load:
if item.module not in _installed_plugins:
_installed_plugins.add(item.name)

Expand Down Expand Up @@ -115,8 +115,9 @@ def load_plugins(splash=None, require_qt_plugins=False, plugins_to_load=None):
from glue._settings_helpers import load_settings
load_settings()


def list_plugins():
"""
Function to list all plugins that are currently loaded
"""
return sorted(_loaded_plugins)
return sorted(_loaded_plugins)
26 changes: 26 additions & 0 deletions glue/plugins/wcs_autolinking/tests/test_wcs_autolinking.py
Original file line number Diff line number Diff line change
Expand Up @@ -591,3 +591,29 @@ def test_wcs_no_approximation():

with pytest.raises(NoAffineApproximation):
link.as_affine_link(tolerance=0.1)


def test_no_wcs_overlap():

wcs1 = WCS(naxis=2)
wcs1.wcs.ctype = 'RA---TAN', 'DEC--TAN'
wcs1.wcs.crval = 10, 20
wcs1.wcs.set()

data1 = Data(label='Data 1')
data1.coords = wcs1
data1['x'] = np.ones((2, 3))

wcs2 = WCS(naxis=2)
wcs2.wcs.ctype = 'RA---TAN', 'DEC--TAN'
wcs2.wcs.crval = 190, -20
wcs2.wcs.set()

data2 = Data(label='Data 2')
data2.coords = wcs2
data2['x'] = np.ones((2, 3))

link = WCSLink(data1, data2)

with pytest.raises(NoAffineApproximation, match='no overlap'):
link.as_affine_link()
14 changes: 14 additions & 0 deletions glue/plugins/wcs_autolinking/wcs_autolinking.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,9 @@ def as_affine_link(self, n_samples=1000, tolerance=1):
For now this will only work for datasets in which two pixel coordinates
are linked.
The deviation to be compared to the tolerance is measured in the frame
of reference of the second dataset.
"""

if len(self.cids1) != 2 or len(self.cids2) != 2:
Expand All @@ -260,6 +263,17 @@ def as_affine_link(self, n_samples=1000, tolerance=1):
# Convert to pixel positions in data2
pixel2 = self.forwards(*pixel1)

keep = np.ones(n_samples, dtype=bool)
for p in pixel1 + pixel2:
keep[np.isnan(p)] = False

if not np.any(keep):
raise NoAffineApproximation(f'Could not find a good affine approximation to '
f'WCSLink with tolerance={tolerance}, as no overlap')

pixel1 = [p[keep] for p in pixel1]
pixel2 = [p[keep] for p in pixel2]

# First try simple offset

def transform_offset(offsets):
Expand Down
6 changes: 2 additions & 4 deletions glue/tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@ def test_load_plugins(capsys):
with patch.object(logger, 'info') as info:
load_plugins()

plugin = [call[0][0] for call in info.call_args_list]
assert False

plugin = [call[0][0] for call in info.call_args_list if 'loaded' in call[0][0]]
assert len(plugin) == 5


def test_no_duplicate_loading(capsys):
Expand All @@ -42,4 +41,3 @@ def test_list_plugins():
load_plugins(require_qt_plugins=False)
plugins = list_plugins()
assert isinstance(plugins, list)
assert len(plugins) == 14
13 changes: 13 additions & 0 deletions glue/viewers/image/tests/test_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -458,3 +458,16 @@ def test_stretch_global():

assert layer_state.v_min == 49.95
assert layer_state.v_max == 949.05


def test_attribute_units_invalid():

# Regression test for a bug that caused a crash if a dataset had an
# unrecognized unit

viewer_state = ImageViewerState()

data = Data(x=np.arange(100).reshape((10, 10)))
data.get_component('x').units = 'banana'

ImageLayerState(layer=data, viewer_state=viewer_state)

0 comments on commit c632393

Please sign in to comment.