caching.memory

Module: caching.memory

Inheritance diagram for nipype.caching.memory:

Inheritance diagram of nipype.caching.memory

Using nipype with persistence and lazy recomputation but without explicit name-steps pipeline: getting back scope in command-line based programming.

Change directory to provide relative paths for doctests >>> import os >>> filepath = os.path.dirname( os.path.realpath( __file__ ) ) >>> datadir = os.path.realpath(os.path.join(filepath, ‘../testing/data’)) >>> os.chdir(datadir)

Classes

Memory

class nipype.caching.memory.Memory(base_dir)

Bases: future.types.newobject.newobject

Memory context to provide caching for interfaces

Parameters:

base_dir: string :

The directory name of the location for the caching

Methods

cache(interface) Returns a callable that caches the output of an interface
clear_previous_runs([warn]) Remove all the cache that where not used in the latest run of the memory object: i.e.
clear_previous_runs([warn]) Remove all the cache that where not used in the latest run of the memory object: i.e.
__init__(base_dir)
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: a PipeFunc callable object :

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.

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

next()

PipeFunc

class nipype.caching.memory.PipeFunc(interface, base_dir, callback=None)

Bases: future.types.newobject.newobject

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')

Methods

__call__(**kwargs)
next()
__init__(interface, base_dir, callback=None)
Parameters:

interface: a nipype interface class :

The interface class to wrap

base_dir: a string :

The directory in which the computation will be stored

callback: a callable :

An optional callable called each time after the function is called.

next()

Functions

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