Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

i.sentinel.coverage: update module to be compatible with the i.sentinel.download EODAG migration #1192

Open
wants to merge 7 commits into
base: grass8
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ <h3>Check Sentinel-2 scenes by names</h3>
<div class="code"><pre>
i.sentinel.coverage settings=credentials.txt output=s2names.txt \
names=S2A_MSIL2A_20200104T024111_N0213_R089_T49MGU_20200104T061337,S2B_MSIL2A_20200129T023939_N0213_R089_T49MGU_20200201T153252 \
producttype=S2MSI2A clouds=20 minpercent=95 area=mangkawuk
producttype=S2MSI2A minpercent=95 area=mangkawuk
</pre></div>

<h3>Use retrieved Sentinel-2 scene names for import</h3>
Expand Down
31 changes: 15 additions & 16 deletions src/imagery/i.sentinel/i.sentinel.coverage/i.sentinel.coverage.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@

# %rules
# % collective: start,end
# % excludes: names,start,end,clouds,producttype
# % excludes: names,start,end,clouds
# %end


Expand Down Expand Up @@ -258,14 +258,15 @@ def main():
if resp[0] != b"":
s_list = resp[0].decode("utf-8").strip().splitlines()
else:
# Experimental version warning needs to be removed from i.eodag
if set(resp) == {b""}:
grass.fatal(_("No products found"))
else:
error_msg = ""
for i in range(0, len(resp)):
error_msg += resp[i].decode("utf-8")
grass.fatal(_("Error using i.sentinel.download: {}").format(error_msg))
name_list_tmp = [x.split(" ")[1] for x in s_list]
name_list_tmp = [x.split(" ")[0] for x in s_list]
else:
name_list_tmp = options["names"].split(",")
name_list = []
Expand All @@ -279,13 +280,10 @@ def main():
grass.run_command(
"i.sentinel.download",
settings=settings,
map=area,
start=start_day,
end=end_day,
footprints=fpi,
producttype=producttype,
query="identifier=%s" % name,
flags="lb",
id=name,
flags="l",
quiet=True,
)
name_list.append(name)
Expand All @@ -310,30 +308,31 @@ def main():
grass.run_command(
"v.db.update",
map=temp_overlay,
column="a_identifier",
query_column='a_identifier || "+" ' + "|| b_identifier",
where="a_identifier NOT NULL AND " + "b_identifier NOT NULL",
column="a_title",
query_column='a_title || "+" ' + "|| b_title",
where="a_title NOT NULL AND " + "b_title NOT NULL",
quiet=True,
)
grass.run_command(
"v.db.update",
map=temp_overlay,
column="a_identifier",
query_column="b_identifier",
where="a_identifier IS NULL",
column="a_title",
query_column="b_title",
where="a_title IS NULL",
quiet=True,
)
grass.run_command(
"v.db.renamecolumn",
map=temp_overlay,
column="a_identifier,identifier",
column="a_title,title",
quiet=True,
)
columns_dict = grass.parse_command("v.info", map=temp_overlay, flags="c")
drop_columns = [
col.split("|")[1]
for col in columns_dict
if col.split("|")[1] not in ["cat", "identifier"]
if col.split("|")[1]
not in ["cat", "title"] # What does cat refer to here?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cat is the geometry identifier in GRASS vector maps, so, like the id in other formats

]
grass.run_command(
"v.db.dropcolumn", map=temp_overlay, columns=drop_columns, quiet=True
Expand Down Expand Up @@ -366,7 +365,7 @@ def main():
# list of scenes that actually intersect with bbox
name_list_updated_tmp = list(
grass.parse_command(
"v.db.select", map=fps_in_area, column="a_identifier", flags="c"
"v.db.select", map=fps_in_area, column="a_title", flags="c"
).keys()
)

Expand Down