caps.toy_datasets: Toy Datasets¶
Data: How to import toy datasets that may be used in various demonstration scripts.
Toy dataset import¶
- caps.toy_datasets.get_sample_data(dataset_name, fsl_dir='/usr/share/fsl/4.1', spm_dir='/i2bm/local/spm8-5236/')[source]¶
Get a sample dataset.
This function loads the requested dataset, downloading it if needed in the ‘$HOME/.local/share/nsap’ directory. If a .zip or .tar.gz file is requested, the function automatically uncompress the file and return the path to the uncompressed file.
Parameters : dataset_name: str (mandatory) :
which sample data you want - one of:
mni_1mm - (mni, brain,mask, mesh, erode_mesh), mni_2mm - (mni, brain, mask), spm_auditory - (fmri, anat, TR, timings), tpm - (all,gm,wm,csf), localizer - (fmri, anat, TR, timings, mean, fmridcm, anatdcm), dwi - (dwi, bvecs, bvals, fa, mask, tensor), brainvisa_palette - (edouard), fa_1mm - (template, nl_config)
fsl_dir: str (optional) :
the function will try first to get the fsl path from the ‘FSLDIR’ environment variable. If not found, the fsl directory will be set with this parameter. Note that the default parameter is only valid for NeuroSpin users.
spm_dir: str (optional) :
the function will try first to get the spm path from the ‘SPMDIR’ environment variable. If not found, the spm directory will be set with this parameter. Note that the default parameter is only valid for NeuroSpin users.
Returns : dataset: Enum :
an Enum object containing the path to the desired dataset.
Examples
>>> from caps.toy_datasets import get_sample_data >>> dataset = get_sample_data("mni_1mm") >>> dataset.mni /usr/share/fsl/4.1/data/standard/MNI152_T1_1mm.nii.gz
Buildingblocks¶
- caps.toy_datasets.download_file(url, data_dir=None, resume=True, overwrite=False, md5sum=None)[source]¶
Load requested file, downloading it if needed or requested.
Parameters : url: str (mandatory) :
the url of the file to be downloaded.
data_dir: str (optional) :
path of the data directory. default is ‘$HOME/.local/share/nsap’
resume: bool (optional) :
if true, try to resume partially downloaded files
overwrite: bool (optional) :
if true and file already exists, delete it.
md5sum: str (optional) :
check if the downloaded file has this MD5 sum.
Returns : file: str :
absolute path of downloaded file.
Notes
If, for any reason, the download procedure fails, all downloaded files are removed.
- caps.toy_datasets.uncompress_file(fname, delete_archive=False)[source]¶
Uncompress files contained in a data_set.
Parameters : fname: str (mandatory) :
path of file to be uncompressed.
delete_archive: bool (optional) :
option to delete the archive once it is uncompressed.
Returns : out: str :
the path to the uncompressed object
Notes
The function handles zip, tar, gzip and bzip files only.