-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: include test data from esm-tools
- Loading branch information
Showing
5 changed files
with
90 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
pymorize: | ||
warn_on_no_rule: False | ||
parallel: False | ||
general: | ||
name: "fesom_2p6_pimesh" | ||
description: "This is a test configuration using esm-tools generated test data on PI Mesh" | ||
maintainer: "pgierz" | ||
email: "[email protected]" | ||
cmor_version: "CMIP6" | ||
mip: "CMIP" | ||
frequency: "mon" | ||
CMIP_Tables_Dir: "./cmip6-cmor-tables/Tables" | ||
rules: | ||
- name: "temp" | ||
experiment_id: "piControl" | ||
output_directory: "./output" | ||
source_id: "FESOM" | ||
variant_label: "r1i1p1f1" | ||
inputs: | ||
- path: "REPLACE_ME" | ||
pattern: "temp.fesom..*.nc" | ||
cmor_variable: "thetao" | ||
model_variable: "temp" |
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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
"""Example data for the FESOM model.""" | ||
|
||
import tarfile | ||
from pathlib import Path | ||
|
||
import pytest | ||
import requests | ||
|
||
URL = "https://nextcloud.awi.de/s/7gtFn38ZGifMAfw/download/fesom_2p6_pimesh.tar.gz" | ||
"""str : URL to download the example data from.""" | ||
|
||
|
||
@pytest.fixture | ||
def download_data(tmp_path_factory): | ||
cache_dir = tmp_path_factory.getbasetemp() / "cached_data" | ||
cache_dir.mkdir(exist_ok=True) | ||
data_path = cache_dir / "fesom_2p6_pimesh.tar.gz" | ||
|
||
if not data_path.exists(): | ||
response = requests.get(URL) | ||
response.raise_for_status() | ||
with open(data_path, "wb") as f: | ||
f.write(response.content) | ||
print(f"Data downloaded: {data_path}.") | ||
else: | ||
print(f"Using cached data: {data_path}.") | ||
|
||
return data_path | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def fesom_2p6_esm_tools_data(download_data): | ||
data_dir = Path(download_data).parent / "fesom_2p6_pimesh_esm_tools" | ||
|
||
# Extract only if the directory doesn't already exist | ||
if not data_dir.exists(): | ||
with tarfile.open(download_data, "r:gz") as tar: | ||
tar.extractall(data_dir.parent) | ||
print(f"Data extracted to: {data_dir}.") | ||
else: | ||
print(f"Using cached extraction: {data_dir}.") | ||
|
||
return data_dir |
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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# import pytest | ||
import yaml | ||
|
||
from pymorize.cmorizer import CMORizer | ||
from pymorize.logging import logger | ||
|
||
|
||
def test_process(fesom_2p6_pimesh_esm_tools_config, fesom_2p6_pimesh_esm_tools_data): | ||
logger.info(f"Processing {fesom_2p6_pimesh_esm_tools_config}") | ||
with open(fesom_2p6_pimesh_esm_tools_config, "r") as f: | ||
cfg = yaml.safe_load(f) | ||
for rule in cfg["rules"]: | ||
for input in rule["inputs"]: | ||
input["path"] = input["path"].replace( | ||
"REPLACE_ME", str(fesom_2p6_pimesh_esm_tools_data) | ||
) | ||
cmorizer = CMORizer.from_dict(cfg) | ||
cmorizer.process() |