Skip to content

Commit c5244ba

Browse files
authored
Merge pull request #47 from neuroinformatics-unit/data-from-gin-fro-binder
Use pooch to retrieve data from gin
2 parents 8d2984a + c059d10 commit c5244ba

File tree

5 files changed

+75
-20
lines changed

5 files changed

+75
-20
lines changed

derotation/sample_data.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
"""Fetch and load sample datasets for derotation examples.
2+
3+
This module provides functions for fetching sample data used in examples.
4+
The data are stored in a remote repository and are downloaded to the user's
5+
local machine the first time they are used.
6+
"""
7+
8+
from pathlib import Path
9+
10+
import pooch
11+
12+
# URL to the remote data repository on GIN
13+
DATA_URL = "https://gin.g-node.org/l.porta/derotation_examples/raw/master/"
14+
15+
# Save data in ~/.derotation/data
16+
DATA_DIR = Path("~", ".derotation", "data").expanduser()
17+
DATA_DIR.mkdir(parents=True, exist_ok=True)
18+
19+
# File registry with SHA256 checksums for data integrity validation
20+
REGISTRY = {
21+
"angles_per_line.npy": (
22+
"0a5dab081acdfb47ebd5cdda4094cc622b1ff708c63f6fadc1e7898d30789896"
23+
),
24+
"rotation_sample.tif": (
25+
"ad8aae61cda9495d9006fb37a1f87be8b6dd6477318b1e8a409417cace208f56"
26+
),
27+
"analog_signals.npy": (
28+
"e04437f86d07db8077c256f912e2bcca75794712d66715f301b99cd9a8d66d95"
29+
),
30+
"stimulus_randperm.csv": (
31+
"214617992d786ee210a7d2f22dbe7420997016846a79c673979913a5b77f0a11"
32+
),
33+
}
34+
35+
# Create a download manager
36+
SAMPLE_DATA = pooch.create(
37+
path=DATA_DIR,
38+
base_url=DATA_URL,
39+
registry=REGISTRY,
40+
)
41+
42+
43+
def fetch_data(filename: str) -> Path:
44+
"""Fetch a sample data file.
45+
46+
Parameters
47+
----------
48+
filename : str
49+
Name of the file to fetch.
50+
51+
Returns
52+
-------
53+
Path
54+
Path to the downloaded file.
55+
"""
56+
if filename not in REGISTRY:
57+
raise ValueError(
58+
f"File '{filename}' not found in registry. "
59+
f"Available files: {list(REGISTRY.keys())}"
60+
)
61+
62+
return Path(SAMPLE_DATA.fetch(filename, progressbar=True))

examples/core_function.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,32 +20,25 @@
2020
"""
2121

2222
# %%
23-
from pathlib import Path
2423

2524
import matplotlib.pyplot as plt
2625
import numpy as np
2726
import tifffile
2827

2928
from derotation.derotate_by_line import derotate_an_image_array_line_by_line
30-
31-
# %%
32-
# Set up
33-
# -----------
34-
35-
current_module_path = Path.cwd()
36-
data_folder = current_module_path / "data"
29+
from derotation.sample_data import fetch_data
3730

3831
# %%
3932
# Load per-line rotation angles
4033

41-
angles_path = data_folder / "angles_per_line.npy"
34+
angles_path = fetch_data("angles_per_line.npy")
4235
print(f"Loading per-line rotation angles from {angles_path}")
4336
angles_per_line = np.load(angles_path) # Shape: (height,)
4437

4538
# %%
4639
# Load the TIFF stack (shape: num_frames × height × width)
4740

48-
tif_path = data_folder / "rotation_sample.tif"
41+
tif_path = fetch_data("rotation_sample.tif")
4942
print(f"Loading image stack from {tif_path}")
5043
image_stack = tifffile.imread(tif_path)
5144

examples/pipeline_with_real_data.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,20 +36,20 @@
3636

3737
from derotation.analysis.full_derotation_pipeline import FullPipeline
3838
from derotation.config.load_config import load_config, update_config_paths
39+
from derotation.sample_data import fetch_data
3940

4041
# %%
4142
# Load and update configuration
4243
# -----------------------------
4344
# We define paths relative to the current working directory
4445
current_module_path = Path.cwd()
45-
data_folder = current_module_path / "data"
4646

4747
config = load_config()
4848
config = update_config_paths(
4949
config=config,
50-
tif_path=str(data_folder / "rotation_sample.tif"),
51-
aux_path=str(data_folder / "analog_signals.npy"),
52-
stim_randperm_path=str(data_folder / "stimulus_randperm.csv"),
50+
tif_path=str(fetch_data("rotation_sample.tif")),
51+
aux_path=str(fetch_data("analog_signals.npy")),
52+
stim_randperm_path=str(fetch_data("stimulus_randperm.csv")),
5353
output_folder=str(current_module_path),
5454
)
5555

examples/use_plotting_hooks.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,22 +38,21 @@
3838

3939
from derotation.analysis.full_derotation_pipeline import FullPipeline
4040
from derotation.config.load_config import load_config, update_config_paths
41+
from derotation.sample_data import fetch_data
4142

4243
# %%
4344
# Load and configure paths
4445
# ------------------------
4546
# We'll use a small example dataset and write output to the current folder.
4647

47-
current_module_path = Path.cwd()
48-
data_folder = current_module_path / "data"
49-
output_folder = current_module_path
48+
output_folder = Path.cwd()
5049

5150
config = load_config()
5251
config = update_config_paths(
5352
config=config,
54-
tif_path=str(data_folder / "rotation_sample.tif"),
55-
aux_path=str(data_folder / "analog_signals.npy"),
56-
stim_randperm_path=str(data_folder / "stimulus_randperm.csv"),
53+
tif_path=str(fetch_data("rotation_sample.tif")),
54+
aux_path=str(fetch_data("analog_signals.npy")),
55+
stim_randperm_path=str(fetch_data("stimulus_randperm.csv")),
5756
output_folder=str(output_folder),
5857
)
5958

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ dependencies = [
3232
"scikit-learn",
3333
"scikit-image",
3434
"bayesian-optimization",
35+
"pooch",
3536
]
3637

3738
[project.urls]

0 commit comments

Comments
 (0)