diff --git a/gwcs/selector.py b/gwcs/selector.py index 12ac7914..8b4d88b4 100644 --- a/gwcs/selector.py +++ b/gwcs/selector.py @@ -531,7 +531,20 @@ def __init__(self, inputs, outputs, selector, label_mapper, undefined_transform_ raise ValueError('"0" and " " are not allowed as keys.') self._input_units_strict = {key: False for key in self._inputs} self._input_units_allow_dimensionless = {key: False for key in self._inputs} - super(RegionsSelector, self).__init__(n_models=1, name=name, **kwargs) + super().__init__(n_models=1, name=name, **kwargs) + # Validate uses_quantity at init time for nicer error message + self.uses_quantity # noqa + + @property + def uses_quantity(self): + all_uses_quantity = [t.uses_quantity for t in self._selector.values()] + not_all_uses_quantity = [not uq for uq in all_uses_quantity] + if all(all_uses_quantity): + return True + elif not_all_uses_quantity: + return False + else: + raise ValueError("You can not mix models which use quantity and do not use quantity inside a RegionSelector") def set_input(self, rid): """ diff --git a/gwcs/tests/test_region.py b/gwcs/tests/test_region.py index 5fe69f90..6304b786 100644 --- a/gwcs/tests/test_region.py +++ b/gwcs/tests/test_region.py @@ -8,8 +8,9 @@ from numpy.testing import assert_equal, assert_allclose from astropy.modeling import models import pytest -from .. import region, selector -from .. import utils as gwutils +from gwcs import region, selector, WCS +from gwcs import utils as gwutils +from gwcs import coordinate_frames as cf def test_LabelMapperArray_from_vertices_int(): @@ -237,6 +238,10 @@ def test_RegionsSelector(): reg_selector.undefined_transform_value = -100 assert_equal(reg_selector(0, 0), [-100, -100]) + wcs = WCS(forward_transform=reg_selector, output_frame=cf.Frame2D()) + out = wcs(1, 1) + assert out == (-100, -100) + def test_overalpping_ranges(): """