Skip to content

Commit

Permalink
More flexible run start time estimation
Browse files Browse the repository at this point in the history
  • Loading branch information
JelleAalbers committed Apr 29, 2020
1 parent a11ef74 commit 905335d
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions strax/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,7 @@ def concat_loader(*args, **kwargs):
savers=dict(savers),
targets=targets)

def estimate_run_start(self, run_id, targets):
def estimate_run_start(self, run_id, targets=None):
"""Return run start time in ns since epoch.
This fetches from run metadata, and if this fails, it
Expand All @@ -663,18 +663,21 @@ def estimate_run_start(self, run_id, targets):
return int(t0.timestamp()) * int(1e9)
except (strax.RunMetadataNotAvailable, KeyError):
pass
# We only get here if there was an exception
if not targets:
warnings.warn(
"Could not estimate run start time from "
"run metadata: assuming it is 0",
UserWarning)
return 0
# Get an approx start from the data itself,
# then floor it to seconds for consistency
t = strax.to_str_tuple(targets)[0]
t0 = self.get_meta(run_id, t)['chunks'][0]['start']
return (int(t0) // int(1e9)) * int(1e9)
if targets:
for t in strax.to_str_tuple(targets):
try:
t0 = self.get_meta(run_id, t)['chunks'][0]['start']
return (int(t0) // int(1e9)) * int(1e9)
except strax.DataNotAvailable:
pass
warnings.warn(
"Could not estimate run start time from "
"run metadata: assuming it is 0",
UserWarning)
return 0


def to_absolute_time_range(self, run_id, targets, time_range=None,
seconds_range=None, time_within=None):
Expand Down

0 comments on commit 905335d

Please sign in to comment.