Skip to content

Commit 69a5ce5

Browse files
Tune downloading settings
1 parent f02fd70 commit 69a5ce5

1 file changed

Lines changed: 9 additions & 19 deletions

File tree

  • insardev_toolkit/insardev_toolkit

insardev_toolkit/insardev_toolkit/ASF.py

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ def _nisar_exists(basedir, granule_id, polarization):
387387
return os.path.exists(out_path)
388388

389389
# https://asf.alaska.edu/datasets/data-sets/derived-data-sets/sentinel-1-bursts/
390-
def download(self, basedir, bursts, polarization=None, frequency=None, session=None, n_jobs=4, joblib_backend='loky', skip_exist=True,
390+
def download(self, basedir, bursts, polarization=None, frequency=None, session=None, n_jobs=4, joblib_backend='threading', skip_exist=True,
391391
retries=30, timeout_second=3, debug=False):
392392
"""
393393
Download SAR data from ASF.
@@ -419,7 +419,7 @@ def download(self, basedir, bursts, polarization=None, frequency=None, session=N
419419
n_jobs : int, optional
420420
Parallel download jobs. Default 8.
421421
joblib_backend : str, optional
422-
Backend for parallel processing. Default 'loky'.
422+
Backend for parallel processing. Default 'threading' (optimal for I/O-bound downloads).
423423
skip_exist : bool, optional
424424
Skip already downloaded data. Default True.
425425
retries : int, optional
@@ -705,26 +705,16 @@ def download_burst(result, basedir, session):
705705
import rasterio
706706
from rasterio.io import MemoryFile
707707

708-
# Download TIFF to memory
708+
# Download TIFF to memory (brotli compression - faster than uncompressed)
709709
tiff_url = get_burst_url(properties['url'])
710710
response = session.get(tiff_url, stream=True)
711711
response.raise_for_status()
712-
cache_status = response.headers.get('x-cache', 'N/A')
713-
cache_enc = response.headers.get('content-encoding', 'none')
714-
# Read raw compressed bytes to measure transfer size
715-
if debug and cache_enc in ('br', 'gzip', 'deflate'):
716-
# Read compressed bytes directly
717-
compressed_bytes = response.raw.read()
718-
transfer_mb = len(compressed_bytes) / 1024 / 1024
719-
# Decompress manually
720-
import brotli
721-
tiff_bytes = brotli.decompress(compressed_bytes)
722-
print(f' TIFF {cache_status:4} {cache_enc:4} {transfer_mb:5.1f}MB {burst}')
723-
else:
724-
tiff_bytes = response.content
725-
if debug:
726-
size_mb = len(tiff_bytes) / 1024 / 1024
727-
print(f' TIFF {cache_status:4} {cache_enc:4} {size_mb:5.1f}MB {burst}')
712+
tiff_bytes = b''.join(response.iter_content(chunk_size=1024*1024))
713+
if debug:
714+
cache_status = response.headers.get('x-cache', 'N/A')
715+
cache_enc = response.headers.get('content-encoding', 'none')
716+
size_mb = len(tiff_bytes) / 1024 / 1024
717+
print(f' TIFF {cache_status:4} {cache_enc:4} {size_mb:5.1f}MB {burst}')
728718
if len(tiff_bytes) == 0:
729719
raise Exception(f'ERROR: Downloaded TIFF is empty: {tiff_url}')
730720

0 commit comments

Comments
 (0)