# NiBabel

### Access a cacophony of neuro-imaging file formats

# `nibabel`

Read and write access to common neuroimaging file formats, including: ANALYZE (plain, SPM99, SPM2 and later), GIFTI, NIfTI1, NIfTI2, CIFTI-2, MINC1, MINC2, AFNI BRIK/HEAD, ECAT and Philips PAR/REC. In addition, NiBabel also supports FreeSurfer’s MGH, geometry, annotation and morphometry files, and provides some limited support for DICOM.

NiBabel’s API gives full or selective access to header information (metadata), and image data is made available via NumPy arrays. For more information, see NiBabel’s documentation site and API reference.

## Installation

To install NiBabel’s current release with `pip`, run:

    pip install nibabel

To install the latest development version, run:

    pip install git+https://github.com/nipy/nibabel

When working on NiBabel itself, it may be useful to install in “editable” mode:

    git clone https://github.com/nipy/nibabel.git
    pip install -e ./nibabel

For more information on previous releases, see the release archive or development changelog.

## Testing

During development, we recommend using tox to run nibabel tests:

    git clone https://github.com/nipy/nibabel.git
    cd nibabel
    tox

To test an installed version of nibabel, install the test dependencies and run pytest:

    pip install nibabel[test]
    pytest --pyargs nibabel

For more information, consult the developer guidelines.

## Mailing List

Please send any questions or suggestions to the neuroimaging mailing list.

## License

NiBabel is licensed under the terms of the MIT license. Some code included with NiBabel is licensed under the BSD license. For more information, please see the COPYING file.

## Citation

NiBabel releases have a Zenodo Digital Object Identifier (DOI) badge at the top of the release notes. Click on the badge for more information.

## Quickstart

    import nibabel as nib

    img1 = nib.load('my_file.nii')
    img2 = nib.load('other_file.nii.gz')
    img3 = nib.load('spm_file.img')

    data = img1.get_fdata()
    affine = img1.affine

    print(img1)

    nib.save(img1, 'my_file_copy.nii.gz')

    new_image = nib.Nifti1Image(data, affine)
    nib.save(new_image, 'new_image.nii.gz')

For more detailed information see the NiBabel Manual.

`bench`([label, verbose, extra_argv]) | Run benchmarks for nibabel using pytest
`get_info`() |
`test`([label, verbose, extra_argv, doctests, ...]) | Run tests for nibabel using pytest

## bench

nibabel.bench(label=None, verbose=1, extra_argv=None)

  Run benchmarks for nibabel using pytest

  The protocol mimics the `numpy.testing.NoseTester.bench()`. Not all features are currently implemented.

  Parameters:
    label None

      Unused.

    verbose: int, optional

      Verbosity value for test outputs. Positive values increase verbosity, and negative values decrease it. Default is 1.

    extra_argv list, optional

      List with any extra arguments to pass to pytest.

  Returns:
    code ExitCode

      Returns the result of running the tests as a `pytest.ExitCode` enum

## get_info

nibabel.get_info()

## test

nibabel.test(label=None, verbose=1, extra_argv=None, doctests=False, coverage=False, raise_warnings=None, timer=False)

  Run tests for nibabel using pytest

  The protocol mimics the `numpy.testing.NoseTester.test()`. Not all features are currently implemented.

  Parameters:
    label None

      Unused.

    verbose: int, optional

      Verbosity value for test outputs. Positive values increase verbosity, and negative values decrease it. Default is 1.

    extra_argv list, optional

      List with any extra arguments to pass to pytest.

    doctests: bool, optional

      If True, run doctests in module. Default is False.

    coverage: bool, optional

      If True, report coverage of NumPy code. Default is False. (This requires the coverage module).

    raise_warnings None

      Unused.

    timer False

      Unused.

  Returns:
    code ExitCode

      Returns the result of running the tests as a `pytest.ExitCode` enum