Header datatypes
There are 10 possible datatypes that a value can have in the header. Below are the valid datatypes along with the datatype they are parsed into in Python and examples of the datatypes.
int
- NRRD Syntax
<i>
- NRRD Example
12
- Python Datatype
- Python Example
12
double
- NRRD Syntax
<d>
- NRRD Example
3.14
- Python Datatype
- Python Example
3.14
string
- NRRD Syntax
<s>
- NRRD Example
test
- Python Datatype
- Python Example
‘test’
int list
- NRRD Syntax
<i> <i> … <i>
- NRRD Example
1 2 3 4
- Python Datatype
numpy.ndarray
(1D, dtype=int)- Python Example
np.array([1, 2, 3, 4])
double list
- NRRD Syntax
<d> <d> … <d>
- NRRD Example
1.2 2.3 3.4 4.5
- Python Datatype
numpy.ndarray
(1D, dtype=float)- Python Example
np.array([1.2, 2.3, 3.4, 4.5])
string list
quoted string list
int vector
- NRRD Syntax
(<i>,<i>,…,<i>)
- NRRD Example
(1,2,3,4)
- Python Datatype
(N,)
numpy.ndarray
ofint
- Python Example
np.array([1, 2, 3, 4])
pynrrd will correctly handle vectors with or without spaces between the comma-delimiter. Saving the NRRD file back will remove all spaces between the comma-delimiters.
double vector
- NRRD Syntax
(<d>,<d>,…,<d>)
- NRRD Example
(1.2,2.3,3.4,4.5)
- Python Datatype
(N,)
numpy.ndarray
offloat
- Python Example
np.array([1.2, 2.3, 3.4, 4.5])
pynrrd will correctly handle vectors with or without spaces between the comma-delimiter. Saving the NRRD file back will remove all spaces between the comma-delimiters.
int matrix
- NRRD Syntax
(<i>,<i>,…,<i>) (<i>,<i>,…,<i>) … (<i>,<i>,…,<i>)
- NRRD Example
(1,0,0) (0,1,0) (0,0,1)
- Python Datatype
(M,N)
numpy.ndarray
ofint
- Python Example
np.array([[1, 0, 0], [0, 1, 0], [0, 0, 1]])
All rows of the matrix are required, unlike that of the double matrix. If some of the rows need to be ‘none’, then use a double matrix instead. The reason is that empty rows (i.e. containing ‘none’) are represented as a row of NaN’s, and NaN’s are only available for floating point numbers.
double matrix
- NRRD Syntax
(<d>,<d>,…,<d>) (<d>,<d>,…,<d>) … (<d>,<d>,…,<d>)
- NRRD Example
(2.54, 1.3, 0.0) (3.14, 0.3, 3.3) none (0.05, -12.3, -3.3)
- Python Datatype
(M,N)
numpy.ndarray
offloat
- Python Example
np.array([[2.54, 1.3, 0.0], [3.14, 0.3, 3.3], [np.nan, np.nan, np.nan], [0.0, -12.3, -3.3]])
This datatype has the added feature where rows can be defined as empty by setting the vector as none
. In the NRRD specification, instead of the row, the none
keyword is used in it’s place. This is represented in the Python NumPy array as a row of all NaN’s. An example use case for this optional row matrix is for the ‘space directions’ field where one row may be empty because it is not a domain type.