Skip to content

Commit ffd6889

Browse files
authored
Merge pull request #373 from MICA-MNI/369-fix-histology-fslr32k-url
Add warning for fslr32k histology data resolution mismatch
2 parents 40dd056 + bd93ef1 commit ffd6889

3 files changed

Lines changed: 40 additions & 6 deletions

File tree

brainstat/_utils.py

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ def deprecated_func(*args, **kwargs):
150150
def _download_file(
151151
url: str, output_file: Path, overwrite: bool = False, verbose=True
152152
) -> None:
153-
"""Downloads a file.
153+
"""Downloads a file with retry logic for network failures.
154154
155155
Parameters
156156
----------
@@ -163,14 +163,36 @@ def _download_file(
163163
verbose : bool
164164
If true, print a download message, defaults to True.
165165
"""
166+
import time
167+
from http.client import RemoteDisconnected
168+
from urllib.error import URLError
166169

167170
if output_file.exists() and not overwrite:
168171
return
169172

170173
if verbose:
171174
logger.info("Downloading " + str(output_file) + " from " + url + ".")
172-
with urllib.request.urlopen(url) as response, open(output_file, "wb") as out_file:
173-
shutil.copyfileobj(response, out_file)
175+
176+
# Retry logic for intermittent network failures
177+
max_retries = 3
178+
retry_delay = 2 # seconds
179+
180+
for attempt in range(max_retries):
181+
try:
182+
with urllib.request.urlopen(url, timeout=30) as response, open(output_file, "wb") as out_file:
183+
shutil.copyfileobj(response, out_file)
184+
return # Success, exit function
185+
except (RemoteDisconnected, URLError, TimeoutError) as e:
186+
if attempt < max_retries - 1:
187+
logger.warning(
188+
f"Download attempt {attempt + 1}/{max_retries} failed: {e}. "
189+
f"Retrying in {retry_delay} seconds..."
190+
)
191+
time.sleep(retry_delay)
192+
retry_delay *= 2 # Exponential backoff
193+
else:
194+
logger.error(f"Download failed after {max_retries} attempts.")
195+
raise # Re-raise the exception after all retries fail
174196

175197

176198

brainstat/context/histology.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,15 @@ def read_histology_profile(
157157

158158
with h5py.File(histology_file, "r") as h5_file:
159159
if template == "fslr32k":
160+
# Known issue #369: The fslr32k data file on the server actually contains
161+
# fs_LR_64k resolution data (64984 vertices) instead of fs_LR_32k (32492 vertices).
162+
# This is a data hosting issue. Users expecting 32k resolution data should be aware
163+
# that they will receive 64k resolution data until this is fixed on the server.
164+
logger.warning(
165+
"Known issue: The fslr32k histology profile data currently contains "
166+
"fs_LR_64k resolution (64984 vertices) instead of fs_LR_32k (32492 vertices). "
167+
"See https://github.com/MICA-MNI/BrainStat/issues/369 for details."
168+
)
160169
profiles = h5_file.get("fs_LR_64k")[...]
161170
else:
162171
profiles = h5_file.get(template)[...]
@@ -196,6 +205,12 @@ def download_histology_profiles(
196205
data_dir.mkdir(parents=True, exist_ok=True)
197206
if template == "fslr32k":
198207
output_file = data_dir / "histology_fslr32k.h5"
208+
# Known issue #369: warn users about data resolution mismatch
209+
logger.warning(
210+
"Note: The fslr32k histology profile data currently contains "
211+
"fs_LR_64k resolution (64984 vertices) instead of fs_LR_32k. "
212+
"See https://github.com/MICA-MNI/BrainStat/issues/369 for details."
213+
)
199214
else:
200215
output_file = data_dir / ("histology_" + template + ".h5")
201216

brainstat/tests/test_histology.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@ def test_urls(template):
1818
template : list
1919
Template names.
2020
"""
21-
if template == "fslr32k":
22-
pytest.skip("Skipping fslr32k due to known netneurotools 0.3.0 Unicode bug")
23-
2421
try:
2522
r = requests.head(json["bigbrain_profiles"][template]["url"], timeout=10)
2623
assert r.status_code == 200

0 commit comments

Comments
 (0)