-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4acf96f
commit 3277b70
Showing
12 changed files
with
178 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
.coverage | ||
.pytest_cache | ||
build | ||
reports | ||
*.pyc | ||
STACpopulator.egg-info/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
tests/data/stac_collection_testdata_xclim_cmip6_catalog.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{ | ||
"type": "Collection", | ||
"id": "test", | ||
"title": "test", | ||
"stac_version": "1.0.0", | ||
"description": "test", | ||
"summaries": {"needs_summaries_update": ["true"]}, | ||
"extent": { | ||
"spatial": { | ||
"bbox": [ | ||
[-180, -90, 180, 90] | ||
] | ||
}, | ||
"temporal": { | ||
"interval": [ | ||
["1850-01-01T00:00:00Z", null] | ||
] | ||
} | ||
}, | ||
"license": "MIT", | ||
"keywords": ["test"], | ||
"links": [ | ||
{ | ||
"href": "https://pavics.ouranos.ca/twitcher/ows/proxy/thredds/catalog/birdhouse/testdata/xclim/cmip6/catalog.xml", | ||
"rel": "source", | ||
"title": "thredds:birdhouse/testdata/xclim/cmip6", | ||
"type": "text/xml" | ||
} | ||
] | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,88 @@ | ||
import json | ||
|
||
import pytest | ||
import requests | ||
import os | ||
import tempfile | ||
from urllib.parse import quote | ||
|
||
import xncml | ||
|
||
from STACpopulator.implementations.CMIP6_UofT.add_CMIP6 import ( | ||
CMIP6ItemProperties, | ||
make_cmip6_item_id, | ||
) | ||
from STACpopulator.implementations.CMIP6_UofT.add_CMIP6 import CMIP6ItemProperties, CMIP6populator | ||
from STACpopulator.input import THREDDSLoader | ||
from STACpopulator.models import GeoJSONPolygon | ||
from STACpopulator.stac_utils import STAC_item_from_metadata | ||
|
||
CUR_DIR = os.path.dirname(__file__) | ||
|
||
|
||
def quote_none_safe(url): | ||
return quote(url, safe="") | ||
|
||
def test_standalone_stac_item(): | ||
url = ( | ||
"https://pavics.ouranos.ca/twitcher/ows/proxy/" | ||
"thredds/ncml/birdhouse/testdata/xclim/cmip6/sic_SImon_CCCma-CanESM5_ssp245_r13i1p2f1_2020.nc" | ||
"?catalog=https%3A%2F%2Fpavics.ouranos.ca%2Ftwitcher%2Fows%2Fproxy%2F" | ||
"thredds%2Fcatalog%2Fbirdhouse%2Ftestdata%2Fxclim%2Fcmip6%2Fcatalog.html" | ||
"&dataset=birdhouse%2Ftestdata%2Fxclim%2Fcmip6%2Fsic_SImon_CCCma-CanESM5_ssp245_r13i1p2f1_2020.nc" | ||
|
||
@pytest.mark.online | ||
def test_standalone_stac_item_thredds_ncml(): | ||
thredds_url = "https://pavics.ouranos.ca/twitcher/ows/proxy/thredds" | ||
thredds_path = "birdhouse/testdata/xclim/cmip6" | ||
thredds_nc = "sic_SImon_CCCma-CanESM5_ssp245_r13i1p2f1_2020.nc" | ||
thredds_catalog = f"{thredds_url}/catalog/{thredds_path}/catalog.html" | ||
thredds_ds = f"{thredds_path}/{thredds_nc}" | ||
thredds_ncml_url = ( | ||
f"{thredds_url}/ncml/{thredds_path}/{thredds_nc}" | ||
f"?catalog={quote_none_safe(thredds_catalog)}&dataset={quote_none_safe(thredds_ds)}" | ||
) | ||
|
||
attrs = xncml.Dataset.from_text(requests.get(url).content).to_cf_dict() | ||
stac_item_id = make_cmip6_item_id(attrs["attributes"]) | ||
# FIXME: avoid hackish workarounds | ||
data = requests.get(thredds_ncml_url).text | ||
attrs = xncml.Dataset.from_text(data).to_cf_dict() | ||
attrs["access_urls"] = { # FIXME: all following should be automatically added, but they are not! | ||
"HTTPServer": f"{thredds_url}/fileServer/{thredds_path}/{thredds_nc}", | ||
"OPENDAP": f"{thredds_url}/dodsC/{thredds_path}/{thredds_nc}", | ||
"WCS": f"{thredds_url}/wcs/{thredds_path}/{thredds_nc}?service=WCS&version=1.0.0&request=GetCapabilities", | ||
"WMS": f"{thredds_url}/wms/{thredds_path}/{thredds_nc}?service=WMS&version=1.3.0&request=GetCapabilities", | ||
"NetcdfSubset": f"{thredds_url}/ncss/{thredds_path}/{thredds_nc}/dataset.html", | ||
} | ||
|
||
stac_item_id = CMIP6populator.make_cmip6_item_id(attrs["attributes"]) | ||
stac_item = STAC_item_from_metadata(stac_item_id, attrs, CMIP6ItemProperties, GeoJSONPolygon) | ||
|
||
with open("tests/ref.json", "r") as ff: | ||
ref_file = os.path.join(CUR_DIR, "data/stac_item_testdata_xclim_cmip6_ncml.json") | ||
with open(ref_file, mode="r", encoding="utf-8") as ff: | ||
reference = json.load(ff) | ||
|
||
assert stac_item.to_dict() == reference | ||
|
||
|
||
class MockedNoSTACUpload(CMIP6populator): | ||
def load_config(self): | ||
# bypass auto-load config | ||
self._collection_info = { | ||
"id": "test", | ||
"title": "test", | ||
"description": "test", | ||
"keywords": ["test"], | ||
"license": "MIT", | ||
"spatialextent": [-180, -90, 180, 90], | ||
"temporalextent": ['1850-01-01', None] | ||
} | ||
|
||
def validate_host(self, stac_host: str) -> str: | ||
pass # don't care | ||
|
||
def publish_stac_collection(self, *_) -> None: | ||
pass # don't push to STAC API | ||
|
||
|
||
@pytest.mark.online | ||
def test_cmip6_stac_thredds_catalog_parsing(): | ||
url = "https://pavics.ouranos.ca/twitcher/ows/proxy/thredds/catalog/birdhouse/testdata/xclim/cmip6/catalog.html" | ||
loader = THREDDSLoader(url) | ||
with tempfile.NamedTemporaryFile(): | ||
populator = MockedNoSTACUpload("https://host-dont-care.com", loader) | ||
|
||
result = populator.create_stac_collection() | ||
|
||
ref_file = os.path.join(CUR_DIR, "data/stac_collection_testdata_xclim_cmip6_catalog.json") | ||
with open(ref_file, mode="r", encoding="utf-8") as ff: | ||
reference = json.load(ff) | ||
|
||
assert result == reference |