AFQ.api.bundle_dict
#
Module Contents#
Classes#
Create a bundle dictionary, needed for the segmentation. |
Functions#
|
|
|
n_bundles: int |
- class AFQ.api.bundle_dict.BundleDict(bundle_info, seg_algo='afq', resample_to=None, resample_subject_to=False, keep_in_memory=False)[source]#
Bases:
collections.abc.MutableMapping
Create a bundle dictionary, needed for the segmentation.
- Parameters
- bundle_infodict,
A dictionary defining custom bundles. See Defining Custom Bundle Dictionaries in the usage section of pyAFQ’s documentation for details.
- seg_algo: One of {“afq”, “reco”}
- The bundle segmentation algorithm to use.
“afq” : Use waypoint ROIs + probability maps, as described in [Yeatman2012] “reco” : Use Recobundles [Garyfallidis2017]
- resample_toNifti1Image or bool, optional
If there are bundles in bundle_info with the ‘space’ attribute set to ‘template’, or with no ‘space’ attribute, their images (all ROIs and probability maps) will be resampled to the affine and shape of this image. If None, the MNI template will be used. If False, no resampling will be done. Default: None
- resample_subject_toNifti1Image or bool, optional
If there are bundles in bundle_info with the ‘space’ attribute set to ‘subject’, their images (all ROIs and probability maps) will be resampled to the affine and shape of this image. If False, no resampling will be done. Default: None
- keep_in_memorybool, optional
Whether, once loaded, all ROIs and probability maps will stay loaded in memory within this object. By default, ROIs are loaded into memory on demand and no references to ROIs are kept, other than their paths. The default 18 bundles use ~6GB when all loaded. Default: False
Examples
# import OR ROIs and create a custom bundle dict # from them import AFQ.data.fetch as afd or_rois = afd.read_or_templates()
- bundles = BundleDict({
- “L_OR”: {
- “include”: [
or_rois[“left_OR_1”], # these can be paths to Nifti files or_rois[“left_OR_2”]], # or they can Nifti images
- “exclude”: [
or_rois[“left_OP_MNI”], or_rois[“left_TP_MNI”], or_rois[“left_pos_thal_MNI”]],
“start”: or_rois[‘left_thal_MNI’], “end”: or_rois[‘left_V1_MNI’], “cross_midline”: False,
}, “R_OR”: {
- “include”: [
or_rois[“right_OR_1”], or_rois[“right_OR_2”]],
- “exclude”: [
or_rois[“right_OP_MNI”], or_rois[“right_TP_MNI”], or_rois[“right_pos_thal_MNI”]],
“start”: or_rois[‘right_thal_MNI’], “end”: or_rois[‘right_V1_MNI’], “cross_midline”: False
}
})
- set_bids_info(bids_layout, bids_path, subject, session)[source]#
Provide the bids_layout, a nearest path, and the subject and session information to load ROIS from BIDS
- copy()[source]#
Generates a copy of this BundleDict where the internal dictionary is a copy of this BundleDict’s internal dictionary. Useful if you want to add or remove bundles from a copy of a BundleDict.
- Returns
- bundle_dictBundleDict
Euclidean norms of vectors.
- apply_to_rois(b_name, func, *args, dry_run=False, **kwargs)[source]#
Applies some transformation to all ROIs (include, exclude, end, start) and the prob_map in a given bundle.
- Parameters
- b_namename
bundle name of bundle whose ROIs will be transformed.
- funcfunction
function whose first argument must be a Nifti1Image and which returns a Nifti1Image
- dry_runbool
Whether to actually apply changes returned by func to the ROIs. If has_return is False, dry_run is not used.
- *args
Additional arguments for func
- **kwargs
Optional arguments for func
- Returns
- A dictionary where keys are
- the roi type and values are the transformed ROIs.
- _cond_load_bundle(b_name, dry_run=False)[source]#
Given a bundle name, resample all ROIs and prob maps into either template or subject space for that bundle, depending on its “space” attribute.
- Parameters
- b_namestr
Name of the bundle to be resampled.
- transform_rois(bundle_name, mapping, new_affine, base_fname=None)[source]#
Get the bundle definition with transformed ROIs for a given bundle into a given subject space using a given mapping. Will only run on bundles which are in template space, otherwise will just return the bundle definition without transformation.
- Parameters
- bundle_namestr
Name of the bundle to be transformed.
- mappingDiffeomorphicMap object
A mapping between DWI space and a template.
- new_affinearray
Affine of space transformed into.
- base_fnamestr, optional
Base file path to save ROIs too. Additional BIDS descriptors will be added to this file path. If None, do not save the ROIs.
- Returns
- If base_fname is None, a dictionary where keys are
- the roi type and values are the transformed ROIs.
- Otherwise, a list of file names where the transformed
- ROIs are saved.