Skip to content
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

[WIP][ENH] Move surface image API from experimental to stable API #4229

Closed
wants to merge 27 commits into from

Conversation

ymzayek
Copy link
Member

@ymzayek ymzayek commented Jan 17, 2024

Changes proposed in this pull request:

  • Changes compared to experimental.surface
    • Fetchers moved to datasets respectively to atlas, func, and struct
      • fetch_destrieux renamed load_sample_atlas_surf_destrieux
      • fetch_nki renamed load_sample_surf_nki_enhanced
      • load_fsaverage renamed load_surf_fsaverage
    • mesh_name parameter of load_surf_fsaverage renamed mesh for consistency with fetch_surf_fsaverage
    • Mesh base class renamed _Mesh
      • Mesh already exists as namedtuple which we will probably deprecate

TODO:

  • Double check public class/method and function names
  • Double check/improve docstrings (still need review of course)
  • How to handle I/O and provide some public functions to replace surface.py loaders
    • At the moment just copied over wrappers from experimental.surface._io to surface._io
  • Remove type hints
  • Update doc/modules/surface.rst and remove experimental.rst
  • Update experimental surface example
    • Integrate parts into stable examples (to do in follow-up PRs)
  • Increase testing
  • What to deprecate from old surface.py API?

The following PRs will depend on merging this one:
#4126
#4205
#4120 - already merged, relevant imports are updated in this PR

Copy link
Contributor

👋 @ymzayek 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.

  • PR has an interpretable title.
  • PR links to Github issue with mention Closes #XXXX (see our documentation on PR structure)
  • Code is PEP8-compliant (see our documentation on coding style)
  • Changelog or what's new entry in doc/changes/latest.rst (see our documentation on PR structure)

For new features:

  • There is at least one unit test per new function / class (see our documentation on testing)
  • The new feature is demoed in at least one relevant example.

For bug fixes:

  • There is at least one test that would fail under the original bug conditions.

We will review it as quick as possible, feel free to ping us with questions if needed.

Copy link

codecov bot commented Jan 17, 2024

Codecov Report

Attention: 7 lines in your changes are missing coverage. Please review.

Comparison is base (cfda9ff) 91.87% compared to head (048c744) 92.03%.

Files Patch % Lines
nilearn/datasets/func.py 64.28% 4 Missing and 1 partial ⚠️
nilearn/_utils/testing.py 66.66% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4229      +/-   ##
==========================================
+ Coverage   91.87%   92.03%   +0.16%     
==========================================
  Files         144      136       -8     
  Lines       16421    16217     -204     
  Branches     3434     3409      -25     
==========================================
- Hits        15086    14925     -161     
+ Misses        792      749      -43     
  Partials      543      543              
Flag Coverage Δ
macos-latest_3.10_test_plotting 91.82% <90.78%> (-0.04%) ⬇️
macos-latest_3.11_test_plotting 91.82% <90.78%> (-0.04%) ⬇️
macos-latest_3.12_test_plotting 91.82% <90.78%> (-0.04%) ⬇️
macos-latest_3.8_test_plotting 91.78% <90.78%> (-0.04%) ⬇️
macos-latest_3.9_test_plotting 91.78% <90.78%> (-0.04%) ⬇️
ubuntu-latest_3.10_test_plotting 91.82% <90.78%> (-0.04%) ⬇️
ubuntu-latest_3.11_test_plotting 91.82% <90.78%> (?)
ubuntu-latest_3.12_test_plotting 91.82% <90.78%> (-0.04%) ⬇️
ubuntu-latest_3.12_test_pre 91.82% <90.78%> (-0.04%) ⬇️
ubuntu-latest_3.8_test_min 68.62% <90.78%> (?)
ubuntu-latest_3.8_test_plot_min 91.53% <90.78%> (?)
ubuntu-latest_3.8_test_plotting 91.78% <90.78%> (?)
ubuntu-latest_3.9_test_plotting 91.78% <90.78%> (?)
windows-latest_3.10_test_plotting 91.80% <90.78%> (-0.04%) ⬇️
windows-latest_3.11_test_plotting 91.80% <90.78%> (-0.04%) ⬇️
windows-latest_3.12_test_plotting 91.80% <90.78%> (-0.04%) ⬇️
windows-latest_3.8_test_plotting 91.76% <90.78%> (-0.04%) ⬇️
windows-latest_3.9_test_plotting 91.76% <90.78%> (-0.04%) ⬇️

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

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.


PolyData = Dict[str, np.ndarray]


class Mesh(abc.ABC):
class _Mesh(abc.ABC):
Copy link
Member Author

Choose a reason for hiding this comment

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

If we want this to be a public class then need to deprecate surface.py's Mesh named tuple right away. Either way, we will need to deprecated the named tuples

Copy link
Collaborator

Choose a reason for hiding this comment

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

Probably worth pinning this one for later.

Copy link
Member

@bthirion bthirion left a comment

Choose a reason for hiding this comment

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

looks good so far.

nilearn/conftest.py Outdated Show resolved Hide resolved
nilearn/datasets/atlas.py Outdated Show resolved Hide resolved
nilearn/datasets/func.py Outdated Show resolved Hide resolved
@Remi-Gau Remi-Gau added the Surface Related to surface data or surface analysis. label Jan 23, 2024
nilearn/conftest.py Outdated Show resolved Hide resolved
nilearn/conftest.py Outdated Show resolved Hide resolved
Copy link
Collaborator

@Remi-Gau Remi-Gau Jan 23, 2024

Choose a reason for hiding this comment

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

TODO

  • move this file out of the experimental example

Copy link
Collaborator

Choose a reason for hiding this comment

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

Do in a follow up PR after we have dealt with:

nilearn/conftest.py Outdated Show resolved Hide resolved
nilearn/conftest.py Outdated Show resolved Hide resolved
@Remi-Gau
Copy link
Collaborator

Remi-Gau commented Jan 24, 2024

How to handle I/O and provide some public functions to replace surface.py loaders

At the moment just copied over wrappers from experimental.surface._io to surface._io

I think I would keep this for another PR probably one with example that shows basic "loading" of surface images because at the moment how to compose those SurfaceImage instances is hidden in our dataset utility functions like nilearn.datasets.func.load_sample_surf_nki_enhanced


n_vertices: int
n_vertices: ...
Copy link
Collaborator

Choose a reason for hiding this comment

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

OK I am sorry but I am putting types back in here because ... is just worse than mentioning the type.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fair. I wasn't sure what to do about these so it's a bit unfinished. I think you should add back PolyMesh and PolyData as well

Copy link
Collaborator

Choose a reason for hiding this comment

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

No worries. I was just confused as to why we were "ellisping" here.

In general, still sad we are removing type hints that were already here though.

Copy link
Member

Choose a reason for hiding this comment

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

you could remove the whole line or leave the type.

In general, still sad we are removing type hints that were already here though.

if they are complete enough within a sub-package that this part can successfully pass the mypy check we could leave them. what I would like to avoid is broken type hints, which is bound to happen if we don't run mypy in the ci

Comment on lines +282 to +285
# TODO check attribute names after PR 3761
# and harmonize with volume labels masker if necessary.
# https://github.com/nilearn/nilearn/pull/3761
def __init__(self, labels_img, label_names=None):
Copy link
Collaborator

Choose a reason for hiding this comment

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

TODO in a follow up PR

@Remi-Gau
Copy link
Collaborator

  • What to deprecate from old surface.py API?

For the moment I would deprecate as little as possible: have both APIs coexist in the next release and then slowly start redirect to the new API after that.

@Remi-Gau Remi-Gau changed the title [WIP][ENH] Move surface image API from experimental to stable API [ENH] Move surface image API from experimental to stable API Jan 24, 2024
@Remi-Gau Remi-Gau marked this pull request as ready for review January 24, 2024 09:21
@Remi-Gau Remi-Gau changed the title [ENH] Move surface image API from experimental to stable API [WIP][ENH] Move surface image API from experimental to stable API Jan 24, 2024
@Remi-Gau Remi-Gau marked this pull request as draft January 24, 2024 16:10
@Remi-Gau
Copy link
Collaborator

let's integrate plotting first before moving out of experimental

@Remi-Gau
Copy link
Collaborator

Remi-Gau commented Jan 24, 2024

TODO

  • extract the fixture renaming or turning into functions out of this PR.

@jeromedockes
Copy link
Member

jeromedockes commented Jan 24, 2024 via email

Copy link
Member

@bthirion bthirion left a comment

Choose a reason for hiding this comment

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

There remain a couple of "to fix" and codecov complaints (maybe wrong ?)
but I don't see anything fishy with the PR.
Nevertheless, we're not going to merge it shortly.

@Remi-Gau
Copy link
Collaborator

Remi-Gau commented Jun 5, 2024

Closing this one as it will be easier to start it from scratch rather than fixing the merge conflicts.

@Remi-Gau Remi-Gau closed this Jun 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Blocked Blocker Surface Related to surface data or surface analysis.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants