Skip to content
Draft
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
39 changes: 38 additions & 1 deletion src/extra/components/pulses.py
Original file line number Diff line number Diff line change
Expand Up @@ -1258,6 +1258,10 @@
extrapolated from past trains if missing, true by default.
An exception is raised if disabled and the PPL anchoring
method is missing the minimum number of required FEL pulses.
fel_shutter (KeyData, optional): Scalar key evaluated as a
shutter state blocking FEL pulses in a given train.
ppl_shutter (KeyData, optional): Scalar key evaluated as a
shutter state blocking PPL pulses in a given train.
"""

# This class inherits from two classes which both have the same
Expand All @@ -1277,7 +1281,8 @@

def __init__(self, data, source=None, instrument=None, *,
bunch_table_position=None, bunch_table_offset=None,
pulse_offset=None, extrapolate=True):
pulse_offset=None, extrapolate=True,
fel_shutter=None, ppl_shutter=None):
self._bunch_table_position = None
self._bunch_table_offset = None
self._pulse_offset = None # Allowed to be float!
Expand Down Expand Up @@ -1325,6 +1330,20 @@

self._sase = sase

if isinstance(fel_shutter, KeyData):
self._fel_shutter = fel_shutter

Check warning on line 1334 in src/extra/components/pulses.py

View check run for this annotation

Codecov / codecov/patch

src/extra/components/pulses.py#L1334

Added line #L1334 was not covered by tests
elif fel_shutter is not None:
raise TypeError('expected KeyData object for fel_shutter')

Check warning on line 1336 in src/extra/components/pulses.py

View check run for this annotation

Codecov / codecov/patch

src/extra/components/pulses.py#L1336

Added line #L1336 was not covered by tests
else:
self._fel_shutter = None

if isinstance(ppl_shutter, KeyData):
self._ppl_shutter = ppl_shutter

Check warning on line 1341 in src/extra/components/pulses.py

View check run for this annotation

Codecov / codecov/patch

src/extra/components/pulses.py#L1341

Added line #L1341 was not covered by tests
elif ppl_shutter is not None:
raise TypeError('expected KeyData object for ppl_shutter')

Check warning on line 1343 in src/extra/components/pulses.py

View check run for this annotation

Codecov / codecov/patch

src/extra/components/pulses.py#L1343

Added line #L1343 was not covered by tests
else:
self._ppl_shutter = None

def __repr__(self):
if self._bunch_table_position is not None:
offset_str = f'@{self._bunch_table_position}b'
Expand Down Expand Up @@ -1385,6 +1404,18 @@
train_ids = self._key.train_id_coordinates()
prev_fel_pids = None

if self._fel_shutter is not None:
is_closed = self._fel_shutter.xarray().astype(bool)
trains_without_fel = set(is_closed.trainId[is_closed].data)

Check warning on line 1409 in src/extra/components/pulses.py

View check run for this annotation

Codecov / codecov/patch

src/extra/components/pulses.py#L1408-L1409

Added lines #L1408 - L1409 were not covered by tests
else:
trains_without_fel = set()

if self._ppl_shutter is not None:
is_closed = self._ppl_shutter.xarray().astype(bool)
trains_without_ppl = set(is_closed.trainId[is_closed].data)

Check warning on line 1415 in src/extra/components/pulses.py

View check run for this annotation

Codecov / codecov/patch

src/extra/components/pulses.py#L1414-L1415

Added lines #L1414 - L1415 were not covered by tests
else:
trains_without_ppl = set()

for train_id, (fel_pids, ppl_pids) in zip(train_ids, iter_pulse_ids):
try:
ppl_pids += self._get_ppl_offset(fel_pids)
Expand Down Expand Up @@ -1413,6 +1444,12 @@
else:
prev_fel_pids = fel_pids

if train_id in trains_without_fel:
fel_pids = np.zeros(0)

Check warning on line 1448 in src/extra/components/pulses.py

View check run for this annotation

Codecov / codecov/patch

src/extra/components/pulses.py#L1448

Added line #L1448 was not covered by tests

if train_id in trains_without_ppl:
ppl_pids = np.zeros(0)

Check warning on line 1451 in src/extra/components/pulses.py

View check run for this annotation

Codecov / codecov/patch

src/extra/components/pulses.py#L1451

Added line #L1451 was not covered by tests

pids = np.union1d(fel_pids, ppl_pids)

pids_by_train.append(pids)
Expand Down