Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update transform loader params API docs #514

Merged
merged 3 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/source/_templates/autosummary/class.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

.. autoclass:: {{ objname }}
:members:
:undoc-members:

{% block methods %}
{% if methods %}
Expand Down
63 changes: 62 additions & 1 deletion httomo/transform_loader_params.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
"""
Types that represent python dicts for angles and preview configuration which are generated from
parsing a pipeline file into python, and functions to transform these python dicts to internal
types that loaders can use.
"""

from typing import Literal, Optional, TypeAlias, TypedDict, Union

from httomo.loaders.types import (
Expand All @@ -9,6 +15,10 @@


class StartStopEntry(TypedDict):
"""
Configuration for a single dimension's previewing in terms of start/stop values.
"""

start: Optional[int]
stop: Optional[int]

Expand All @@ -17,6 +27,10 @@ class StartStopEntry(TypedDict):


class PreviewParam(TypedDict):
"""
Preview configuration dict.
"""

angles: Optional[StartStopEntry]
detector_y: Optional[PreviewParamEntry]
detector_x: Optional[PreviewParamEntry]
Expand All @@ -29,6 +43,24 @@ def parse_preview(
param_value: Optional[PreviewParam],
data_shape: tuple[int, int, int],
) -> PreviewConfig:
"""
Convert python dict representing preview information generated from parsing the
pipeline file, into an internal preview configuration type that loaders can use.

Parameters
----------
param_value : Optional[PreviewParam]
The python dict parsed from the pipeline file that represents the preview configuration
in the loader.

data_shape : tuple[int, int, int]
The shape of the 3D input data.

Returns
-------
PreviewConfig
Preview configuration that loaders can use.
"""
DIMENSION_MAPPINGS: dict[PreviewKeys, int] = {
"angles": 0,
"detector_y": 1,
Expand Down Expand Up @@ -94,23 +126,52 @@ def _get_middle_slice_indices(dim_len: int) -> tuple[int, int]:


class RawAnglesParam(TypedDict):
"""
Angles configuration dict for when the rotation angle values are in a dataset within the
input NeXuS/hdf5 file.
"""

data_path: str


class UserDefinedAnglesParamInner(TypedDict):
"""
Start, stop, and total angles configuration to generate the rotation angle values.
"""

start_angle: int
stop_angle: int
angles_total: int


class UserDefinedAnglesParam(TypedDict):
"""
Angles configuration dict for when the rotation angle values are manually defined (rather
than taken from the input NeXuS/hdf5 file).
"""

user_defined: UserDefinedAnglesParamInner


AnglesParam: TypeAlias = Union[RawAnglesParam, UserDefinedAnglesParam]


def parse_angles(angles_data: dict) -> AnglesConfig:
def parse_angles(angles_data: AnglesParam) -> AnglesConfig:
"""
Convert python dict representing angles information generated from parsing the
pipeline file, into an internal angles configuration type that loaders can use.

Parameters
----------
angles_data : AnglesParam
The python dict parsed from the pipeline file that represents the angles configuration
in the loader.

Returns
-------
AnglesConfig
Angles configuration that loaders can use.
"""
if "data_path" in angles_data and isinstance(angles_data["data_path"], str):
return RawAngles(data_path=angles_data["data_path"])

Expand Down
Loading