pylib.brains package

Submodules

pylib.brains.stats module

class pylib.brains.stats.SliceRow(num, mean, std, snr)

Bases: tuple

mean

Alias for field number 1

num

Alias for field number 0

snr

Alias for field number 3

std

Alias for field number 2

class pylib.brains.stats.SliceStats(summary, mean, std, snr)

Bases: tuple

mean

Alias for field number 1

snr

Alias for field number 3

std

Alias for field number 2

summary

Alias for field number 0

class pylib.brains.stats.VoxelStats(mean_dat, std_dat, snr_dat, snr)

Bases: tuple

mean_dat

Alias for field number 0

snr

Alias for field number 3

snr_dat

Alias for field number 2

std_dat

Alias for field number 1

pylib.brains.stats.slice_based_stats(dat, mask)

Compute slice-based statistics

Parameters:
  • dat (numpy.array) – Data matrix
  • mask (numpy.array) – Binary mask
Returns:

Tuple of [‘summary’, ‘mean’, ‘std’, ‘snr’]

Return type:

collections.namedtuple

pylib.brains.stats.voxel_based_stats(dat, mask)

Compute voxel-based statistics

Parameters:
  • dat (numpy.array) – Data matrix
  • mask (numpy.array) – Binary mask
Returns:

Tuple of [‘mean_dat’, ‘std_dat’, ‘snr_dat’, ‘snr’]

Return type:

collections.namedtuple

Module contents

class pylib.brains.DcmFile(meta, file)

Bases: tuple

DICOM file container. Contains fields for metadata (header data) and a file location.

file

Alias for field number 1

meta

Alias for field number 0

exception pylib.brains.DuplicateDicomError

Bases: exceptions.Exception

class pylib.brains.Fmt(ext, type)

Bases: tuple

File format container. Contains fields for the file extension and file type.

ext

Alias for field number 0

type

Alias for field number 1

class pylib.brains.Format

Bases: object

Convenience class to store file extensions and FSL output types together.

Note

If you pass an instance of Format.Fmt to a Nipype Funtion interface, it will be cast down to a regular tuple.

Example usage::
>>> from pylib.brains import Format
>>> Format.NIFTI.ext, Format.NIFTI.type
('nii', 'NIFTI')
ANALYZE = Fmt(ext='.img', type='ANALYZE')
DICOM = Fmt(ext='.dcm', type='DICOM')
NIFTI = Fmt(ext='nii', type='NIFTI')
NIFTI_GZ = Fmt(ext='nii.gz', type='NIFTI_GZ')
pylib.brains.fcfast(sid, tr, anatscan, boldscans, roi, clean, rawdir, kernel, outdir, launcher=<function local>)

Run fcfast command

Example usage::
>>> from pylib.brains import fcfast
>>> fcfast(sid, tr, anatscan, boldscans, roi, clean, rawdir, kernel, outdir)
Parameters:
  • sid (str) – MR Session ID
  • anatscan (int) – ANAT scan number
  • boldscans (list) – BOLD scan numbers
  • roi (str) – Functional connectivity ROI
  • stackcheck (bool) – Run stackcheck QA script
  • clean (bool) – Remove intermediate files
  • rawdir (str) – Raw data directory
  • kernel (float) – Smoothing kernel (mm)
  • outdir (str) – Output directory
  • launcher (function) – Job launcher e.g., pylib.fun.local
pylib.brains.morphometry(raw_dir, raw_type, out_dir, launcher, scratch_dir=None, args=None)

Run morphometry.py command.

Example usage::
>>> from pylib.brains import morphometry
>>> morphometry(raw_dir, raw_type, out_dir)
Parameters:
  • raw_dir (str) – Raw data directory
  • raw_type (str) – Type of raw data e.g., nifti, dicom
  • out_dir (str) – Output directory
  • launcher (function) – Launcher
  • scratch_dir (str) – Path to scratch directory
  • args (str) – Additional recon-all arguments
pylib.brains.orient(f, orientation)

Reorient a NIfTI file.

Warning

This function modifies the file in-place

Parameters:
  • f (str) – File name
  • orientation (list) – Orientation to force
pylib.brains.procsurffast(fsdir, session, anatscan, boldscans, lh_roi, rh_roi, outdir, volproj=False, volproj_lowmem=False, launcher=<function local>)

Run procsurffast.csh command.

Example usage::
>>> from pylib.brains import procsurffast
>>> procsurffast(fsdir, session, anatscan, boldscans, lh_roi, rh_roi, outdir)
Parameters:
  • fsdir (str) – FreeSurfer output directory
  • session (str) – MR Session label
  • anatscan (int) – ANAT scan number
  • boldscans (list) – BOLD scan numbers
  • lh_roi (str) – Path to left hemisphere ROI
  • rh_roi (str) – Path to right hemisphere ROI
  • outdir (str) – Output directory
  • volproj (bool) – Volume projection
  • volproj_lowmem (bool) – Volume projection low memory support
  • launcher (function) – Job launcher e.g., pylib.fun.local
pylib.brains.search_dicoms(d, recursive=True, store_meta=True)

Search for DICOM files within a given directory and receive a dictionary of {StudyInstanceUID: {SeriesNumber: [files]}}

Example usage::
>>> from pylib.brains import search_dicoms
>>> search_dicoms("~/dicoms").keys()
['1.2.340.500067.8.9.10.11012.13000001401516017181900000200']
Parameters:
  • d (str) – Directory name
  • recursive (bool) – Search recursively
  • store_meta (bool) – Read and store metadata for each file for fast lookup
Returns:

Dictionary of {StudyInstanceUID: {SeriesNumber: [files]}}

Return type:

dict

pylib.brains.swapdim(f, rule)

Swap dimensions of NIFTI file and outputs a second file with “_reorient” appended.

Parameters:
  • f (str) – File name
  • rule (list) – Dimension swap rules e.g., [“-x”, “y”, “z”]
Returns:

Output file base

Return type:

str