Skip to content

Commit

Permalink
added checks in test_auxiliary_variables
Browse files Browse the repository at this point in the history
  • Loading branch information
huard committed Feb 28, 2024
2 parents a585d9e + d4bc6aa commit 2bc0b21
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 2 deletions.
5 changes: 5 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@

## [Unreleased](https://github.com/crim-ca/stac-populator) (latest)

<!-- insert list items of new changes here -->
* Make sure *bounds* variables are given the auxiliary type attribute.
* Fix for variables that have no attributes.
* 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)

Expand Down
13 changes: 12 additions & 1 deletion STACpopulator/implementations/CMIP6_UofT/collection_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
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

35 changes: 34 additions & 1 deletion STACpopulator/populator_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down
3 changes: 3 additions & 0 deletions tests/test_cmip6_datacube.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,6 @@ def test_auxiliary_variables():
p = dc_ext.properties
assert set(['time', 'lat', 'lon']) == set(p['cube:dimensions'].keys())
assert p["cube:variables"]["lon_bnds"]["unit"] == "degrees_east"
assert p["cube:variables"]["time_bnds"]["unit"] == "days since 1850-01-01"
assert p["cube:variables"]["clt"]["type"] == "data"
assert p["cube:variables"]["time_bnds"]["type"] == "auxiliary"

0 comments on commit 2bc0b21

Please sign in to comment.