Home · Quickstart · User Guide and Examples · Interfaces Index · Developers · About · Nipy

# nipype.utils.misc module

Miscellaneous utility functions

nipype.utils.misc.container_to_string(cont)

  Convert a container to a command line string.

  Elements of the container are joined with a space between them, suitable for a command line parameter.

  If the container cont is only a sequence, like a string and not a container, it is returned unmodified.

  Parameters:

    cont (container) – A container object like a list, tuple, dict, or a set.

  Returns:

    cont_str – Container elements joined into a string.

  Return type:

    string

nipype.utils.misc.dict_diff(dold, dnew, indent=0)

  Helper to log what actually changed from old to new values of dictionaries.

  typical use – log difference for hashed_inputs

nipype.utils.misc.find_indices(condition)

  Return the indices where ravel(condition) is true

nipype.utils.misc.flatten(S)

nipype.utils.misc.human_order_sorted(l)

  Sorts string in human order (i.e. ‘stat10’ will go after ‘stat2’)

nipype.utils.misc.is_container(item)

  Checks if item is a container (list, tuple, dict, set)

  Parameters:

    item (object) – object to check for .__iter__

  Returns:

    output – True if container False if not (eg string)

  Return type:

    Boolean

nipype.utils.misc.normalize_mc_params(params, source)

  Normalize a single row of motion parameters to the SPM format.

  SPM saves motion parameters as:

    x Right-Left (mm) y Anterior-Posterior (mm) z Superior-Inferior (mm) rx Pitch (rad) ry Roll (rad) rz Yaw (rad)

nipype.utils.misc.package_check(pkg_name, version=None, app=None, checker=<class 'looseversion.LooseVersion'>, exc_failed_import=<class 'ImportError'>, exc_failed_check=<class 'RuntimeError'>)

  Check that the minimal version of the required package is installed.

  Parameters:

    - pkg_name (string) – Name of the required package.

    - version (string, optional) – Minimal version number for required package.

    - app (string, optional) – Application that is performing the check. For instance, the name of the tutorial being executed that depends on specific packages. Default is Nipype.

    - checker (object, optional) – The class that will perform the version checking. Default is nipype.external.version.LooseVersion.

    - exc_failed_import (Exception, optional) – Class of the exception to be thrown if import failed.

    - exc_failed_check (Exception, optional) – Class of the exception to be thrown if version check failed.

  Examples

  package_check(‘numpy’, ‘1.3’) package_check(‘scipy’, ‘0.7’, ‘tutorial1’)

nipype.utils.misc.rgetcwd(error=True)

  Robust replacement for getcwd when folders get removed If error==True, this is just an alias for os.getcwd()

nipype.utils.misc.str2bool(v)

  Convert strings (and bytearrays) to boolean values

      >>> all([str2bool(v) for v in (True, "yes", "true",
      ...      "y", "t", "Yes", "True", "1", "on", "On")])
      True
      >>> all([str2bool(v.encode('utf-8'))
      ...      for v in ("yes", "true", "y", "t", "1", "Yes", "on", "On")])
      True
      >>> any([str2bool(v) for v in (False, "no", "false", "n", "f",
      ...      "False", "0", "off", "Off")])
      False
      >>> any([str2bool(v.encode('utf-8'))
      ...      for v in ("no", "false", "n", "f", "0", "off", "Off")])
      False
      >>> str2bool(None)
      Traceback (most recent call last):
          ...
      ValueError: ...
      >>> str2bool('/some/path')
      Traceback (most recent call last):
          ...
      ValueError: ...
      >>> str2bool('Agg')
      Traceback (most recent call last):
          ...
      ValueError: ...
      >>> str2bool('INFO')
      Traceback (most recent call last):
          ...
      ValueError: ...
      >>> str2bool('/some/bytes/path'.encode('utf-8'))
      Traceback (most recent call last):
          ...
      ValueError: ...

nipype.utils.misc.trim(docstring, marker=None)

nipype.utils.misc.unflatten(in_list, prev_structure)