-
Notifications
You must be signed in to change notification settings - Fork 16
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
Feat: Implement a visualisation feature to NiTransforms #212
Open
jmarabotto
wants to merge
58
commits into
nipy:master
Choose a base branch
from
jmarabotto:feat/vis
base: master
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 46 commits
Commits
Show all changes
58 commits
Select commit
Hold shift + click to select a range
05b61b8
feat: Implement vis
b2cac3b
enh: Update plotting
7722545
enh: Reworked figure formatting and code structure
227e330
enh: code structure. Plotting now a class object.
59104c6
fix: remove straneous spaces
3865b65
fix: remove straneous spaces
76ca16a
enh: code structure
3c9be6d
N/A
304f362
enh: update progress on vis
62801e5
enh: Implemented function descriptions, reworked some lines.
b745a9f
feat: First implementation of draft dsm plots.
7f96037
feat: First draft of vis.py
ac31803
Feat: Addition of new, improved file vis_v2.py with new developments …
2ffa28a
enh: 1. Implemented 3d quiver; 2. Updated formatting; 3. Updated func…
6bb8afd
fix: Reworked file naming and versions
a3cef8d
fix: Relocate draft files
b426904
Feat: New file version, implemented divergence of deltas field. New (…
f13716a
Fix: ajust location of draft files
8601490
enh: finalised div map, removed normalised dsm plot. Prepared V5
f489927
Fix: fixed jacobian calculations, implemented jacobian-mapped scatter…
6b86390
Feat: Created v6 and reorganised drafts
d560077
Feat: Created v6 and reorganised drafts
9d2cab8
fix: debug grid, partial fix
68e72ef
Feat: Finalised grid, code functional. Required: clean up files; clea…
ead2351
Enh: formatting
dc87338
Enh: Removed draft files, rename final vis.py
f051b7d
fix: corrected descriptions
bde247b
enh: code structure
ef53ff8
remove example
1507e77
Enh: New file test_vis.py for implementation of tests. Added checks f…
6b14738
removed draft python files
af24af8
enh: Further additions to test_vis, output path for figures added to …
ed381b3
Fix: test 3d quiver fixed, fixed identical savefig filenames
30e1967
fix: accidentally running examples
6a1eb59
Fix: pacify flake8
2d54dc1
Fix: pacify flake8
85621c1
Fix: pacify flake8
164372c
Fix: pacify flake8
c047b3c
Enh: increase CodeCov coverage
0aa2d08
Enh: increase CodeCov coverage, pacify flake8
b66fee3
Fix Pacify flake8
94bab2a
Fix: RGB quiver plot failing if plotting transforms independent of on…
138b81e
Fix: pacify flake8
07f94f7
Fix: pacify flake8
011cf30
Fix: pacify flake8
67da55c
Feat: creation of notebook for vis module
a1fcdc7
feat: plot linear, planar and spherical coefficient. Other code tidying.
6bef93f
pacify flake8
2384469
fix: mistakenly broke syntax
c25a501
enh: added tests for codecov
f51e93f
Update nitransforms/tests/test_vis.py
jmarabotto d44da6c
Update nitransforms/tests/test_vis.py
jmarabotto 91191ae
Update nitransforms/vis.py
jmarabotto 0d8d997
Update nitransforms/vis.py
jmarabotto c262c55
Update nitransforms/vis.py
jmarabotto 8863189
fix: pacify flake8, updated notebook
664f6f5
fix? read the docs
36dae68
Link to notebook
effigies 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 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
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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 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 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 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 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,139 @@ | ||
import numpy as np | ||
import matplotlib.pyplot as plt | ||
import pytest | ||
|
||
import nibabel as nb | ||
from nitransforms.nonlinear import DenseFieldTransform | ||
from nitransforms.vis import PlotDenseField | ||
|
||
|
||
def test_read_path(data_path): | ||
"Check that filepaths are a supported method for loading " | ||
"and reading transforms with PlotDenseField" | ||
jmarabotto marked this conversation as resolved.
Show resolved
Hide resolved
|
||
PlotDenseField(transform=data_path / "ds-005_sub-01_from-OASIS_to-T1_warp_fsl.nii.gz") | ||
|
||
|
||
def test_slice_values(): | ||
"""Check that ValueError is issued if negative slices are provided""" | ||
with pytest.raises(ValueError): | ||
PlotDenseField( | ||
transform=np.zeros((10, 10, 10, 3)), | ||
reference=nb.Nifti1Image(np.zeros((10, 10, 10, 3)), np.eye(4), None), | ||
).test_slices( | ||
xslice=-1, | ||
yslice=-1, | ||
zslice=-1, | ||
) | ||
|
||
"Check that IndexError is issued if provided slices are beyond range of transform dimensions" | ||
xfm = DenseFieldTransform( | ||
field=np.zeros((10, 10, 10, 3)), | ||
reference=nb.Nifti1Image(np.zeros((10, 10, 10, 3)), np.eye(4), None), | ||
) | ||
for idx in range(0,3): | ||
if idx == 0: | ||
i, j, k = 1, 0, 0 | ||
elif idx == 1: | ||
i, j, k = 0, 1, 0 | ||
elif idx == 2: | ||
i, j, k = 0, 0, 1 | ||
|
||
with pytest.raises(IndexError): | ||
PlotDenseField( | ||
transform=xfm._field, | ||
reference=xfm._reference, | ||
).test_slices( | ||
xslice=xfm._field.shape[0] + i, | ||
yslice=xfm._field.shape[1] + j, | ||
zslice=xfm._field.shape[2] + k, | ||
) | ||
|
||
|
||
def test_show_transform(data_path, output_path): | ||
PlotDenseField( | ||
transform=data_path / "ds-005_sub-01_from-OASIS_to-T1_warp_fsl.nii.gz" | ||
).show_transform( | ||
xslice=45, | ||
yslice=50, | ||
zslice=55, | ||
) | ||
if output_path is not None: | ||
plt.savefig(output_path / "show_transform.svg", bbox_inches="tight") | ||
else: | ||
plt.show() | ||
|
||
|
||
def test_plot_distortion(data_path, output_path): | ||
fig, axes = plt.subplots(1, 3, figsize=(12, 4)) | ||
PlotDenseField( | ||
transform=data_path / "ds-005_sub-01_from-OASIS_to-T1_warp_fsl.nii.gz" | ||
).plot_distortion( | ||
axes=axes, | ||
xslice=50, | ||
yslice=50, | ||
zslice=50, | ||
show_grid=True, | ||
show_brain=True, | ||
) | ||
if output_path is not None: | ||
plt.savefig(output_path / "plot_distortion.svg", bbox_inches="tight") | ||
else: | ||
plt.show() | ||
|
||
|
||
def test_plot_quiverdsm(data_path, output_path): | ||
fig, axes = plt.subplots(1, 3, figsize=(12, 4)) | ||
PlotDenseField( | ||
transform=data_path / "ds-005_sub-01_from-OASIS_to-T1_warp_fsl.nii.gz" | ||
).plot_quiverdsm( | ||
axes=axes, | ||
xslice=50, | ||
yslice=50, | ||
zslice=50, | ||
) | ||
|
||
if output_path is not None: | ||
plt.savefig(output_path / "plot_quiverdsm.svg", bbox_inches="tight") | ||
else: | ||
plt.show() | ||
|
||
|
||
def test_3dquiver(data_path, output_path): | ||
with pytest.raises(NotImplementedError): | ||
fig = plt.figure() | ||
axes = fig.add_subplot(projection='3d') | ||
PlotDenseField( | ||
transform=data_path / "ds-005_sub-01_from-OASIS_to-T1_warp_fsl.nii.gz", | ||
).plot_quiverdsm( | ||
axes=axes, | ||
xslice=None, | ||
yslice=None, | ||
zslice=None, | ||
three_D=True | ||
) | ||
|
||
if output_path is not None: | ||
plt.savefig(output_path / "plot_3dquiver.svg", bbox_inches="tight") | ||
else: | ||
plt.show() | ||
|
||
|
||
def test_plot_jacobian(data_path, output_path): | ||
fig, axes = plt.subplots(1, 3, figsize=(12, 5)) | ||
PlotDenseField( | ||
transform=data_path / "ds-005_sub-01_from-OASIS_to-T1_warp_fsl.nii.gz" | ||
).plot_jacobian( | ||
axes=axes, | ||
xslice=50, | ||
yslice=50, | ||
zslice=50, | ||
) | ||
|
||
if output_path is not None: | ||
plt.savefig(output_path / "plot_jacobian.svg", bbox_inches="tight") | ||
else: | ||
plt.show() | ||
|
||
|
||
if __name__ == "__main__": | ||
pytest.main([__file__]) | ||
jmarabotto marked this conversation as resolved.
Show resolved
Hide resolved
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The final cell seems to have failed:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've worked more on the notebook and fixed this since the last commit, it simply requires a 3x3 subplot (I carelessly copy pasted a 1x3 figure)
Edit: committed to fix, should work now 👍