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

added overwrite / inserts

parent 2296fbb5
No related branches found
No related tags found
No related merge requests found
No preview for this file type
No preview for this file type
[project]
name = "h5schemas"
version = "0.1.15"
version = "0.1.16"
description = "Add your description here"
readme = "README.md"
authors = [
......
......@@ -48,10 +48,12 @@ def uuid_time_from_json_header(json_header_obj: header.JsonHeader) -> tuple[str,
if __name__ == "__main__":
test_file = File("./examples/header.h5", "w")
from h5schemas.header.overwrite_header import overwrite_header_at_index
test_file = File("./examples/header.h5", "a")
init_header(test_file)
add_header_sample(test_file, None)
add_header_sample(test_file, None)
add_header_sample(test_file, None)
add_header_sample(test_file, *uuid_time_from_json_header(header.generate_header()))
overwrite_header_at_index(test_file, 0, 'test', 0.0)
\ No newline at end of file
from h5py import File, Group
from h5schemas.header.add_header import check_uuid_time_stamp
def overwrite_header_at_index(
h5_file: File | Group, index: int, uuid: str | None, timestamp: float | None = None
):
uuid, timestamp = check_uuid_time_stamp(uuid, timestamp)
dst = h5_file["uuid"]
dst[index] = uuid
dst = h5_file["timestamp"]
dst[index] = timestamp
\ No newline at end of file
from h5py import File, Group
import numpy as np
from pathlib import Path
from h5schemas.header.overwrite_header import overwrite_header_at_index
def overwrite_image_at_index(h5_file: File | Group,
image: Path | np.ndarray,
index: int,
uuid: str | None = None,
timestamp: int | None = None,
):
if isinstance(image, Path):
dst = h5_file["image_path"]
dst[index] = str(image)
else:
dst = h5_file["image_array"]
dst[index] = image
overwrite_header_at_index(h5_file["header"], index, uuid, timestamp)
\ No newline at end of file
......@@ -101,6 +101,7 @@ def add_projection_geometry_sample(
if __name__ == "__main__":
from h5schemas.projection_geometry.overwrite_projection_geometry import overwrite_projection_geometry_at_index
test_file = File("./examples/projection_geometry.h5", "w")
init_projection_geometry(test_file)
add_projection_geometry_sample(
......@@ -113,3 +114,13 @@ if __name__ == "__main__":
add_projection_geometry_sample(
test_file, [0.0, 1.0, 2.0], [3.0, 4.0, 5.0, 6.0], [7.0, 8.0, 9.0]
)
overwrite_projection_geometry_at_index(
test_file,
0,
[1.0, 1.0, 1.0],
[3.0, 4.0, 5.0, 6.0],
[1.0, 1.0, 1.0],
[10.0, 11.0, 12.0, 13],
uuid='test',
)
\ No newline at end of file
from h5py import File, Group
import numpy as np
from h5schemas.header.overwrite_header import overwrite_header_at_index
def overwrite_projection_geometry_at_index(
h5_file: File | Group,
index: int,
detector_center_position_mm: tuple[float, float, float],
detector_center_orientation_quat: tuple[float, float, float, float],
focal_spot_position_mm: tuple[float, float, float],
focal_spot_orientation_quat: tuple[float, float, float, float] | None = None,
uuid: str | None = None,
timestamp: float | None = None,
):
update_values = list()
def insert_update(values):
dst, value = values
dst[index] = value
update_values.append(
[h5_file["detector_center_position_mm/x"], detector_center_position_mm[0]]
)
update_values.append(
[h5_file["detector_center_position_mm/y"], detector_center_position_mm[1]]
)
update_values.append(
[h5_file["detector_center_position_mm/z"], detector_center_position_mm[2]]
)
update_values.append(
[
h5_file["detector_center_orientation_quat/x"],
detector_center_orientation_quat[0],
]
)
update_values.append(
[
h5_file["detector_center_orientation_quat/y"],
detector_center_orientation_quat[1],
]
)
update_values.append(
[
h5_file["detector_center_orientation_quat/z"],
detector_center_orientation_quat[2],
]
)
update_values.append(
[
h5_file["detector_center_orientation_quat/w"],
detector_center_orientation_quat[3],
]
)
update_values.append(
[h5_file["focal_spot_position_mm/x"], focal_spot_position_mm[0]]
)
update_values.append(
[h5_file["focal_spot_position_mm/y"], focal_spot_position_mm[1]]
)
update_values.append(
[h5_file["focal_spot_position_mm/z"], focal_spot_position_mm[2]]
)
if focal_spot_orientation_quat is None:
focal_spot_orientation_quat = (0.0, 0.0, 0.0, 1.0)
update_values.append(
[h5_file["focal_spot_orientation_quat/x"], focal_spot_orientation_quat[0]]
)
update_values.append(
[h5_file["focal_spot_orientation_quat/y"], focal_spot_orientation_quat[1]]
)
update_values.append(
[h5_file["focal_spot_orientation_quat/z"], focal_spot_orientation_quat[2]]
)
update_values.append(
[h5_file["focal_spot_orientation_quat/w"], focal_spot_orientation_quat[3]]
)
for value in update_values:
insert_update(value)
overwrite_header_at_index(h5_file['header'], index, uuid, timestamp)
\ No newline at end of file
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