-
Notifications
You must be signed in to change notification settings - Fork 51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow custom field map to override default field types #149
base: master
Are you sure you want to change the base?
Conversation
The next step to make life easier for users wanting to generate these sort of space dimensions fields with some number of |
It's been awhile since I've used the library, but the docs state that any rows that are Are you having issues with loading Fundamentally, I think we'll want to consider #148 where a list of a vectors datatype is added to better handle this field instead. |
Thanks a lot, I had missed that aspect of the behavior. That does address my current needs, though:
|
Regarding point 1, I agree that handling None like NaN makes sense. I would be in favor of refactoring the formatting of ‘none’ to return a list of None instead of NaN. I’m not sure NaN is very intuitive. Could do a breaking release or make it an option that you can select between. For point 2, I’m all for flexibility for the user but I don’t see the need to give flexibility for the predefined header fields in the NRRD spec. I’m not sure why anyone would want to customize that and go against the NRRD spec. In this case, the fundamental problem was poor handling of the fields in this library. |
…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
Thanks for writing this library! The nrrd spec says that the
space directions
field must be a list of some combination of vectors (for spatial axes) andnone
(for non-spatial axes like color). It looks to me like pynrrd insists thatspace directions
is a matrix and so it does not support the ability to addnone
entries. I made a small change to enable this.With this commit, it becomes possible to override the default type of a header field. By overriding the default type of
space directions
with'string'
, users can provide a string value for this that is directly put into the file header. Users will have to know that the proper format of thespace directions
field is something liketo produce a valid .nrrd header, but at least this is now possible.
As a result, a command like this succeeds in producing a nrrd file that has a correctly specified header for a dataset that is xyz plus a color channel:
And get a proper header:
I have confirmed that this is a proper header according to the nrrd spec using the
unu
tool from teem, (which the devs have said here is the recommended way to confirm header conformance):Note that if I remove the
none
from the header, I get the appropriate complaint fromunu
:I would guess this commit wouldn't cause any issues in existing code anywhere in the world, since before this the custom field map would just be ignored for any standard metadata fields, and the behavior is only changed when providing custom field types for the standard fields.
Feel free to merge this PR if you agree this change is a move in the correct direction. Thanks!