Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • roboct-public/artist-api
1 result
Show changes
Commits on Source (2)
......@@ -28,4 +28,4 @@ build-backend = "hatchling.build"
[tool.uv.sources]
thd-json = { git = "https://mygit.th-deg.de/roboct-public/roboct-schemas" }
h5schemas = { git = "https://mygit.th-deg.de/roboct/definitions/h5schemas" }
h5schemas = { git = "https://mygit.th-deg.de/roboct-public/roboct-h5" }
......@@ -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
)
......@@ -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
......@@ -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" },
......