Skip to content

Add HDF5 support to Python ISMRMRD -> MRD converter#54

Open
naegelejd wants to merge 4 commits intomainfrom
naegelejd/add-hdf5-to-python-converter
Open

Add HDF5 support to Python ISMRMRD -> MRD converter#54
naegelejd wants to merge 4 commits intomainfrom
naegelejd/add-hdf5-to-python-converter

Conversation

@naegelejd
Copy link
Collaborator

This enables converting directly from ISMRMRD HDF5 to an MRD stream, without having to to convert to the intermediate ISMRMRD stream format.

Example usage:

ismrmrd_generate_cartesian_shepp_logan -o phantom.h5
python -m mrd.tools.ismrmrd_to_mrd --dataset phantom.h5 -o phantom.mrd

@naegelejd naegelejd marked this pull request as ready for review February 18, 2026 21:07
@naegelejd naegelejd requested review from Copilot and xueh2 February 18, 2026 21:08
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR extends the Python ismrmrd_to_mrd converter so it can convert directly from an ISMRMRD HDF5 file into an MRD stream, and updates end-to-end tests to cover ISMRMRD↔MRD roundtrips for both the C++ and Python converters.

Changes:

  • Add --dataset mode to python/mrd/tools/ismrmrd_to_mrd.py to convert ISMRMRD HDF5 directly to MRD.
  • Extend test/test-all.sh to validate ISMRMRD↔MRD roundtrip equivalence (including recon stream cases).
  • Remove redundant converter-specific just targets and pin Miniforge version in the conda workflow.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

File Description
python/mrd/tools/ismrmrd_to_mrd.py Adds HDF5 dataset conversion path and updates CLI plumbing.
test/test-all.sh Expands end-to-end coverage with ISMRMRD↔MRD conversion/roundtrip checks.
justfile Removes standalone converter test recipes and relies on end-to-end coverage.
.github/workflows/mrd_conda.yml Pins Miniforge version for more reproducible CI setup.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@@ -2,6 +2,7 @@
"""Convert ISMRMRD stream to MRD stream."""
Copy link

Copilot AI Feb 18, 2026

Choose a reason for hiding this comment

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

The module docstring still says this tool converts an ISMRMRD stream only, but main() now also supports converting directly from an ISMRMRD HDF5 dataset (--dataset). Please update the docstring to reflect the expanded functionality so generated docs/help stay accurate.

Suggested change
"""Convert ISMRMRD stream to MRD stream."""
"""Convert ISMRMRD data (stream or HDF5 dataset) to an MRD stream."""

Copilot uses AI. Check for mistakes.
Comment on lines 492 to 496
# Try integer first
try:
int_val = int(str_val)
# Check if it's actually an integer (not a float like "3.0")
if '.' not in str_val and 'e' not in str_val.lower():
if str_val.isdigit():
try:
int_val = int(str_val)
meta_values.append(mrd.ImageMetaValue.Int64(int_val))
Copy link

Copilot AI Feb 18, 2026

Choose a reason for hiding this comment

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

str_val.isdigit() only returns true for unsigned integer strings, so metadata values like "-1"/"+3" will no longer be emitted as Int64 and will instead fall through to the float or string paths. This is a behavioral regression from the previous int()-based parsing; consider using a sign-aware integer check (or the earlier int() attempt with an explicit float-notation guard) to preserve integer typing.

Copilot uses AI. Check for mistakes.
Comment on lines +144 to +145
ismrmrd_hdf5_to_stream -i phantom.h5 --use-stdout | ismrmrd_stream_recon_cartesian_2d --use-stdin --use-stdout | ismrmrd_to_mrd | mrd_to_ismrmrd > recon_rountrip.ismrmrd
diff direct.ismrmrd roundtrip.ismrmrd && diff recon_direct.ismrmrd recon_rountrip.ismrmrd
Copy link

Copilot AI Feb 18, 2026

Choose a reason for hiding this comment

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

Typo in the output filename recon_rountrip.ismrmrd (missing 'd' in 'roundtrip'). Even though it works, it makes the test harder to read/search; consider renaming consistently to recon_roundtrip.ismrmrd.

Copilot uses AI. Check for mistakes.
Comment on lines +155 to +156
ismrmrd_hdf5_to_stream -i phantom.h5 --use-stdout | ismrmrd_stream_recon_cartesian_2d --use-stdin --use-stdout | python -m mrd.tools.ismrmrd_to_mrd | python -m mrd.tools.mrd_to_ismrmrd > recon_rountrip.ismrmrd
python diff-ismrmrd-streams.py recon_direct.ismrmrd recon_rountrip.ismrmrd
Copy link

Copilot AI Feb 18, 2026

Choose a reason for hiding this comment

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

Typo in the output filename recon_rountrip.ismrmrd (missing 'd' in 'roundtrip'). Even though it works, it makes the test harder to read/search; consider renaming consistently to recon_roundtrip.ismrmrd.

Copilot uses AI. Check for mistakes.
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.

1 participant

Comments