Skip to content

Fix MRDS output corruption and orientation handling - #1358

Merged
arnaudbore merged 7 commits into
scilus:dev_3.0.xfrom
frheault:split_branch_4_mrds
Oct 21, 2026
Merged

arnaudbore merged 7 commits into
scilus:dev_3.0.xfrom
frheault:split_branch_4_mrds

Conversation

@frheault

@frheault frheault commented Sep 22, 2026 •

Copy link
Copy Markdown
Member

Quick description

Depends on PR 1 (split_branch_1_core), included here so this PR's tests pass on their own (see why below).

Updates scil_mrds_metrics and scil_mrds_select_number_of_tensors to scilpy's newer image-loading code, making both robust to any input orientation.

While testing this in isolation, a real bug turned up in scil_mrds_select_number_of_tensors: it could silently write its output (eigenvector directions, signal fractions, etc.) using the wrong numeric precision, because it borrowed file-type information from the NUFO/label map instead of its own data. This quietly rounded/corrupted output values by 1-3%, with no crash or warning. Fixed by PR 1's dtype fix, included here.

I validated the before/after behavior using this data/code.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Provide data, screenshots, command line to test (if relevant)

pytest src/scilpy/cli/tests/test_mrds_metrics.py src/scilpy/cli/tests/test_mrds_select_number_of_tensors.py src/scilpy/io/tests/test_stateful_image.py -v
46 passed.

Checklist

  • My code follows the style guidelines of this project (run autopep8)
  • I added relevant citations to scripts, modules and functions docstrings and descriptions
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I moved all functions from the script file (except the argparser and main) to scilpy modules
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

🤖 Generated with Claude Code

…tatefulImage, requires the header/dtype fix so uint8 NUFO references do not silently quantize float outputs

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟡 Changes recommended

Preserve source metadata and filename when reorienting non-RAS images, and add regression coverage.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 1 Medium severity

Open (1)
What changed in this PR

Updates MRDS tools to use StatefulImage for orientation-safe processing and correct output precision.

Changes:

  • Reorient MRDS inputs and masks consistently.
  • Preserve output orientation and data types.
  • Add orientation, dtype, and metadata regression tests.
File Summary
src/​scilpy/​io/​tests/​test_stateful_image.py Tests dtype, header, metadata, and orientation handling.
src/​scilpy/​io/​stateful_image.py Extends orientation, metadata, and dtype handling.
src/​scilpy/​cli/​tests/​test_mrds_select_number_of_tensors.py Tests tensor selection across orientations.
src/​scilpy/​cli/​tests/​test_mrds_metrics.py Tests MRDS metrics with LAS/RAS inputs.
src/​scilpy/​cli/​scil_mrds_select_number_of_tensors.py Adds orientation-safe MRDS selection and output preservation.
src/​scilpy/​cli/​scil_mrds_metrics.py Adds orientation-safe metric generation.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/scilpy/io/stateful_image.py Resolved
@codecov

codecov Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 73.03%. Comparing base (26a224e) to head (b58e2b1).
⚠️ Report is 8 commits behind head on dev_3.0.x.

Additional details and impacted files
@@              Coverage Diff              @@
##           dev_3.0.x    #1358      +/-   ##
=============================================
+ Coverage      72.95%   73.03%   +0.07%     
=============================================
  Files            304      304              
  Lines          27053    27097      +44     
  Branches        3839     3845       +6     
=============================================
+ Hits           19737    19789      +52     
+ Misses          5707     5698       -9     
- Partials        1609     1610       +1     
Flag Coverage Δ
smoketests 69.97% <100.00%> (+0.07%) ⬆️
unittests 15.41% <0.00%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
Scripts 75.58% <100.00%> (-0.03%) ⬇️
Library 70.05% <ø> (+0.18%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@frheault
frheault requested a review from arnaudbore October 14, 2026 17:37
@frheault frheault changed the title (WIP) Fix MRDS output corruption and orientation handling Fix MRDS output corruption and orientation handling Oct 14, 2026
@arnaudbore
arnaudbore requested a review from CHrlS98 October 19, 2026 16:11

@arnaudbore arnaudbore left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@CHrlS98 CHrlS98 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Small request

Comment on lines +110 to +114
# and test runs. On this branch, PIR mask is reoriented correctly
# to match the LAS dataset, so the rendered peak glyphs on the mid-slice
# match the reference exactly.
# On dev_3.0.x, scil_mrds_select_number_of_tensors crashes with IndexError.
ret_viz_ref = script_runner.run([

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this is a comment that should not be included in the source code (the "On this branch..." part).

@arnaudbore
arnaudbore merged commit 97285c9 into scilus:dev_3.0.x Oct 21, 2026
2 checks passed
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.

4 participants