Skip to content

Commit 2408191

Browse files
author
Hanna Ruth
committed
FEAT: added tool for getting volumes from task files, which allows for easy comparisons to be made.
1 parent ec71af3 commit 2408191

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

src/pyxalign/plotting/results_analysis/volume_comparison.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
from typing import Optional, Sequence, Union
22
import numpy as np
33
import tifffile
4+
import tqdm
45
import matplotlib.pyplot as plt
56
from mpl_toolkits.axes_grid1.inset_locator import zoomed_inset_axes, mark_inset
7+
from pyxalign.data_structures.task import load_task
68
from pyxalign.plotting.plotters import add_scalebar
79
from pyxalign.transformations.functions import image_crop
810

@@ -286,3 +288,28 @@ def _clamped_crop_bounds(h: int, w: int, crop: int, cy: int, cx: int):
286288
if y2 - y1 < 1:
287289
y2 = min(h, y1 + 1)
288290
return x1, x2, y1, y2
291+
292+
293+
def collect_volumes_from_task_files(
294+
file_paths: list[str],
295+
rotate_volumes: bool = False,
296+
volume_width_multiplier: Optional[float] = None,
297+
rotation_angles: Optional[list[float]] = None,
298+
):
299+
volumes = []
300+
for i, path in tqdm.tqdm(enumerate(file_paths)):
301+
task = load_task(path, exclude="complex_projections")
302+
if volume_width_multiplier is not None:
303+
task.phase_projections.options.volume_width.use_custom_width = True
304+
task.phase_projections.options.volume_width.multiplier = volume_width_multiplier
305+
task.phase_projections.masks = None
306+
task.phase_projections.apply_staged_shift()
307+
task.phase_projections.get_3D_reconstruction()
308+
if i == 0 and rotate_volumes and (rotation_angles is None):
309+
task.phase_projections.volume.get_optimal_rotation_of_reconstruction()
310+
rotation_angles = task.phase_projections.volume.optimal_rotation_angles
311+
if rotate_volumes:
312+
task.phase_projections.volume.optimal_rotation_angles = rotation_angles
313+
task.phase_projections.volume.rotate_reconstruction()
314+
volumes += [task.phase_projections.volume.data]
315+
return volumes

0 commit comments

Comments
 (0)