Skip to content

ENH: Add type hints across miscellaneous methods #68

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

Merged
merged 3 commits into from
Jan 27, 2025
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
13 changes: 7 additions & 6 deletions src/nifreeze/data/dmri.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import h5py
import nibabel as nb
import numpy as np
import numpy.typing as npt
from nibabel.spatialimages import SpatialImage
from nitransforms.linear import Affine

Expand Down Expand Up @@ -369,11 +370,11 @@ def load(


def find_shelling_scheme(
bvals,
num_bins=DEFAULT_NUM_BINS,
multishell_nonempty_bin_count_thr=DEFAULT_MULTISHELL_BIN_COUNT_THR,
bval_cap=DEFAULT_HIGHB_THRESHOLD,
):
bvals: np.ndarray,
num_bins: int = DEFAULT_NUM_BINS,
multishell_nonempty_bin_count_thr: int = DEFAULT_MULTISHELL_BIN_COUNT_THR,
bval_cap: float = DEFAULT_HIGHB_THRESHOLD,
) -> tuple[str, list[npt.NDArray[np.floating]], list[np.floating]]:
"""
Find the shelling scheme on the given b-values.

Expand All @@ -390,7 +391,7 @@ def find_shelling_scheme(
Number of bins.
multishell_nonempty_bin_count_thr : :obj:`int`, optional
Bin count to consider a multi-shell scheme.
bval_cap : :obj:`int`, optional
bval_cap : :obj:`float`, optional
Maximum b-value to be considered in a multi-shell scheme.

Returns
Expand Down
4 changes: 2 additions & 2 deletions src/nifreeze/model/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class ModelFactory:
"""A factory for instantiating data models."""

@staticmethod
def init(model=None, **kwargs):
def init(model: str | None = None, **kwargs):
"""
Instantiate a diffusion model.

Expand Down Expand Up @@ -136,7 +136,7 @@ def __init__(self, dataset, stat="median", **kwargs):
super().__init__(dataset, **kwargs)
self._stat = stat

def fit_predict(self, index, **kwargs):
def fit_predict(self, index: int, **kwargs):
"""
Return the expectation map.

Expand Down
21 changes: 15 additions & 6 deletions src/nifreeze/model/dmri.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
from nifreeze.data.dmri import (
DEFAULT_CLIP_PERCENTILE,
DTI_MIN_ORIENTATIONS,
DWI,
)
from nifreeze.model.base import BaseModel, ExpectationModel

Expand All @@ -51,7 +52,7 @@
"_modelargs": "Arguments acceptable by the underlying DIPY-like model.",
}

def __init__(self, dataset, **kwargs):
def __init__(self, dataset: DWI, **kwargs):
r"""Initialization.

Parameters
Expand Down Expand Up @@ -117,7 +118,7 @@
self._model = None # Preempt further actions on the model
return n_jobs

def fit_predict(self, index, **kwargs):
def fit_predict(self, index: int, **kwargs):
"""
Predict asynchronously chunk-by-chunk the diffusion signal.

Expand All @@ -140,7 +141,7 @@
if n_models == 1:
predicted, _ = _exec_predict(self._model, **(kwargs | {"gtab": gradient, "S0": S0}))
else:
S0 = np.array_split(S0, n_models) if S0 is not None else [None] * n_models
S0 = np.array_split(S0, n_models) if S0 is not None else np.full(n_models, None)

Check warning on line 144 in src/nifreeze/model/dmri.py

View check run for this annotation

Codecov / codecov/patch

src/nifreeze/model/dmri.py#L144

Added line #L144 was not covered by tests

predicted = [None] * n_models

Expand Down Expand Up @@ -173,7 +174,15 @@

__slots__ = ("_th_low", "_th_high", "_detrend")

def __init__(self, dataset, stat="median", th_low=100, th_high=100, detrend=False, **kwargs):
def __init__(
self,
dataset: DWI,
stat: str = "median",
th_low: float = 100.0,
th_high: float = 100.0,
detrend: bool = False,
**kwargs,
):
r"""
Implement object initialization.

Expand All @@ -183,10 +192,10 @@
Reference to a DWI object.
stat : :obj:`str`, optional
Whether the summary statistic to apply is ``"mean"`` or ``"median"``.
th_low : :obj:`numbers.Number`, optional
th_low : :obj:`float`, optional
A lower bound for the b-value corresponding to the diffusion weighted images
that will be averaged.
th_high : :obj:`numbers.Number`, optional
th_high : :obj:`float`, optional
An upper bound for the b-value corresponding to the diffusion weighted images
that will be averaged.
detrend : :obj:`bool`, optional
Expand Down
Loading