diff --git a/examples/image.h5 b/examples/image.h5 index 62524357a7e50fd63d8be3800f28cba5e14e6887..9de42c8f61ab92826a1231c831241e3fa2846c4b 100644 Binary files a/examples/image.h5 and b/examples/image.h5 differ diff --git a/pyproject.toml b/pyproject.toml index 8e80d5a1cd354e0ad209349a93e470faa5da5d28..c4ca58adbcd04e957a22435b9222e812ef00f9f7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "h5schemas" -version = "0.1.19" +version = "0.1.20" description = "Add your description here" readme = "README.md" authors = [ diff --git a/src/h5schemas/h5_types/image.py b/src/h5schemas/h5_types/image.py index 8a844fc34bb5a0108562f47bc1f57441a73c743c..ccdb79b33d91604ede8d77f14ef52d0166a75b91 100644 --- a/src/h5schemas/h5_types/image.py +++ b/src/h5schemas/h5_types/image.py @@ -11,6 +11,8 @@ 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, diff --git a/src/h5schemas/image/add_image.py b/src/h5schemas/image/add_image.py index 6f52c5cc76fba9b14c2741a835228a1892ef1b44..5abbabf86a0c62982353149ab82313aabb77155b 100644 --- a/src/h5schemas/image/add_image.py +++ b/src/h5schemas/image/add_image.py @@ -20,14 +20,20 @@ def add_image_sample( uuid: str | None = None, timestamp: int | None = None, ): + if isinstance(image, Path): dst = h5_file["image_path"] dst.resize((dst.shape[0] + 1,)) dst[-1,] = str(image) else: dst = h5_file["image_array"] - dst.resize((dst.shape[0] + 1, image.shape[0], image.shape[1])) - dst[-1] = image + + if len(image.shape) == 2: + image = np.expand_dims(image, 0) + + number_of_images = image.shape[0] + dst.resize((dst.shape[0] + number_of_images, image.shape[1], image.shape[2])) + dst[-number_of_images:] = image add_header_sample(h5_file["header"], uuid, timestamp) diff --git a/src/h5schemas/load_utilities/projection_geometry.py b/src/h5schemas/load_utilities/projection_geometry.py index f4598071b51e743970b5c10bbee279441c5e6c8a..7c9aecb83f6c71ec1145980c7ecddfd2ff141c52 100644 --- a/src/h5schemas/load_utilities/projection_geometry.py +++ b/src/h5schemas/load_utilities/projection_geometry.py @@ -34,4 +34,7 @@ if __name__ == '__main__': test_file = File("./examples/projection_geometry.h5", "r") proj_geom = extract_projection_geometry(test_file, slice(2)) + print(proj_geom) + + proj_geom = extract_projection_geometry(test_file, 0) print(proj_geom) \ No newline at end of file diff --git a/src/h5schemas/projection/add_projection.py b/src/h5schemas/projection/add_projection.py index 9bc49fc5b21a70480b402711ea384d6cd3608c0c..b2dd9397e457b5e1afbfba63006a14419e26b2d1 100644 --- a/src/h5schemas/projection/add_projection.py +++ b/src/h5schemas/projection/add_projection.py @@ -38,8 +38,8 @@ def add_projection_sample( 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, + current_ma: float | None = None, + voltage_kv: float | None = None, uuid: str | None = None, timestamp: int | None = None, ): @@ -63,6 +63,13 @@ def add_projection_sample( uuid, timestamp, ) + + if current_ma is None: + current_ma = np.zeros(image.shape[0]) + + if voltage_kv is None: + voltage_kv = np.zeros(image.shape[0]) + add_source_sample(h5_file["/source"], current_ma, voltage_kv)