xcp_d.utils.plotting module

Plotting tools.

class xcp_d.utils.plotting.FMRIPlot(func_file, mask_file=None, data=None, confound_file=None, seg_file=None, TR=None, usecols=None, units=None, vlines=None, spikes_files=None)[source]

Bases: object

Generates the fMRI Summary Plot.

Parameters:
  • func_file

  • mask_file

  • data

  • confound_file

  • seg_file

  • TR (float) – Repetition time of the BOLD run, in seconds.

  • usecols

  • units

  • vlines

  • spikes_files

TR
confounds
func_file
mask_data
plot(labelsize, figure=None)[source]

Perform main plotting step.

seg_data
spikes
xcp_d.utils.plotting.plot_alff_reho_surface(output_path, filename, name_source)[source]

Plot ReHo and ALFF for ciftis on surface.

NOTE: This is a Node function.

Parameters:
  • output_path (str) – path to save plot

  • filename (str) – surface file

  • name_source (str) – original input bold file

Returns:

output_path – path to plot

Return type:

str

xcp_d.utils.plotting.plot_alff_reho_volumetric(output_path, filename, name_source)[source]

Plot ReHo and ALFF mosaics for niftis.

NOTE: This is a Node function.

Parameters:
  • output_path (str) – path to save plot

  • filename (str) – surface file

  • name_source (str) – original input bold file

Returns:

output_path – path to plot

Return type:

str

xcp_d.utils.plotting.plot_carpet(func, atlaslabels=None, detrend=True, size=(950, 800), labelsize=30, subplot=None, output_file=None, legend=True, TR=None, lut=None, colorbar=False)[source]

Plot an image representation of voxel intensities across time.

This is also known as the “carpet plot” or “Power plot”. See Jonathan Power Neuroimage 2017 Jul 1; 154:150-158.

Parameters:
  • func (str) – Path to NIfTI or CIFTI BOLD image

  • atlaslabels (numpy.ndarray, optional) – A 3D array of integer labels from an atlas, resampled into img space. Required if func is a NIfTI image. Unused if func is a CIFTI.

  • detrend (bool, optional) – Detrend and standardize the data prior to plotting.

  • size (tuple, optional) – Size of figure.

  • labelsize (int, optional)

  • subplot (matplotlib Subplot, optional) – Subplot to plot figure on.

  • output_file (str or None, optional) – The name of an image file to export the plot to. Valid extensions are .png, .pdf, .svg. If output_file is not None, the plot is saved to a file, and the display is closed.

  • legend (bool) – Whether to render the average functional series with atlaslabels as overlay.

  • TR (float, optional) – Specify the TR, if specified it uses this value. If left as None, # of frames is plotted instead of time.

  • lut (numpy.ndarray, optional) – Look up table for segmentations

  • colorbar (bool, optional) – Default is False.

xcp_d.utils.plotting.plot_confounds(time_series, grid_spec_ts, gs_dist=None, name=None, units=None, TR=None, hide_x=True, color='b', cutoff=None, ylims=None)[source]

Create a time series plot for confounds.

Adapted from niworkflows.

Parameters:
  • time_series (numpy.ndarray) – Time series to plot in the figure.

  • grid_spec_ts (GridSpec) – The GridSpec object in which the time series plot will be stored.

  • name – file name

  • units – time_series unit

  • TR (float or None, optional) – Repetition time for the time series. Default is None.

Returns:

  • time_series_axis

  • grid_specification

xcp_d.utils.plotting.plot_design_matrix(design_matrix, temporal_mask=None)[source]

Plot design matrix TSV with Nilearn.

NOTE: This is a Node function.

Parameters:
  • design_matrix (str) – Path to TSV file containing the design matrix.

  • temporal_mask (str, optional) – Path to TSV file containing a list of volumes to censor.

Returns:

design_matrix_figure – Path to SVG figure file.

Return type:

str

xcp_d.utils.plotting.plot_dvars_es(time_series, ax, run_index=None)[source]

Create DVARS plot for the executive summary.

xcp_d.utils.plotting.plot_fmri_es(preprocessed_bold, uncensored_denoised_bold, interpolated_filtered_bold, TR, filtered_motion, preprocessed_bold_figure, denoised_bold_figure, standardize, mask=None, seg_data=None, run_index=None)[source]

Generate carpet plot with DVARS, FD, and WB for the executive summary.

Parameters:
  • preprocessed_bold (str) – Preprocessed BOLD file, dummy scan removal.

  • uncensored_denoised_bold (str) – Path to the uncensored, denoised BOLD file. This file is the result of denoising the full (uncensored) preprocessed BOLD data using betas estimated using the censored BOLD data and nuisance regressors.

    This output should not be used for analysis. It is primarily used for DCAN QC plots.

  • interpolated_filtered_bold (str) – Path to the censored, denoised, interpolated, and filtered BOLD file. This file is the result of denoising the censored preprocessed BOLD data, followed by cubic spline interpolation and band-pass filtering.

    This output should not be used for analysis. It is primarily for DCAN QC plots.

  • TR (float) – Repetition time of the BOLD run, in seconds.

  • filtered_motion (str) – Framewise displacement timeseries, potentially after bandstop or low-pass filtering. This is a TSV file with one column: ‘framewise_displacement’.

  • preprocessed_bold_figure (str) – output file svg before processing

  • denoised_bold_figure (str) – output file svg after processing

  • standardize (bool) – Whether to standardize the data or not. If False, then the preferred DCAN version of the plot will be generated, where the BOLD data are not rescaled, and the carpet plot has color limits of -600 and 600. If True, then the BOLD data will be z-scored and the color limits will be -2 and 2.

  • mask (str, optional) – Brain mask file. Used only when the pre- and post-processed BOLD data are NIFTIs.

  • seg_data (str, optional) – Three-tissue segmentation file. This is only used for NIFTI inputs. With CIFTI inputs, the tissue types are inferred directly from the CIFTI file.

  • run_index (None or array_like, optional) – An index indicating splits between runs, for concatenated data. If not None, this should be an array/list of integers, indicating the volumes.

xcp_d.utils.plotting.plot_framewise_displacement_es(time_series, ax, TR, run_index=None)[source]

Create framewise displacement plot for the executive summary.

xcp_d.utils.plotting.plot_global_signal_es(time_series, ax, run_index=None)[source]

Create global signal plot for the executive summary.

xcp_d.utils.plotting.surf_data_from_cifti(data, axis, surf_name)[source]

From https://neurostars.org/t/separate-cifti-by-structure-in-python/17301/2.

https://nbviewer.org/github/neurohackademy/nh2020-curriculum/blob/master/ we-nibabel-markiewicz/NiBabel.ipynb