From f1348ede80842717e235c85f2efba77ff74663db Mon Sep 17 00:00:00 2001 From: "J.A. de Jong - Redu-Sone B.V., ASCEE V.O.F" Date: Mon, 3 Apr 2023 13:16:39 +0200 Subject: [PATCH] Cached time string of measurement time stamp --- src/lasp/lasp_measurement.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/lasp/lasp_measurement.py b/src/lasp/lasp_measurement.py index 8d2a012..924d466 100644 --- a/src/lasp/lasp_measurement.py +++ b/src/lasp/lasp_measurement.py @@ -52,6 +52,7 @@ import os, time, wave, logging from .lasp_common import SIQtys, Qty, getFreq from .lasp_cpp import Window, DaqChannel, LASP_VERSION_MAJOR, AvPowerSpectra from typing import List +from functools import lru_cache def getSampWidth(dtype): @@ -248,6 +249,9 @@ class Measurement: except KeyError: self._sens = np.ones(self.nchannels) + # The time is cached AND ALWAYS ASSUMED TO BE AN IMMUTABLE OBJECT. + # It is also cached. Changing the measurement timestamp should not + # be done. self._time = f.attrs['time'] # Quantity stored as channel. @@ -375,6 +379,7 @@ class Measurement: self._comment = cmt @property + @lru_cache() def recTime(self): """Returns the total recording time of the measurement, in float seconds.""" @@ -385,6 +390,19 @@ class Measurement: """Returns the measurement time in seconds since the epoch.""" return self._time + @property + @lru_cache() + def timestr(self): + """ + Return a properly formatted string of the measurement time, in order of + + year-month-day hour etc. + + """ + time_struct = time.localtime(self.time) + time_string = time.strftime('%Y-%m-%d %H:%M:%S', time_struct) + return time_string + def rms(self, channels=None, substract_average=False): """Returns the root mean square values for each channel