Skip to content

Commit

Permalink
refactor data download
Browse files Browse the repository at this point in the history
  • Loading branch information
ilkilic committed Jan 26, 2024
1 parent dcb6923 commit 9d587e8
Showing 1 changed file with 15 additions and 22 deletions.
37 changes: 15 additions & 22 deletions tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,18 @@
import shutil
from pathlib import Path

def download_datafiles(pathname, channels, numbers, output_dir, gb_url):
paths = [f"{pathname}_{ch}_{n}.ibw" for ch in channels for n in numbers]

Path(output_dir).mkdir(exist_ok=True, parents=True)
for path in paths:
output_path = f"{output_dir}{path}"
if not Path(output_path).is_file():
with urllib.request.urlopen(f"{gb_url}{path}") as response, open(output_path, "wb") as out_file:
shutil.copyfileobj(response, out_file)

def download_sahp_datafiles():
"""Download data files for sAHP and IDthresh traces"""
"""Download data files for sAHP and IDthresh traces."""
output_dir = "./tests/exp_data/X/"
gb_url = "https://raw.githubusercontent.com/BlueBrain/SSCxEModelExamples/main/feature_extraction/input-traces/C060109A1-SR-C1/"
sahp_pathname = "X_sAHP"
Expand All @@ -16,19 +25,11 @@ def download_sahp_datafiles():
idthresh_ch = ["ch0", "ch1"]
idthresh_numbers = list(range(349, 358)) + list(range(362, 371))

sahp_paths = [f"{sahp_pathname}_{ch}_{n}.ibw" for ch in sahp_ch for n in sahp_numbers]
idthresh_paths = [f"{idthresh_pathname}_{ch}_{n}.ibw" for ch in idthresh_ch for n in idthresh_numbers]
pathnames = sahp_paths + idthresh_paths

Path(output_dir).mkdir(exist_ok=True, parents=True)
for pathname in pathnames:
output_path = f"{output_dir}{pathname}"
if not Path(output_path).is_file():
with urllib.request.urlopen(f"{gb_url}{pathname}") as response, open(output_path, "wb") as out_file:
shutil.copyfileobj(response, out_file)
download_datafiles(sahp_pathname, sahp_ch, sahp_numbers, output_dir, gb_url)
download_datafiles(idthresh_pathname, idthresh_ch, idthresh_numbers, output_dir, gb_url)

def download_apthresh_datafiles():
"""Download data files for APThreshold and IDthresh traces"""
"""Download data files for APThreshold and IDthresh traces."""
output_dir = "./tests/exp_data/X/"
gb_url = "https://raw.githubusercontent.com/BlueBrain/SSCxEModelExamples/main/feature_extraction/input-traces/C060109A1-SR-C1/"
apthresh_pathname = "X_APThreshold"
Expand All @@ -38,13 +39,5 @@ def download_apthresh_datafiles():
idthresh_ch = ["ch0", "ch1"]
idthresh_numbers = list(range(349, 358)) + list(range(362, 371))

apthresh_paths = [f"{apthresh_pathname}_{ch}_{n}.ibw" for ch in apthresh_ch for n in apthresh_numbers]
idthresh_paths = [f"{idthresh_pathname}_{ch}_{n}.ibw" for ch in idthresh_ch for n in idthresh_numbers]
pathnames = apthresh_paths + idthresh_paths

Path(output_dir).mkdir(exist_ok=True, parents=True)
for pathname in pathnames:
output_path = f"{output_dir}{pathname}"
if not Path(output_path).is_file():
with urllib.request.urlopen(f"{gb_url}{pathname}") as response, open(output_path, "wb") as out_file:
shutil.copyfileobj(response, out_file)
download_datafiles(apthresh_pathname, apthresh_ch, apthresh_numbers, output_dir, gb_url)
download_datafiles(idthresh_pathname, idthresh_ch, idthresh_numbers, output_dir, gb_url)

0 comments on commit 9d587e8

Please sign in to comment.