Skip to content
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

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open

Conversation

grlee77
Copy link
Contributor

@grlee77 grlee77 commented Oct 19, 2018

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 the general_info and image_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 and PARRECImage, but many methods from PARRECHeader had to be overridden. Sometimes these were just to change image_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.

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.
Copy link
Member

@effigies effigies left a 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,
Copy link
Member

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)
Copy link
Member

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:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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
Copy link
Member

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():

nibabel/nibabel/loadsave.py

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants