-
Notifications
You must be signed in to change notification settings - Fork 0
Fix longitudinal functional template #331
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
Open
kaitj
wants to merge
12
commits into
main
Choose a base branch
from
maint/long-func-template
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 10 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
1ba6f5a
Resample long templ to bold grid for ref
kaitj 05f0b3e
Generate bold ref once after template created
kaitj 2f95eff
Update tests for bold ref template
kaitj 06929ef
Replace data loading for long template resampling
kaitj 11b7722
Resample longitudinal mask for QC
kaitj 6553dc5
Fix docstrings
kaitj ee0da2a
Rename bold_ref to bold_template due to shadowing
kaitj 6608565
Refactor to resample template per task
kaitj 6dc432d
Address review comments
kaitj 35ad7b1
Extract row entities to find refs + file naming
kaitj 0cdaed6
Address reviews, round 2
kaitj b0ca8ef
Apply session-to-longitudinal template xfm
kaitj File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| """Resampling utilities for longitudinal templates.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from typing import TYPE_CHECKING | ||
|
|
||
| import nibabel as nib | ||
| from nibabel.processing import resample_from_to | ||
|
|
||
| if TYPE_CHECKING: | ||
| from pathlib import Path | ||
|
|
||
| from rbc.core.niwrap import generate_exec_folder | ||
|
|
||
|
|
||
| def resample_img_to_bold_grid(bold_ref: Path, img: Path, order: int = 3) -> Path: | ||
| """Resample template to BOLD grid if shapes differ. | ||
|
|
||
| Args: | ||
| bold_ref: BOLD reference volume. | ||
| img: 3D image in target space to resample. | ||
| order: Interpolation order used during resampling | ||
|
|
||
| Returns: | ||
| Resampled 3D image with BOLD grid | ||
| """ | ||
| bold_ref_img = nib.nifti1.load(bold_ref) | ||
| img_obj = nib.nifti1.load(img) | ||
|
|
||
| # If 4D, extract first volume | ||
| if len(bold_ref_img.shape) > 3: | ||
| bold_ref_img = bold_ref_img.slicer[..., 0] | ||
| # If same shape, no need to resample | ||
| if bold_ref_img.shape == img_obj.shape: | ||
| return img | ||
|
kaitj marked this conversation as resolved.
Outdated
|
||
|
|
||
| img_resampled = resample_from_to(img_obj, bold_ref_img, order=order) | ||
| img_resampled_path = ( | ||
| generate_exec_folder("img_resample_to_bold_grid") / "resampled.nii.gz" | ||
| ) | ||
| nib.save(img_resampled, img_resampled_path) | ||
| return img_resampled_path | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.