From 33439354f8a7dd3a25784c1c579d296f5fafe9a5 Mon Sep 17 00:00:00 2001 From: Casper Date: Thu, 14 Mar 2024 11:31:07 +0100 Subject: [PATCH] Sort MeasurementSet by time stamp --- python_src/lasp/lasp_measurementset.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/python_src/lasp/lasp_measurementset.py b/python_src/lasp/lasp_measurementset.py index 51b84f4..c4a6769 100644 --- a/python_src/lasp/lasp_measurementset.py +++ b/python_src/lasp/lasp_measurementset.py @@ -27,6 +27,8 @@ class MeasurementSet(list): if any([not isinstance(i, Measurement) for i in mlist]): raise TypeError('Object in list should be of Measurement type') + # Sort by time stamp, otherwise the order is random + mlist.sort(key=lambda x: x.time, reverse=True) super().__init__(mlist) def getNewestReferenceMeasurement(self, mtype: MeasurementType): @@ -44,7 +46,7 @@ class MeasurementSet(list): if mnewest.time < m.time: mnewest = m return mnewest - + def getNewestReferenceMeasurements(self): """Returns a dictionary with newest measurement of each type that is not specific returns None in case no measurement is found.""" newest = {} @@ -106,4 +108,3 @@ class MeasurementSet(list): return all([first == meas.channelConfig for meas in self]) else: return False -