Welcome to pndni_utils’s documentation!

Installation

Python tools

  1. download source git clone https://github.com/pndni/pndni_utils.git
  2. pip install -e pndni_utils (Note, if you’re not using a virtual environment, you will probably need to use pip install --user -e pndni_utils)

Bash tools

  1. download source git clone https://github.com/pndni/pndni_utils.git
  2. export PATH=$PATH:$PWD/pndni_utils/bin (or add this command to your .bashrc to make persistent, with $PWD expanded appropriately)

Command Line Utilities

allequal

Compare two images after lining them up in world coordinates. May be used to compare images with different data layouts, or where one is a cropped version of the other (so long as the image orientations in world coordinates are consistent).

usage: allequal [-h] [--close | --round] [--intersection_only]
                [--round_offset] [--normalize] [--verbose]
                image1 image2

Positional Arguments

image1 Filename of first image to be compared
image2 Filename of first image to be compared

Named Arguments

--close

Use numpy.allclose instead of checking for strict equality.

Default: False

--round

Round each image to the nearest int before comparing.

Default: False

--intersection_only
 

Only compare data where the images overlap in world coordinates

Default: False

--round_offset

If the images are not offset by an integer amount, this flag rounds the offset value. This can help if the calculated offset is a non-integer due to rounding errors.

Default: False

--normalize

Remap images to the range 0-1 before comparing. Only valid for floating point images (otherwise raises error).

Default: False

--verbose Default: False

combined_dirs.sh

combine_dirs.sh combines multiple directories. If multiple files of the same name exist, combine_dirs.sh ensures that they are equal or returns with status 1

Example

Say we have a folder organized as:

.
├── out-1
│   ├── info.txt
│   └── sub-1
│       └── result.txt
├── out-2
│   ├── info.txt
│   └── sub-2
│       └── result.txt
└── out-3
    ├── info.txt
    └── sub-3
        └── result.txt

where all the info.txt are identical. Running

mkdir combined
combine_dirs combined out*/*

results in:

.
├── combined
│   ├── info.txt
│   ├── sub-1
│   │   └── result.txt
│   ├── sub-2
│   │   └── result.txt
│   └── sub-3
│       └── result.txt
├── out-1
│   ├── info.txt
│   └── sub-1
│       └── result.txt
├── out-2
│   ├── info.txt
│   └── sub-2
│       └── result.txt
└── out-3
    ├── info.txt
    └── sub-3
        └── result.txt

combinelabels

Combine multiple label files into one, where output labels are the intersection of the input labels. For example, if labelfile1.nii and labelfile2.nii have the following labels:

labelfile1.nii label name Value
Grey matter 1
White matter 2
labelfile2.nii label name Value
Left hemisphere 1
Right hemisphere 2

the command

combinelabels out.nii labelfile1.nii labelfile2.nii

will result in

out.nii label name Value
Grey matter + left hemi. 1
White matter + left hemi. 2
Grey matter + right hemi. 3
White matter + right hemi. 4

A value of 0 in any label file will result in 0 in the output.

More than two label files may be used. For example

combinelabels out.nii labelfile1.nii labelfile2.nii labelfile3.nii

is equivalent to

combinelabels tmp.nii labelfile1.nii labelfile2.nii
combinelabels out.nii tmp.nii labelfile3.nii

usage: combinelabels [-h] output_file input_files [input_files ...]

Positional Arguments

output_file Output file name
input_files input label files. each image must be of integer values >= 0

create_readme

Creates a starting point readme file. Calling create_readme file1 file2 file3 will write the following to stdout

Name:
Dataset:
Authors:
PI:
Description:
Scripts:
  -name: file1
   desc:
   md5sum: FILE1_MD5
  -name: file2
   desc:
   md5sum: FILE2_MD5
  -name: file3
   desc:
   md5sum: FILE3_MD5
Outputs:
Server:
Notes:

convertpoints

Convert a points file to a different format

usage: convertpoints [-h] infile outfile

Positional Arguments

infile

Input file. Format determined by extension. May be

a TSV file with (extension .tsv) “x”, “y”, “z”, and “index” columns (of types float, float, float, and int, respectively). All other columns will be ignored. Coordinates are in RAS.

A CSV file (extension .csv) with “x”, “y”, “z”, and “index” columns (of types float, float, float, and int, respectively). All other columns will be ignored. Coordinates are in LPS.

A minc tag file (extension .tag). In this case, we assume each point has 7 parameters, and that the text label is quoted. Therefore it is more restrictive than the linked specification. All information besides x, y, z, and label are ignored. Coordinates are in RAS.

A slicer fiducial file (extension .fcsv’) Containing only the columns id, x, y, z, label (int, float, float, float, and int, respectively). Id is ignored. Coordinates are in RAS.

outfile Output file. Format determined by extension. See infile.

flattenhtml

Convert an html file with dependent png images into a flat file (i.e., embed those images into the html file). Currently only png images are supported, and any other image format will cause an error.

flattenhtml input.html > output.html

usage: flattenhtml [-h] input_file

Positional Arguments

input_file Input html file.

forceqform

usage: forceqform [-h] [--maxangle MAXANGLE] input_file output_file

Positional Arguments

input_file Input file
output_file Output file

Named Arguments

--maxangle

The maximum permissible angle (in radians) that the differences in the coordinate axes are permitted to deviate from 90 degres. In other words limits the shearing in the input affine (The qform cannot encode shear.

Default: 1e-06

fscombine

Combine FreeSurfer files extracted with freesurfer’s asegstats2table and aparcstats2table

usage: fscombine [-h] inputs [inputs ...] output

Positional Arguments

inputs input files generated with aparcstats2table or asegstats2table
output output file

labels2probmaps

Create probability maps from a list of segmented files.

usage: labels2probmaps [-h] [--labels [LABELS [LABELS ...]]] [--bids_labels]
                       [--show_bids_labels]
                       out_template input_file [input_file ...]

Positional Arguments

out_template Template for output files. Must contain “{label}”, which will be replaced with the label index for that probability map (or an anatomical label if –bids_labels is used).
input_file List of input files. Must be integer images with values >= 0.

Named Arguments

--labels Calculate probability maps for these labels. If not specified, use all labels
--bids_labels

Assume label numbers correspond to the standard anatomical labels in BEP011. use “labels2probmap –show_bids_labels” for a list.

Default: False

--show_bids_labels
 

show the standard bids labels from BEP011.

Default: False

minc_default_dircos

If direction_cosines for xpsace, yspace, and zspace are not set, set them to the default values.

usage: minc_default_dircos [-h] in_file out_file

Positional Arguments

in_file Input minc2.0 file
out_file Output minc2.0 file

minc_force_regular_spacing

If xspace, yspace, and/or zspace is set to irregular spacing, check that the actually spacing is close enough to nominal (“step”), and if so set the “spacing” parameter to regular.

usage: minc_force_regular_spacing [-h] [--atol ATOL] [--rtol RTOL]
                                  in_file out_file

Positional Arguments

in_file Input minc file
out_file Output minc file

Named Arguments

--atol

passed to numpy.allclose when comparing spacing to nominal

Default: 1e-08

--rtol

passed to numpy.allclose when comparing spacing to nominal

Default: 1e-05

mnclabel2niilabel

Converts a minc file to a nifti file using mnc2nii, then rounds all the data to the nearest integer and converts the nifti file to an unsigned integer type. Checks that all the values are within 0.1 of the nearest integer.

usage: mnclabel2niilabel [-h] input_file output_file

Positional Arguments

input_file
output_file

niftiheader

Output the nifti header using hexdump

stats

Behaves like fslstats, but with different statistics.

usage: stats [-h] [-K [K]] [-m] [-s] [--skew] [--kurtosis] [--median] input

Positional Arguments

input Input image (nii or nii.gz)

Named Arguments

-K Label mask
-m Mean
-s Standard deviation
--skew
--kurtosis
--median

swaplabels

Swap/remap labels in an image. For example, to change all the values of 2 in the image to 1 and all the values of 5 to 10

swaplabels "2: 1, 5: 10" input.nii output.nii

Any unspecified value will be set to 0.

usage: swaplabels [-h] map input output

Positional Arguments

map Mapping string of the form ‘inval1: outval1, inval2: outval2, …’ All values must be integers.
input
output