From 9bcc2e417337a93829b6731bb3aa69c04b7d4001 Mon Sep 17 00:00:00 2001 From: Casper Date: Fri, 21 Jun 2024 14:05:53 +0200 Subject: [PATCH] Update comments + minor change --- python_src/lasp/lasp_measurementset.py | 72 ++++++++++++++++++-------- 1 file changed, 49 insertions(+), 23 deletions(-) diff --git a/python_src/lasp/lasp_measurementset.py b/python_src/lasp/lasp_measurementset.py index 6973868..98904c2 100644 --- a/python_src/lasp/lasp_measurementset.py +++ b/python_src/lasp/lasp_measurementset.py @@ -14,17 +14,16 @@ class MeasurementSet(list): """ Group of measurements that have some correspondence to one another. Class is used to operate on multiple measurements at once. - """ def __init__(self, mlist: List[Measurement] = []): """ Initialize a measurement set - Args: + Arg: mlist: Measurement list - """ + if any([not isinstance(i, Measurement) for i in mlist]): raise TypeError("Object in list should be of Measurement type") @@ -33,11 +32,17 @@ class MeasurementSet(list): super().__init__(mlist) def getNewestReferenceMeasurement(self, mtype: MeasurementType): - """Return the newest (in time) measurement in the current list of a certain type. Returns None in case no measurement could be found. - - Args: - mtype (MeasurementType): The type required. """ + Get the NEWEST ref. measurement of a current type, in the current set. + + Arg: + mtype (MeasurementType): The type required. + + Return: + - The newest (in time) measurement in the current list of a certain type. + - None, in case no measurement could be found. + """ + mnewest = None for m in self: if m.measurementType() == mtype: @@ -49,19 +54,26 @@ class MeasurementSet(list): return mnewest def getReferenceMeasurements(self, mtype: MeasurementType): - """Get all available reference measurements of a certain type in the - current set. + """Get ALL ref. measurements of a certain type, in the current set. - Args: + Arg: mtype (MeasurementType): The type of which to list - Returns: - a new measurement set including all measurements of a certain type + Return: + A new measurement set, including all measurements of a certain type """ + return [m for m in self if m.measurementType() == mtype] def getNewestReferenceMeasurements(self): - """Returns a dictionary with newest measurement of each type that is not specific returns None in case no measurement is found.""" + """ + Get the NEWEST ref. measurement of all types, in the current set. + + Return: + - A dictionary with the newest measurement of each type that is not specific + - None, in case no measurement is found. + """ + newest = {} for m in self: mtype = m.measurementType() @@ -75,8 +87,17 @@ class MeasurementSet(list): return newest def newestReferenceOlderThan(self, secs): - """Returns a dictionary of references with the newest reference, that is still - older than `secs` seconds.""" + """ + Get a dictionary of reference measurements which are older than a + specified threshold. Only one of each type is returned. + + Args: + - secs: time threshold, in seconds + + Return: + - a dictionary of references with the newest reference, that is still + older than `secs` seconds + """ curtime = time.time() newest = self.getNewestReferenceMeasurements() newest_older_than = {} @@ -87,25 +108,29 @@ class MeasurementSet(list): def measTimeSame(self): """ - Returns True if all measurements have the same measurement - time (recorded time) - + Returns True if all measurements have the same measurement length and + sample rate """ + if len(self) > 0: - first = self[0].N - return all([first == meas.N for meas in self]) + firstN = self[0].N # samples + firstFS = self[0].samplerate # sample rate + sameN = all([firstN == meas.N for meas in self]) + sameFS = all([firstFS == meas.samplerate for meas in self]) + return sameN and sameFS else: return False def measSimilar(self): """ Similar means: channel metadata is the same, and the measurement time - is the same. It means that the recorded data is, of course, different. + is the same. Returns: - True if measChannelsSame() and measTimeSame() else False - + - True if measChannelsSame() and measTimeSame() + - False otherwise """ + return self.measTimeSame() and self.measChannelsSame() def measChannelsSame(self): @@ -115,6 +140,7 @@ class MeasurementSet(list): a set of measurements, simultaneously. If the channel data is the same (name, sensitivity, ...) it returns True. """ + if len(self) > 0: first = self[0].channelConfig return all([first == meas.channelConfig for meas in self])