brainsmash.utils package

Submodules

brainsmash.utils.checks module

brainsmash.utils.checks.check_extensions(filename, exts)

Test filename for a set of file extensions.

Parameters
  • filename (str) – Path to file

  • exts (List[str]) – List of allowed file extensions for filename

Returns

True if filename’s extensions is in exts

Return type

bool

:raises TypeError : filename is not string-like:

brainsmash.utils.checks.check_outfile(filename)

Warn if file exists and throw error if parent directory does not exist.

Parameters

filename (filename) – File to be written

Returns

Return type

None

:raises IOError : Parent directory of filename does not exist: :raises ValueError : directory was provided instead of file:

brainsmash.utils.checks.check_pv(pv)

Check input argument pv.

Parameters

pv (int) – Percentile of the pairwise distance distribution at which to truncate during variogram fitting.

Returns

Return type

int

:raises ValueError : pv lies outside range (0, 100]:

brainsmash.utils.checks.check_deltas(deltas)

Check input argument deltas.

Parameters

deltas (np.ndarray or List[float]) – Proportions of neighbors to include for smoothing, in (0, 1]

Returns

Return type

None

:raises TypeError : deltas is not a List or np.ndarray object: :raises ValueError : One or more elements of deltas lies outside (0,1]:

brainsmash.utils.checks.check_map(x)

Check that brain map conforms to expectations.

Parameters

x (np.ndarray) – Brain map

Returns

Return type

None

:raises TypeError : x is not a np.ndarray object: :raises ValueError : x is not one-dimensional:

brainsmash.utils.checks.check_distmat(D)

Check that a distance matrix conforms to expectations.

Parameters

D ((N,N) np.ndarray) – Pairwise distance matrix

Returns

Return type

None

:raises ValueError : D is not symmetric:

brainsmash.utils.checks.check_file_exists(f)

Check that file exists and has nonzero size.

Parameters

f (filename) –

Returns

Return type

None

:raises IOError : file does not exist or has zero size:

brainsmash.utils.checks.check_sampled(D, index)

Check arguments provided to brainsmash.mapgen.sampled.Sampled.

Parameters
Returns

Return type

None

:raises ValueError : Arguments do not have identical dimensions: :raises ValueError : D has not been sorted column-wise: :raises TypeError : rows of D or index are not sorted (ascending):

brainsmash.utils.checks.is_string_like(obj)

Check whether obj behaves like a string.

brainsmash.utils.checks.count_lines(filename)

Count number of lines in a file.

Parameters

filename (filename) –

Returns

number of lines in file

Return type

int

brainsmash.utils.checks.stripext(f)

Strip extension from a file.

Parameters

f (filename) – Path to file with extension

Returns

objective – Path to file without extension

Return type

filename

brainsmash.utils.dataio module

brainsmash.utils.dataio.dataio(x)

Data I/O for core classes.

To facilitate flexible user inputs, this function loads data from:
  • neuroimaging files

  • txt files

  • npy files (memory-mapped arrays)

  • array_like data

Parameters

x (filename or np.ndarray or np.memmap) –

Returns

Return type

np.ndarray or np.memmap

:raises FileExistsError : file does not exist: :raises RuntimeError : file is empty: :raises ValueError : file type cannot be determined or is not implemented: :raises TypeError : input is not a filename or array_like object:

brainsmash.utils.dataio.export_cifti_mapping(image=None)

Compute the map from CIFTI indices to surface vertices and volume voxels.

Parameters

image (filename or None, default None) – Path to NIFTI-2 format (.nii) neuroimaging file. The metadata from this file is used to determine the CIFTI indices and voxel coordinates of elements in the image. This file must include all subcortical volumes and both cortical hemispheres.

Returns

maps – A dictionary containing the maps between CIFTI indices, surface vertices, and volume voxels. Keys include ‘cortex_left’, ‘cortex_right’, and ‘volume’.

Return type

dict

Notes

image must be a whole-brain NIFTI file for this function to work as-written. See the Workbench documentation here for more details: https://www.humanconnectome.org/software/workbench-command/-cifti-export-dense-mapping.

brainsmash.utils.dataio.load(filename)

Load data contained in a CIFTI2-/GIFTI-format neuroimaging file.

Parameters

filename (filename) – Path to neuroimaging file

Returns

Brain map data stored in filename

Return type

(N,) np.ndarray

:raises TypeError : filename has unknown filetype:

Module contents