diff --git a/CHANGES.md b/CHANGES.md index 8cb305a..f3f8fee 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -3,6 +3,10 @@ ## [Unreleased](https://github.com/crim-ca/stac-populator) (latest) +- Adding ability to add collection level assets +- Adding ability to add collection level links +- Adding collection links to `CMIP6_UofT` +- Adding an end date to `CMIP6_UofT`'s temporal extent for better rendering in STAC Browser ## [0.6.0](https://github.com/crim-ca/stac-populator/tree/0.6.0) (2024-02-22) diff --git a/STACpopulator/implementations/CMIP6_UofT/collection_config.yml b/STACpopulator/implementations/CMIP6_UofT/collection_config.yml index 0f43c78..9d3665f 100644 --- a/STACpopulator/implementations/CMIP6_UofT/collection_config.yml +++ b/STACpopulator/implementations/CMIP6_UofT/collection_config.yml @@ -4,4 +4,15 @@ description: Coupled Model Intercomparison Project phase 6 keywords: ['CMIP', 'CMIP6', 'WCRP', 'Climate Change'] license: "CC-BY-4.0" spatialextent: [-180, -90, 180, 90] -temporalextent: ['1850-01-01', null] \ No newline at end of file +temporalextent: ['1850-01-01', '2500-01-01'] + +links: + - rel: about + title : Project homepage + target : https://wcrp-cmip.org/cmip-phase-6-cmip6/ + media_type: text/html + - rel: license + title : License + target : https://raw.githubusercontent.com/WCRP-CMIP/CMIP6_CVs/main/LICENSE-CC-BY + media_type: text/plain + diff --git a/STACpopulator/populator_base.py b/STACpopulator/populator_base.py index 9e5fa53..44341f3 100644 --- a/STACpopulator/populator_base.py +++ b/STACpopulator/populator_base.py @@ -5,7 +5,7 @@ import os from abc import ABC, abstractmethod from datetime import datetime -from typing import Any, MutableMapping, Optional, Type, Union +from typing import Any, Dict, List, MutableMapping, Optional, Type, Union import pystac from requests.sessions import Session @@ -135,13 +135,46 @@ def create_stac_collection(self) -> dict[str, Any]: ) self._collection_info["extent"] = pystac.Extent(sp_extent, tmp_extent) self._collection_info["summaries"] = pystac.Summaries({"needs_summaries_update": ["true"]}) + + # Add any assets if provided in the config + self._collection_info["assets"] = self.__make_collection_assets() + + # 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) + if collection_links: + collection.add_links(collection_links) collection.add_links(self._ingest_pipeline.links) collection_data = collection.to_dict() self.publish_stac_collection(collection_data) return collection_data + def __make_collection_links(self) -> List[pystac.Link]: + """Create collection level links based on data read in from the configuration file. + + :return: List of pystac Link objects + :rtype: List[pystac.Link] + """ + links = [] + config_links = self._collection_info.pop("links", {}) + for link_info in config_links: + links.append(pystac.Link(**link_info)) + return links + + def __make_collection_assets(self) -> Dict[str, pystac.Asset]: + """Creates collection level assets based on data read in from the configuration file. + + :return: Dictionary of pystac Asset objects + :rtype: Dict[pystac.Asset] + """ + pystac_assets = {} + 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: post_stac_collection(self.stac_host, collection_data, self.update, session=self._session)