-
Notifications
You must be signed in to change notification settings - Fork 3
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
Integrate BrainGlobe Atlas API to download atlases from within the GUI #75
Merged
Conversation
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
Add a panel to interface with the BrainGlobe Atlas API, which hosts atlases in a uniform and downloadable format. Provide a `BrainGlobeMM` class to interface with this API, accessing the listing of available atlases, downloading and removing atlases, and comparing with local copies. Provide another class, `BrainGlobePanel`, for handling these tasks in threads and with callbacks. Display this panel as another tab in the controls section of the app.
The functions to generate lookup references use the loaded reference stored as an instance attribute when the given argument is None. Make these arguments None by default.
Provide a parameter in the images setup function to take a BrainGlobe atlas object. Extract the image and labels reference data from this atlas to use as imaging data for display. Also, provide a simple wrapper to convert NumPy arrays to SimpleITK Image objects.
Integrate BrainGlobe atlases so that after downloading an atlas, the GUI displays it. Extend the handler for opening BrainGlobe atlases to set up the atlas for use throughout the app and display it. - Reset registered image suffixes even if ignoring filename changes if specified to reset - Simplify checks before opening and removing atlases - Provide feedback on fetching the atlas listing - Fix to still show local atlases when unable to fetch cloud atlases - Provide debugging when removing an atlas - Add type hints to the BrainGlobe model module
- Group into a sub-package - Rename the modules to reflect the Model-View-Controller organization
The BrainGlobe Atlas API package is now a required dependency to access cloud-based atlases.
Add changelog description and dependency requirement.
- Clarify that the update is for the table of atlases rather than the whole panel - Add docs
# Conflicts: # docs/release/release_v1.5.md # magmap/gui/visualizer.py # magmap/io/np_io.py # magmap/settings/config.py # setup.py
Flip from `x,y,z` to `z,y,x` when loading in MagellanMapper.
# Conflicts: # magmap/gui/visualizer.py # magmap/io/np_io.py
Re-add import missing after merge.
Commit 0c60b4c introduced a regression where loading an image through the image path control ignored the new path since the filename reset is True by default. Fix by reverting to the original behavior where the filename is skipped only if flagged to be ignored or if the filename is empty while still resetting the registered suffixes associated with the filename if flagged. For clarity, add a separate case to immediate return if the filename is empty. This change also avoids clearing registered suffixes when programmatically triggering a filename update by first clearing it with an empty string, which should be ignored in the handler.
Replace setting the reference in `config.labels_ref_lookup` to the new `config.labels_ref` location. - Set the BrainGlobe labels reference in place of the regular reference setup - Store the reference lookup dictionary in the reference object - Fix to use the new config attribute - Add an attribute to the `BrainAtlasGlobe` to store the path to the labels reference file
Now that labels references are loaded without requiring an annotation image, the warning has been issued anytime labels are not loaded, even if no labels were intended. Fix by filtering out all missing paths, which also simplifies the reference loading slightly.
…l label IDs Reloading an image in the GUI has set up the labels reference by setting it in `config.load_labels`. If another image were loaded afterward without original label IDs, image setup would use this old config reference to identify these original label IDs, leading to incorrect color mapping. Now that labels references are loaded from labels metadata when available, stop setting this config value when reloading an image. - Remove setting config labels path when reloading an image in the GUI - Add a parameter in image setup and pass in the path selected in the GUI when reloading an image in case the user has selected a custom path - Reset the reference path when opening a new image to prevent stale settings from the GUI - Group the labels reference path and level settings in `config` and clarify their intention to hold values set by the CLI
Per discussion at brainglobe/bg-atlasgen#25 (comment), the BrainGlobe resolutions correspond to the image's orientation in NumPy space. Commit 454fa60 introduced resolution reversal, but the resolution should be used as-is. Manually revert this change.
3 tasks
# Conflicts: # docs/release/release_v1.6.md # magmap/gui/visualizer.py
Add a library function to format values given in bytes into human-readable units, such as 1.0 KB instead of 1024 bytes. Inspired by solutions provided by: https://stackoverflow.com/a/58467404/1911852 https://lindevs.com/convert-file-size-in-bytes-into-human-readable-string-using-python/
Remove PyCharm file inadvertently introduced when merging master into this branch in commit 8480160.
Simplify and generalize panel name in the tabbed pane.
- Update task progress in the main GUI's progress bar rather than in the text area - Move attribute docstrings in-line - Quote type hints from own package to avoid potential circular import errors
7 tasks
Provide real-time updates by supplying a handler to BrainGlobe, which requires brainglobe/brainglobe-atlasapi#126. Format download sizes in human-readable units for the progress bar message.
# Conflicts: # docs/release/release_v1.6.md # magmap/tests/test_libmag.py
- Treat the percentage completed as unknown when reported size is 0 - Turn off logging for each progress update to reduce noise from download increments
Change the dependency from PyPi to the Git repository to use the pre-released progress function handler.
Shift atlas-related GUI controls from the ROI panel to the new atlases panel. This move will not only group the controls perhaps more intuitively, but also fix an issue where the GUI is too tall to fit on smaller screens.
- Pin dependencies for an environment with BrainGlobe dependencies installed - Build this environment in Python 3.6 since we are continue to support this version, even though some packages will be downgraded compared to the current requirements that were based on Python 3.7
Python 3.6 testing was removed when the pinned requirements were advanced to Python 3.8, but they were later brought back to 3.7 and now 3.6 since we are still supporting this version for the time being.
Add existing unit tests that had not been included in the automated testing.
Prior versions of Scikit-image could not be installed by Python 3.9 (see scikit-image/scikit-image#4919). Bump Scikit-image to the latest released version specifically for Python >= 3.9 in the pinned requirements file.
This test requires input images, which have not yet been supplied. Also, fix name of module.
Defer `Visualizer` testing until setting up UI testing within GitHub Actions.
Prepare for adding additional OSes by limiting these installs to Linux builds since the commands are specific to Ubuntu.
Test on macOS in addition to Ubuntu Linux.
Add Windows as another OS for CI testing.
Remove the Shell-style if-statement to avoid error when building in Windows PowerShell environment. This file is currently present in the repo and therefore does not need to be checked, as a missing file would suggest an error in and of itself.
Try using an environment variable defined using CI syntax to allow platform-agnostic usage.
Use the repo ZIP archive instead of downloading through Git to allow users without Git to set up the environment.
The atlas string contains multiple lines, which expands the progress bar height on Windows platforms. Simply remove this string since the atlas name is already included.
The Rich console used during BrainGlobe downloads generates log messages that require UTF-8 file encoding when saved to file. Change the rotating file handler to set this encoding.
The dtype matching used to convert NumPy arrays to SimpleITK `Image` objects may miss some dtypes, likely because of dynamic dtype construction that creates different identities. As a workaround, fall back to finding the appropriate dtype based on dtype string names and construct the `Image` object directly.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
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.
The BrainGlobe Atlas API provides access to a suite of readily available atlases. This PR utilizes the API in a new GUI panel to browse and download atlases for use in MagellanMapper. The panel provides a table showing the available atlases along with current download status, such as local copies available and whether they are up to date. Atlases can be selected and downloaded, using the API to download them to the default location specified by the API. The downloaded intensity image, annotation image, and labels reference files are loaded directly into the GUI's viewer to display similarly to other atlases loaded in MagellanMapper.
Currently, the API provides download feedback through its CLI. This feedback does not appear to be directly accessible from the API, meaning that the download progress is not available. The GUI runs the download in a separate thread to maintain interactivity during the download but will need a way to monitor the download progress.
UPDATE 2022-07-29
The following additional changes have been integrated (almost ready to go!):