Skip to content

Commit

Permalink
refactoring logic for adding collection links and assets
Browse files Browse the repository at this point in the history
  • Loading branch information
dchandan committed Feb 27, 2024
1 parent cce3a36 commit 269d66a
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions STACpopulator/populator_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,16 +137,10 @@ def create_stac_collection(self) -> dict[str, Any]:
self._collection_info["summaries"] = pystac.Summaries({"needs_summaries_update": ["true"]})

# Add any assets if provided in the config
if "assets" in self._collection_info:
self._collection_info["assets"] = self.__make_collection_assets()
self._collection_info["assets"] = self.__make_collection_assets()

# Construct links if provided in the config
if "links" in self._collection_info:
collection_links = self.__make_collection_links()
# need to remove the links item other constructing a collection object fails
_ = self._collection_info.pop("links")
else:
collection_links = []
# Construct links if provided in the config. This needs to be done before constructing a collection object.
collection_links = self.__make_collection_links()

collection = pystac.Collection(**self._collection_info)

Expand All @@ -164,7 +158,8 @@ def __make_collection_links(self) -> List[pystac.Link]:
:rtype: List[pystac.Link]
"""
links = []
for link_name, link_info in self._collection_info["links"].items():
config_links = self._collection_info.pop("links", [])
for link_name, link_info in config_links.items():
links.append(pystac.Link(**link_info))
return links

Expand All @@ -175,8 +170,9 @@ def __make_collection_assets(self) -> Dict[str, pystac.Asset]:
:rtype: Dict[pystac.Asset]
"""
pystac_assets = {}
for asset_name, asset_info in self._collection_info["assets"].items():
pystac_assets[asset_name] = pystac.Asset(**asset_info)
if "assets" in self._collection_info:
for asset_name, asset_info in self._collection_info["assets"].items():
pystac_assets[asset_name] = pystac.Asset(**asset_info)
return pystac_assets

def publish_stac_collection(self, collection_data: dict[str, Any]) -> None:
Expand Down

0 comments on commit 269d66a

Please sign in to comment.