Skip to content

Commit

Permalink
Add failing test for tels_with_trigger being a numpy array
Browse files Browse the repository at this point in the history
  • Loading branch information
maxnoe committed Apr 27, 2023
1 parent 4cea6a8 commit dfc0d3a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 15 deletions.
31 changes: 18 additions & 13 deletions ctapipe/instrument/tests/test_trigger.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import numpy as np
import pytest
from numpy.testing import assert_equal

from ctapipe.containers import ArrayEventContainer


def test_software_trigger(subarray_prod5_paranal):
@pytest.mark.parametrize("data_type", (list, np.array))
def test_software_trigger(subarray_prod5_paranal, data_type):
from ctapipe.instrument.trigger import SoftwareTrigger

subarray = subarray_prod5_paranal
Expand All @@ -16,37 +21,37 @@ def test_software_trigger(subarray_prod5_paranal):

# only one telescope, no SWAT
event = ArrayEventContainer()
event.trigger.tels_with_trigger = [5]
event.trigger.tels_with_trigger = data_type([5])
assert trigger(event) == False
assert event.trigger.tels_with_trigger == []
assert_equal(event.trigger.tels_with_trigger, data_type([]))

# 1 LST + 1 MST, 1 LST would not have triggered LST hardware trigger
# and after LST is removed, we only have 1 telescope, so no SWAT either
event = ArrayEventContainer()
event.trigger.tels_with_trigger = [1, 6]
event.trigger.tels_with_trigger = data_type([1, 6])
assert trigger(event) == False
assert event.trigger.tels_with_trigger == []
assert_equal(event.trigger.tels_with_trigger, data_type([]))

# two MSTs and 1 LST, -> remove single LST
event = ArrayEventContainer()
event.trigger.tels_with_trigger = [1, 5, 6]
event.trigger.tels_with_trigger = data_type([1, 5, 6])
assert trigger(event) == True
assert event.trigger.tels_with_trigger == [5, 6]
assert_equal(event.trigger.tels_with_trigger, data_type([5, 6]))

# two MSTs, nothing to change
event = ArrayEventContainer()
event.trigger.tels_with_trigger = [5, 6]
event.trigger.tels_with_trigger = data_type([5, 6])
assert trigger(event) == True
assert event.trigger.tels_with_trigger == [5, 6]
assert_equal(event.trigger.tels_with_trigger, data_type([5, 6]))

# three LSTs, nothing to change
event = ArrayEventContainer()
event.trigger.tels_with_trigger = [1, 2, 3]
event.trigger.tels_with_trigger = data_type([1, 2, 3])
assert trigger(event) == True
assert event.trigger.tels_with_trigger == [1, 2, 3]
assert_equal(event.trigger.tels_with_trigger, data_type([1, 2, 3]))

# thee LSTs, plus MSTs, nothing to change
event = ArrayEventContainer()
event.trigger.tels_with_trigger = [1, 2, 3, 5, 6, 7]
event.trigger.tels_with_trigger = data_type([1, 2, 3, 5, 6, 7])
assert trigger(event) == True
assert event.trigger.tels_with_trigger == [1, 2, 3, 5, 6, 7]
assert_equal(event.trigger.tels_with_trigger, data_type([1, 2, 3, 5, 6, 7]))
4 changes: 2 additions & 2 deletions ctapipe/io/simteleventsource.py
Original file line number Diff line number Diff line change
Expand Up @@ -892,9 +892,9 @@ def _fill_trigger_info(self, array_event):
trigger["triggered_telescopes"],
self.subarray.tel_ids,
assume_unique=True,
)
).tolist()
else:
tels_with_trigger = trigger["triggered_telescopes"]
tels_with_trigger = trigger["triggered_telescopes"].tolist()

central_time = parse_simtel_time(trigger["gps_time"])

Expand Down

0 comments on commit dfc0d3a

Please sign in to comment.