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

Improve types and docstrings #109

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions .github/workflows/unit_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@ jobs:

steps:
- uses: actions/checkout@v4
- name: Setup pip cache
uses: actions/cache@v3
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements*.txt') }}
- name: Set up Python 3.10
uses: actions/setup-python@v5
with:
Expand All @@ -28,17 +23,18 @@ jobs:
conda env update --file .github/additional_files/environment.yml --name base
- name: Install package
run: |
pip install .
pip install uv
uv pip install --system .

- name: Install pre-commit
run: |
pip install pre-commit
uv pip install --system pre-commit
- name: Run pre-commit checks
run: |
pre-commit install
pre-commit run --all-files

- name: Test with pytest
run: |
pip install pytest
uv pip install --system pytest
pytest
108 changes: 43 additions & 65 deletions src/scportrait/data/_datasets.py
Original file line number Diff line number Diff line change
@@ -1,145 +1,123 @@
import os
from pathlib import Path

from scportrait.data._dataloader import _download
from scportrait.tools.ml.pretrained_models import _get_data_dir
from scportrait.tools.ml.pretrained_models import get_data_dir


def dataset_1():
"""
Download and extract the example dataset 1 images.
def dataset_1() -> Path:
"""Download and extract the example dataset 1 images.

Returns:
Path to the downloaded and extracted images.
"""
data_dir = _get_data_dir()
save_path = os.path.join(data_dir, "example_1_images")

if not Path(save_path).exists():
data_dir = Path(get_data_dir())
save_path = data_dir / "example_1_images"
if not save_path.exists():
_download(
url="https://zenodo.org/records/13385933/files/example_1_images.zip?download=1",
output_path=save_path,
output_path=str(save_path),
archive_format="zip",
)

return save_path


def dataset_2():
"""
Download and extract the example dataset 2 images.
def dataset_2() -> Path:
"""Download and extract the example dataset 2 images.

Returns:
Path to the downloaded and extracted images.
"""
data_dir = _get_data_dir()
save_path = os.path.join(data_dir, "example_2_images")

if not Path(save_path).exists():
data_dir = Path(get_data_dir())
save_path = data_dir / "example_2_images"
if not save_path.exists():
_download(
url="https://zenodo.org/records/13742316/files/example_2_images.zip?download=1",
output_path=save_path,
output_path=str(save_path),
archive_format="zip",
)

return save_path


def dataset_3():
"""
Download and extract the example dataset 3 images.
def dataset_3() -> Path:
"""Download and extract the example dataset 3 images.

Returns:
Path to the downloaded and extracted images.
"""
data_dir = _get_data_dir()
save_path = os.path.join(data_dir, "example_3_images")

if not Path(save_path).exists():
data_dir = Path(get_data_dir())
save_path = data_dir / "example_3_images"
if not save_path.exists():
_download(
url="https://zenodo.org/records/13742319/files/example_3_images.zip?download=1",
output_path=save_path,
output_path=str(save_path),
archive_format="zip",
)

return save_path


def dataset_4():
"""
Download and extract the example dataset 4 images.
def dataset_4() -> Path:
"""Download and extract the example dataset 4 images.

Returns:
Path to the downloaded and extracted images.
"""
data_dir = _get_data_dir()
save_path = os.path.join(data_dir, "example_4_images")

if not Path(save_path).exists():
data_dir = Path(get_data_dir())
save_path = data_dir / "example_4_images"
if not save_path.exists():
_download(
url="https://zenodo.org/records/13742331/files/example_4_images.zip?download=1",
output_path=save_path,
output_path=str(save_path),
archive_format="zip",
)

return save_path


def dataset_5():
"""
Download and extract the example dataset 5 images.
def dataset_5() -> Path:
"""Download and extract the example dataset 5 images.

Returns:
Path to the downloaded and extracted images.
"""
data_dir = _get_data_dir()
save_path = os.path.join(data_dir, "example_5_images")

if not Path(save_path).exists():
data_dir = Path(get_data_dir())
save_path = data_dir / "example_5_images"
if not save_path.exists():
_download(
url="https://zenodo.org/records/13742344/files/example_5_images.zip?download=1",
output_path=save_path,
output_path=str(save_path),
archive_format="zip",
)

return save_path


def dataset_6():
"""
Download and extract the example dataset 6 images.
def dataset_6() -> Path:
"""Download and extract the example dataset 6 images.

Returns:
Path to the downloaded and extracted images.
"""
data_dir = _get_data_dir()
save_path = os.path.join(data_dir, "example_6_images")

if not Path(save_path).exists():
data_dir = Path(get_data_dir())
save_path = data_dir / "example_6_images"
if not save_path.exists():
_download(
url="https://zenodo.org/records/13742373/files/example_6_images.zip?download=1",
output_path=save_path,
output_path=str(save_path),
archive_format="zip",
)

return save_path


def dataset_stitching_example():
"""
Download and extract the example dataset for stitching images.
def dataset_stitching_example() -> Path:
"""Download and extract the example dataset for stitching images.

Returns:
Path to the downloaded and extracted images.
"""
data_dir = _get_data_dir()
save_path = os.path.join(data_dir, "stitching_example")

if not Path(save_path).exists():
data_dir = Path(get_data_dir())
save_path = data_dir / "stitching_example"
if not save_path.exists():
_download(
url="https://zenodo.org/records/13742379/files/example_stitching.zip?download=1",
output_path=save_path,
output_path=str(save_path),
archive_format="zip",
)

return save_path
Loading