Repository navigation
Move source to _skimage2, copy tests - #8204
Conversation
From: scikit-image#7980 - the filter is redundant because we're already using pytest.warns for these.
| if inspect.isclass(func_or_class): | ||
| func_or_class.__init__ = self._wrap_callable_with_warning( | ||
| func_or_class.__init__, warn_msg, warning_cls | ||
| ) | ||
| return func_or_class |
There was a problem hiding this comment.
This misses initialization with classmethods which we use / may use for the transform classes.
We should probably revisit this after merging or when we get to that.
There was a problem hiding this comment.
Yes, reasonable point - raise an issue so we don't forget?
The name isn't very useful to glean the purpose but probably not worth chaning right now. So just note for future readers.
Note especially the new behavior of always looking for a public name in skimage!
From @lagru's suggestion.
| @@ -13,6 +13,8 @@ | |||
| __getattr__ = _skimage2.__getattr__ | |||
|
|
|||
|
|
|||
| # Re-use the warning category defined on ``_skimage2`` so filters and test | |||
| # harnesses can target ``ExperimentalAPIWarning`` consistently. | |||
There was a problem hiding this comment.
I don't understand this comment. Is that an appeal to the reader to use this class? If so where? Or is that describing the following line where a warning is raised?
What is the harness in reference to? LLM-related?
There was a problem hiding this comment.
Happy to remove the comment. It was LLM-generated - I believe "harness" just means pytest + CI, and the comment was to explain why we're importing the warning rather than using a new one.
to match the warning text and porting document.
There was a problem hiding this comment.
I wouldn't mind more (any) documentation for this script. I'm unsure what this does without having spent time reading it in detail.
Is this meant to be used in the future? If so for what? Or is this documenting an automated part of this PR?
There was a problem hiding this comment.
Happy to remove it if you prefer. I was imagining that someone following in our footsteps might want to use it, but maybe not. I can always move it to the private scripts repository.
| from _skimage2 import filters, feature | ||
| from _skimage2.util.dtype import img_as_float32 | ||
|
|
||
| # Ski2: address legacy scaling. |
There was a problem hiding this comment.
Are these kind of TODOs listed somewhere else?
Maybe we can update these to start with # TODO since that is commonly recognized by tooling as a TODO-item out of the box.
marching_cubes with a mask only consulted one corner per cube, so voxels at index 0 could never be masked and the surface could leak one cube past the mask boundary (scikit-imagegh-8202). Gate each cube on all eight corners it reads. Rebased onto the _skimage2 source migration (scikit-image#8204); the fix and tests now live in the _skimage2 tree, with the area assertion in test_masked_marching_cubes updated in both test copies.
This is the promised megamove.
src/_skimage2, andtests/skimagetotests/skimage2.src/_skimage2.tools/port_module.pyscript (now in https://github.com/scikit-image/internal-scripts/blob/b92065b/src/megamove/_port_module.py) on thesrc/_skimage2tree to make shim modules in theskimagetree.src/_skimage2functions in the
src/skimagetree._imports not picked up by the shims, that were using
import *.particular, the original
skimagetests, now copied, were testing theskimagebehavior, and in some cases, this had changed because of our pre-existingedits in the
_skimage2tree. The tests needed to be adapted.Here are some thoughts that came up, as I was doing this:
filters/_gaussian.py:difference_of_gaussians, asa temporary workaround. We should test the unscaled behavior.
src/_skimage2/feature/_basic_features.py.Using
# TODO - ski2:as comment marker for port issues that must be addressed.tests/skimage2/segmentation/test_active_contour_model.py._skimage2/feature/corner.py:corner_peakshas to callpeak_local_max,which pulls in the
_skimage2version ofpeak_local_max, changing defaultbehavior. For the moment, adapt to that, waiting for Lars' PR to remove
corner_peaksin_skimage2.find_boundariesnow pulls in the Skimage2erosionanddilation. Thedefault edge mode has changed for those functions, from
mode='reflect'tomode='ignore'. It appears, from discussion with Cursor, thatmode='reflect'is correct and necessary for image edges infind_boundaries. Added a# TODO - ski2comment to remind us to review.tests/skimage2/feature/test_peak.pyto adapt tonew
peak_local_maxdefaults. These need review.morphology/footprints.pyinto
_footprintsor something else.util/look_for.pytoutil/_look_for.py. Module namepreviously shadowed in
utilnamespace by functionlookfor. I could findno code instances of
/(from|import) skimage.util.lookfor/on Github.morphology/max_tree.pytomorphology/_max_tree.py. Modulename previously shadowed in
morphologynamespace by functionmax_tree.I could find no code instances of
/(from|import) skimage.morphology.max_tree/on Github.morphology/_max_tree.pyxtomorphology/_max_tree_cy.py.No code instances on Github with
/(from|import) skimage.morphology._max_tree/.Although these last renaming changes are technically API changes in
skimage, given (as far as we can see) no-one appears to be using the implied API, I think it's OK to make this silent.For an analysis of why these renames were needed, after implementing lazy loading of
morphologyandlookforin the_skimage2tree: https://github.com/matthew-brett/lazy-load-pain . In sum, with lazy loading, if one first loads a lazy-loaded namespace withfrom ns import *, and there is a module (saymy_name) with the same name as one of the attributes, then a subsequent access ofns.my_namepicks up the module not the intended attribute. I believe this was a bug in lazy-loading, fixed by scientific-python/lazy-loader#171 .For review - it would be useful to have a look at the following commits:
skimagefor dispatching backends.skimageandskimage2searchpublic_api_namesto shim namespaces inskimage.AI usage - I've noted this in the commit messages. For the later commits, I leaned fairly heavily on Cursor, but of course I reviewed and usually edited / renegotiated before committing.
We'll need to revert commit cea28da when this gets merged. That commit makes Pooch look for test data in the original
tests/skimagetree, but after this is merged, data will be in thetests/skimage2tree.This change makes all pre-megamove PRs generate rather ugly merge conflicts. Cursor wrote a utility to route the changes appropriately, and specifically:
tests/skimage2and the originaltest/skimage.src/skimagecode changes do not go inskimageunless they areskimagewrappers for forskimage2code. Instead they go tosrc/_skimage2.I've put Cursor's scripts in a private repo for now: https://github.com/scikit-image/internal-scripts . Private because a) I haven't reviewed the code and b) I can't vouch for copyright.
Note that - after this PR - the
skimagedoctests will read as being_skimage2doctests. We should adapt the shimmed functions to useskimageinstead of_skimage2for doctests. Draft Cursor implementation as follow-up PR at #8219The code move will mess up any pickles expecting implementations to be in
skimagemodules. We could fix that, with the addition of some complexity. See: #8220 .