diff --git a/bdpy/dataform/features.py b/bdpy/dataform/features.py index f3785380..1a181f5b 100644 --- a/bdpy/dataform/features.py +++ b/bdpy/dataform/features.py @@ -466,9 +466,6 @@ def __parse_dir(self, path: str, keys: Optional[List[str]] = None) -> 'FileDatab return db - def __init_db(self, keys): - raise NotImplementedError - class FileDatabase(object): def __init__(self, keys: List[str]): diff --git a/bdpy/dl/torch/dataset.py b/bdpy/dl/torch/dataset.py index 6f71f833..87d0c028 100644 --- a/bdpy/dl/torch/dataset.py +++ b/bdpy/dl/torch/dataset.py @@ -12,31 +12,6 @@ _FeatureTypeNP = Dict[str, np.ndarray] -def _removesuffix(s: str, suffix: str) -> str: - """Remove suffix from string. - - Note - ---- - This function is available from Python 3.9 as `str.removesuffix`. We can - remove this function when we drop support for Python 3.8. - - Parameters - ---------- - s : str - String. - suffix : str - Suffix to remove. - - Returns - ------- - str - String without suffix. - """ - if suffix and s.endswith(suffix): - return s[: -len(suffix)] - return s[:] - - class FeaturesDataset(Dataset): """Dataset of features. diff --git a/bdpy/mri/fmriprep.py b/bdpy/mri/fmriprep.py index 7e786d0f..4128d494 100644 --- a/bdpy/mri/fmriprep.py +++ b/bdpy/mri/fmriprep.py @@ -813,52 +813,6 @@ def __create_bdata_fmriprep_subject(subject_data, data_mode, data_path='./', lab return bdata -def __get_xyz(img): - if len(img.shape) == 4: - # 4D-image - i_len, j_len, k_len, t = img.shape - affine = np.delete(np.delete(img.coordmap.affine, 3, axis=0), 3, axis=1) - else: - # 3D-image - i_len, j_len, k_len = img.shape - affine = img.coordmap.affine - ijk = np.array(list(itertools.product(range(i_len), - range(j_len), - range(k_len), - [1]))).T - return np.dot(affine, ijk)[:-1] - - -def __load_mri(fpath): - """Load a MRI image. - - - Returns data as 2D array (sample x voxel) - - Returns voxle xyz coordinates (3 x voxel) - - Returns voxel ijk indexes (3 x voxel) - - Data, xyz, and ijk are flattened by Fortran-like index order - """ - img = nibabel.load(fpath) - - data = img.get_fdata() - if data.ndim == 4: - data = data.reshape(-1, data.shape[-1], order='F').T - i_len, j_len, k_len, t = img.shape - affine = np.delete(np.delete(img.affine, 3, axis=0), 3, axis=1) - elif data.ndim == 3: - data = data.flatten(order='F') - i_len, j_len, k_len = img.shape - affine = img.affine - else: - raise ValueError('Invalid shape.') - - ijk = np.array(np.unravel_index(np.arange(i_len * j_len * k_len), - (i_len, j_len, k_len), order='F')) - ijk_b = np.vstack([ijk, np.ones((1, i_len * j_len * k_len))]) - xyz_b = np.dot(affine, ijk_b) - xyz = xyz_b[:-1] - - return data, xyz, ijk - if __name__ == '__main__': pass diff --git a/bdpy/recon/torch/task/inversion.py b/bdpy/recon/torch/task/inversion.py index 25eef43a..23259308 100644 --- a/bdpy/recon/torch/task/inversion.py +++ b/bdpy/recon/torch/task/inversion.py @@ -1,6 +1,6 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Callable, Dict, Iterable +from typing import TYPE_CHECKING, Dict, Iterable from bdpy.task import BaseTask from bdpy.task.callback import BaseCallback, unused @@ -14,12 +14,6 @@ _FeatureType = Dict[str, torch.Tensor] -def _apply_to_features( - fn: Callable[[torch.Tensor], torch.Tensor], features: _FeatureType -) -> _FeatureType: - return {k: fn(v) for k, v in features.items()} - - class FeatureInversionCallback(BaseCallback): """Callback for feature inversion task.