Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace 10**9 by straxen.units.s #1540

Merged
merged 1 commit into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion straxen/analyses/bokeh_waveform_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,7 @@ def _make_event_title(event, run_id, width=1600):
"""
start = event["time"]
date = np.datetime_as_string(start.astype("<M8[ns]"), unit="s")
start_ns = start - (start // 10**9) * 10**9
start_ns = start - (start // straxen.units.s) * straxen.units.s
end = strax.endtime(event)
end_ns = end - start + start_ns
event_number = event["event_number"]
Expand Down
2 changes: 1 addition & 1 deletion straxen/config/protocols.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,5 +315,5 @@ def get_run_start(run_id):
)
start_time = doc["start"]
start_time_unix = start_time.replace(tzinfo=pytz.utc).timestamp()
start_time_unix = np.int64(start_time_unix) * 10**9
start_time_unix = np.int64(start_time_unix) * straxen.units.s
return start_time_unix
4 changes: 2 additions & 2 deletions straxen/holoviews/holoviews_tpc_event_display.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def _pmt_pattern_callback(self, event_index, top_pmt_array=True, pattern_ops=imm
s2_plot = pmt_array.plot_pmt_array(
self._s2,
label="S2",
logz=True, # TODO make me optional?
logz=True, # TODO: make me optional?
**pattern_ops,
)
s2_point = hv.Points(
Expand All @@ -178,7 +178,7 @@ def _pmt_pattern_callback(self, event_index, top_pmt_array=True, pattern_ops=imm
alt_s2_plot = pmt_array.plot_pmt_array(
self._alt_s2,
label="alt. S2",
logz=True, # TODO make me optional?
logz=True, # TODO: make me optional?
**pattern_ops,
)
alt_s2_point = hv.Points(
Expand Down
2 changes: 1 addition & 1 deletion straxen/holoviews_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ def _make_title(self, ind):
"""Function which creates title test in markdown format."""
start = self.df_event_time.loc[ind, "time"]
date = np.datetime_as_string(start.astype("<M8[ns]"), unit="s")
start_ns = start - (start // 10**9) * 10**9
start_ns = start - (start // straxen.units.s) * straxen.units.s
end = self.df_event_time.loc[ind, "endtime"]
end_ns = end - start + start_ns
return "".join(
Expand Down
4 changes: 2 additions & 2 deletions straxen/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,11 +228,11 @@ def get_start_end(self):
start, start_ns = self._convert_to_datetime(self._start_widget, time_zone)
start = start.astimezone(tz=pytz.UTC)
start = start.timestamp()
start = int(start * 10**9) + start_ns
start = int(start * straxen.units.s) + start_ns
end, end_ns = self._convert_to_datetime(self._end_widget, time_zone)
end = end.astimezone(tz=pytz.UTC)
end = end.timestamp()
end = int(end * 10**9) + end_ns
end = int(end * straxen.units.s) + end_ns

if start > end:
warnings.warn("Start time is larger than endtime are you sure you wanted this?")
Expand Down
8 changes: 4 additions & 4 deletions straxen/plugins/gps_syncing/gps_syncing.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class GpsSync(strax.OverlapWindowPlugin):
1. Finds the TTL GPS pulses coming into the AM from the gps
module and their pairs coming from the module for the
correspondent run.
2. Corrects the timestamp of all events by linearly interpolating
2. Corrects the timestamp of all events by linearly interpolating
between the previous and next sync pulses.

"""
Expand Down Expand Up @@ -51,7 +51,7 @@ class GpsSync(strax.OverlapWindowPlugin):
def get_window_size(self):
# Use a large window to ensure that multiple GPS pulses are found
# within the current chunk. Specified window is in nanoseconds.
return int(120 * 10**9)
return int(120 * straxen.units.s)

def setup(self):
# Load GPS-module pulses
Expand Down Expand Up @@ -101,8 +101,8 @@ def match_gps_pulses_with_truth(gps_pulse_time, gps_truth_time, vicinity):

"""
_gps_pulses = np.zeros(len(gps_pulse_time), strax.time_fields)
_gps_pulses["time"] = gps_pulse_time - int(vicinity * 10**9)
_gps_pulses["endtime"] = gps_pulse_time + int(vicinity * 10**9)
_gps_pulses["time"] = gps_pulse_time - int(vicinity * straxen.units.s)
_gps_pulses["endtime"] = gps_pulse_time + int(vicinity * straxen.units.s)

_gps_truth = np.zeros(len(gps_truth_time), strax.time_fields)
_gps_truth["time"] = gps_truth_time
Expand Down
30 changes: 16 additions & 14 deletions straxen/scada.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ def get_scada_values(
df = df.tz_localize(tz="UTC")
df.index.rename("time UTC", inplace=True)

if (end // 10**9) > now.astype(np.int64):
if (end // straxen.units.s) > now.astype(np.int64):
df.loc[now:, :] = np.nan

return df
Expand Down Expand Up @@ -240,20 +240,20 @@ def _get_and_check_start_end(self, run_id, start, end, time_selection_kwargs):
)

now = np.datetime64("now")
if (end // 10**9) > now.astype(np.int64):
if (end // straxen.units.s) > now.astype(np.int64):
mes = (
"You are asking for an endtime which is in the future,"
" I may be written by a physicist, but I am neither self-"
"aware nor can I predict the future like they can. You "
f"asked for the endtime: {end // 10**9} but current utc "
f"asked for the endtime: {end // straxen.units.s} but current utc "
f"time is {now.astype(np.int64)}. I will return for the values for the "
"corresponding times as nans instead."
)
warnings.warn(mes)

# Chop start/end time if precision is higher then seconds level.
start = (start // 10**9) * 10**9
end = (end // 10**9) * 10**9
start = (start // straxen.units.s) * straxen.units.s
end = (end // straxen.units.s) * straxen.units.s

return int(start), int(end), now

Expand Down Expand Up @@ -302,9 +302,11 @@ def _query_single_parameter(
if query_type_lab:
# In the lab case we get interpolated data without nans so the df can be set
# accordingly.
seconds = np.arange(start, end + 1, 10**9 * every_nth_value)
seconds = np.arange(start, end + 1, straxen.units.s * every_nth_value)
else:
seconds = np.arange(start, end + 1, 10**9) # +1 to make sure endtime is included
seconds = np.arange(
start, end + 1, straxen.units.s
) # +1 to make sure endtime is included

df = pd.DataFrame()
df.loc[:, "time"] = seconds
Expand All @@ -319,7 +321,7 @@ def _query_single_parameter(
# This is only needed in case of raw data since here it can
# happen that the user queries a range without any data.
temp_df = self._query(
query, self.SCLastValue_URL, end=(start // 10**9) + 1
query, self.SCLastValue_URL, end=(start // straxen.units.s) + 1
) # +1 since it is end before exclusive

# Store value as first value in our df
Expand All @@ -328,7 +330,7 @@ def _query_single_parameter(
else:
offset = 0

one_year_in_ns = int(24 * 3600 * 360 * 10**9)
one_year_in_ns = int(24 * 3600 * 360 * straxen.units.s)
starts = np.arange(start + offset, end, one_year_in_ns)
if len(starts):
ends = starts + one_year_in_ns
Expand Down Expand Up @@ -401,8 +403,8 @@ def _query_data_per_year(
temp_df = self._query(
query,
self.SCData_URL,
start=(start // 10**9),
end=(end // 10**9),
start=(start // straxen.units.s),
end=(end // straxen.units.s),
query_type_lab=query_type_lab,
seconds_interval=seconds_interval,
raise_error_message=False, # No valid value in query range...
Expand All @@ -411,12 +413,12 @@ def _query_data_per_year(
# In case WebInterface does not return any data, e.g. if query range too small
break

times = (temp_df["timestampseconds"].values * 10**9).astype("<M8[ns]")
times = (temp_df["timestampseconds"].values * straxen.units.s).astype("<M8[ns]")
result_dataframe.loc[times, parameter_name] = temp_df.loc[:, "value"].values
endtime = temp_df["timestampseconds"].values[-1].astype(np.int64) * 10**9
endtime = temp_df["timestampseconds"].values[-1].astype(np.int64) * straxen.units.s
start = endtime # Next query should start at the last time seen.
ntries += 1
if not (len(temp_df) == 35000 and endtime != end // 10**9):
if not (len(temp_df) == 35000 and endtime != end // straxen.units.s):
# Max query are 35000 values, if end is reached the
# length of the dataframe is either smaller or the last
# time value is equivalent to queried range.
Expand Down
3 changes: 1 addition & 2 deletions straxen/scripts/ajax.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@
# this many seconds ago to e.g. allow for saving et cetera
"wait_after_processing": 12 * 3600, # s
# Remove high level plugins if the run is this old
# TODO
# change the value to a different one
# TODO: change the value to a different one
"remove_high_level_data": 365 * 24 * 3600, # s
# Minimum time for restarting ajax to check for new stuff to clean (essentially the
# timeout)
Expand Down
2 changes: 1 addition & 1 deletion straxen/scripts/bootstrax.py
Original file line number Diff line number Diff line change
Expand Up @@ -1333,7 +1333,7 @@ def run_strax(
log.info(f"Starting strax to make {run_id} with input dir {input_dir}")

if targets == strax.to_str_tuple("led_calibration"):
# TODO, still true?
# TODO: still true?
# timeout *= 5
pass

Expand Down
2 changes: 1 addition & 1 deletion straxen/storage/rucio_remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ def _saver(self, dirname, metadata, **kwargs):

@export
class RucioSaver(strax.Saver):
"""TODO Saves data to rucio if you are the production user."""
"""TODO: Saves data to rucio if you are the production user."""

def __init__(self, *args, **kwargs):
raise NotImplementedError
Expand Down
4 changes: 2 additions & 2 deletions tests/plugins/peak_building.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def test_sum_wf(self: PluginTestCase):
np.testing.assert_array_almost_equal(
peaks["area_fraction_top"],
np.sum(peaks["data_top"], axis=1) / np.sum(peaks["data"], axis=1),
# TODO rather high tolerance is needed to pass the test -> possible bug?
# TODO: rather high tolerance is needed to pass the test -> possible bug?
decimal=4,
)

Expand Down Expand Up @@ -56,7 +56,7 @@ def test_saturation_correction(self: PluginTestCase):
records=records["records"], start=np.min(rr["time"]), end=np.max(strax.endtime(rr))
)
assert len(peaklets)
# TODO add more tests to see if results make sense
# TODO: add more tests to see if results make sense


@PluginTestAccumulator.register("test_tight_coincidence")
Expand Down
2 changes: 1 addition & 1 deletion tests/test_scada.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def setUp(self):
self.start = 1609682275000000000
# Add micro-second to check if query does not fail if inquery precsion > SC precision
self.start += 10**6
self.end = self.start + 5 * 10**9
self.end = self.start + 5 * straxen.units.s

def test_wrong_querries(self):
parameters = {"SomeParameter": "XE1T.CTPC.Board06.Chan011.VMon"}
Expand Down
Loading