Skip to content

Commit

Permalink
Merge branch 'main' into fix-serializability-typo
Browse files Browse the repository at this point in the history
  • Loading branch information
alejoe91 authored Nov 22, 2023
2 parents 09d9259 + 514dd6f commit 4b1272c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 18 deletions.
27 changes: 15 additions & 12 deletions src/spikeinterface/extractors/mdaextractors.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,18 +442,21 @@ def is_url(path):


def _download_bytes_to_tmpfile(url, start, end):
try:
import requests
except:
raise Exception("Unable to import module: requests")
headers = {"Range": "bytes={}-{}".format(start, end - 1)}
r = requests.get(url, headers=headers, stream=True)
fd, tmp_fname = tempfile.mkstemp()
os.close(fd)
with open(tmp_fname, "wb") as f:
for chunk in r.iter_content(chunk_size=1024):
if chunk:
f.write(chunk)
import requests

headers = {"Range": f"bytes={start}-{end - 1}"}

with requests.get(url, headers=headers, stream=True) as r:
r.raise_for_status() # Exposes HTTPError if one occurred

with tempfile.NamedTemporaryFile(delete=False, mode="wb") as f:
for chunk in r.iter_content(chunk_size=1024):
if chunk:
f.write(chunk)

# Store the temp file name for return
tmp_fname = f.name

return tmp_fname


Expand Down
14 changes: 8 additions & 6 deletions src/spikeinterface/preprocessing/deepinterpolation/generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,11 @@ def __init__(
sequential_generator_params["total_samples"] = self.total_samples
sequential_generator_params["pre_post_omission"] = pre_post_omission

json_fd, json_path = tempfile.mkstemp(suffix=".json")
os.close(json_fd)
with open(json_path, "w") as f:
with tempfile.NamedTemporaryFile(suffix=".json", mode="w", delete=False, dir="/tmp") as f:
json.dump(sequential_generator_params, f)
f.flush()
json_path = f.name

super().__init__(json_path)

self._update_end_frame(total_num_samples)
Expand Down Expand Up @@ -245,10 +246,11 @@ def __init__(
sequential_generator_params["total_samples"] = self.total_samples
sequential_generator_params["pre_post_omission"] = pre_post_omission

json_fd, json_path = tempfile.mkstemp(suffix=".json")
os.close(json_fd)
with open(json_path, "w") as f:
with tempfile.NamedTemporaryFile(suffix=".json", mode="w", delete=False, dir="/tmp") as f:
json.dump(sequential_generator_params, f)
f.flush()
json_path = f.name

super().__init__(json_path)

self._update_end_frame(num_segment_samples)
Expand Down

0 comments on commit 4b1272c

Please sign in to comment.