Class for reading AFNI BRIK/HEAD datasets
See https://afni.nimh.nih.gov/pub/dist/doc/program_help/README.attributes.html for information on what is required to have a valid BRIK/HEAD dataset.
Unless otherwise noted, descriptions AFNI attributes in the code refer to this document.
In the AFNI HEAD file, the first two values of the attribute DATASET_RANK determine the shape of the data array stored in the corresponding BRIK file. The first value, DATASET_RANK[0], must be set to 3 denoting a 3D image. The second value, DATASET_RANK[1], determines how many “sub-bricks” (in AFNI parlance) / volumes there are along the fourth (traditionally, but not exclusively) time axis. Thus, DATASET_RANK[1] will (at least as far as I (RM) am aware) always be >= 1. This permits sub-brick indexing common in AFNI programs (e.g., example4d+orig’[0]’).
AFNIArrayProxy(*args, **kwargs) | Proxy object for AFNI image array. |
AFNIHeader(info) | Class for AFNI header |
AFNIHeaderError | Error when reading AFNI HEAD file |
AFNIImage(dataobj, affine[, header, extra, ...]) | AFNI Image file |
AFNIImageError | Error when reading AFNI BRIK files |
parse_AFNI_header(fobj) | Parses fobj to extract information from HEAD file |
Bases: nibabel.arrayproxy.ArrayProxy
Proxy object for AFNI image array.
Attributes
scaling |
Initialize AFNI array proxy
Parameters: | file_like : file-like object
header : AFNIHeader object mmap : {True, False, ‘c’, ‘r’}, optional, keyword only
keep_file_open : { None, ‘auto’, True, False }, optional, keyword only
|
---|
Initialize AFNI array proxy
Parameters: | file_like : file-like object
header : AFNIHeader object mmap : {True, False, ‘c’, ‘r’}, optional, keyword only
keep_file_open : { None, ‘auto’, True, False }, optional, keyword only
|
---|
Bases: nibabel.spatialimages.SpatialHeader
Class for AFNI header
Initialize AFNI header object
Parameters: | info : dict
|
---|
Examples
>>> fname = os.path.join(datadir, 'example4d+orig.HEAD')
>>> header = AFNIHeader(parse_AFNI_header(fname))
>>> header.get_data_dtype()
dtype('int16')
>>> header.get_zooms()
(3.0, 3.0, 3.0, 3.0)
>>> header.get_data_shape()
(33, 41, 25, 3)
Initialize AFNI header object
Parameters: | info : dict
|
---|
Examples
>>> fname = os.path.join(datadir, 'example4d+orig.HEAD')
>>> header = AFNIHeader(parse_AFNI_header(fname))
>>> header.get_data_dtype()
dtype('int16')
>>> header.get_zooms()
(3.0, 3.0, 3.0, 3.0)
>>> header.get_data_shape()
(33, 41, 25, 3)
Returns affine of dataset
Examples
>>> fname = os.path.join(datadir, 'example4d+orig.HEAD')
>>> header = AFNIHeader(parse_AFNI_header(fname))
>>> header.get_affine()
array([[ -3. , -0. , -0. , 49.5 ],
[ -0. , -3. , -0. , 82.312 ],
[ 0. , 0. , 3. , -52.3511],
[ 0. , 0. , 0. , 1. ]])
Data offset in BRIK file
Offset is always 0.
AFNI applies volume-specific data scaling
Examples
>>> fname = os.path.join(datadir, 'scaled+tlrc.HEAD')
>>> header = AFNIHeader(parse_AFNI_header(fname))
>>> header.get_data_scaling()
array([ 3.88336300e-08])
Use self.get_data_scaling() instead
Holdover because AFNIArrayProxy (inheriting from ArrayProxy) requires this functionality so as to not error.
Return label for anatomical space to which this dataset is aligned.
Returns: | space : str
|
---|
Notes
There appears to be documentation for these spaces at https://afni.nimh.nih.gov/pub/dist/atlases/elsedemo/AFNI_atlas_spaces.niml
Returns volume labels
Returns: | labels : list of str
|
---|
Examples
>>> header = AFNIHeader(parse_AFNI_header(os.path.join(datadir, 'example4d+orig.HEAD')))
>>> header.get_volume_labels()
['#0', '#1', '#2']
Bases: nibabel.spatialimages.HeaderDataError
Error when reading AFNI HEAD file
x.__init__(...) initializes x; see help(type(x)) for signature
Bases: nibabel.spatialimages.SpatialImage
AFNI Image file
Can be loaded from either the BRIK or HEAD file (but MUST specify one!)
Examples
>>> import nibabel as nib
>>> brik = nib.load(os.path.join(datadir, 'example4d+orig.BRIK.gz'))
>>> brik.shape
(33, 41, 25, 3)
>>> brik.affine
array([[ -3. , -0. , -0. , 49.5 ],
[ -0. , -3. , -0. , 82.312 ],
[ 0. , 0. , 3. , -52.3511],
[ 0. , 0. , 0. , 1. ]])
>>> head = load(os.path.join(datadir, 'example4d+orig.HEAD'))
>>> np.array_equal(head.get_data(), brik.get_data())
True
Initialize image
The image is a combination of (array-like, affine matrix, header), with optional metadata in extra, and filename / file-like objects contained in the file_map mapping.
Parameters: | dataobj : object
affine : None or (4,4) array-like
header : None or mapping or header instance, optional
extra : None or mapping, optional
file_map : mapping, optional
|
---|
Initialize image
The image is a combination of (array-like, affine matrix, header), with optional metadata in extra, and filename / file-like objects contained in the file_map mapping.
Parameters: | dataobj : object
affine : None or (4,4) array-like
header : None or mapping or header instance, optional
extra : None or mapping, optional
file_map : mapping, optional
|
---|
alias of AFNIArrayProxy
Make file_map from filename filespec
AFNI BRIK files can be compressed, but HEAD files cannot - see afni.nimh.nih.gov/pub/dist/doc/program_help/README.compression.html. Thus, if you have AFNI files my_image.HEAD and my_image.BRIK.gz and you want to load the AFNI BRIK / HEAD pair, you can specify:
- The HEAD filename - e.g., my_image.HEAD
- The BRIK filename w/o compressed extension - e.g., my_image.BRIK
- The full BRIK filename - e.g., my_image.BRIK.gz
Parameters: | filespec : str
|
---|---|
Returns: | file_map : dict
|
Raises: | ImageFileError :
|
Creates an AFNIImage instance from file_map
Parameters: | file_map : dict
mmap : {True, False, ‘c’, ‘r’}, optional, keyword only
keep_file_open : {None, ‘auto’, True, False}, optional, keyword only
|
---|
Creates an AFNIImage instance from filename
Parameters: | filename : str
mmap : {True, False, ‘c’, ‘r’}, optional, keyword only
keep_file_open : {None, ‘auto’, True, False}, optional, keyword only
|
---|
alias of AFNIHeader
Creates an AFNIImage instance from filename
Parameters: | filename : str
mmap : {True, False, ‘c’, ‘r’}, optional, keyword only
keep_file_open : {None, ‘auto’, True, False}, optional, keyword only
|
---|
Bases: nibabel.spatialimages.ImageDataError
Error when reading AFNI BRIK files
x.__init__(...) initializes x; see help(type(x)) for signature
Parses fobj to extract information from HEAD file
Parameters: | fobj : file-like object
|
---|---|
Returns: | info : dict
|
Examples
>>> fname = os.path.join(datadir, 'example4d+orig.HEAD')
>>> info = parse_AFNI_header(fname)
>>> print(info['BYTEORDER_STRING'])
LSB_FIRST
>>> print(info['BRICK_TYPES'])
[1, 1, 1]