pipeline helpers

The helpers module includes convenience utilities.


exception qipipe.helpers.bolus_arrival.BolusArrivalError

Bases: exceptions.Exception

Error calculating the bolus arrival.


Determines the DCE bolus arrival time point index. The bolus arrival is the first occurence of a difference in average signal larger than double the difference from first two points.

Parameters:time_series – the 4D NIfTI scan image file path
Returns:the bolus arrival time point index
Raises:BolusArrivalError – if the bolus arrival could not be determined



Command qipipe command options.


Configure the logger for the qi* modules.


qipipe.helpers.constants.CONF_DIR = '/home/docs/checkouts/'

The common configuration directory.

qipipe.helpers.constants.MASK_FILE = 'mask.nii.gz'

The XNAT mask file name with extension.

qipipe.helpers.constants.MASK_RESOURCE = 'mask'

The XNAT mask resource name.

qipipe.helpers.constants.SCAN_TS_BASE = 'scan_ts'

The XNAT scan time series file base name without extension.

qipipe.helpers.constants.SCAN_TS_FILE = 'scan_ts.nii.gz'

The XNAT scan time series file name with extension.

qipipe.helpers.constants.SESSION_FMT = 'Session%02d'

The XNAT session name format with argument session number.

qipipe.helpers.constants.SUBJECT_FMT = '%s%03d'

The XNAT subject name format with argument collection and subject number.

qipipe.helpers.constants.VOLUME_DIR_PAT = <_sre.SRE_Pattern object>

The volume directory name pattern. The directory name is volume``*number*, where *number* is the zero-padded, one-based volume number matched as the ``volume_number group, as determined by the qipipe.pipeline.staging.volume_format() function.

qipipe.helpers.constants.VOLUME_FILE_PAT = <_sre.SRE_Pattern object>

The volume file name pattern. The image file name is the VOLUME_DIR_PAT pattern followed by the extension .nii.gz.


qipipe.helpers.distributable.DISTRIBUTABLE = False

Flag indicating whether the workflow can be distributed over a cluster. This flag is True if qsub is in the execution path, False otherwise.


qipipe.helpers.image.discretize(in_file, out_file, nvalues, start=0, threshold=None, normalizer=<function normalize>)

Transforms the given input image file to an integer range with the given number of values. The range starts at the given start value. The input values are uniformly mapped into the output range. For example, if the input values range from 0.0 to 3.0 nvalues is 101, and the start is 0, then an input value of 0 is transformed to 0, 3.0 is transformed to 100, and the intermediate input values are proportionately transformed to the output range.

If a threshold is specified, then every input value which maps to an output value less than (threshold * nvalues) - start is transformed to the output start value. For example, if the input values range from 0.0 to 3.0, then:

discretize(in_file, out_file, 1001, threshold=0.5)

transforms input values as follows:

  • If the input value maps to the first half of the output range, then the output value is 0.
  • Otherwise, the input value v maps to the output value (v * 1000) / 3.
  • in_file – the input file path
  • out_file – the output file path
  • nvalues – the number of output entries
  • start – the starting output value (default 0)
  • threshold – the threshold in the range start to nvalues (default start)
  • normalize – an optional function to normalize the input value (default normalize())

IndexError – if the threshold is not in the color range

qipipe.helpers.image.normalize(value, vmin, vspan)

Maps the given input value to [0, 1].

  • value – the input value
  • vmin – the minimum input range value
  • vspan – the value range span (maxium - minimum)

(in_val - vmin) / vspan


qipipe.helpers.logging.NIPYPE_LOG_DIR_ENV_VAR = 'NIPYPE_LOG_DIR'

The environment variable used by Nipype to set the log directory.


Configures the logger as follows:

  • If there is a log option, then the logger is a conventional qiutil.logging logger which writes to the given log file.
  • Otherwise, the logger delegates to a mock logger that writes to stdout.


In a cluster environment, Nipype kills the dispatched job log config. Logging falls back to the default. For this reason, the default mock logger level is DEBUG rather than INFO. The dispatched node’s log is the stdout captured in the file work/batch/node_name.onode_id, where work the execution work directory.

Parameters:opts – the qiutil.command.configure_log options
Returns:the logger factory

This method overrides qiutil.logging.logger to work around the following Nipype bug:

  • Nipype stomps on any other application’s logging. The work-around is to mock a “logger” that writes to stdout.
Parameters:name – the caller’s context __name__
Returns:the logger facade


qipipe.helpers.metadata.EXCLUDED_OPTS = set(['plugin_args', 'run_without_submitting'])

The config options to exclude in the profile.

exception qipipe.helpers.metadata.MetadataError

Bases: exceptions.Exception

Metadata parsing error.

qipipe.helpers.metadata.create_profile(configuration, sections, dest, **opts)

Creates a metadata profile from the given configuration. The configuration input is a {section: {option: value}} dictionary. The target profile is a Python configuration file which includes the given sections. The section content is determined by the input configuration and the keyword arguments. The keyword item overrides a matching input configuration item. The resulting profile is written to a new file.

  • configuration – the configuration dictionary
  • sections – the target profile sections
  • dest – the target profile file location
  • opts – additional {section: {option: value}} items

the target file location