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
[FIX] check data format passed to surface plotting functions #4323
Conversation
👋 @Remi-Gau Thanks for creating a PR! Until this PR is ready for review, you can include the [WIP] tag in its title, or leave it as a github draft. Please make sure it is compliant with our contributing guidelines. In particular, be sure it checks the boxes listed below.
For new features:
For bug fixes:
We will review it as quick as possible, feel free to ping us with questions if needed. |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #4323 +/- ##
==========================================
+ Coverage 91.85% 92.13% +0.28%
==========================================
Files 144 143 -1
Lines 16419 16462 +43
Branches 3434 3452 +18
==========================================
+ Hits 15082 15168 +86
+ Misses 792 749 -43
Partials 545 545
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
@@ -879,101 +879,102 @@ def test_plot_surf_roi_colorbar_vmin_equal_across_engines(kwargs): | |||
|
|||
|
|||
def test_plot_img_on_surf_hemispheres_and_orientations(img_3d_mni): | |||
nii = img_3d_mni |
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.
Several tests had this futile reassigning of the fixture, cleaning it up here.
@@ -1362,7 +1380,7 @@ def plot_img_on_surf(stat_map, surf_mesh='fsaverage5', mask_img=None, | |||
|
|||
Parameters | |||
---------- | |||
stat_map : str or 3D Niimg-like object | |||
stat_map : :obj:`str` or :class:`pathlib.Path` or 3D Niimg-like object |
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.
Tested that the code works with both string and path so updated the doc.
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.
On that note, it may be worth checking in the public API that users can also pass a Path in places where they can pass a string to a file.
I have not checked but it seems that many functions require a string and that Paths are not supported (or at least the doc string is not necessarily explicit - or I missed it).
May be done as some internal refactoring to rely more on pathlib rather than os (where relevant) - to be discussed.
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.
Yes, we should open an issue and address that later.
def img_3d_mni_as_file(tmp_path): | ||
"""Return path to a random 3D Nifti1Image in MNI space saved to disk.""" | ||
filename = tmp_path / "img.nii" | ||
nb.save(_img_3d_mni(), filename) | ||
return filename |
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.
Added in this as I needed it but probably reusable in other tests.
def _get_img(): | ||
@pytest.fixture(scope="session") | ||
def mni152_template_res_2(): |
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.
refactor this as fixture to help reusing it
def test_view_img_on_surf_errors(img_3d_mni): | ||
with pytest.raises(DimensionError): | ||
view_img_on_surf([img_3d_mni, img_3d_mni]) |
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.
extract errors in a separate test
def test_view_img_on_surf_input_as_file(img_3d_mni_as_file): | ||
view_img_on_surf(img_3d_mni_as_file) | ||
view_img_on_surf(str(img_3d_mni_as_file)) |
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.
check that files are accepted as string or paths
img = _get_img() | ||
surfaces = datasets.fetch_surf_fsaverage() | ||
html = html_surface.view_img_on_surf(img, threshold='92.3%') | ||
def test_view_img_on_surf(mni152_template_res_2): |
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.
sorry for the horrible diff on this part but this test was pretty unreadable
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.
Did not spot any issue. Thx.
@@ -1362,7 +1380,7 @@ def plot_img_on_surf(stat_map, surf_mesh='fsaverage5', mask_img=None, | |||
|
|||
Parameters | |||
---------- | |||
stat_map : str or 3D Niimg-like object | |||
stat_map : :obj:`str` or :class:`pathlib.Path` or 3D Niimg-like object |
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.
Yes, we should open an issue and address that later.
Changes proposed in this pull request: