Skip to content

Commit

Permalink
Merge pull request #217 from icecube/livetime_update
Browse files Browse the repository at this point in the history
Prefer 'livetime' field from GRL for the total livetime calculation.
  • Loading branch information
tomaskontrimas authored Feb 20, 2024
2 parents cad1a64 + b640884 commit 6343341
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions skyllh/i3/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,15 +355,22 @@ def prepare_data( # noqa: C901
# Set the livetime of the dataset from the GRL data when no livetime
# was specified previously.
if data.livetime is None and data.grl is not None:
if 'start' not in data.grl:
raise KeyError(
f'The GRL data for dataset "{self.name}" has no data '
'field named "start"!')
if 'stop' not in data.grl:
raise KeyError(
f'The GRL data for dataset "{self.name}" has no data '
'field named "stop"!')
data.livetime = np.sum(data.grl['stop'] - data.grl['start'])
if 'livetime' in data.grl:
# The `livetime` column accounts for livetime gaps within run,
# therefore it is more precise than `stop` - `start`.
data.livetime = np.sum(data.grl['livetime'])
else:
# If `livetime` field does not exist fall back to
# `stop` - `start` implementation.
if 'start' not in data.grl:
raise KeyError(
f'The GRL data for dataset "{self.name}" has no data '
'field named "start"!')
if 'stop' not in data.grl:
raise KeyError(
f'The GRL data for dataset "{self.name}" has no data '
'field named "stop"!')
data.livetime = np.sum(data.grl['stop'] - data.grl['start'])

# Execute all the data preparation functions for this dataset.
super().prepare_data(
Expand Down

0 comments on commit 6343341

Please sign in to comment.