diff --git a/examples/projection.h5 b/examples/projection.h5 index 442d5ed9173aa20d98a231ac535cc936d4cb9ff7..2108942efaabed2f349b99d5756098b5395640e6 100644 Binary files a/examples/projection.h5 and b/examples/projection.h5 differ diff --git a/pyproject.toml b/pyproject.toml index 75d5612df15f3f36efbef06d73f9077675cde8c1..17de555a7d427c7503656f0e8117e3a5ebfb9097 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "h5schemas" -version = "0.1.16" +version = "0.1.17" description = "Add your description here" readme = "README.md" authors = [ diff --git a/src/h5schemas/image/overwrite_image.py b/src/h5schemas/image/overwrite_image.py index e9238c0f77a3c8bd91bbac0885c71e7f15418e12..76d06852f74aca5f2a8c3729f561094b5ac3f21d 100644 --- a/src/h5schemas/image/overwrite_image.py +++ b/src/h5schemas/image/overwrite_image.py @@ -5,8 +5,8 @@ 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, + image: Path | np.ndarray, uuid: str | None = None, timestamp: int | None = None, ): @@ -15,6 +15,6 @@ def overwrite_image_at_index(h5_file: File | Group, dst[index] = str(image) else: dst = h5_file["image_array"] - dst[index] = image + dst[index, :, :] = image overwrite_header_at_index(h5_file["header"], index, uuid, timestamp) \ No newline at end of file diff --git a/src/h5schemas/projection/add_projection.py b/src/h5schemas/projection/add_projection.py index 1afd74cf93d7d90f36323fbe9e94ae4d131e7c0d..9bc49fc5b21a70480b402711ea384d6cd3608c0c 100644 --- a/src/h5schemas/projection/add_projection.py +++ b/src/h5schemas/projection/add_projection.py @@ -67,6 +67,8 @@ def add_projection_sample( if __name__ == "__main__": + from h5schemas.projection.overwrite_projection import overwrite_projection_at_index + test_file = File("./examples/projection.h5", "w") init_projection_dataset(test_file, False, (128, 128), (0.139, 0.139)) @@ -88,3 +90,15 @@ if __name__ == "__main__": voltage_kv=100, ) print(test_file["/image/image_array"][...]) + + overwrite_projection_at_index( + test_file, + 0, + 1e5 * np.random.random((128, 128)), + [0.0, 1.0, 2.0], + [3.0, 4.0, 5.0, 6.0], + [7.0, 8.0, 9.0], + [10.0, 11.0, 12.0, 13], + current_ma=69., + voltage_kv=420. + ) diff --git a/src/h5schemas/projection/overwrite_projection.py b/src/h5schemas/projection/overwrite_projection.py new file mode 100644 index 0000000000000000000000000000000000000000..ab344989c6c6867dcaf8d57f64d73a4bac01f8bc --- /dev/null +++ b/src/h5schemas/projection/overwrite_projection.py @@ -0,0 +1,49 @@ +from h5py import File, Group +from pathlib import Path +import numpy as np + +from h5schemas.header.add_header import check_uuid_time_stamp +from h5schemas.image.overwrite_image import overwrite_image_at_index +from h5schemas.projection_geometry.overwrite_projection_geometry import overwrite_projection_geometry_at_index +from h5schemas.source.overwrite_source import overwrite_source_at_index + + + +def overwrite_projection_at_index( + h5_file: File, + index: int, + image: Path | np.ndarray, + 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, + current_ma: float = 0, + voltage_kv: float = 0, + uuid: str | None = None, + timestamp: int | None = None, +): + uuid, timestamp = check_uuid_time_stamp(uuid, timestamp) + overwrite_image_at_index(h5_file["/image"], index, image, uuid, timestamp) + + overwrite_projection_geometry_at_index( + h5_file["/projection_geometry"], + index, + detector_center_position_mm, + detector_center_orientation_quat, + focal_spot_position_mm, + focal_spot_orientation_quat, + uuid, + timestamp, + ) + overwrite_projection_geometry_at_index( + h5_file["/projection_geometry_nominal"], + index, + detector_center_position_mm, + detector_center_orientation_quat, + focal_spot_position_mm, + focal_spot_orientation_quat, + uuid, + timestamp, + ) + + overwrite_source_at_index(h5_file["/source"], index, current_ma, voltage_kv) diff --git a/src/h5schemas/source/overwrite_source.py b/src/h5schemas/source/overwrite_source.py new file mode 100644 index 0000000000000000000000000000000000000000..1ee2a419092145c52bab0dbca0f239c80653ee39 --- /dev/null +++ b/src/h5schemas/source/overwrite_source.py @@ -0,0 +1,11 @@ +from h5py import File, Group + + +def overwrite_source_at_index( + h5_file: File | Group, index: int, current_ma: float, voltage_kv: float): + dst = h5_file["current_ma"] + dst[index] = current_ma + + dst = h5_file["voltage_kv"] + dst[index] = voltage_kv +