Added fromFile() method to overcome problem of multiple times opening same file
This commit is contained in:
parent
936f2d5708
commit
311a1274bf
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user