Skip to content
Snippets Groups Projects
Commit cfc49459 authored by Simon Wittl's avatar Simon Wittl
Browse files

group setter added

parent 68d2c965
No related branches found
No related tags found
No related merge requests found
No preview for this file type
[project]
name = "h5schemas"
version = "0.1.20"
version = "0.1.21"
description = "Add your description here"
readme = "README.md"
authors = [
......
......@@ -9,12 +9,24 @@ class BaseDataset:
maximum: int | float | None = None
dtype: str | np.float64 | np.float32 | np.uint16 | None = None
_group: str | None = None
def __init__(self, definition: GroupDefinition):
self.path = definition.path
self.dataset_name = definition.path.rsplit("/")[-1]
self.group = definition.path[1 : -len(self.dataset_name)]
self.description = definition.description
@property
def group(self) -> str | None:
return self._group
@group.setter
def group(self, group_value: str | None):
if len(group_value) == 0:
group_value = '/'
self._group = group_value
@classmethod
def with_file(cls, definition: GroupDefinition, h5_file: h5py.File):
instance = cls(definition)
......
......@@ -11,8 +11,6 @@ class ImageDataset(BaseDataset):
super().__init__(definition)
def add_to_file(self, h5_file: h5py.File):
if len(self.group) == 0:
self.group = '/'
group = h5_file.require_group(self.group)
self.dataset = group.create_dataset(
name=self.dataset_name,
......
......@@ -3,6 +3,7 @@ from thd_json import header
from h5schemas.scan_schema import open_schema
from h5schemas.initialize_dataset import initialize_dataset
from datetime import datetime
import numpy as np
def init_header(
......@@ -28,17 +29,22 @@ def check_uuid_time_stamp(uuid: str | None = None, timestamp: int | None = None)
def add_header_sample(
h5_file: File | Group, uuid: str | None, timestamp: float | None = None
h5_file: File | Group, uuid: str | np.ndarray | None, timestamp: float | np.ndarray | None = None
):
uuid, timestamp = check_uuid_time_stamp(uuid, timestamp)
if isinstance(uuid, np.ndarray):
uuid_shape = uuid.shape[0]
else:
uuid_shape = 1
dst = h5_file["uuid"]
dst.resize((dst.shape[0] + 1,))
dst[-1,] = uuid
dst.resize((dst.shape[0] + uuid_shape,))
dst[-uuid_shape,] = uuid
dst = h5_file["timestamp"]
dst.resize((dst.shape[0] + 1,))
dst[-1,] = timestamp
dst.resize((dst.shape[0] + uuid_shape,))
dst[-uuid_shape,] = timestamp
def uuid_time_from_json_header(json_header_obj: header.JsonHeader) -> tuple[str, float]:
......@@ -49,7 +55,7 @@ def uuid_time_from_json_header(json_header_obj: header.JsonHeader) -> tuple[str,
if __name__ == "__main__":
from h5schemas.header.overwrite_header import overwrite_header_at_index
test_file = File("./examples/header.h5", "a")
test_file = File("./examples/header.h5", "w")
init_header(test_file)
add_header_sample(test_file, None)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment