Compare commits

...

2 Commits

Author SHA1 Message Date
Anne de Jong 46d1eda94d Merged in develop
Building, testing and releasing LASP if it has a tag / Build-Test-Ubuntu (push) Successful in 1m51s Details
Building, testing and releasing LASP if it has a tag / Release-Ubuntu (push) Has been skipped Details
2024-03-19 13:40:39 +01:00
Anne de Jong 3005f17400 Added extra getReferemenceMeasurements() method to MeasurementSet. Bumped therefore to v1.6.0 2024-03-19 13:39:17 +01:00
2 changed files with 19 additions and 7 deletions

View File

@ -5,7 +5,7 @@ requires-python = ">=3.10"
description = "Library for Acoustic Signal Processing" description = "Library for Acoustic Signal Processing"
license = { "file" = "LICENSE" } license = { "file" = "LICENSE" }
authors = [{ "name" = "J.A. de Jong", "email" = "j.a.dejong@ascee.nl" }] authors = [{ "name" = "J.A. de Jong", "email" = "j.a.dejong@ascee.nl" }]
version = "1.5.1" version = "1.6.0"
keywords = ["DSP", "DAQ", "Signal processing"] keywords = ["DSP", "DAQ", "Signal processing"]

View File

@ -3,7 +3,8 @@ Provides class MeasurementSet, a class used to perform checks and adjustments
on a group of measurements at the same time. on a group of measurements at the same time.
""" """
__all__ = ['MeasurementSet']
__all__ = ["MeasurementSet"]
from .lasp_measurement import Measurement, MeasurementType from .lasp_measurement import Measurement, MeasurementType
from typing import List from typing import List
import time import time
@ -16,7 +17,7 @@ class MeasurementSet(list):
""" """
def __init__(self, mlist: List[Measurement]=[]): def __init__(self, mlist: List[Measurement] = []):
""" """
Initialize a measurement set Initialize a measurement set
@ -25,7 +26,7 @@ class MeasurementSet(list):
""" """
if any([not isinstance(i, Measurement) for i in mlist]): if any([not isinstance(i, Measurement) for i in mlist]):
raise TypeError('Object in list should be of Measurement type') raise TypeError("Object in list should be of Measurement type")
# Sort by time stamp, otherwise the order is random # Sort by time stamp, otherwise the order is random
mlist.sort(key=lambda x: x.time, reverse=True) mlist.sort(key=lambda x: x.time, reverse=True)
@ -47,6 +48,18 @@ class MeasurementSet(list):
mnewest = m mnewest = m
return mnewest return mnewest
def getReferenceMeasurements(self, mtype: MeasurementType):
"""Get all available reference measurements of a certain type in the
current set.
Args:
mtype (MeasurementType): The type of which to list
Returns:
a new measurement set including all measurements of a certain type
"""
return [m for m in self if m.measurementType() == mtype]
def getNewestReferenceMeasurements(self): def getNewestReferenceMeasurements(self):
"""Returns a dictionary with newest measurement of each type that is not specific returns None in case no measurement is found.""" """Returns a dictionary with newest measurement of each type that is not specific returns None in case no measurement is found."""
newest = {} newest = {}
@ -63,16 +76,15 @@ class MeasurementSet(list):
def newestReferenceOlderThan(self, secs): def newestReferenceOlderThan(self, secs):
"""Returns a dictionary of references with the newest reference, that is still """Returns a dictionary of references with the newest reference, that is still
older than `secs` seconds. """ older than `secs` seconds."""
curtime = time.time() curtime = time.time()
newest = self.getNewestReferenceMeasurements() newest = self.getNewestReferenceMeasurements()
newest_older_than = {} newest_older_than = {}
for key, m in newest.items(): for key, m in newest.items():
if curtime - m.time >= secs: if curtime - m.time >= secs:
newest_older_than[key] = m newest_older_than[key] = m
return newest_older_than return newest_older_than
def measTimeSame(self): def measTimeSame(self):
""" """
Returns True if all measurements have the same measurement Returns True if all measurements have the same measurement