nipype.caching.memory module¶
Using nipype with persistence and lazy recomputation but without explicit name-steps pipeline: getting back scope in command-line based programming.
- class nipype.caching.memory.Memory(base_dir)¶
Bases:
object
Memory context to provide caching for interfaces
- Parameters
base_dir (string) – The directory name of the location for the caching
- cache()¶
Creates a cacheable function from an nipype Interface class
- clear_previous_runs()¶
Removes from the disk all the runs that where not used after the creation time of the specific Memory instance
- clear_previous_runs()¶
Removes from the disk all the runs that where not used after the given time
- cache(interface)¶
Returns a callable that caches the output of an interface
- Parameters
interface (nipype interface) – The nipype interface class to be wrapped and cached
- Returns
pipe_func – An object that can be used as a function to apply the interface to arguments. Inputs of the interface are given as keyword arguments, bearing the same name as the name in the inputs specs of the interface.
- Return type
a PipeFunc callable object
Examples
>>> from tempfile import mkdtemp >>> mem = Memory(mkdtemp()) >>> from nipype.interfaces import fsl
Here we create a callable that can be used to apply an fsl.Merge interface to files
>>> fsl_merge = mem.cache(fsl.Merge)
Now we apply it to a list of files. We need to specify the list of input files and the dimension along which the files should be merged.
>>> results = fsl_merge(in_files=['a.nii', 'b.nii'], ... dimension='t')
We can retrieve the resulting file from the outputs: >>> results.outputs.merged_file # doctest: +SKIP ‘…’
- clear_previous_runs(warn=True)¶
Remove all the cache that where not used in the latest run of the memory object: i.e. since the corresponding Python object was created.
- Parameters
warn (boolean, optional) – If true, echoes warning messages for all directory removed
- clear_runs_since(day=None, month=None, year=None, warn=True)¶
Remove all the cache that where not used since the given date
- Parameters
day, month, year (integers, optional) – The integers specifying the latest day (in localtime) that a node should have been accessed to be kept. If not given, the current date is used.
warn (boolean, optional) – If true, echoes warning messages for all directory removed
- class nipype.caching.memory.PipeFunc(interface, base_dir, callback=None)¶
Bases:
object
Callable interface to nipype.interface objects
Use this to wrap nipype.interface object and call them specifying their input with keyword arguments:
fsl_merge = PipeFunc(fsl.Merge, base_dir='.') out = fsl_merge(in_files=files, dimension='t')
- nipype.caching.memory.read_log(filename, run_dict=None)¶
- nipype.caching.memory.rm_all_but(base_dir, dirs_to_keep, warn=False)¶
Remove all the sub-directories of base_dir, but those listed
- Parameters
base_dir (string) – The base directory
dirs_to_keep (set) – The names of the directories to keep