Commit 6afd7e27 authored by Cresson Remi's avatar Cresson Remi
Browse files

WIP: S2 download

1 merge request!12ENH: S2A and S3A support
Showing with 41 additions and 7 deletions
+41 -7
...@@ -173,7 +173,40 @@ class TheiaDownloader: ...@@ -173,7 +173,40 @@ class TheiaDownloader:
else: else:
print("\t{} already downloaded. Skipping.".format(acq_date)) print("\t{} already downloaded. Skipping.".format(acq_date))
def download_closest(config_file, acq_envelope, acq_date, level="LEVEL3A"): def download_in_range(config_file, bbox_wgs84, start_date, end_date, download_dir=None, level="LEVEL3A",
max_records=500):
"""
Download all images within spatial and temporal ranges
:param config_file: theia config file
:param bbox_wgs84: bounding box (WGS84)
:param start_date: start date (datetime.datetime)
:param end_date: end date (datetime.datetime)
:param download_dir: download directory
:param level: LEVEL2A, LEVEL3A, ...
:param max_records: maximum number of records
"""
# lonmin, latmin, lonmax, latmax
box = '{},{},{},{}'.format(bbox_wgs84[2], bbox_wgs84[0], bbox_wgs84[3], bbox_wgs84[1])
dict_query = {
"box": box,
"startDate": start_date.strftime("%Y-%m-%d"),
"completionDate": end_date.strftime("%Y-%m-%d"),
"maxRecords": max_records,
"processingLevel": level
}
# Theia downloader
downloader = TheiaDownloader(config_file)
# Search products
search_results = downloader.query(dict_query)
# Download products
if download_dir:
downloader.download(search_results, download_dir)
def download_closest(config_file, bbox_wgs84, acq_date, download_dir=None, level="LEVEL3A"):
""" """
query theia catalog, download_closest the files query theia catalog, download_closest the files
""" """
...@@ -182,9 +215,9 @@ def download_closest(config_file, acq_envelope, acq_date, level="LEVEL3A"): ...@@ -182,9 +215,9 @@ def download_closest(config_file, acq_envelope, acq_date, level="LEVEL3A"):
ndays_seek = datetime.timedelta(days=17) # temporal range to check for monthly synthesis ndays_seek = datetime.timedelta(days=17) # temporal range to check for monthly synthesis
# Query products # Query products
print(acq_envelope) print(bbox_wgs84)
# box={lonmin},{latmin},{lonmax},{latmax}' # box={lonmin},{latmin},{lonmax},{latmax}'
box = '{},{},{},{}'.format(acq_envelope[2], acq_envelope[0], acq_envelope[3], acq_envelope[1]) box = '{},{},{},{}'.format(bbox_wgs84[2], bbox_wgs84[0], bbox_wgs84[3], bbox_wgs84[1])
dict_query = {'box': box} dict_query = {'box': box}
start_date = acq_date - ndays_seek start_date = acq_date - ndays_seek
end_date = acq_date + ndays_seek end_date = acq_date + ndays_seek
...@@ -234,6 +267,5 @@ def download_closest(config_file, acq_envelope, acq_date, level="LEVEL3A"): ...@@ -234,6 +267,5 @@ def download_closest(config_file, acq_envelope, acq_date, level="LEVEL3A"):
print("\t{} ({})".format(description_date, selected_tile[tile_name][description_date]["delta"])) print("\t{} ({})".format(description_date, selected_tile[tile_name][description_date]["delta"]))
# Download products # Download products
#downloader.download(selected_tile, get_local_file) if download_dir:
downloader.download(selected_tile, download_dir)
return selected_tile
...@@ -6,9 +6,11 @@ import datetime ...@@ -6,9 +6,11 @@ import datetime
parser = argparse.ArgumentParser(description="Download test",) parser = argparse.ArgumentParser(description="Download test",)
parser.add_argument("--refimage", required=True) parser.add_argument("--refimage", required=True)
parser.add_argument("--theia_cfg", required=True) parser.add_argument("--theia_cfg", required=True)
parser.add_argument("--download_dir")
params = parser.parse_args() params = parser.parse_args()
# Get all scenes in the root_dir # Get all scenes in the root_dir
_, _, bbox = utils.get_epsg_extent_bbox(params.refimage) _, _, bbox = utils.get_epsg_extent_bbox(params.refimage)
acq_date = datetime.datetime(year=2020, month=1, day=1) acq_date = datetime.datetime(year=2020, month=1, day=1)
download.download_closest(config_file=params.theia_cfg, acq_envelope=bbox, acq_date=acq_date) download.download_closest(config_file=params.theia_cfg, acq_envelope=bbox, acq_date=acq_date,
\ No newline at end of file download_dir=params.download_dir)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment