Skip to content
Open
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
3 changes: 0 additions & 3 deletions bdpy/dataform/features.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]):
Expand Down
25 changes: 0 additions & 25 deletions bdpy/dl/torch/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
46 changes: 0 additions & 46 deletions bdpy/mri/fmriprep.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,13 @@
# File name patterns
# FIXME
if self.__fmriprep_version == '1.2':
file_pattern = {'volume_native' : '.*_space-T1w_desc-preproc_bold\.nii\.gz$',

Check warning on line 97 in bdpy/mri/fmriprep.py

View workflow job for this annotation

GitHub Actions / test (3.10)

invalid escape sequence '\.'

Check warning on line 97 in bdpy/mri/fmriprep.py

View workflow job for this annotation

GitHub Actions / test (3.11)

invalid escape sequence '\.'
'volume_standard' : '.*_space-MNI152NLin2009cAsym_desc-preproc_bold\.nii\.gz$',

Check warning on line 98 in bdpy/mri/fmriprep.py

View workflow job for this annotation

GitHub Actions / test (3.10)

invalid escape sequence '\.'

Check warning on line 98 in bdpy/mri/fmriprep.py

View workflow job for this annotation

GitHub Actions / test (3.11)

invalid escape sequence '\.'
'surf_native_left' : '.*_space-fsnative_hemi-L\.func\.gii$',

Check warning on line 99 in bdpy/mri/fmriprep.py

View workflow job for this annotation

GitHub Actions / test (3.10)

invalid escape sequence '\.'

Check warning on line 99 in bdpy/mri/fmriprep.py

View workflow job for this annotation

GitHub Actions / test (3.11)

invalid escape sequence '\.'
'surf_native_right' : '.*_space-fsnative_hemi-R\.func\.gii$',

Check warning on line 100 in bdpy/mri/fmriprep.py

View workflow job for this annotation

GitHub Actions / test (3.10)

invalid escape sequence '\.'

Check warning on line 100 in bdpy/mri/fmriprep.py

View workflow job for this annotation

GitHub Actions / test (3.11)

invalid escape sequence '\.'
'surf_standard_left' : '.*_space-fsaverage_hemi-L\.func\.gii$',

Check warning on line 101 in bdpy/mri/fmriprep.py

View workflow job for this annotation

GitHub Actions / test (3.10)

invalid escape sequence '\.'

Check warning on line 101 in bdpy/mri/fmriprep.py

View workflow job for this annotation

GitHub Actions / test (3.11)

invalid escape sequence '\.'
'surf_standard_right' : '.*_space-fsaverage_hemi-R\.func\.gii$',

Check warning on line 102 in bdpy/mri/fmriprep.py

View workflow job for this annotation

GitHub Actions / test (3.10)

invalid escape sequence '\.'

Check warning on line 102 in bdpy/mri/fmriprep.py

View workflow job for this annotation

GitHub Actions / test (3.11)

invalid escape sequence '\.'
'surf_standard_41k_left' : '.*_space-fsaverage6_hemi-L\.func\.gii$',

Check warning on line 103 in bdpy/mri/fmriprep.py

View workflow job for this annotation

GitHub Actions / test (3.10)

invalid escape sequence '\.'

Check warning on line 103 in bdpy/mri/fmriprep.py

View workflow job for this annotation

GitHub Actions / test (3.11)

invalid escape sequence '\.'
'surf_standard_41k_right' : '.*_space-fsaverage6_hemi-R\.func\.gii$',
'surf_standard_10k_left' : '.*_space-fsaverage5_hemi-L\.func\.gii$',
'surf_standard_10k_right' : '.*_space-fsaverage5_hemi-R\.func\.gii$',
Expand Down Expand Up @@ -813,52 +813,6 @@
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
8 changes: 1 addition & 7 deletions bdpy/recon/torch/task/inversion.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -14,12 +14,6 @@
_FeatureType = Dict[str, torch.Tensor]
Comment thread
KenyaOtsuka marked this conversation as resolved.


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.

Expand Down
Loading