-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add vector list datatype & add configurable
SPACE_DIRECTIONS_TYPE
o…
…ption (#157) ## Changes * Add `int vector list` and `double vector list` datatypes that are lists of Numpy arrays or `None`. * These new types are similar to their `int matrix` and `double matrix` counterparts except they are **not** 2D Numpy matrices. * Add `nrrd.SPACE_DIRECTIONS_TYPE` to enable switching the datatype for the `space directions` field. * Valid options are `double matrix` or `double vector list`. The current default is `double matrix` for backwards compatibility but will be switched to `double vector list` in the next major release. * `double vector list` is superior over `double matrix` because it doesn't have the confusing row-of-NaN's representation and it doesn't imply an affine transform by being a matrix. * Support row-of-None in addition to row-of-NaN for `parse_optional_matrix` & `format_optional_matrix` in addition to new vector list parsing/formatting functions Fixes #148 Revises #149
- Loading branch information
1 parent
bb38ec2
commit 62b75f8
Showing
14 changed files
with
410 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,46 @@ | ||
from typing_extensions import Literal | ||
|
||
from nrrd._version import __version__ | ||
from nrrd.formatters import * | ||
from nrrd.parsers import * | ||
from nrrd.reader import read, read_data, read_header | ||
from nrrd.types import NRRDFieldMap, NRRDFieldType, NRRDHeader | ||
from nrrd.writer import write | ||
|
||
# TODO Change to 'double vector list' in next major release | ||
SPACE_DIRECTIONS_TYPE: Literal['double matrix', 'double vector list'] = 'double matrix' | ||
"""Datatype to use for 'space directions' field when reading/writing NRRD files | ||
The 'space directions' field can be represented in two different ways: as a matrix or as a list of vectors. Per the | ||
NRRD specification, the 'space directions' field is a per-axis definition that represents the direction and spacing of | ||
each axis. Non-spatial axes are represented as 'none'. | ||
The current default is to return a matrix, where each non-spatial axis is represented as a row of `NaN` in the matrix. | ||
In the next major release, this default option will change to return a list of optional vectors, where each non | ||
spatial axis is represented as `None`. | ||
Example: | ||
Reading a NRRD file with space directions type set to 'double matrix' (the default). | ||
>>> nrrd.SPACE_DIRECTIONS_TYPE = 'double matrix' | ||
>>> data, header = nrrd.read('file.nrrd') | ||
>>> print(header['space directions']) | ||
[[1.5 0. 0. ] | ||
[0. 1.5 0. ] | ||
[0. 0. 1. ] | ||
[nan nan nan]] | ||
Reading a NRRD file with space directions type set to 'double vector list'. | ||
>>> nrrd.SPACE_DIRECTIONS_TYPE = 'double vector list' | ||
>>> data, header = nrrd.read('file.nrrd') | ||
>>> print(header['space directions']) | ||
[array([1.5, 0. , 0. ]), array([0. , 1.5, 0. ]), array([0., 0., 1.]), None] | ||
""" | ||
|
||
__all__ = ['read', 'read_data', 'read_header', 'write', 'format_number_list', 'format_number', 'format_matrix', | ||
'format_optional_matrix', 'format_optional_vector', 'format_vector', 'parse_matrix', | ||
'parse_number_auto_dtype', 'parse_number_list', 'parse_optional_matrix', 'parse_optional_vector', | ||
'parse_vector', 'NRRDFieldType', 'NRRDFieldMap', 'NRRDHeader', '__version__'] | ||
'format_optional_matrix', 'format_optional_vector', 'format_vector', 'format_vector_list', | ||
'format_optional_vector_list', 'parse_matrix', 'parse_number_auto_dtype', 'parse_number_list', | ||
'parse_optional_matrix', | ||
'parse_optional_vector', 'parse_vector', 'parse_vector_list', 'parse_optional_vector_list', 'NRRDFieldType', | ||
'NRRDFieldMap', 'NRRDHeader', 'SPACE_DIRECTIONS_TYPE', '__version__'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.