Bugfixes: store UUID attribute early when recording is done. Some small improvements
All checks were successful
Building, testing and releasing LASP if it has a tag / Build-Test-Ubuntu (push) Successful in 2m15s
Building, testing and releasing LASP if it has a tag / Release-Ubuntu (push) Successful in -1m38s

This commit is contained in:
Anne de Jong 2023-12-19 14:34:47 +01:00
parent 2cd4c616b3
commit 0be8dd71d9
2 changed files with 22 additions and 13 deletions

View File

@ -126,7 +126,7 @@ def scaleBlockSens(block, sens):
fac = 2 ** (8 * sw - 1) - 1 fac = 2 ** (8 * sw - 1) - 1
else: else:
fac = 1.0 fac = 1.0
return block.astype(LASP_NUMPY_FLOAT_TYPE) / fac / sens[np.newaxis, :] return block.astype(LASP_NUMPY_FLOAT_TYPE) / fac / sens[np.newaxis,:]
class IterRawData: class IterRawData:
@ -199,7 +199,7 @@ class IterRawData:
# print(f'block: {block}, starto: {start_offset}, stopo {stop_offset}') # print(f'block: {block}, starto: {start_offset}, stopo {stop_offset}')
self.i += 1 self.i += 1
return fa[block, start_offset:stop_offset, :][:, self.channels] return fa[block, start_offset:stop_offset,:][:, self.channels]
class IterData(IterRawData): class IterData(IterRawData):
@ -235,9 +235,6 @@ class Measurement:
# Full filepath # Full filepath
self.fn = fn 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 # Open the h5 file in read-plus mode, to allow for changing the
# measurement comment. # measurement comment.
with h5.File(fn, "r") as f: with h5.File(fn, "r") as f:
@ -365,15 +362,23 @@ class Measurement:
def rename(self, newname: str): def rename(self, newname: str):
""" """
Try to rename the measurement file. Try to rename the measurement file.
Args:
newname: New name, with or without extension
""" """
_ , ext = os.path.splitext(newname) _ , ext = os.path.splitext(newname)
# Add proper extension if new name is given without extension. # Add proper extension if new name is given without extension.
if ext != DOTMEXT: if ext != DOTMEXT:
newname = newname + 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) os.rename(self.fn, newname_full)
self.fn = newname_full
def genNewUUID(self): def genNewUUID(self):
""" """
Create new UUID for measurement and store in file. 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 # Last resort, see if we can find the right measurement in the same folder
if m is None: if m is None:
try: 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') 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 # Update the measurement file name in the list, such that next time it
# can be opened just by its name. # 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.') 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 Set an attribute in the measurement file, and keep a local copy in
memory for efficient accessing. memory for efficient accessing.
Args: 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: with self.file("r+") as f:
# Update comment attribute in the file # Update comment attribute in the file
@ -535,7 +542,8 @@ class Measurement:
@property @property
def name(self): def name(self):
"""Returns filename base without extension.""" """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 @property
def channelNames(self): def channelNames(self):
@ -1063,8 +1071,8 @@ class Measurement:
sensitivity, sensitivity,
mfn, mfn,
timestamp=None, timestamp=None,
qtys: List[SIQtys] = None, qtys: List[SIQtys]=None,
channelNames: List[str] = None, channelNames: List[str]=None,
force=False, force=False,
) -> Measurement: ) -> Measurement:
""" """
@ -1126,7 +1134,6 @@ class Measurement:
if len(qtys) != nchannels: if len(qtys) != nchannels:
raise RuntimeError("Illegal length of qtys list given") raise RuntimeError("Illegal length of qtys list given")
with h5.File(mfn, "w") as hf: with h5.File(mfn, "w") as hf:
hf.attrs["samplerate"] = samplerate hf.attrs["samplerate"] = samplerate
hf.attrs["sensitivity"] = sensitivity hf.attrs["sensitivity"] = sensitivity

View File

@ -9,6 +9,7 @@ import numpy as np
from .lasp_atomic import Atomic from .lasp_atomic import Atomic
from .lasp_cpp import InDataHandler, StreamMgr from .lasp_cpp import InDataHandler, StreamMgr
from .lasp_version import LASP_VERSION_MAJOR, LASP_VERSION_MINOR from .lasp_version import LASP_VERSION_MAJOR, LASP_VERSION_MINOR
import uuid
@dataclasses.dataclass @dataclasses.dataclass
@ -139,6 +140,7 @@ class Recording:
f.attrs["blocksize"] = blocksize f.attrs["blocksize"] = blocksize
f.attrs["sensitivity"] = [ch.sensitivity for ch in in_ch] f.attrs["sensitivity"] = [ch.sensitivity for ch in in_ch]
f.attrs["channelNames"] = [ch.name 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 # Add the start delay here, as firstFrames() is called right after the
# constructor is called. time.time() returns a floating point # constructor is called. time.time() returns a floating point