diff --git a/straxen/analyses/bokeh_waveform_plot.py b/straxen/analyses/bokeh_waveform_plot.py index 33b984234..6eff2147c 100644 --- a/straxen/analyses/bokeh_waveform_plot.py +++ b/straxen/analyses/bokeh_waveform_plot.py @@ -727,7 +727,7 @@ def _make_event_title(event, run_id, width=1600): """ start = event["time"] date = np.datetime_as_string(start.astype(" end: warnings.warn("Start time is larger than endtime are you sure you wanted this?") diff --git a/straxen/plugins/gps_syncing/gps_syncing.py b/straxen/plugins/gps_syncing/gps_syncing.py index 0d937cf5e..d8133ddaa 100644 --- a/straxen/plugins/gps_syncing/gps_syncing.py +++ b/straxen/plugins/gps_syncing/gps_syncing.py @@ -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. """ @@ -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 @@ -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 diff --git a/straxen/scada.py b/straxen/scada.py index aa98c869c..18fd3580d 100644 --- a/straxen/scada.py +++ b/straxen/scada.py @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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... @@ -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(" possible bug? + # TODO: rather high tolerance is needed to pass the test -> possible bug? decimal=4, ) @@ -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") diff --git a/tests/test_scada.py b/tests/test_scada.py index 189f1fcac..54fa2a149 100644 --- a/tests/test_scada.py +++ b/tests/test_scada.py @@ -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"}