Commit 72808c10 authored by BorjaEst's avatar BorjaEst
Browse files

Add metadata output tests

parent 2530da17
......@@ -6,6 +6,7 @@ import o3skim
import pytest
import tests.mockup as mockup_data
import xarray
import yaml
# configurations ----------------------------------------------------
year_line = range(2000, 2022)
......@@ -105,6 +106,20 @@ def variable(request):
return request.param
@pytest.fixture()
def metadata_file(skimmed, model_name):
_, source_name = skimmed
with o3skim.cd("{}_{}".format(source_name, model_name)):
yield "metadata.yaml"
@pytest.fixture()
def metadata_dict(metadata_file):
with open(metadata_file, "r") as ymlfile:
config = yaml.safe_load(ymlfile)
return config
@pytest.fixture()
def skimed_file(skimmed, model_name, variable, year):
groupby, source_name = skimmed
......
SourceSplit:
metadata:
meta_0: Source metadata string example
ModelTCO3:
metadata:
meta_1: Model metadata string example
meta_2: 0
tco3_zm:
name: tco3
paths: SourceSplit/tco3_????.nc
......@@ -7,7 +12,13 @@ SourceSplit:
time: time
lat: latitude
lon: longitude
metadata:
meta_tco3_1: TCO3 metadata string example
meta_tco3_2: 0
ModelVMRO3:
metadata:
meta_1: Model metadata string example
meta_2: 0
vmro3_zm:
name: vmro3
paths: SourceSplit/vmro3_????.nc
......@@ -16,7 +27,13 @@ SourceSplit:
plev: pressure_level
lat: latitude
lon: longitude
metadata:
meta_vmro3_1: VMRO3 metadata string example
meta_vmro3_2: 0
ModelALL:
metadata:
meta_1: Model metadata string example
meta_2: 0
tco3_zm:
name: tco3
paths: SourceSplit/tco3_????.nc
......@@ -24,6 +41,9 @@ SourceSplit:
time: time
lat: latitude
lon: longitude
metadata:
meta_tco3_1: TCO3 metadata string example
meta_tco3_2: 0
vmro3_zm:
name: vmro3
paths: SourceSplit/vmro3_????.nc
......@@ -31,9 +51,17 @@ SourceSplit:
time: time
plev: pressure_level
lat: latitude
lon: longitude
lon: longitude
metadata:
meta_vmro3_1: VMRO3 metadata string example
meta_vmro3_2: 0
SourceMerged:
metadata:
meta_0: Source metadata string example
ModelTCO3:
metadata:
meta_1: Model metadata string example
meta_2: 0
tco3_zm:
name: tco3
paths: SourceMerged/merged_????.nc
......@@ -41,7 +69,13 @@ SourceMerged:
time: time
lat: latitude
lon: longitude
metadata:
meta_tco3_1: TCO3 metadata string example
meta_tco3_2: 0
ModelVMRO3:
metadata:
meta_1: Model metadata string example
meta_2: 0
vmro3_zm:
name: vmro3
paths: SourceMerged/merged_????.nc
......@@ -50,7 +84,13 @@ SourceMerged:
plev: pressure_level
lat: latitude
lon: longitude
metadata:
meta_vmro3_1: VMRO3 metadata string example
meta_vmro3_2: 0
ModelALL:
metadata:
meta_1: Model metadata string example
meta_2: 0
tco3_zm:
name: tco3
paths: SourceMerged/merged_????.nc
......@@ -58,6 +98,9 @@ SourceMerged:
time: time
lat: latitude
lon: longitude
metadata:
meta_tco3_1: TCO3 metadata string example
meta_tco3_2: 0
vmro3_zm:
name: vmro3
paths: SourceMerged/merged_????.nc
......@@ -66,4 +109,6 @@ SourceMerged:
plev: pressure_level
lat: latitude
lon: longitude
metadata:
meta_vmro3_1: VMRO3 metadata string example
meta_vmro3_2: 0
......@@ -85,3 +85,24 @@ class TestSkimming_ByDecade:
assert not 'plev' in skimmed_model.coords
assert 'lat' in skimmed_model.coords
assert not 'lon' in skimmed_model.coords
@pytest.mark.parametrize('groupby', [None, 'year', 'decade'], indirect=True)
class TestSkimming_Common:
@pytest.mark.parametrize('model_name', conftest.models_tco3, indirect=True)
def test_isTCO3metadata(self, metadata_file, variable):
assert os.path.isfile(metadata_file)
@pytest.mark.parametrize('model_name', conftest.models_tco3, indirect=True)
def test_metadata_commons(self, metadata_dict, variable):
assert metadata_dict["meta_0"] == "Source metadata string example"
assert metadata_dict["meta_1"] == "Model metadata string example"
assert metadata_dict["meta_2"] == 0
@pytest.mark.parametrize('model_name', conftest.models_tco3, indirect=True)
def test_metadata_tco3(self, metadata_dict, variable):
assert variable in metadata_dict
metadata_tco3 = metadata_dict[variable]
assert metadata_tco3["meta_tco3_1"] == "TCO3 metadata string example"
assert metadata_tco3["meta_tco3_2"] == 0
......@@ -86,3 +86,24 @@ class TestSkimming_ByDecade:
assert 'plev' in skimmed_model.coords
assert 'lat' in skimmed_model.coords
assert not 'lon' in skimmed_model.coords
@pytest.mark.parametrize('groupby', [None, 'year', 'decade'], indirect=True)
class TestSkimming_Common:
@pytest.mark.parametrize('model_name', conftest.models_vmro3, indirect=True)
def test_isVMRO3metadata(self, metadata_file, variable):
assert os.path.isfile(metadata_file)
@pytest.mark.parametrize('model_name', conftest.models_vmro3, indirect=True)
def test_metadata_commons(self, metadata_dict, variable):
assert metadata_dict["meta_0"] == "Source metadata string example"
assert metadata_dict["meta_1"] == "Model metadata string example"
assert metadata_dict["meta_2"] == 0
@pytest.mark.parametrize('model_name', conftest.models_vmro3, indirect=True)
def test_metadata_vmro3(self, metadata_dict, variable):
assert variable in metadata_dict
metadata_vmro3 = metadata_dict[variable]
assert metadata_vmro3["meta_vmro3_1"] == "VMRO3 metadata string example"
assert metadata_vmro3["meta_vmro3_2"] == 0
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment