Bugfixes: store UUID attribute early when recording is done. Some small improvements
This commit is contained in:
parent
2cd4c616b3
commit
0be8dd71d9
@ -235,9 +235,6 @@ class Measurement:
|
||||
# Full filepath
|
||||
self.fn = fn
|
||||
|
||||
# Folder, Base filename + extension
|
||||
self.folder, self.fn_base = os.path.split(fn)
|
||||
|
||||
# Open the h5 file in read-plus mode, to allow for changing the
|
||||
# measurement comment.
|
||||
with h5.File(fn, "r") as f:
|
||||
@ -365,15 +362,23 @@ class Measurement:
|
||||
def rename(self, newname: str):
|
||||
"""
|
||||
Try to rename the measurement file.
|
||||
|
||||
Args:
|
||||
newname: New name, with or without extension
|
||||
"""
|
||||
_ , ext = os.path.splitext(newname)
|
||||
# Add proper extension if new name is given without extension.
|
||||
if ext != DOTMEXT:
|
||||
newname = newname + DOTMEXT
|
||||
|
||||
newname_full = str(pathlib.Path(self.folder) / newname)
|
||||
# Folder, Base filename + extension
|
||||
folder, _ = os.path.split(self.fn)
|
||||
|
||||
newname_full = str(pathlib.Path(folder) / newname)
|
||||
os.rename(self.fn, newname_full)
|
||||
|
||||
self.fn = newname_full
|
||||
|
||||
def genNewUUID(self):
|
||||
"""
|
||||
Create new UUID for measurement and store in file.
|
||||
@ -419,7 +424,8 @@ class Measurement:
|
||||
# Last resort, see if we can find the right measurement in the same folder
|
||||
if m is None:
|
||||
try:
|
||||
m = Measurement.fromFolderWithUUID(required_uuid, self.folder, skip=[self.name])
|
||||
folder, _ = os.path.split(self.fn)
|
||||
m = Measurement.fromFolderWithUUID(required_uuid, folder, skip=[self.name])
|
||||
logging.info('Found reference measurement in folder with correct UUID. Updating name of reference measurement')
|
||||
# Update the measurement file name in the list, such that next time it
|
||||
# can be opened just by its name.
|
||||
@ -497,13 +503,14 @@ class Measurement:
|
||||
|
||||
raise RuntimeError(f'Measurement with UUID {uuid_str} could not be found.')
|
||||
|
||||
def setAttribute(self, attrname, value):
|
||||
def setAttribute(self, attrname: str, value):
|
||||
"""
|
||||
Set an attribute in the measurement file, and keep a local copy in
|
||||
memory for efficient accessing.
|
||||
|
||||
Args:
|
||||
atrname
|
||||
attrname: name of attribute, a string
|
||||
value: the value. Should be anything that can be stored as an attribute in HDF5.
|
||||
"""
|
||||
with self.file("r+") as f:
|
||||
# Update comment attribute in the file
|
||||
@ -535,7 +542,8 @@ class Measurement:
|
||||
@property
|
||||
def name(self):
|
||||
"""Returns filename base without extension."""
|
||||
return os.path.splitext(self.fn_base)[0]
|
||||
_, fn = os.path.split(self.fn)
|
||||
return os.path.splitext(fn)[0]
|
||||
|
||||
@property
|
||||
def channelNames(self):
|
||||
@ -1126,7 +1134,6 @@ class Measurement:
|
||||
if len(qtys) != nchannels:
|
||||
raise RuntimeError("Illegal length of qtys list given")
|
||||
|
||||
|
||||
with h5.File(mfn, "w") as hf:
|
||||
hf.attrs["samplerate"] = samplerate
|
||||
hf.attrs["sensitivity"] = sensitivity
|
||||
|
@ -9,6 +9,7 @@ import numpy as np
|
||||
from .lasp_atomic import Atomic
|
||||
from .lasp_cpp import InDataHandler, StreamMgr
|
||||
from .lasp_version import LASP_VERSION_MAJOR, LASP_VERSION_MINOR
|
||||
import uuid
|
||||
|
||||
|
||||
@dataclasses.dataclass
|
||||
@ -139,6 +140,7 @@ class Recording:
|
||||
f.attrs["blocksize"] = blocksize
|
||||
f.attrs["sensitivity"] = [ch.sensitivity for ch in in_ch]
|
||||
f.attrs["channelNames"] = [ch.name for ch in in_ch]
|
||||
f.attrs["UUID"] = str(uuid.uuid1())
|
||||
|
||||
# Add the start delay here, as firstFrames() is called right after the
|
||||
# constructor is called. time.time() returns a floating point
|
||||
|
Loading…
Reference in New Issue
Block a user