Skip to content

Commit a55e92f

Browse files
committed
Merge remote-tracking branch 'upstream/master' into enh/cifti2
* upstream/master: Update parrec.py NF: add routine to read zero-terminal strings DOC: more typos in BV format doc DOC: more small edits to PAR / REC docstrings DOC: fixes to bv_formats links, text DOC: fix link to VTC format DOC: small fixes to parrec docstring DOC: start of document on BrainVoyager formats MAINT: some git / .gitignore housekeeping Simplify idioms, delete unnecessary 'global' definition. Change idioms for selecting the 2nd output arg. Fix for #324 - use consistent syntax for have_scipy. DOC: more ReST markup edits to get_data docstring DOC: fix ReST markup error in get_data docstring BUG: work round int overflow in size calculation RF: allow extensions to be passed to `exts2pars` ENH: reading PAR headers from NIfTI extensions
2 parents b6fcb50 + 1475594 commit a55e92f

17 files changed

+412
-97
lines changed

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,12 @@
1515
*.tmp
1616
.project
1717
.pydevproject
18+
*.py.orig
1819

19-
# Not sure what the next two are for
20+
# Not sure what the next one is for
2021
*.kpf
22+
23+
# Makefile target file markers
2124
*-stamp
2225

2326
# Compiled source #
@@ -58,6 +61,7 @@ dist/
5861
.shelf
5962
.tox/
6063
.coverage
64+
.ropeproject/
6165

6266
# Logs and databases #
6367
######################

Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,5 +284,8 @@ tox-stale:
284284
refresh-readme:
285285
$(PYTHON) tools/refresh_readme.py
286286

287-
.PHONY: orig-src pylint
287+
rm-orig:
288+
# Remove .orig temporary diff files generated by git
289+
find . -name "*.orig" -print | grep -v "fsaverage" | xargs rm
288290

291+
.PHONY: orig-src pylint

doc/source/devel/bv_formats.rst

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
#########################
2+
BrainVoyager file formats
3+
#########################
4+
5+
With notes on nibabel support.
6+
7+
PR for some BrainVoyager support at https://github.com/nipy/nibabel/pull/216.
8+
9+
********
10+
Overview
11+
********
12+
13+
See :
14+
15+
* All files are little-endian byte order regardless of byte-order on the
16+
machine writing the data;
17+
* BV apparently provides a "BVQXtools" library for reading writing BV files in
18+
MATLAB;
19+
20+
.. _bv-internal-axes:
21+
22+
***********************
23+
BV internal format axes
24+
***********************
25+
26+
BV files have a internal format that has axes named `X`, `Y` and `Z`. Quoting
27+
from the `VMR format definition`_::
28+
29+
BV X front -> back = Y in Tal space
30+
BV Y top -> bottom = Z in Tal space
31+
BV Z left -> right = X in Tal space
32+
33+
Put another way |--| the correspondence of BV XYZ to Talairach axes is:
34+
35+
* BV X -> Anterior to Posterior;
36+
* BV Y -> Superior to Inferior;
37+
* BV Z -> Left to Right.
38+
39+
or:
40+
41+
* BV X -> Talairach -Y;
42+
* BV Y -> Talairach -Z;
43+
* BV Z -> Talairach X;
44+
45+
Nice!
46+
47+
*****************
48+
Types of BV files
49+
*****************
50+
51+
There appear to be 38 BV file types at the time of writing of which 18 appear
52+
to have a page of description on the `BV file format index page`_.
53+
54+
Here are some examples of BV formats:
55+
56+
* FMR |--| "FMR project files are simple text files containing the information
57+
defining a functional project created from raw MRI data". This text file
58+
contains meta-data about the functional time course data, stored in one or
59+
more STC files. See the `FMR format definition`_.
60+
* STC |--| "A STC file (STC = "slice time course") contains the functional
61+
data (time series) of a FMR project." The time-course data of a 4D
62+
("single-slice") format STC file are stored on disk in
63+
fastest-to-slowest-changing order: columns, rows, time, slice. STC files
64+
can also contain the data for one single slice ("multi-slice format"), in
65+
which case the data are in fast-to-slow order: columns, rows, time. This is
66+
a raw data file where the relevant meta-data such as image size come from an
67+
associated FMR format file. See `STC format definition`_;
68+
* VTC |--| "A VTC file contains the functional data (time series) of one
69+
experimental run (one functional scan) in the space of a 3D anatomical data
70+
set (VMR), e.g. in Talairach space.". See `VTC format definition`_;
71+
This is a different format to the STC (raw data in native-space) format.
72+
The file is a header followed by ints or floats in
73+
fastest-to-slowest-changing order of: time; BV X; BV Y; BV Z; where BV X, BV
74+
Y, BV Z refer to the :ref:`bv-internal-axes`, and therefore Talairach -Y,
75+
-Z, X.
76+
* NR-VMP |--| "A native resolution volume map (NR-VMP) file contains
77+
statistical results in 3D format.". See `NR-VMP format definition`_
78+
* AR-VMP |--| "An anatomical-resolution VMP (volume map) file contains
79+
statistical results in 3D format" at anatomical scan resolution. See
80+
`AR-VMP format definition`_;
81+
* VMR |--| 'high-resolution anatomical MR' - see `VMR format definition`_.
82+
* MSK |--| mask file. Only documentation appears to be
83+
http://www.brainvoyager.com/ubb/Forum8/HTML/000087.html
84+
* SMP |--| 'surface map'. See `SMP format definition`_. Contains one or more
85+
"maps", where a map is a ``NrOfVertices`` (number of vertices) length vector
86+
of float64 values.
87+
88+
.. _BV file format index page: http://support.brainvoyager.com/automation-aamp-development/23-file-formats.html
89+
.. _AR-VMP format definition: http://support.brainvoyager.com/automation-aamp-development/23-file-formats/376-users-guide-23-the-format-of-ar-vmp-files.html
90+
.. _NR-VMP format definition: http://support.brainvoyager.com/automation-aamp-development/23-file-formats/377-users-guide-23-the-format-of-nr-vmp-files.html
91+
.. _VTC format definition: http://support.brainvoyager.com/automation-aamp-development/23-file-formats/379-users-guide-23-the-format-of-vtc-files.html
92+
.. _BV file format overview: http://support.brainvoyager.com/automation-aamp-development/23-file-formats/382-developer-guide-26-file-formats-overview.html
93+
.. _FMR format definition: http://support.brainvoyager.com/installation-introduction/23-file-formats/383-developer-guide-26-the-format-of-fmr-files.html
94+
.. _STC format definition: http://support.brainvoyager.com/automation-aamp-development/23-file-formats/384-developer-guide-26-the-format-of-stc-files.html
95+
.. _vmr format definition: http://support.brainvoyager.com/automation-aamp-development/23-file-formats/385-developer-guide-26-the-format-of-vmr-files.html
96+
.. _SMP format definition: : http://support.brainvoyager.com/automation-aamp-development/23-file-formats/476-the-format-of-smp-files.html
97+
98+
.. include:: ../links_names.txt

doc/source/notebooks/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.ipynb_checkpoints/

nibabel/fileutils.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# emacs: -*- mode: python-mode; py-indent-offset: 4; indent-tabs-mode: nil -*-
2+
# vi: set ft=python sts=4 ts=4 sw=4 et:
3+
# ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ##
4+
#
5+
# See COPYING file distributed along with the NiBabel package for the
6+
# copyright and license terms.
7+
#
8+
# ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ##
9+
""" Utilities for reading and writing to binary file formats
10+
"""
11+
12+
def read_zt_byte_strings(fobj, n_strings=1, bufsize=1024):
13+
"""Read zero-terminated byte strings from a file object `fobj`
14+
15+
Returns byte strings with terminal zero stripped.
16+
17+
Found strings can be of any length.
18+
19+
The file position of `fobj` on exit will be at the byte after the terminal
20+
0 of the final read byte string.
21+
22+
Parameters
23+
----------
24+
f : fileobj
25+
File object to use. Should implement ``read``, returning byte objects
26+
(str in Python 2), and ``seek(n, 1)`` to seek from current file
27+
position.
28+
n_strings : int, optional
29+
Number of byte strings to return
30+
bufsize: int, optional
31+
Define chunk size to load from file while searching for zero terminals.
32+
We load this many bytes at a time from the file, but the returned
33+
strings can be longer than `bufsize`.
34+
35+
Returns
36+
-------
37+
byte_strings : list
38+
List of byte strings, where strings do not include the terminal 0
39+
"""
40+
byte_strings = []
41+
trailing = b''
42+
while True:
43+
buf = fobj.read(bufsize)
44+
eof = len(buf) < bufsize # end of file
45+
zt_strings = buf.split(b'\x00')
46+
if len(zt_strings) > 1: # At least one 0
47+
byte_strings += [trailing + zt_strings[0]] + zt_strings[1:-1]
48+
trailing = zt_strings[-1]
49+
else: # No 0
50+
trailing += zt_strings[0]
51+
n_found = len(byte_strings)
52+
if eof or n_found >= n_strings:
53+
break
54+
if n_found < n_strings:
55+
raise ValueError('Expected {0} strings, found {1}'.format(
56+
n_strings, n_found))
57+
n_extra = n_found - n_strings
58+
leftover_strings = byte_strings[n_strings:] + [trailing]
59+
# Add number of extra strings to account for lost terminal 0s
60+
extra_bytes = sum(len(bs) for bs in leftover_strings) + n_extra
61+
fobj.seek(-extra_bytes, 1) # seek back from current position
62+
return byte_strings[:n_strings]

nibabel/imageclasses.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,9 @@
1515
from .freesurfer import MGHImage
1616
from .parrec import PARRECImage
1717
from .volumeutils import Recoder
18+
from .optpkg import optional_package
19+
_, have_scipy, _ = optional_package('scipy')
1820

19-
# If we don't have scipy, then we cannot write SPM format files
20-
try:
21-
import scipy.io
22-
except ImportError:
23-
have_scipy = False
24-
else:
25-
have_scipy = True
2621

2722
# mapping of names to classes and class functionality
2823

0 commit comments

Comments
 (0)