Skip to content

Commit

Permalink
Adjust nilearn calls for bleeding-edge
Browse files Browse the repository at this point in the history
  • Loading branch information
emdupre committed Dec 21, 2023
1 parent 2af1774 commit 0e1ce05
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 18 deletions.
12 changes: 5 additions & 7 deletions fmralign/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

import nibabel as nib
import numpy as np
from nilearn._utils.niimg_conversions import _check_same_fov
from nilearn._utils.niimg_conversions import check_same_fov
from nilearn.image import index_img, new_img_like, smooth_img
from nilearn.masking import _apply_mask_fmri, intersect_masks
from nilearn.masking import apply_mask_fmri, intersect_masks
from nilearn.regions.parcellations import Parcellations


Expand Down Expand Up @@ -107,8 +107,8 @@ def _make_parcellation(
"""
# check if clustering is provided
if isinstance(clustering, nib.nifti1.Nifti1Image) or os.path.isfile(clustering):
_check_same_fov(masker.mask_img_, clustering)
labels = _apply_mask_fmri(clustering, masker.mask_img_).astype(int)
check_same_fov(masker.mask_img_, clustering)
labels = apply_mask_fmri(clustering, masker.mask_img_).astype(int)

# otherwise check it's needed, if not return 1 everywhere
elif n_pieces == 1:
Expand Down Expand Up @@ -140,9 +140,7 @@ def _make_parcellation(
)
err.args += (errmsg,)
raise err
labels = _apply_mask_fmri(parcellation.labels_img_, masker.mask_img_).astype(
int
)
labels = apply_mask_fmri(parcellation.labels_img_, masker.mask_img_).astype(int)

if verbose > 0:
unique_labels, counts = np.unique(labels, return_counts=True)
Expand Down
12 changes: 6 additions & 6 deletions fmralign/fetch_example_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import os

import pandas as pd
from nilearn.datasets.utils import _fetch_files, _get_dataset_dir
from nilearn.datasets._utils import fetch_files, get_dataset_dir


def fetch_ibc_subjects_contrasts(subjects, data_dir=None, verbose=1):
Expand Down Expand Up @@ -34,7 +34,7 @@ def fetch_ibc_subjects_contrasts(subjects, data_dir=None, verbose=1):
Path to the mask to be used on the data
Notes
------
This function is a caller to nilearn.datasets.utils._fetch_files in order
This function is a caller to nilearn.datasets._utils.fetch_files in order
to simplify examples reading and understanding for fmralign.
See Also
---------
Expand All @@ -45,11 +45,11 @@ def fetch_ibc_subjects_contrasts(subjects, data_dir=None, verbose=1):
if subjects == "all":
subjects = ["sub-{i:02d}" for i in [1, 2, 4, 5, 6, 7, 8, 9, 11, 12, 13, 14, 15]]
dataset_name = "ibc"
data_dir = _get_dataset_dir(dataset_name, data_dir=data_dir, verbose=verbose)
data_dir = get_dataset_dir(dataset_name, data_dir=data_dir, verbose=verbose)

# download or retrieve metadatas, put it in a dataframe,
# list all condition and specify path to the right directory
metadata_path = _fetch_files(
metadata_path = fetch_files(
data_dir,
[
(
Expand All @@ -67,7 +67,7 @@ def fetch_ibc_subjects_contrasts(subjects, data_dir=None, verbose=1):
metadata_df = metadata_df[metadata_df.subject.isin(subjects)]

# download / retrieve mask niimg and find its path
mask = _fetch_files(
mask = fetch_files(
data_dir,
[("gm_mask_3mm.nii.gz", "https://osf.io/yvju3/download", {"uncompress": True})],
verbose=verbose,
Expand Down Expand Up @@ -106,5 +106,5 @@ def fetch_ibc_subjects_contrasts(subjects, data_dir=None, verbose=1):
for condition in conditions
]
)
files.append(_fetch_files(data_dir, filenames, verbose=verbose))
files.append(fetch_files(data_dir, filenames, verbose=verbose))
return files, metadata_df, mask
6 changes: 3 additions & 3 deletions fmralign/pairwise_alignment.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import numpy as np
from joblib import Memory, Parallel, delayed
from nilearn.image import concat_imgs, load_img
from nilearn.maskers._masker_validation import _check_embedded_nifti_masker
from nilearn._utils.masker_validation import check_embedded_masker
from sklearn.base import BaseEstimator, TransformerMixin, clone
from sklearn.model_selection import ShuffleSplit

Expand Down Expand Up @@ -313,7 +313,7 @@ def fit(self, X, Y):
-------
self
"""
self.masker_ = _check_embedded_nifti_masker(self)
self.masker_ = check_embedded_masker(self)
self.masker_.n_jobs = self.n_jobs

if self.masker_.mask_img is None:
Expand All @@ -330,7 +330,7 @@ def fit(self, X, Y):
self.clustering, self.masker_.mask_img
)
self.mask = reduced_mask
self.masker_ = _check_embedded_nifti_masker(self)
self.masker_ = check_embedded_masker(self)
self.masker_.n_jobs = self.n_jobs
self.masker_.fit()
warnings.warn(
Expand Down
4 changes: 2 additions & 2 deletions fmralign/template_alignment.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import numpy as np
from joblib import Memory, Parallel, delayed
from nilearn.image import concat_imgs, index_img, load_img
from nilearn.maskers._masker_validation import _check_embedded_nifti_masker
from nilearn._utils.masker_validation import check_embedded_masker
from sklearn.base import BaseEstimator, TransformerMixin

from fmralign.pairwise_alignment import PairwiseAlignment
Expand Down Expand Up @@ -388,7 +388,7 @@ def fit(self, imgs):
if isinstance(imgs[0], (list, np.ndarray)):
imgs = [concat_imgs(img) for img in imgs]

self.masker_ = _check_embedded_nifti_masker(self)
self.masker_ = check_embedded_masker(self)
self.masker_.n_jobs = self.n_jobs # self.n_jobs

# if masker_ has been provided a mask_img
Expand Down

0 comments on commit 0e1ce05

Please sign in to comment.