Skip to content

Commit 52d0cff

Browse files
committed
Make data downloading more reliable
Previously, downloads from CDSE were failing for any non-trivial amount of data. This is because they were using creodias_finder's download_list method, which only requests an access token once per invocation. This meant that the token would expire after a few downloads. I have added a new method download_list_safe to run_efast, which offers similar functionality to download_list but fetches a new access token for each download. In tests, this has worked as expected, entirely eliminating the previous "token expired" errors during large data downloads. download_list_safe does not implement multi-threading since I'm not sure whether CDSE allows multiple access tokens to be active simultaneously.
1 parent 17a4003 commit 52d0cff

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

run_efast.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
from enhancement_tools.time_measurement import Timer
3838
from creodias_finder import download, query
3939
from dateutil import rrule
40+
from tqdm import tqdm
4041

4142
from efast import binning
4243
import efast.efast as efast
@@ -337,7 +338,7 @@ def download_from_cdse(
337338
productType="SY_2_SYN___",
338339
timeliness="NT",
339340
)
340-
download.download_list(
341+
download_list_safe(
341342
[result["id"] for result in results.values()],
342343
outdir=s3_download_dir,
343344
threads=1,
@@ -356,7 +357,7 @@ def download_from_cdse(
356357
geometry=aoi_geometry,
357358
productType="L2A",
358359
)
359-
download.download_list(
360+
download_list_safe(
360361
[result["id"] for result in results.values()],
361362
outdir=s2_download_dir,
362363
threads=3,
@@ -366,6 +367,25 @@ def download_from_cdse(
366367
with zipfile.ZipFile(zip_file, "r") as zip_ref:
367368
zip_ref.extractall(s2_download_dir)
368369

370+
def download_list_safe(uids, username, password, outdir, threads=1, show_progress=True):
371+
from creodias_finder.download import _get_token, download
372+
373+
if show_progress:
374+
pbar = tqdm(total=len(uids), unit="files")
375+
376+
def _download(uid):
377+
token = _get_token(username, password)
378+
outfile = Path(outdir) / f"{uid}.zip"
379+
download(
380+
uid, username, password, outfile=outfile, show_progress=False, token=token
381+
)
382+
if show_progress:
383+
pbar.update(1)
384+
return uid, outfile
385+
386+
paths = [_download(u) for u in uids]
387+
return paths
388+
369389

370390
if __name__ == "__main__":
371391
parser = argparse.ArgumentParser()

0 commit comments

Comments
 (0)