diff --git a/src/artist_pythonlib/api.py b/src/artist_pythonlib/api.py index 5ed2e43bb4de23ac43f44fcf0124bcf454095db3..f28c0ccd6631ea0833602f400b2141f0c822017a 100644 --- a/src/artist_pythonlib/api.py +++ b/src/artist_pythonlib/api.py @@ -23,13 +23,17 @@ from h5py import File, Group from artist_pythonlib.geometries import projection_geometry, thd_projection_geometry from artist_pythonlib.common_types import PROJECTIONGEOMETRIES, SAVEMODES from artist_pythonlib.remote_connection import Junction, _rc -from h5schemas.projection.add_projection import init_projection_dataset, add_projection_sample +from h5schemas.projection.add_projection import ( + init_projection_dataset, + add_projection_sample, +) import tempfile from artist_pythonlib.utility import load_projection H5_INIT = True + class API: def __init__(self, remote_control: Junction = None) -> None: if remote_control is None: @@ -68,10 +72,10 @@ class API: if save_projection_geometry == PROJECTIONGEOMETRIES.THD: geom = self.projection_geometry(save_projection_geometry) - name = f'{geom["image"]["image_path"][:-4]}_{save_path.stem}' + name = f"{geom['image']['image_path'][:-4]}_{save_path.stem}" save_path = save_path.parent / f"{name}.tif" save_path_json = save_path.parent / f"{name}.json" - geom['image']['image_path'] = save_path.name + geom["image"]["image_path"] = save_path.name elif save_projection_geometry == PROJECTIONGEOMETRIES.STANDARD: save_path_json = save_path.parent / f"{save_path.stem}.json" @@ -90,61 +94,68 @@ class API: self._save_image_png(save_path) return save_path - def save_hdf5(self, - save_path: Path | File | Group, - initialize_dataset: bool = False): - + def save_hdf5( + self, save_path: Path | File | Group, initialize_dataset: bool = False + ): global H5_INIT if isinstance(save_path, Path): - save_path = File(save_path, 'a') + save_path = File(save_path, "a") - file = Path(tempfile.gettempdir()) / 'image.tif' + file = Path(tempfile.gettempdir()) / "image.tif" file = self.save_image(file, save_projection_geometry=PROJECTIONGEOMETRIES.THD) projection, current_geometry = load_projection(file) if H5_INIT or initialize_dataset: H5_INIT = False - image_dimensions_px = [current_geometry['detector']['image_dimensions_px']['u'], current_geometry['detector']['image_dimensions_px']['v']] - pixel_pitch_mm = [current_geometry['detector']['pixel_pitch_mm']['u'], current_geometry['detector']['pixel_pitch_mm']['v']] - init_projection_dataset(save_path, False, image_dimensions_px, pixel_pitch_mm) - - + image_dimensions_px = [ + current_geometry["detector"]["image_dimensions_px"]["u"], + current_geometry["detector"]["image_dimensions_px"]["v"], + ] + pixel_pitch_mm = [ + current_geometry["detector"]["pixel_pitch_mm"]["u"], + current_geometry["detector"]["pixel_pitch_mm"]["v"], + ] + init_projection_dataset( + save_path, False, image_dimensions_px, pixel_pitch_mm + ) source_pos = [ - current_geometry['projection_geometry']['focal_spot_position_mm']['x'], - current_geometry['projection_geometry']['focal_spot_position_mm']['y'], - current_geometry['projection_geometry']['focal_spot_position_mm']['z'], + current_geometry["projection_geometry"]["focal_spot_position_mm"]["x"], + current_geometry["projection_geometry"]["focal_spot_position_mm"]["y"], + current_geometry["projection_geometry"]["focal_spot_position_mm"]["z"], ] detector_pos = [ - current_geometry['projection_geometry']['detector_center_position_mm']['x'], - current_geometry['projection_geometry']['detector_center_position_mm']['y'], - current_geometry['projection_geometry']['detector_center_position_mm']['z'], + current_geometry["projection_geometry"]["detector_center_position_mm"]["x"], + current_geometry["projection_geometry"]["detector_center_position_mm"]["y"], + current_geometry["projection_geometry"]["detector_center_position_mm"]["z"], ] source_ori = [ - current_geometry['projection_geometry']['focal_spot_orientation_quat']['x'], - current_geometry['projection_geometry']['focal_spot_orientation_quat']['y'], - current_geometry['projection_geometry']['focal_spot_orientation_quat']['z'], - current_geometry['projection_geometry']['focal_spot_orientation_quat']['w'], + current_geometry["projection_geometry"]["focal_spot_orientation_quat"]["x"], + current_geometry["projection_geometry"]["focal_spot_orientation_quat"]["y"], + current_geometry["projection_geometry"]["focal_spot_orientation_quat"]["z"], + current_geometry["projection_geometry"]["focal_spot_orientation_quat"]["w"], ] detector_ori = [ - current_geometry['projection_geometry']['detector_center_orientation_quat']['x'], - current_geometry['projection_geometry']['detector_center_orientation_quat']['y'], - current_geometry['projection_geometry']['detector_center_orientation_quat']['z'], - current_geometry['projection_geometry']['detector_center_orientation_quat']['w'], + current_geometry["projection_geometry"]["detector_center_orientation_quat"][ + "x" + ], + current_geometry["projection_geometry"]["detector_center_orientation_quat"][ + "y" + ], + current_geometry["projection_geometry"]["detector_center_orientation_quat"][ + "z" + ], + current_geometry["projection_geometry"]["detector_center_orientation_quat"][ + "w" + ], ] - add_projection_sample( - save_path, - projection, - detector_pos, - detector_ori, - source_pos, - source_ori + save_path, projection, detector_pos, detector_ori, source_pos, source_ori ) def _save_image_uint16(self, save_path: Path): @@ -156,7 +167,7 @@ class API: # self.rc.send('set imgList [Engine::Go]') save_path_projection = str(save_path.absolute()).replace("\\", "\\\\") self.rc.send( - f'set imgList [Engine::Go]; Image::SaveFloatTIFF [lindex $imgList 0] {save_path_projection} True; {r"foreach i $imgList {$i Delete}"}' + f"set imgList [Engine::Go]; Image::SaveFloatTIFF [lindex $imgList 0] {save_path_projection} True; {r'foreach i $imgList {$i Delete}'}" ) def _save_image_uint8(self, save_path: Path): @@ -171,7 +182,7 @@ class API: save_path.parent / (save_path.stem + ".json") ) # Image::SaveFile [lindex $imgList 0] [file join $env(HOME) Pictures/artistlib2.tif] true', self.rc.send( - f'set imgList [Engine::Go]; Image::SaveFloatTIFF [lindex $imgList 0] {save_path_projection} True; {r"foreach i $imgList {$i Delete}"}' + f"set imgList [Engine::Go]; Image::SaveFloatTIFF [lindex $imgList 0] {save_path_projection} True; {r'foreach i $imgList {$i Delete}'}" ) with open(str(save_path_json), "w") as f: @@ -186,7 +197,7 @@ class API: # self.rc.send('set imgList [Engine::Go]') save_path_projection = str(save_path.absolute()).replace("\\", "\\\\") self.rc.send( - f'set imgList [Engine::Go]; Image::SaveFloatTIFF [lindex $imgList 0] {save_path_projection} True; {r"foreach i $imgList {$i Delete}"}' + f"set imgList [Engine::Go]; Image::SaveFloatTIFF [lindex $imgList 0] {save_path_projection} True; {r'foreach i $imgList {$i Delete}'}" ) # self.rc.send('foreach i $imgList {$i Delete}') @@ -202,7 +213,7 @@ class API: save_path.parent / (save_path.stem + ".json") ) # Image::SaveFile [lindex $imgList 0] [file join $env(HOME) Pictures/artistlib2.tif] true', self.rc.send( - f'set imgList [Engine::Go]; Image::SaveFloatTIFF [lindex $imgList 0] {save_path_projection} True; {r"foreach i $imgList {$i Delete}"}' + f"set imgList [Engine::Go]; Image::SaveFloatTIFF [lindex $imgList 0] {save_path_projection} True; {r'foreach i $imgList {$i Delete}'}" ) with open(str(save_path_json), "w") as f: @@ -217,7 +228,7 @@ class API: # self.rc.send('set imgList [Engine::Go]') save_path_projection = str(save_path.absolute()).replace("\\", "\\\\") self.rc.send( - f'set imgList [Engine::Go]; Image::SaveFloatTIFF [lindex $imgList 0] {save_path_projection} True; {r"foreach i $imgList {$i Delete}"}' + f"set imgList [Engine::Go]; Image::SaveFloatTIFF [lindex $imgList 0] {save_path_projection} True; {r'foreach i $imgList {$i Delete}'}" ) def translate( @@ -450,4 +461,4 @@ class API: ) self.rc.send( f'::XRayProject::LoadProject "{self.path_to_artist(project_file)}"' - ) \ No newline at end of file + ) diff --git a/src/artist_pythonlib/geometries/thd_format.py b/src/artist_pythonlib/geometries/thd_format.py index 5d850a31c0809a45c5813c5014a70cd26c465bf3..d0f83dd25bed4bfb895dce9f541d8418705b5996 100644 --- a/src/artist_pythonlib/geometries/thd_format.py +++ b/src/artist_pythonlib/geometries/thd_format.py @@ -40,7 +40,7 @@ def thd_projection_geometry(api) -> dict: np.asarray(detector_pixel_count), np.asarray(detector_resolution), json_header, - Rotation.from_matrix(source_orientation).as_quat()) - + Rotation.from_matrix(source_orientation).as_quat(), + ) return data_dict diff --git a/uv.lock b/uv.lock index 7e75d2e672a94703b3940e9b8b22213adf7f1b0e..a405b310156e27afd134ca4f1a77dfa972efecb8 100644 --- a/uv.lock +++ b/uv.lock @@ -22,7 +22,7 @@ thd = [ [package.metadata] requires-dist = [ - { name = "h5schemas", git = "https://mygit.th-deg.de/roboct/definitions/h5schemas" }, + { name = "h5schemas", git = "https://mygit.th-deg.de/roboct-public/roboct-h5" }, { name = "matplotlib", specifier = "<=3.9" }, { name = "numpy", specifier = ">=1.23" }, { name = "pillow", specifier = ">=10.0" }, @@ -249,7 +249,7 @@ wheels = [ [[package]] name = "h5schemas" version = "0.1.0" -source = { git = "https://mygit.th-deg.de/roboct/definitions/h5schemas#3624c61163e3230bd2ac42884aa7b39d2cfcdeb8" } +source = { git = "https://mygit.th-deg.de/roboct-public/roboct-h5#3624c61163e3230bd2ac42884aa7b39d2cfcdeb8" } dependencies = [ { name = "h5py" }, { name = "jsonref" },