-
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.
Merge pull request #60 from esm-tools/test/pi-mesh
PI Mesh Test Fixtures
- Loading branch information
Showing
14 changed files
with
190 additions
and
7 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
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
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/outdata/fesom" | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
pymorize: | ||
warn_on_no_rule: False | ||
parallel: False | ||
general: | ||
name: "pi_uxarray" | ||
description: "This is a test configuration using the UXArray 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
Empty file.
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(scope="session") | ||
def fesom_2p6_esm_tools_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_pimesh_esm_tools_data(fesom_2p6_esm_tools_download_data): | ||
data_dir = Path(fesom_2p6_esm_tools_download_data).parent / "fesom_2p6_pimesh" | ||
|
||
# Extract only if the directory doesn't already exist | ||
if not data_dir.exists(): | ||
with tarfile.open(fesom_2p6_esm_tools_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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
"""Example data for the FESOM model.""" | ||
|
||
import tarfile | ||
from pathlib import Path | ||
|
||
import pytest | ||
import requests | ||
|
||
URL = "https://nextcloud.awi.de/s/swqyFgbL2jjgjRo/download/pi_uxarray.tar" | ||
"""str : URL to download the example data from.""" | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def pi_uxarray_download_data(tmp_path_factory): | ||
cache_dir = tmp_path_factory.getbasetemp() / "cached_data" | ||
cache_dir.mkdir(exist_ok=True) | ||
data_path = cache_dir / "pi_uxarray.tar" | ||
|
||
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 pi_uxarray_data(pi_uxarray_download_data): | ||
|
||
data_dir = Path(pi_uxarray_download_data).parent | ||
with tarfile.open(pi_uxarray_download_data, "r") as tar: | ||
tar.extractall(data_dir) | ||
|
||
return data_dir / "pi_uxarray" |
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() |
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,16 @@ | ||
# import pytest | ||
import yaml | ||
|
||
from pymorize.cmorizer import CMORizer | ||
from pymorize.logging import logger | ||
|
||
|
||
def test_process(pi_uxarray_config, pi_uxarray_data): | ||
logger.info(f"Processing {pi_uxarray_config}") | ||
with open(pi_uxarray_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(pi_uxarray_data)) | ||
cmorizer = CMORizer.from_dict(cfg) | ||
cmorizer.process() |