-
Notifications
You must be signed in to change notification settings - Fork 259
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
WIP: adding Philips XML/REC support #683
base: master
Are you sure you want to change the base?
Conversation
Philips now encourages the XML-style headers over the older PAR format. This initial implementation reads the XML file, converting each field to its PAR file equivalent and then inherits from the PARRECHeader and PARRECImage to avoid excessive code duplication.
…ecognized enum strings. add an error message with a hint regarding truncated XML files
Add an xmlrec2nii command line script. This currently is identical to parrec2nii because the underlying function now supports both formats.
prior to this commit, both would get stored as true because bool('N') == True
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @grlee77. I found a few review comments sitting here. Not sure whether I was waiting on something or just forgot to hit "Submit".
Let me know when you're ready for a thorough review.
% bitpix) | ||
# REC data always little endian | ||
dt = np.dtype('uint' + str(bitpix)).newbyteorder('<') | ||
super(PARRECHeader, self).__init__(data_dtype=dt, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be super(XMLRECHeader, ...
|
||
@classmethod | ||
def filespec_to_file_map(klass, filespec): | ||
file_map = super(PARRECImage, klass).filespec_to_file_map(filespec) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
super(XMLRECImage, ...
@@ -46,6 +47,15 @@ def load(filename, **kwargs): | |||
for image_klass in all_image_classes: | |||
is_valid, sniff = image_klass.path_maybe_image(filename, sniff) | |||
if is_valid: | |||
if image_klass is PARRECImage and '.REC' in filename: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if image_klass is PARRECImage and '.REC' in filename: | |
if image_klass is PARRECImage and filename.endswith('.REC'): |
@@ -19,6 +19,7 @@ | |||
from .arrayproxy import is_proxy | |||
from .py3k import FileNotFoundError | |||
from .deprecated import deprecate_with_version | |||
from .parrec import PARRECImage |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you import this inside load
? See the comment involved in importing Nifti*
in save()
:
Lines 109 to 112 in d5494f3
# Special-case Nifti singles and Pairs | |
# Inline imports, as this module really shouldn't reference any image type | |
from .nifti1 import Nifti1Image, Nifti1Pair | |
from .nifti2 import Nifti2Image, Nifti2Pair |
This is a PR based on the discussion in #681. It is still a work in progress.
I have now refactored the code so that there is no conversion from XML header names to PAR names. The native XML names are all retained. I think this makes it so that @Roosted7 can work from this PR.
Due to the large refactor to remove the PAR conversion, it does not make sense to review the PR starting from the first commit. I should probably rebase and squash some of that history.
@Roosted7. Does this version look suitable for you to work from? Feel free to modify or replace
parse_XML_header
. As long as you provide thegeneral_info
andimage_defs
in the same format so we can keep the same API as in the PARREC classes. New functions/methods can be added for writing an XML file. I don't intend to work on that part myself, but hopefully you can work from what I have started here instead of starting from scratch.Other things to potentially look into:
1.) I currently subclassed
PARRECHeader
andPARRECImage
, but many methods fromPARRECHeader
had to be overridden. Sometimes these were just to changeimage_defs
field names to the XML conventions. I suppose this could be refactored somewhat to use a common base class instead.2.) The XML parsing could/should probably reuse things from
xml_utils.py
Obviously tests are still needed. @Roosted7 had linked to some PAR/XML/REC data in #681 and I can potentially provide some small example XML files from phantom scans.