Update comments + minor change
All checks were successful
Building, testing and releasing LASP if it has a tag / Build-Test-Ubuntu (push) Successful in -52s
Building, testing and releasing LASP if it has a tag / Release-Ubuntu (push) Has been skipped

This commit is contained in:
Casper Jansen 2024-06-21 14:05:53 +02:00
parent c8a4ded750
commit 9bcc2e4173

View File

@ -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])