-
Notifications
You must be signed in to change notification settings - Fork 48
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
Refactor segmentation_to_objects
#304
Conversation
These changes are to enable @ania-m-b to do some "advanced" analysis. |
Preview page for your plugin is ready here: |
@paddyroddy and @p-j-smith - this should also help with some aspects of running this from the napari plugin |
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.
Have added some thoughts
def extra_prop(_mask) -> float: | ||
return np.sum(_mask) | ||
|
||
extra_properties = (extra_prop,) |
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.
Why not just something like this?
extra_properties = (extra_prop,) | |
extra_properties = (np.sum(_mask),) |
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.
Happy to do it this way, but I was trying to emulate how an end user would actually use this. Probably doesn't matter in the tests
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.
Ah I see. I couldn't really make sense of it.
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 idea is that you can now provide functions that work on the image data and return properties that become part of the PyTrackObject
properties - it's much cleaner to use and makes end-use much more powerful
btrack/io/_localization.py
Outdated
# this provides a dummy progress bar in case `tqdm` is not installed. | ||
def tqdm(iterator, *args, **kwargs): | ||
logger.info("Try installing ``tqdm`` for progress bar rendering.") | ||
return iterator |
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.
Why wouldn't tqdm
be installed?
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 just left it optional, we could add to the requirements
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 don't see any harm in that?
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.
If we want it optional could add something similar to optional-dependencies.docs
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 added it as a requirement. I think it could be useful in other parts of the codebase too
def _next_array(self) -> Tuple[npt.NDArray, Optional[npt.NDArray]]: | ||
"""__next__ method for an array-like input.""" | ||
if self._iter >= len(self): | ||
raise StopIteration |
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.
What happens when this is raised? Should we have some sort of logging?
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.
This StopIteration
just allows the iterator to stop when it get's to the end of the data. It doesn't interrupt execution of the code
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.
Cool
centroid_type: str = "centroid" | ||
intensity_image: Optional[npt.NDArray] = None | ||
scale: Optional[Tuple[float]] = None | ||
assign_class_ID: bool = False # noqa: N815 |
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.
Once python=3.10
is the min we support, we can use dataclasses.KW_ONLY
to avoid the noqa
here
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.
Nice! I think this is actually because of the mixed case here
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.
Oops, I should have checked what the error is for
btrack/io/_localization.py
Outdated
import logging | ||
from typing import Generator, List, Optional, Tuple, Union | ||
from multiprocessing.pool import ThreadPool as Pool |
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.
Have you considered concurrent.futures.ThreadPoolExecutor
?
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.
Oops - this is a good catch, it's actually supposed to be just a Pool
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 feel like this is something we can take a look at when this is integrated into the napari plugin - I'm not sure what the best way to play with that is yet
Co-authored-by: Patrick Roddy <patrickjamesroddy@gmail.com>
Co-authored-by: Patrick Roddy <patrickjamesroddy@gmail.com>
Co-authored-by: Patrick Roddy <patrickjamesroddy@gmail.com>
Codecov ReportPatch coverage:
📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more Additional details and impacted files@@ Coverage Diff @@
## main #304 +/- ##
==========================================
+ Coverage 84.09% 84.47% +0.37%
==========================================
Files 30 30
Lines 1905 1932 +27
Branches 295 295
==========================================
+ Hits 1602 1632 +30
+ Misses 216 215 -1
+ Partials 87 85 -2
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report in Codecov by Sentry. |
Thanks for the review @paddyroddy - I think I took care of everything. |
This PR refactors a critical function
segmentation_to_objects
:tqdm
is installed, to provide feedbackPool
for more performant detectionextra_properties