From dcb59d96db03b14ccb4f230ff3ca9f8ebbfe467a Mon Sep 17 00:00:00 2001 From: Maximilian Linhoff Date: Mon, 17 Jul 2023 14:09:38 +0200 Subject: [PATCH] Remove EventSource.from_config, fixes #2258 --- ctapipe/io/eventsource.py | 24 ------------------------ ctapipe/io/tests/test_event_source.py | 8 ++++---- ctapipe/tools/display_dl1.py | 2 +- docs/changes/2384.api.rst | 2 ++ 4 files changed, 7 insertions(+), 29 deletions(-) create mode 100644 docs/changes/2384.api.rst diff --git a/ctapipe/io/eventsource.py b/ctapipe/io/eventsource.py index 40de7dd7891..8fa293c8bb0 100644 --- a/ctapipe/io/eventsource.py +++ b/ctapipe/io/eventsource.py @@ -417,30 +417,6 @@ def _find_input_url_in_config(cls, config=None, parent=None): return input_url - @classmethod - def from_config(cls, config=None, parent=None, **kwargs): - """ - Find compatible EventSource for the EventSource.input_url traitlet - specified via the config. - - This method is typically used in Tools, where the input_url is chosen via - the command line using the traitlet configuration system. - - Parameters - ---------- - config : traitlets.config.loader.Config - Configuration created in the Tool - kwargs - Named arguments for the EventSource - - Returns - ------- - instance - Instance of a compatible EventSource subclass - """ - input_url = cls._find_input_url_in_config(config=config, parent=parent) - return cls.from_url(input_url, config=config, parent=parent, **kwargs) - def close(self): """Close this event source. diff --git a/ctapipe/io/tests/test_event_source.py b/ctapipe/io/tests/test_event_source.py index 639d3547181..71074ddcb01 100644 --- a/ctapipe/io/tests/test_event_source.py +++ b/ctapipe/io/tests/test_event_source.py @@ -102,14 +102,14 @@ def test_from_config(tmp_path): assert reader.input_url == dataset -def test_from_config_parent(): +def test_parent(): dataset = get_dataset_path(prod5_path) class Parent(Component): def __init__(self, config=None, parent=None): super().__init__(config=config, parent=parent) - self.source = EventSource.from_config(parent=self) + self.source = EventSource(parent=self) # test with EventSource in root of config config = Config({"EventSource": {"input_url": dataset}}) @@ -132,7 +132,7 @@ def test_from_config_default(): dataset = get_dataset_path(prod5_path) EventSource.input_url.default_value = dataset config = Config() - reader = EventSource(config=config, parent=None) + reader = EventSource(config=config) assert isinstance(reader, SimTelEventSource) assert reader.input_url == dataset EventSource.input_url.default_value = old_default @@ -143,7 +143,7 @@ def test_from_config_invalid_type(): EventSource.input_url.default_value = dataset config = Config({"EventSource": {"input_url": 124}}) with pytest.raises(TraitError): - EventSource(config=config, parent=None) + EventSource(config=config) def test_event_source_input_url_config_override(): diff --git a/ctapipe/tools/display_dl1.py b/ctapipe/tools/display_dl1.py index af6bde705f7..7a27305b60b 100644 --- a/ctapipe/tools/display_dl1.py +++ b/ctapipe/tools/display_dl1.py @@ -173,7 +173,7 @@ def __init__(self, **kwargs): self.plotter = None def setup(self): - self.eventsource = self.enter_context(EventSource.from_config(parent=self)) + self.eventsource = self.enter_context(EventSource(parent=self)) self.quality_query = QualityQuery(parent=self) compatible_datalevels = [DataLevel.R1, DataLevel.DL0, DataLevel.DL1_IMAGES] diff --git a/docs/changes/2384.api.rst b/docs/changes/2384.api.rst new file mode 100644 index 00000000000..32647abe5eb --- /dev/null +++ b/docs/changes/2384.api.rst @@ -0,0 +1,2 @@ +Remove ``EventSource.from_config``, simply use ``EventSource(config=config)`` or +``EventSource(parent=parent)``.