Skip to content

Commit

Permalink
Merge pull request #2384 from cta-observatory/remove_from_config
Browse files Browse the repository at this point in the history
Remove EventSource.from_config, fixes #2258
  • Loading branch information
kosack committed Jul 18, 2023
2 parents 2f8226d + dcb59d9 commit cfacbe1
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 29 deletions.
24 changes: 0 additions & 24 deletions ctapipe/io/eventsource.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 4 additions & 4 deletions ctapipe/io/tests/test_event_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}})
Expand All @@ -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
Expand All @@ -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():
Expand Down
2 changes: 1 addition & 1 deletion ctapipe/tools/display_dl1.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 2 additions & 0 deletions docs/changes/2384.api.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Remove ``EventSource.from_config``, simply use ``EventSource(config=config)`` or
``EventSource(parent=parent)``.

0 comments on commit cfacbe1

Please sign in to comment.