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

add projection load utility

parent d8333008
No related branches found
No related tags found
No related merge requests found
from h5schemas.load_utilities.projection_geometry import extract_projection_geometry, ProjectionGeometry
from h5py import Group
import numpy as np
from typing import NamedTuple, ClassVar, Literal
from dataclasses import dataclass
@dataclass
class GeomOptions:
PROJECTION_GEOMETRY: ClassVar[str] = "projection_geometry"
PROJECTION_GEOMETRY_NOMINAL: ClassVar[str] = "projection_geometry_nominal"
DEFAULT = "projection_geometry"
NOMINAL = "projection_geometry_nominal"
GeomElement = Literal[DEFAULT, NOMINAL]
class Projection(NamedTuple):
projection_geometry: ProjectionGeometry
image_array: np.ndarray
uuid: np.ndarray
timestamp: np.ndarray
def extract_projection(h5_group: Group, indices: slice | int, projection_geometry_group: str = GeomOptions.PROJECTION_GEOMETRY, crop: list[slice] | None = None) -> Projection:
if crop is None:
crop = (slice(0, None, 1), slice(0, None, 1))
if len(crop) != 3 and isinstance(indices, slice):
crop = (slice(0, None), crop[0], crop[1])
projection_geometry = extract_projection_geometry(h5_group[projection_geometry_group], indices)
uuid = h5_group["image"]["header"]["uuid"][indices]
timestamp = h5_group["image"]["header"]["timestamp"][indices]
image = h5_group["image"]["image_array"][indices][crop]
return Projection(
projection_geometry,
image,
uuid,
timestamp,
)
if __name__ == "__main__":
from h5py import File
test_file = File("./examples/projection.h5", "r")
projection = extract_projection(test_file, 1, GeomOptions.PROJECTION_GEOMETRY)
print(projection)
print(projection.image_array.shape)
projection = extract_projection(test_file, slice(0, 2), GeomOptions.PROJECTION_GEOMETRY, crop=(slice(20, 50), slice(50, 100)))
print(projection)
print(projection.image_array.shape)
...@@ -14,7 +14,7 @@ class ProjectionGeometry(NamedTuple): ...@@ -14,7 +14,7 @@ class ProjectionGeometry(NamedTuple):
timestamp: np.ndarray timestamp: np.ndarray
def extract_projection_geometry(h5_group: Group, indices: slice) -> ProjectionGeometry: def extract_projection_geometry(h5_group: Group, indices: slice | int) -> ProjectionGeometry:
detector_center_position_mm = extract_vector( detector_center_position_mm = extract_vector(
h5_group["detector_center_position_mm"], indices, CommonVectors.XYZ h5_group["detector_center_position_mm"], indices, CommonVectors.XYZ
) )
......
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