diff --git a/python_src/lasp/lasp_measurement.py b/python_src/lasp/lasp_measurement.py index f415a02..17010ee 100644 --- a/python_src/lasp/lasp_measurement.py +++ b/python_src/lasp/lasp_measurement.py @@ -970,6 +970,22 @@ class Measurement: wavfile.write(fn, int(self.samplerate), data.astype(newtype)) + @staticmethod + def fromFile(fn): + """ + Try to open measurement from a given file name. First checks + whether the measurement is already open. Otherwise it might + happen that a Measurement object is created twice for the same backing file, which we do not allow. + """ + # See if the base part of the filename is referring to a file that is already open + with h5.File(fn, 'r') as f: + uuid = f.attrs['UUID'] + + if uuid in Measurement.uuid_s.keys(): + return Measurement.uuid_s[uuid] + + return Measurement(fn) + @staticmethod def fromtxt( fn,