From 859e1d48f81a064654d07a22ec432524bb3161dd Mon Sep 17 00:00:00 2001 From: Thomas Robitaille Date: Mon, 6 Jan 2025 12:15:41 +0000 Subject: [PATCH 1/2] Provide a way to avoid creating world<->pixel links in datasets --- glue/config.py | 2 +- glue/core/data.py | 3 ++- glue/core/tests/test_data.py | 18 ++++++++++++++++++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/glue/config.py b/glue/config.py index d12b55dce..d81e6ce0a 100644 --- a/glue/config.py +++ b/glue/config.py @@ -930,7 +930,7 @@ def _default_search_order(): settings.add('SHOW_WARN_PROFILE_DUPLICATE', True, validator=bool) settings.add('FONT_SIZE', -1.0, validator=float) settings.add('AUTOLINK', {}, validator=dict) - +settings.add('AUTO_COMPUTE_COORDS_LINKS', True, validator=bool) def check_unit_converter(value): if value != 'default' and value not in unit_converter.members: diff --git a/glue/core/data.py b/glue/core/data.py index 77359b96c..db6e6738c 100644 --- a/glue/core/data.py +++ b/glue/core/data.py @@ -1179,7 +1179,8 @@ def delay_callbacks(): label = axis_label(self.coords, i) cid = self.add_component(comp, label) self._world_component_ids.append(cid) - self._set_up_coordinate_component_links(ndim) + if settings.AUTO_COMPUTE_COORDS_LINKS: + self._set_up_coordinate_component_links(ndim) def _set_up_coordinate_component_links(self, ndim): diff --git a/glue/core/tests/test_data.py b/glue/core/tests/test_data.py index baa1aa825..f497d9585 100644 --- a/glue/core/tests/test_data.py +++ b/glue/core/tests/test_data.py @@ -7,6 +7,7 @@ from astropy.utils import NumpyRNGContext from glue import core +from glue.config import settings from ..component import Component, DerivedComponent, CategoricalComponent, DateTimeComponent from ..component_id import ComponentID @@ -1185,3 +1186,20 @@ def test_compute_histogram_random_subset_dask(): result = data.compute_histogram([data.id['x'], data.id['y']], range=[[-0.5, 10.5], [-0.5, 1.5]], bins=[5, 1], weights=data.id['y'], random_subset=100_000) assert_allclose(result[:, 0], [178535., 230694., 229997., 231215., 178135.], atol=20_000) + + +def test_disable_auto_links(): + + settings.AUTO_COMPUTE_COORDS_LINKS = False + + data1 = Data(a=[1, 2, 3], b=[2, 3, 4], label='data1', + coords=IdentityCoordinates(n_dim=1)) + + assert len(data1.links) == 0 + + settings.AUTO_COMPUTE_COORDS_LINKS = True + + data2 = Data(a=[1, 2, 3], b=[2, 3, 4], label='data1', + coords=IdentityCoordinates(n_dim=1)) + + assert len(data2.links) == 2 From 4c4f65171e357863d4b249318dc4857d5c326367 Mon Sep 17 00:00:00 2001 From: Thomas Robitaille Date: Mon, 6 Jan 2025 14:37:32 +0000 Subject: [PATCH 2/2] Fix code style --- glue/config.py | 1 + 1 file changed, 1 insertion(+) diff --git a/glue/config.py b/glue/config.py index d81e6ce0a..3d789e77b 100644 --- a/glue/config.py +++ b/glue/config.py @@ -932,6 +932,7 @@ def _default_search_order(): settings.add('AUTOLINK', {}, validator=dict) settings.add('AUTO_COMPUTE_COORDS_LINKS', True, validator=bool) + def check_unit_converter(value): if value != 'default' and value not in unit_converter.members: raise KeyError(f'Unit converter {value} is not defined')