Skip to content

Commit 0cd803d

Browse files
committed
Rename retrieve_example_data to download_example_data
1 parent 8121227 commit 0cd803d

File tree

2 files changed

+44
-8
lines changed

2 files changed

+44
-8
lines changed

optimap/utils.py

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"print_properties",
88
"enable_interactive_backend_switching",
99
"disable_interactive_backend_switching",
10-
"retrieve_example_data",
10+
"download_example_data",
1111
]
1212

1313
import functools
@@ -24,7 +24,9 @@
2424
VERBOSE = False
2525
INTERACTIVE_BACKEND = "QtAgg"
2626
INTERACTIVE_BACKEND_SWITCHING = True
27-
FILE_HASHES = {
27+
28+
# old example file names and hashes, will be removed in the future
29+
OLD_FILE_HASHES = {
2830
"Example_01_Sinus_Rabbit_Basler.npy":
2931
"sha256:5c692cca0459c931b7f767c27162a42b31e3df90a6aeac53bb182affa2135678",
3032
"Example_02_VF_Rabbit_Di-4-ANEPPS_Basler_acA720-520um.npy":
@@ -42,6 +44,28 @@
4244
"Example_02_VF_Rabbit_Di-4-ANEPPS_Basler_acA720-520um_warped.npy":
4345
"sha256:a1781582b669a69a9753b1c43d23e0acf26fb372426eeb6d880d2e66420b2107",
4446
"Example_02_VF_Rabbit_Di-4-ANEPPS_Basler_acA720-520um_warped_mask.npy":
47+
"sha256:3f5d8402c8251f3cb8e8d235b459264ff7e7e2cf2b81f08129f0897baa262db6",
48+
}
49+
50+
# New example file names and hashes
51+
FILE_HASHES = {
52+
"Example_01_Sinus.npy":
53+
"sha256:5c692cca0459c931b7f767c27162a42b31e3df90a6aeac53bb182affa2135678",
54+
"Example_02_VF.npy":
55+
"sha256:6252da91db434cad95758830fdf7c13a9db6793da30dd8e85e6878736e20787e",
56+
"Example_03_Pacing.npy":
57+
"sha256:50113334e6955f5abb3658b5027447f507fd9eef6bfef766a628c2365ff848be",
58+
"Example_04_Pacing.npy":
59+
"sha256:674603f64ccf754f73a264986e0bf1ee93d03ce3a9ea88f248620632046e3c40",
60+
"Example_05_Ratiometry.npy":
61+
"sha256:10a59863ee23abc689d8ee4cd27542ef1b7b8b8eb5668a7f2dc49572f18319f2",
62+
# used in tests
63+
"test-download-file.npy":
64+
"sha256:0d3cfca36d8e3ad935de4d0681ddd510c1590212a99dccb196353c8ce85b7491",
65+
# warped version of Example_02, used to speed up documentation build
66+
"Example_02_VF_warped.npy":
67+
"sha256:a1781582b669a69a9753b1c43d23e0acf26fb372426eeb6d880d2e66420b2107",
68+
"Example_02_VF_warped_mask.npy":
4569
"sha256:3f5d8402c8251f3cb8e8d235b459264ff7e7e2cf2b81f08129f0897baa262db6"
4670
}
4771

@@ -175,7 +199,12 @@ def wrapper(*args, **kwargs):
175199

176200
return wrapper
177201

202+
@deprecated("Use download_example_data instead")
178203
def retrieve_example_data(name, directory="./example_data", silent=False):
204+
return download_example_data(name, directory=directory, silent=silent)
205+
206+
207+
def download_example_data(name, directory="./example_data", silent=False):
179208
"""Download example data if not already present.
180209
181210
Parameters
@@ -192,16 +221,23 @@ def retrieve_example_data(name, directory="./example_data", silent=False):
192221
str
193222
Path to the file.
194223
"""
195-
known_hash = FILE_HASHES.get(name, None)
196-
if known_hash is None:
197-
warnings.warn(f"WARNING: Example file '{name}' is not known. Attempting to download it anyway.", UserWarning)
198224
if silent:
199225
silent = pooch.get_logger().level
200226
pooch.get_logger().setLevel("WARNING")
201227

228+
known_hash = FILE_HASHES.get(name, None)
229+
remote_path = urllib.parse.quote(f"optimap-{name}", safe="")
230+
231+
# Compatibility with old file names, will be removed in the future
232+
if known_hash is None and name in OLD_FILE_HASHES:
233+
known_hash = OLD_FILE_HASHES[name]
234+
remote_path = urllib.parse.quote(f"{name}", safe="")
235+
236+
if known_hash is None:
237+
warnings.warn(f"WARNING: Example file '{name}' is not known. Attempting to download it anyway.", UserWarning)
238+
202239
# The CMS server only allows files with a certain extensions to be uploaded.
203240
# We use .webm as dummy extension to upload the files, and rename them after download.
204-
remote_path = urllib.parse.quote(f"{name}", safe="")
205241
url = f"https://cardiacvision.ucsf.edu/sites/g/files/tkssra6821/f/{remote_path}_.webm"
206242

207243
path = pooch.retrieve(

tests/test_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
import optimap as om
66

77

8-
def test_retrieve_sample():
9-
filename = om.utils.retrieve_example_data("optimap-test-download-file.npy")
8+
def test_download_example_data():
9+
filename = om.utils.download_example_data("test-download-file.npy")
1010
assert Path(filename).exists()
1111
assert Path(filename).is_file()
1212
assert Path(filename).suffix == ".npy"

0 commit comments

Comments
 (0)