Skip to content

Commit

Permalink
Models/shifts: added utility function to combine vertical and horizon…
Browse files Browse the repository at this point in the history
…tal shifts

Signed-off-by: Nicola VIGANO <[email protected]>
  • Loading branch information
Obi-Wan committed Mar 19, 2024
1 parent d9c2bc0 commit c76df31
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions corrct/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,37 @@ def get_default_from_volume(volume: NDArray) -> "VolumeGeometry":
return get_vol_geom_from_volume(volume=volume)


def combine_shifts_vu(shifts_v: NDArray, shifts_u: NDArray, cor: Union[float, NDArray, None] = None) -> NDArray:
"""Combine vertical and horizontal shifts.
Parameters
----------
shifts_v : NDArray
The vertical shifts
shifts_u : NDArray
The horizontal shifts
cor : Union[float, NDArray, None], optional
The center-of-rotation, if applicable, by default None
Returns
-------
NDArray
The combined shifts
"""
if np.sum(np.array(shifts_v.shape) > 1) > 1:
raise ValueError(f"Expected 1-dimensional array for vertical shifts, but an array {shifts_v.shape = } was passed")
if np.sum(np.array(shifts_u.shape) > 1) > 1:
raise ValueError(f"Expected 1-dimensional array for horizontal shifts, but an array {shifts_u.shape = } was passed")
if shifts_v.size != shifts_u.size:
raise ValueError(f"Number of vertical shifts ({shifts_v.size}) and horizontal shifts ({shifts_u.size}) should match")
if cor is not None:
cor = np.array(cor)
if cor.ndim > 0 and np.any(np.array(shifts_u.shape) > 1):
raise ValueError(f"Expected 0-dimensional array for center-of-rotation, but an array {cor.shape = } was passed")

return np.stack([shifts_v, shifts_u + cor if cor is not None else 0], axis=-1)


def get_rot_axis_dir(rot_axis_dir: Union[str, ArrayLike, NDArray] = "clockwise") -> NDArray:
"""Process the requested rotation axis direction and return a meaningful value.
Expand Down

0 comments on commit c76df31

Please sign in to comment.