diff --git a/ctapipe/core/tests/test_traits.py b/ctapipe/core/tests/test_traits.py index abf2aaebf71..64d27a6733f 100644 --- a/ctapipe/core/tests/test_traits.py +++ b/ctapipe/core/tests/test_traits.py @@ -298,6 +298,13 @@ def test_telescope_parameter_lookup_by_type(mock_subarray): assert lookup["LST_LST_LSTCam"] == 100 assert lookup["MST_MST_MSTCam"] == 10 + # no global default + lookup = TelescopeParameterLookup([("type", "LST*", 100)]) + lookup.attach_subarray(mock_subarray) + assert lookup["LST_LST_LSTCam"] == 100 + with pytest.raises(KeyError): + assert lookup["MST_MST_MSTCam"] == 10 + def test_telescope_parameter_patterns(mock_subarray): """Test validation of TelescopeParameters""" diff --git a/ctapipe/core/traits.py b/ctapipe/core/traits.py index d9a51739b78..9a9975dfba4 100644 --- a/ctapipe/core/traits.py +++ b/ctapipe/core/traits.py @@ -393,12 +393,10 @@ def __init__(self, telescope_parameter_list): self._value_for_tel_id = None self._value_for_type = None self._subarray = None - self._subarray_global_value = None - self._subarray_global_value_set = False + self._subarray_global_value = Undefined for param in telescope_parameter_list: if param[1] == "*": self._subarray_global_value = param[2] - self._subarray_global_value_set = True def attach_subarray(self, subarray): """ @@ -440,7 +438,7 @@ def __getitem__(self, tel: Optional[Union[int, str]]): Returns the resolved parameter for the given telescope id """ if tel is None: - if self._subarray_global_value_set: + if self._subarray_global_value is not Undefined: return self._subarray_global_value raise KeyError("No subarray global value set for TelescopeParameter") @@ -464,7 +462,7 @@ def __getitem__(self, tel: Optional[Union[int, str]]): if isinstance(tel, str): try: - if self._subarray_global_value_set: + if self._subarray_global_value is not Undefined: return self._value_for_type.get(tel, self._subarray_global_value) return self._value_for_type[tel] except KeyError: