Skip to content

Commit

Permalink
i.sentinel.parallel.download: allow download from GCS with scenename …
Browse files Browse the repository at this point in the history
…specifications and without credentials (#786)

* make parallel download without credentials possible

* add replacement of .SAFE

* MM review

* remove comments
  • Loading branch information
griembauer committed Sep 1, 2022
1 parent e1ca85a commit b7f1a70
Showing 1 changed file with 21 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

# %option G_OPT_F_INPUT
# % key: settings
# % required: no
# % label: Full path to settings file (user, password)
# %end

Expand Down Expand Up @@ -148,7 +149,7 @@ def scenename_split(scenename, datasource, esa_name_for_usgs=False):
date -1 day
end_day(string): Date in the format YYYY-MM-DD, it is the acquisition
date +1 day
query_string(string): string in the format "filename=..."
query_string(string): string in the format "identifier=..."
"""
if datasource == "ESA_COAH" or datasource == "GCS" or esa_name_for_usgs is True:
Expand All @@ -164,10 +165,7 @@ def scenename_split(scenename, datasource, esa_name_for_usgs=False):
end_day_dt = dt_obj + timedelta(days=1)
start_day = start_day_dt.strftime("%Y-%m-%d")
end_day = end_day_dt.strftime("%Y-%m-%d")
# get query string
if not scenename.endswith(".SAFE"):
scenename = scenename + ".SAFE"
query_string = "filename={}".format(scenename)
query_string = f"identifier={scenename.replace('.SAFE', '')}"
else:
# when usgs downloads via identifier, start/end are ignored
producttype = "S2MSI1C"
Expand All @@ -190,6 +188,10 @@ def main():
datasource = options["datasource"]
use_scenenames = flags["s"]
ind_folder = flags["f"]
if use_scenenames and datasource == "GCS":
settings_required = False
else:
settings_required = True

if datasource == "USGS_EE" and producttype != "S2MSI1C":
grass.fatal(
Expand All @@ -216,8 +218,9 @@ def main():
)

# Test if all required data are there
if not os.path.isfile(settings):
grass.fatal(_("Settings file <{}> not found").format(settings))
if settings_required is True:
if not os.path.isfile(settings):
grass.fatal(_("Settings file <{}> not found").format(settings))

# set some common environmental variables, like:
os.environ.update(
Expand Down Expand Up @@ -305,16 +308,20 @@ def main():
outpath = os.path.join(output, "dl_s2_%s" % str(idx + 1))
else:
outpath = output
download_kwargs = {
"start": start_date,
"end": end_date,
"producttype": producttype,
"query": query_string,
"output": outpath,
"datasource": datasource,
}
if settings_required is True:
download_kwargs["settings"] = settings
i_sentinel_download = Module(
"i.sentinel.download",
settings=settings,
start=start_date,
end=end_date,
producttype=producttype,
query=query_string,
output=outpath,
datasource=datasource,
run_=False,
**download_kwargs,
)
queue_download.put(i_sentinel_download)
queue_download.wait()
Expand Down

0 comments on commit b7f1a70

Please sign in to comment.