Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions docs/api-reference/io/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,9 @@ into one big table, joining the simulation information if available:

from ctapipe.io import TableLoader

loader = TableLoader("events.dl1.h5")
events = loader.read_subarray_events()
tel_events = loader.read_telescope_events()
with TableLoader("events.dl1.h5") as loader:
events = loader.read_subarray_events()
tel_events = loader.read_telescope_events()

print(loader.subarray, len(events), len(tel_events))

Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ filterwarnings = [
"error::ctapipe.utils.deprecation.CTAPipeDeprecationWarning",
"error::ctapipe.instrument.FromNameWarning",
"error::ctapipe.core.traits.NoneDefaultNotAllowedWarning",
"error::tables.UnclosedFileWarning",
"ignore:`np.MachAr` is deprecated:DeprecationWarning",
"ignore::ctapipe.core.provenance.MissingReferenceMetadata",
]
Expand Down
7 changes: 7 additions & 0 deletions src/ctapipe/core/tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,13 @@ def _repr_html_(self):

return "\n".join(lines)

def __enter__(self):
self._exit_stack.__enter__()
return self

def __exit__(self, exc_value, exc_type, traceback):
return self._exit_stack.__exit__(exc_value, exc_type, traceback)


def export_tool_config_to_commented_yaml(tool_instance: Tool, classes=None):
"""
Expand Down
9 changes: 7 additions & 2 deletions src/ctapipe/tools/tests/test_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ def test_read_yaml_toml_json_config(dl1_image_file, config_files):

tool.config.EventSource.input_url = dl1_image_file
tool.config.DataWriter.overwrite = True
tool.setup()

with tool:
tool.setup()

assert (
tool.get_current_config()["ProcessorTool"]["DataWriter"]["contact_info"].name
== "YOUR-NAME-HERE"
Expand All @@ -69,7 +72,9 @@ def test_multiple_configs(dl1_image_file):

tool.config.EventSource.input_url = dl1_image_file
tool.config.DataWriter.overwrite = True
tool.setup()

with tool:
tool.setup()

# ensure the overwriting works (base config has this option disabled)
assert tool.get_current_config()["ProcessorTool"]["DataWriter"]["write_dl2"] is True
Expand Down