Skip to content

Commit

Permalink
Merge pull request #104 from MAAP-Project/fix/collections-err-bug
Browse files Browse the repository at this point in the history
Update collections logic to skip bad collections
  • Loading branch information
sandrahoang686 authored Sep 5, 2023
2 parents 05b0978 + fd896ae commit bf9780d
Show file tree
Hide file tree
Showing 4 changed files with 243 additions and 180 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ TITILER_STAC_ENDPOINT=https://titiler-stac.maap-project.org
TITILER_ENDPOINT=https://titiler.maap-project.org
STAC_CATALOG_NAME=MAAP STAC
STAC_CATALOG_URL=https://stac.maap-project.org
STAC_BROWSER_URL=https://stac-browser.maap-project.org/external/
```
5. Run `jupyter lab` and this should reveal two links in the log, you would want to click and open any of those two!
![](/public/images/getting-started-links.png)
Expand Down
1 change: 1 addition & 0 deletions stac_ipyleaflet/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@
TITILER_ENDPOINT = os.getenv("TITILER_ENDPOINT")
TITILER_STAC_ENDPOINT = os.getenv("TITILER_STAC_ENDPOINT")
STAC_CATALOG = {"name": os.getenv("STAC_CATALOG_NAME"), "url": os.getenv("STAC_CATALOG_URL")}
STAC_BROWSER_URL = os.getenv("STAC_BROWSER_URL")
131 changes: 67 additions & 64 deletions stac_ipyleaflet/stac_discovery/stac.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from stac_ipyleaflet.constants import RESCALE
from typing import TypedDict, Optional


class OutputCollectionObj(TypedDict):
id: str
title: str
Expand All @@ -23,71 +22,75 @@ class Stac:
@staticmethod
def organize_collections(collections=[]):
output_collections = []
for collection in collections:
try:
data = collection.to_dict()

has_cog = True if data["item_assets"] else False

id = data["id"].strip()
title = data["title"].strip()

start_date = data["extent"]["temporal"]["interval"][0][0]
end_date = data["extent"]["temporal"]["interval"][0][1]

if start_date is not None:
start_date = start_date.split("T")[0]
else:
start_date = ""

if end_date is not None:
end_date = end_date.split("T")[0]
else:
end_date = ""

bbox = ", ".join(
[str(coord) for coord in data["extent"]["spatial"]["bbox"][0]]
)

metadata = None
href = None
for l in data["links"]:
if l["rel"] == "about":
metadata = l["href"]
if l["rel"] == "self":
href = l["href"]

description = (
data["description"]
.replace("\n", " ")
.replace("\r", " ")
.replace("\\u", " ")
.replace(" ", " ")
)

license = data["license"]
collection_obj = OutputCollectionObj(
{
"id": id,
"title": title,
"has_cog": has_cog,
"start_date": start_date,
"end_date": end_date,
"bbox": bbox,
"metadata": metadata,
"href": href,
"description": description,
"license": license,
}
)
output_collections.append(collection_obj)
except Exception as err:
error = {"error": err, "collection": collection}
logging.error(error)
return None
bad_collections = []
try:
for collection in collections:
try:
data = collection.to_dict()
has_cog = True if data["item_assets"] else False
id = data["id"].strip()
title = data["title"].strip()
start_date = data["extent"]["temporal"]["interval"][0][0]
end_date = data["extent"]["temporal"]["interval"][0][1]

if start_date is not None:
start_date = start_date.split("T")[0]
else:
start_date = ""

if end_date is not None:
end_date = end_date.split("T")[0]
else:
end_date = ""

if (bbox := collection.extent.spatial.bboxes):
bbox = ", ".join(
[str(coord) for coord in bbox[0]]
)
metadata = None
href = None
for l in data["links"]:
if l["rel"] == "about":
metadata = l["href"]
if l["rel"] == "self":
href = l["href"]

description = (
data["description"]
.replace("\n", " ")
.replace("\r", " ")
.replace("\\u", " ")
.replace(" ", " ")
)

license = data["license"]

collection_obj = OutputCollectionObj(
{
"id": id,
"title": title,
"has_cog": has_cog,
"start_date": start_date,
"end_date": end_date,
"bbox": bbox,
"metadata": metadata,
"href": href,
"description": description,
"license": license,
}
)
output_collections.append(collection_obj)
else:
bad_collections.append(collection.id)
except Exception as err:
error = {"message": "Error caught with collection", "error": err, "collection": collection.to_dict()}
logging.error(error)
except Exception as err:
error = {"message": "Error caught when organizing collections", "error": err}
# @TODO: We should report these errors to some type of monitoring service for us to debug
if len(output_collections) > 0:
output_collections.sort(key=lambda x: x["title"])
return output_collections
return output_collections, bad_collections

@staticmethod
def get_item_info(url=None, **kwargs):
Expand Down
Loading

0 comments on commit bf9780d

Please sign in to comment.