fmralign/_utils.py
def _make_parcellation(imgs, clustering, n_pieces, masker, smoothing_fwhm=5, verbose=0):
    """Convenience function to use nilearn Parcellation class in our pipeline.
    It is used to find local regions of the brain in which alignment will be later applied.
    For alignment computational efficiency, regions should be of hundreds of voxels.

    Parameters
    ----------
    imgs: Niimgs
        data to cluster
    clustering: string or 3D Niimg
        In : {'kmeans', 'ward', 'rena'}, passed to nilearn Parcellations class.
        If you aim for speed, choose k-means (and check kmeans_smoothing_fwhm parameter)
        If you want spatially connected and/or reproducible regions use 'ward'
        For 'rena', need nilearn > 0.5.2
        If 3D Niimg, image used as predefined clustering, n_pieces is ignored
    n_pieces: int
        number of different labels
    masker: instance of NiftiMasker or MultiNiftiMasker
        Masker to be used on the data. For more information see:
        http://nilearn.github.io/manipulating_images/masker_objects.html
    smoothing_fwhm: None or int
        By default 5mm smoothing will be applied before kmeans clustering to have
        more compact clusters (but this will not change the data later).
        To disable this option, this parameter should be None.

    Returns
    -------
    labels : list of ints (len n_features)
        Parcellation of features in clusters
    """
    if type(clustering) == nibabel.nifti1.Nifti1Image:
        # check image makes suitable labels, this will return friendly error message if needed
        _check_same_fov(masker.mask_img_, clustering)
        labels_img = clustering
    else:
        if clustering == "kmeans" and smoothing_fwhm is not None:
            images_to_parcel = smooth_img(imgs, smoothing_fwhm)
        try:
            parcellation = Parcellations(method=clustering, n_parcels=n_pieces, mask=masker,
                                         scaling=False, n_iter=20, verbose=verbose)
            parcellation.fit()
        except TypeError:
            if clustering == "rena":
                raise InputError(
                    ('ReNA algorithm is only available in Nilearn version > 0.5.2. \
                     If you want to use it, please run "pip install --upgrade nilearn"'))
            else:
                parcellation = Parcellations(
                    method=clustering, n_parcels=n_pieces, mask=masker, verbose=verbose)
        parcellation.fit(imgs)
        labels_img = parcellation.labels_img_
    return _apply_mask_fmri(labels_img, masker.mask_img_).astype(int)
Convenience function to use nilearn Parcellation class in our pipeline.
    It is used to find local regions of the brain in which alignment will be later applied.
    For alignment computational efficiency, regions should be of hundreds of voxels.

    Parameters
    ----------
    imgs: Niimgs
        data to cluster
    clustering: string or 3D Niimg
        In : {'kmeans', 'ward', 'rena'}, passed to nilearn Parcellations class.
        If you aim for speed, choose k-means (and check kmeans_smoothing_fwhm parameter)
        If you want spatially connected and/or reproducible regions use 'ward'
        For 'rena', need nilearn > 0.5.2
        If 3D Niimg, image used as predefined clustering, n_pieces is ignored
    n_pieces: int
        number of different labels
    masker: instance of NiftiMasker or MultiNiftiMasker
        Masker to be used on the data. For more information see:
        http://nilearn.github.io/manipulating_images/masker_objects.html
    smoothing_fwhm: None or int
        By default 5mm smoothing will be applied before kmeans clustering to have
        more compact clusters (but this will not change the data later).
        To disable this option, this parameter should be None.

    Returns
    -------
    labels : list of ints (len n_features)
        Parcellation of features in clusters
    
Convenience function to use nilearn Parcellation class in our pipeline.
It is used to find local regions of the brain in which alignment will be later applied.
For alignment computational efficiency, regions should be of hundreds of voxels.

Parameters



Returns

labels : list of ints (len n_features)
Parcellation of features in clusters
Convenience function to use nilearn Parcellation class in our pipeline . It is used to find local regions of the brain in which alignment will be later applied . For alignment computational efficiency regions should be of hundreds of voxels . Parameters Returns labels : list of ints ( len n_features ) Parcellation of features in clusters
def _make_parcellation(imgs, clustering, n_pieces, masker, smoothing_fwhm=5, verbose=0):
    if type(clustering) == nibabel.nifti1.Nifti1Image:
        _check_same_fov(masker.mask_img_, clustering)
        labels_img = clustering
    else:
        if clustering == "kmeans" and smoothing_fwhm is not None:
            images_to_parcel = smooth_img(imgs, smoothing_fwhm)
        try:
            parcellation = Parcellations(method=clustering, n_parcels=n_pieces, mask=masker,
                                         scaling=False, n_iter=20, verbose=verbose)
            parcellation.fit()
        except TypeError:
            if clustering == "rena":
                raise InputError(
                    ('ReNA algorithm is only available in Nilearn version > 0.5.2. \
                     If you want to use it, please run "pip install --upgrade nilearn"'))
            else:
                parcellation = Parcellations(
                    method=clustering, n_parcels=n_pieces, mask=masker, verbose=verbose)
        parcellation.fit(imgs)
        labels_img = parcellation.labels_img_
    return _apply_mask_fmri(labels_img, masker.mask_img_).astype(int)
def _make_parcellation ( imgs , clustering , n_pieces , masker , smoothing_fwhm = 5 , verbose = 0 ) : if type ( clustering ) == nibabel . nifti1 . Nifti1Image : _check_same_fov ( masker . mask_img_ , clustering ) labels_img = clustering else : if clustering == "kmeans" and smoothing_fwhm is not None : images_to_parcel = smooth_img ( imgs , smoothing_fwhm ) try : parcellation = Parcellations ( method = clustering , n_parcels = n_pieces , mask = masker , scaling = False , n_iter = 20 , verbose = verbose ) parcellation . fit ( ) except TypeError : if clustering == "rena" : raise InputError ( ( 'ReNA algorithm is only available in Nilearn version > 0.5.2. \
                     If you want to use it, please run "pip install --upgrade nilearn"' ) ) else : parcellation = Parcellations ( method = clustering , n_parcels = n_pieces , mask = masker , verbose = verbose ) parcellation . fit ( imgs ) labels_img = parcellation . labels_img_ return _apply_mask_fmri ( labels_img , masker . mask_img_ ) . astype ( int )
Convenience function to use nilearn Parcellation class in our pipeline.
Convenience function to use nilearn Parcellation class in our pipeline .
"""Convenience function to use nilearn Parcellation class in our pipeline.
    It is used to find local regions of the brain in which alignment will be later applied.
    For alignment computational efficiency, regions should be of hundreds of voxels.

    Parameters
    ----------
    imgs: Niimgs
        data to cluster
    clustering: string or 3D Niimg
        In : {'kmeans', 'ward', 'rena'}, passed to nilearn Parcellations class.
        If you aim for speed, choose k-means (and check kmeans_smoothing_fwhm parameter)
        If you want spatially connected and/or reproducible regions use 'ward'
        For 'rena', need nilearn > 0.5.2
        If 3D Niimg, image used as predefined clustering, n_pieces is ignored
    n_pieces: int
        number of different labels
    masker: instance of NiftiMasker or MultiNiftiMasker
        Masker to be used on the data. For more information see:
        http://nilearn.github.io/manipulating_images/masker_objects.html
    smoothing_fwhm: None or int
        By default 5mm smoothing will be applied before kmeans clustering to have
        more compact clusters (but this will not change the data later).
        To disable this option, this parameter should be None.

    Returns
    -------
    labels : list of ints (len n_features)
        Parcellation of features in clusters
    """ # check image makes suitable labels, this will return friendly error message if needed
imgs
clustering
n_pieces
masker
smoothing_fwhm
verbose