-
Notifications
You must be signed in to change notification settings - Fork 99
Adding a registry to have the hashes of datasets (restructured for aws s3) #1076
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
Open
selmanozleyen
wants to merge
24
commits into
scverse:main
Choose a base branch
from
selmanozleyen:add-dataset-hashes
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+2,085
−656
Open
Changes from 17 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
1f0ef4e
init
selmanozleyen 0a063ce
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] b301fdc
Merge branch 'main' into add-dataset-hashes
selmanozleyen 2f7cd58
linter errors
selmanozleyen 63a5d58
readthedocs fix
selmanozleyen a2cb8bc
extension bug fix
selmanozleyen 8e3685e
Merge branch 'main' into add-dataset-hashes
selmanozleyen 03288db
use cache dir
selmanozleyen b06f7a7
all downloads cache to squidpy default. Don't use scanpy default sinc…
selmanozleyen e7f8399
format
selmanozleyen dc21ced
add docs
selmanozleyen 5f75195
PathLike refactor
selmanozleyen 001a733
redirect notebooks to the correct module
selmanozleyen ec6b02b
update script
selmanozleyen f086493
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 7ce86a3
since we have the hash of downloaded files we don't need to update fo…
selmanozleyen b4a0074
Merge branch 'add-dataset-hashes' of https://github.com/selmanozleyen…
selmanozleyen 2adb236
update script
selmanozleyen 09e3cba
format
selmanozleyen d51b08c
remove agent spoofing
selmanozleyen 8e99d3c
remove fallbacks
selmanozleyen 383c820
if path is not None
selmanozleyen adc9d53
more structured logic
selmanozleyen d38caf2
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,77 +1,81 @@ | ||
| #!/usr/bin/env python3 | ||
| """Download datasets to populate CI cache. | ||
| This script downloads all datasets that tests might need. | ||
| The downloader handles caching to DEFAULT_CACHE_DIR (~/.cache/squidpy). | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import argparse | ||
| from pathlib import Path | ||
| from typing import Any | ||
|
|
||
| from squidpy.datasets import visium_hne_sdata | ||
|
|
||
| _CNT = 0 # increment this when you want to rebuild the CI cache | ||
| _ROOT = Path.home() / ".cache" / "squidpy" | ||
|
|
||
|
|
||
| def _print_message(func_name: str, path: Path, *, dry_run: bool = False) -> None: | ||
| prefix = "[DRY RUN]" if dry_run else "" | ||
| if path.is_file(): | ||
| print(f"{prefix}[Loading] {func_name:>25} <- {str(path):>25}") | ||
| else: | ||
| print(f"{prefix}[Downloading] {func_name:>25} -> {str(path):>25}") | ||
|
|
||
|
|
||
| def _maybe_download_data(func_name: str, path: Path) -> Any: | ||
| import squidpy as sq | ||
|
|
||
| try: | ||
| return getattr(sq.datasets, func_name)(path=path) | ||
| except Exception as e: # noqa: BLE001 | ||
| print(f"File {str(path):>25} seems to be corrupted: {e}. Removing and retrying") | ||
| path.unlink() | ||
|
|
||
| return getattr(sq.datasets, func_name)(path=path) | ||
|
|
||
|
|
||
| def main(args: argparse.Namespace) -> None: | ||
| from anndata import AnnData | ||
|
|
||
| import squidpy as sq | ||
| from squidpy.datasets._downloader import DEFAULT_CACHE_DIR | ||
| from squidpy.datasets._registry import get_registry | ||
|
|
||
| all_datasets = sq.datasets._dataset.__all__ + sq.datasets._image.__all__ | ||
| all_extensions = ["h5ad"] * len(sq.datasets._dataset.__all__) + ["tiff"] * len(sq.datasets._image.__all__) | ||
| registry = get_registry() | ||
| print(f"Cache directory: {DEFAULT_CACHE_DIR}") | ||
|
|
||
| # Visium samples tested in CI | ||
| # Add any sample here that's used in tests to ensure it's cached | ||
| visium_samples_to_cache = [ | ||
| "V1_Mouse_Kidney", | ||
| "Targeted_Visium_Human_SpinalCord_Neuroscience", | ||
| "Visium_FFPE_Human_Breast_Cancer", | ||
| ] | ||
|
|
||
| if args.dry_run: | ||
| for func_name, ext in zip(all_datasets, all_extensions): | ||
| if func_name == "visium_hne_sdata": | ||
| ext = "zarr" | ||
| path = _ROOT / f"{func_name}.{ext}" | ||
| _print_message(func_name, path, dry_run=True) | ||
| print("\nWould download:") | ||
selmanozleyen marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| print(f" - {len(registry.anndata_datasets)} AnnData datasets") | ||
| print(f" - {len(registry.image_datasets)} Image datasets") | ||
| print(f" - {len(registry.spatialdata_datasets)} SpatialData datasets") | ||
| print(f" - {len(visium_samples_to_cache)} Visium samples") | ||
| return | ||
|
|
||
| # could be parallelized, but on CI it largely does not matter (usually limited to 2 cores + bandwidth limit) | ||
| for func_name, ext in zip(all_datasets, all_extensions): | ||
| if func_name == "visium_hne_sdata": | ||
| ext = "zarr" | ||
| path = _ROOT / f"{func_name}.{ext}" | ||
|
|
||
| _print_message(func_name, path) | ||
| obj = visium_hne_sdata(_ROOT) | ||
|
|
||
| assert path.is_dir(), f"Expected a .zarr folder at {path}" | ||
| continue | ||
|
|
||
| path = _ROOT / f"{func_name}.{ext}" | ||
| _print_message(func_name, path) | ||
| obj = _maybe_download_data(func_name, path) | ||
|
|
||
| # we could do without the AnnData check as well (1 less req. in tox.ini), but it's better to be safe | ||
| assert isinstance(obj, AnnData | sq.im.ImageContainer), type(obj) | ||
| assert path.is_file(), path | ||
| # Download AnnData datasets - just call the function, it handles caching | ||
| print("\nDownloading AnnData datasets...") | ||
selmanozleyen marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| for name in registry.anndata_datasets: | ||
| print(f" {name}") | ||
| obj = getattr(sq.datasets, name)() | ||
| assert isinstance(obj, AnnData), f"Expected AnnData, got {type(obj)}" | ||
|
|
||
| # Download image datasets | ||
| print("\nDownloading image datasets...") | ||
| for name in registry.image_datasets: | ||
| print(f" {name}") | ||
| obj = getattr(sq.datasets, name)() | ||
| assert isinstance(obj, sq.im.ImageContainer) | ||
|
|
||
| # Download SpatialData datasets | ||
| print("\nDownloading SpatialData datasets...") | ||
| for name in registry.spatialdata_datasets: | ||
| print(f" {name}") | ||
| obj = getattr(sq.datasets, name)() | ||
| # Returns SpatialData object | ||
|
|
||
| # Download Visium samples (needed for tests) | ||
| # Include high-res images since tests use include_hires_tiff=True | ||
| print("\nDownloading Visium samples (with high-res images)...") | ||
| for sample in visium_samples_to_cache: | ||
| print(f" {sample}") | ||
| obj = sq.datasets.visium(sample, include_hires_tiff=True) | ||
| assert isinstance(obj, AnnData), f"Expected AnnData, got {type(obj)}" | ||
|
|
||
| print("\nDone!") | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| parser = argparse.ArgumentParser(description="Download data used for tutorials/examples.") | ||
| parser = argparse.ArgumentParser(description="Download datasets to populate CI cache.") | ||
| parser.add_argument( | ||
| "--dry-run", action="store_true", help="Do not download any data, just print what would be downloaded." | ||
| "--dry-run", | ||
| action="store_true", | ||
| help="Do not download, just print what would be downloaded.", | ||
| ) | ||
|
|
||
| main(parser.parse_args()) | ||
This file contains hidden or 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
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.