Skip to content

Add -normalize-PAM50 argument to metric extraction script to allow interpolation to PAM50 space - #5236

Open
valosekj wants to merge 25 commits into
masterfrom
jv/sct_extract_metric_normalize_pam50
Open

Add -normalize-PAM50 argument to metric extraction script to allow interpolation to PAM50 space#5236
valosekj wants to merge 25 commits into
masterfrom
jv/sct_extract_metric_normalize_pam50

Conversation

@valosekj

@valosekj valosekj commented Jun 3, 2026

Copy link
Copy Markdown
Member

Checklist

  • PR Sidebar: I've filled these options within the PR sidebar:
  • Guidelines: I've read the Contributing guidelines to make sure my branch and pull request meet SCT's guidelines. (Feel free to stop and fixup your commits before submitting.)
  • Documentation: I've updated the relevant documentation for my changes, including argparse descriptions, docstrings, and ReadTheDocs tutorial pages.
  • Tests: I've added relevant tests for my contribution, if necessary. I've also made sure that my contribution passes all of the automated tests (which will be triggered after the PR is submitted).
  • Only after the automated test suite passes: I will tag a reviewer in the PR sidebar. (You can also ask for help with specific questions in the PR comments before the tests pass.)

Description

This PR implements per-slice interpolation to sct_extract_metric to enable computing DTI maps in the native and then interpolating them per vert level to the PAM50 template space.
I'm reusing spinalcordtoolbox.metrics_to_PAM50.interpolate_metrics.

image

Example usage

sct_extract_metric.py
-i sub-amu01_dwi_moco_FA.nii.gz
-f label_sub-amu01_dwi_moco/atlas
-method map
-l 51
-vertfile label_sub-amu01_dwi_moco/template/PAM50_levels.nii.gz
-perslice 1
-normalize-PAM50 1
-o amu01_dwi_moco_FA.csv
amu01_dwi_moco_FA.csv sample: image

Files:
PR5236.zip

TODO

Due to high DWI slice thickness (5mm), there are “steps” at the “interface” of discs (see slide 8) --> try to include one slice above and below each level for the interpolation.

Linked issues

Related: spinalcordtoolbox/PAM50-normalized-metrics#41

Comment thread spinalcordtoolbox/metrics_to_PAM50.py Outdated
@valosekj
valosekj marked this pull request as ready for review June 8, 2026 06:42
@valosekj

valosekj commented Jun 8, 2026

Copy link
Copy Markdown
Member Author

@sandrinebedard reviewed the PR. @joshuacwnewton, could you also review the PR? Thank you 🙏

@joshuacwnewton

Copy link
Copy Markdown
Member

In the progress of reviewing this PR. Just trying to figure out why the tests are failing! 🤔

@joshuacwnewton joshuacwnewton left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

There are a lot of good things to this PR (thanks for adding tests!) but I think I may have found an important thing to discuss in terms of the order of aggregation and interpolation.

Comment thread spinalcordtoolbox/scripts/sct_extract_metric.py Outdated
Comment thread testing/cli/test_cli_sct_extract_metric.py Outdated
Comment thread testing/cli/test_cli_sct_extract_metric.py Outdated
Comment thread spinalcordtoolbox/scripts/sct_extract_metric.py Outdated
Comment thread spinalcordtoolbox/scripts/sct_extract_metric.py Outdated
Comment thread spinalcordtoolbox/scripts/sct_extract_metric.py Outdated
Comment thread spinalcordtoolbox/scripts/sct_extract_metric.py
@joshuacwnewton joshuacwnewton changed the title sct_extract_metric: normalize DWI to PAM50 Add -normalize-PAM50 argument to metric extraction script (to allow interpolating DTI in PAM50 space) Jun 15, 2026
@joshuacwnewton joshuacwnewton added sct_extract_metric context: feature PR Category (used to generate the release changelog) labels Jun 15, 2026
@joshuacwnewton joshuacwnewton added this to the 7.4 milestone Jun 15, 2026
@valosekj valosekj changed the title Add -normalize-PAM50 argument to metric extraction script (to allow interpolating DTI in PAM50 space) Add -normalize-PAM50 argument to metric extraction script to allow interpolation to PAM50 space Aug 11, 2026
Since `-normalize-PAM50` already requires `-perslice 1`, the two separate
`extract_metric()` calls were redundant.

Context: #5236 (comment)
interpolate_metrics() expects compute_shape()'s output form (one Metric
object per metric, multiple slices), while _build_pam50_agg_metric()
works with extract_metric()'s output form (one dict per slice, multiple
metrics).

Context: #5236 (comment)
valosekj and others added 2 commits August 12, 2026 08:58
sct_extract_metric aggregates in native space then interpolates to
PAM50, while sct_process_segmentation interpolates to PAM50 first then
aggregates.

Context: #5236 (comment)
@joshuacwnewton
joshuacwnewton self-requested a review August 12, 2026 12:40

@joshuacwnewton joshuacwnewton left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think this LGTM! I just had a few small comments to address the remaining open conversations, but I think the overall structure/plan of this PR seems sound, and I appreciate the new tests. :)

Comment thread spinalcordtoolbox/metrics_to_PAM50.py Outdated
Comment thread spinalcordtoolbox/metrics_to_PAM50.py Outdated
Comment thread spinalcordtoolbox/metrics_to_PAM50.py Outdated
Comment thread spinalcordtoolbox/metrics_to_PAM50.py Outdated
@valosekj

Copy link
Copy Markdown
Member Author

I think this LGTM! I just had a few small comments to address the remaining open conversations, but I think the overall structure/plan of this PR seems sound, and I appreciate the new tests. :)

Thank you for your review and suggestions, @joshuacwnewton!

Let me test the PR on the spine-generic dataset before merging it!

@joshuacwnewton

Copy link
Copy Markdown
Member

Let me test the PR on the spine-generic dataset before merging it!

Sounds good to me! :)

valosekj added a commit to spinalcordtoolbox/PAM50-normalized-metrics that referenced this pull request Aug 22, 2026
…oolbox#5236

- comment out perlevel native extraction-- used in another analysis; not needed now
- update config_process_data_dwi.json
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature PR Category (used to generate the release changelog) sct_extract_metric context:

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants