nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: cta-observatory/ctapipe
Pull request #1958 (2022-06-27 13:52:17)

fixed bug that prevented printing of QualityQuery
`__str__` returned nothing rather than a string


Patch:
diff --git a/ctapipe/core/qualityquery.py b/ctapipe/core/qualityquery.py
index 3fd23b31..fe3c3458 100644
--- a/ctapipe/core/qualityquery.py
+++ b/ctapipe/core/qualityquery.py
@@ -102,7 +102,7 @@ class QualityQuery(Component):
 
     def __str__(self):
         """Print a formatted string representation of the entire table."""
-        return self.to_table().pprint_all(show_unit=True, show_dtype=True)
+        return str(self.to_table())
 
     def __call__(self, **kwargs) -> np.ndarray:
         """


Test patch:
diff --git a/ctapipe/core/tests/test_qualityquery.py b/ctapipe/core/tests/test_qualityquery.py
index b70f7dc3..85c631c0 100644
--- a/ctapipe/core/tests/test_qualityquery.py
+++ b/ctapipe/core/tests/test_qualityquery.py
@@ -123,3 +123,12 @@ def test_table_mask():
     stats = query.to_table()
     np.testing.assert_equal(stats["counts"], [5, 3, 2])
     np.testing.assert_equal(stats["cumulative_counts"], [5, 3, 1])
+
+
+def test_printing():
+    """Just check the query can be stringified correctly"""
+    query = QualityQuery(
+        quality_criteria=[("check", "x>3")],
+    )
+
+    assert isinstance(str(query), str)
Repository: cta-observatory/ctapipe
Pull request #2002 (2022-07-11 09:34:41)

Use correct traitlet for event type enum in eventtypefilter


Patch:
diff --git a/ctapipe/utils/event_type_filter.py b/ctapipe/utils/event_type_filter.py
index aac751c5..6369608a 100644
--- a/ctapipe/utils/event_type_filter.py
+++ b/ctapipe/utils/event_type_filter.py
@@ -1,28 +1,30 @@
-from ..core import Component
-from ..core.traits import Enum, Set
 from ..containers import EventType
-
+from ..core import Component
+from ..core.traits import Set, UseEnum
 
 __all__ = ["EventTypeFilter"]
 
 
+_values = ", ".join([f"{e.name} or {e.value}" for e in EventType])
+
+
 class EventTypeFilter(Component):
     """Check that an event has one of the allowed types"""
 
     allowed_types = Set(
         # add both the enum instance and the integer values to support
         # giving the integers in config files.
-        trait=Enum(list(EventType) + [t.value for t in EventType]),
+        trait=UseEnum(EventType),
         default_value=None,
         allow_none=True,
-        help="The allowed types. Set to None to allow all types.",
+        help=(
+            "The allowed types. Set to None to allow all types."
+            f"Possible values: {_values}."
+        ),
     ).tag(config=True)
 
     def __init__(self, *args, **kwargs):
         super().__init__(*args, **kwargs)
-        # convert ints to enum type
-        if self.allowed_types is not None:
-            self.allowed_types = {EventType(e) for e in self.allowed_types}
 
     def __call__(self, event):
         """Returns True if the event should be kept"""


Test patch:
diff --git a/ctapipe/utils/tests/test_event_filter.py b/ctapipe/utils/tests/test_event_filter.py
index 5ed56795..6a0fc599 100644
--- a/ctapipe/utils/tests/test_event_filter.py
+++ b/ctapipe/utils/tests/test_event_filter.py
@@ -1,5 +1,6 @@
 from traitlets.config import Config
-from ctapipe.containers import EventType, ArrayEventContainer
+
+from ctapipe.containers import ArrayEventContainer, EventType
 
 
 def test_event_filter():
@@ -18,12 +19,40 @@ def test_event_filter():
     assert not event_filter(e)
 
 
+def test_event_filter_none():
+    from ctapipe.utils import EventTypeFilter
+
+    event_filter = EventTypeFilter(allowed_types=None)
+
+    # all event types should pass
+    e = ArrayEventContainer()
+    for value in EventType:
+        e.trigger.event_type = value
+        assert event_filter(e)
+
+
 def test_event_filter_config():
     from ctapipe.utils import EventTypeFilter
 
-    config = Config({"EventTypeFilter": {"allowed_types": [EventType.SUBARRAY.value]}})
+    config = Config(
+        {
+            "EventTypeFilter": {
+                "allowed_types": [
+                    EventType.SUBARRAY.value,
+                    "FLATFIELD",
+                    1,
+                ]
+            }
+        }
+    )
     event_filter = EventTypeFilter(config=config)
 
+    assert event_filter.allowed_types == {
+        EventType.SUBARRAY,
+        EventType.FLATFIELD,
+        EventType.SINGLE_PE,
+    }
+
     e = ArrayEventContainer()
     e.trigger.event_type = EventType.DARK_PEDESTAL
     assert not event_filter(e)
Repository: cta-observatory/ctapipe
Pull request #2312 (2023-04-20 14:51:20)

Fix activity start order
By not starting the activity before calling initialize,
an extra activity was started only containing the config files
and the config files were not included in the provenance of the actual
tool run.


Patch:
diff --git a/ctapipe/core/tool.py b/ctapipe/core/tool.py
index 56de387a..e39dcaff 100644
--- a/ctapipe/core/tool.py
+++ b/ctapipe/core/tool.py
@@ -405,11 +405,14 @@ class Tool(Application):
 
         with self._exit_stack:
             try:
-                self.initialize(argv)
                 self.log.info(f"Starting: {self.name}")
                 Provenance().start_activity(self.name)
+
+                self.initialize(argv)
+
                 self.setup()
                 self.is_setup = True
+
                 self.log.debug(f"CONFIG: {self.get_current_config()}")
                 Provenance().add_config(self.get_current_config())
 
diff --git a/docs/changes/2312.bugfix.rst b/docs/changes/2312.bugfix.rst
new file mode 100644
index 00000000..cdcf85d1
--- /dev/null
+++ b/docs/changes/2312.bugfix.rst
@@ -0,0 +1,1 @@
+Fix for config files not being included as inputs in provenance log.


Test patch:
diff --git a/ctapipe/core/tests/test_tool.py b/ctapipe/core/tests/test_tool.py
index 8db62479..a65ecf83 100644
--- a/ctapipe/core/tests/test_tool.py
+++ b/ctapipe/core/tests/test_tool.py
@@ -426,3 +426,38 @@ def test_exit_stack():
     assert run_tool(tool, raises=False) == 1
     assert tool.manager.enter_called
     assert tool.manager.exit_called
+
+
+def test_activity(tmp_path):
+    """check that the config is correctly in the provenance"""
+
+    class MyTool(Tool):
+        name = "test_prov_log"
+        description = "test"
+        userparam = Float(5.0, help="parameter").tag(config=True)
+
+    tool = MyTool()
+
+    config_path = tmp_path / "config.json"
+    config_path.write_text(json.dumps({"MyTool": {"userparam": 10.0}}))
+    provenance_path = tmp_path / "provenance.json"
+
+    run_tool(
+        tool,
+        [
+            "--config",
+            str(config_path),
+            f"--provenance-log={provenance_path}",
+        ],
+    )
+
+    activities = json.loads(tool.provenance_log.read_text())
+    # provlog contains all activities from all tests, last one is the tool we just ran
+    provlog = activities[-1]
+    assert provlog["activity_name"] == MyTool.name
+
+    # test config file is in inputs, regression test for #2313
+    inputs = provlog["input"]
+    assert len(inputs) == 1
+    assert inputs[0]["role"] == "Tool Configuration"
+    assert inputs[0]["url"] == str(config_path)
Repository: cta-observatory/ctapipe
Pull request #2354 (2023-06-19 13:32:23)

Fill reference_location into SubarrayDescription.tel_coords
The `GroundFrame` instance of the `SubarrayDescription.tel_coords` instance was missing the `reference_location`, making direct transformation to `EarthLocation` impossible.


Patch:
diff --git a/ctapipe/instrument/subarray.py b/ctapipe/instrument/subarray.py
index 89ed8ddd..e664dacc 100644
--- a/ctapipe/instrument/subarray.py
+++ b/ctapipe/instrument/subarray.py
@@ -154,7 +154,9 @@ class SubarrayDescription:
         pos_y = [p[1].to_value(u.m) for p in self.positions.values()]
         pos_z = [p[2].to_value(u.m) for p in self.positions.values()]
 
-        return SkyCoord(x=pos_x, y=pos_y, z=pos_z, unit=u.m, frame=GroundFrame())
+        frame = GroundFrame(reference_location=self.reference_location)
+
+        return SkyCoord(x=pos_x, y=pos_y, z=pos_z, unit=u.m, frame=frame)
 
     @lazyproperty
     def tel_ids(self):
diff --git a/docs/changes/2354.bugfix.rst b/docs/changes/2354.bugfix.rst
new file mode 100644
index 00000000..f247d205
--- /dev/null
+++ b/docs/changes/2354.bugfix.rst
@@ -0,0 +1,1 @@
+Correctly fill ``reference_location`` for ``SubarrayDescription.tel_coords``.


Test patch:
diff --git a/ctapipe/instrument/tests/test_subarray.py b/ctapipe/instrument/tests/test_subarray.py
index ea908abb..73f3ed6f 100644
--- a/ctapipe/instrument/tests/test_subarray.py
+++ b/ctapipe/instrument/tests/test_subarray.py
@@ -15,6 +15,8 @@ from ctapipe.instrument import (
     TelescopeDescription,
 )
 
+LOCATION = EarthLocation(lon=-17 * u.deg, lat=28 * u.deg, height=2200 * u.m)
+
 
 def create_subarray(tel_type, n_tels=10):
     """generate a simple subarray for testing purposes"""
@@ -31,11 +33,7 @@ def create_subarray(tel_type, n_tels=10):
         "test array",
         tel_positions=pos,
         tel_descriptions=tel,
-        reference_location=EarthLocation(
-            lon=-17 * u.deg,
-            lat=28 * u.deg,
-            height=2200 * u.m,
-        ),
+        reference_location=LOCATION,
     )
 
 
@@ -65,6 +63,8 @@ def test_subarray_description(prod5_mst_nectarcam):
     assert isinstance(sub.tel_coords, SkyCoord)
     assert len(sub.tel_coords) == n_tels
 
+    assert sub.tel_coords.reference_location == LOCATION
+
     subsub = sub.select_subarray([2, 3, 4, 6], name="newsub")
     assert subsub.n_tels == 4
     assert set(subsub.tels.keys()) == {2, 3, 4, 6}