Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 16 additions & 17 deletions Test/test_cmor_CMIP7.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from netCDF4 import Dataset

CMIP7_TABLES_PATH = "cmip7-cmor-tables/tables"
CV_PATH = "TestTables/CMIP7_CV.json"
CV_PATH = "cmip7-cmor-tables/tables-cvs/cmor-cvs.json"

USER_INPUT = {
"_AXIS_ENTRY_FILE": "CMIP7_coordinate.json",
Expand All @@ -17,19 +17,17 @@
"activity_id": "CMIP",
"calendar": "360_day",
"cv_version": "6.2.19.0",
"drs_specs": "MIP-DRS7",
"experiment_id": "piControl",
"forcing_index": "f30",
"grid_label": "gn",
"initialization_index": "i000001d",
"institution_id": "PCMDI",
"license_id": "CC BY 4.0",
"nominal_resolution": "250 km",
"experiment_id": "amip",
"forcing_index": "f3",
"grid_label": "g999",
"initialization_index": "i1",
"institution_id": "CCCma",
"license_id": "CC-BY-4.0",
"nominal_resolution": "100 km",
"outpath": ".",
"physics_index": "p1",
"realization_index": "r009",
"source_id": "PCMDI-test-1-0",
"tracking_prefix": "hdl:21.14100",
"realization_index": "r9",
"source_id": "DUMMY-MODEL",
"host_collection": "CMIP7",
"frequency": "mon",
"region": "glb",
Expand Down Expand Up @@ -122,22 +120,23 @@ def test_cmip7(self):
'frequency': 'mon',
'archive_id': 'WCRP',
'mip_era': 'CMIP7',
'data_specs_version': 'CMIP-7.0.0.0',
'data_specs_version': 'MIP-DS7.1.0.0',
'host_collection': 'CMIP7',
}

for attr, val in test_attrs.items():
self.assertIn(attr, attrs)
self.assertEqual(val, ds.getncattr(attr))
institution_id = USER_INPUT["institution_id"]
license_id = "CC BY 4.0"
license_id = "CC-BY-4.0"
license_type = "Creative Commons Attribution 4.0 International"
license_url = "https://creativecommons.org/licenses/by/4.0/"
license_url = "https://creativecommons.org/licenses/by/4.0"
license = \
(f"{license_id}; CMIP7 data produced by {institution_id} is "
f"licensed under a {license_type} License ({license_url}). "
"Consult https://wcrp-cmip.github.io/cmip7-guidance/docs/CMIP7/"
"Guidance_for_users for terms of "
"Guidance_for_users/#2-terms-of-use-and-citations-requirements "
"for terms of "
"use governing CMIP7 output, including citation requirements and "
"proper acknowledgment. The data producers and data providers "
"make no warranty, either express or implied, including, but not "
Expand Down Expand Up @@ -204,7 +203,7 @@ def test_secondary_modeling_realm(self):
'frequency': 'mon',
'archive_id': 'WCRP',
'mip_era': 'CMIP7',
'data_specs_version': 'CMIP-7.0.0.0',
'data_specs_version': 'MIP-DS7.1.0.0',
'host_collection': 'CMIP7',
'realm': 'atmos land landIce',
}
Expand Down
38 changes: 14 additions & 24 deletions Test/test_cmor_check_cv_structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,27 @@
from base_CMIP6_CV import BaseCVsTest

CMIP7_TABLES_PATH = "cmip7-cmor-tables/tables"
CV_PATH = "TestTables/CMIP7_CV.json"
CV_PATH = "cmip7-cmor-tables/tables-cvs/cmor-cvs.json"

USER_INPUT = {
"_AXIS_ENTRY_FILE": "CMIP7_coordinate.json",
"_FORMULA_VAR_FILE": "CMIP7_formula_terms.json",
"_cmip7_option": 1,
"_controlled_vocabulary_file": None,
"activity_id": "CMIP",
"branch_time_in_child": 30.0,
"branch_time_in_parent": 10800.0,
"calendar": "360_day",
"cv_version": "6.2.19.0",
"drs_specs": "MIP-DRS7",
"experiment_id": "piControl",
"forcing_index": "f30",
"grid_label": "gn",
"initialization_index": "i000001d",
"institution_id": "PCMDI",
"license_id": "CC BY 4.0",
"nominal_resolution": "250 km",
"experiment_id": "amip",
"forcing_index": "f3",
"grid_label": "g999",
"initialization_index": "i1",
"institution_id": "CCCma",
"license_id": "CC-BY-4.0",
"nominal_resolution": "100 km",
"outpath": ".",
"parent_mip_era": "CMIP7",
"parent_time_units": "days since 1850-01-01",
"parent_activity_id": "CMIP",
"parent_source_id": "PCMDI-test-1-0",
"parent_experiment_id": "piControl",
"parent_variant_label": "r1i1p1f3",
"physics_index": "p1",
"realization_index": "r009",
"source_id": "PCMDI-test-1-0",
"tracking_prefix": "hdl:21.14100",
"realization_index": "r9",
"source_id": "DUMMY-MODEL",
"host_collection": "CMIP7",
"frequency": "mon",
"region": "glb",
Expand Down Expand Up @@ -149,7 +139,7 @@ def test_check_cv_single_value_pairs(self):

with open(CV_PATH, "r") as cv_infile:
cv = json.load(cv_infile)
cv["CV"]["institution_id"]["PCMDI"] = {"LLNL": "Livermore, CA"}
cv["CV"]["institution_id"]["CCCma"] = {"Toronto": "Toronto, ON"}
with open(cv_path, "w") as cv_outfile:
json.dump(cv, cv_outfile, sort_keys=True, indent=4)

Expand All @@ -166,7 +156,7 @@ def test_check_cv_single_value_pairs(self):

self.assertCV(
"in attribute \"institution_id\" cannot be an object",
"Value for \"PCMDI\""
"Value for \"CCCma\""
)

os.remove(cv_path)
Expand All @@ -182,7 +172,7 @@ def test_check_cv_array_values(self):
netcdf_file_action=cmor.CMOR_REPLACE,
logfile=self.tmpfile)

with open("TestTables/CMIP7_CV.json", "r") as cv_infile:
with open(CV_PATH, "r") as cv_infile:
cv = json.load(cv_infile)
cv["CV"]["source_type"] = [
"AER",
Expand Down Expand Up @@ -221,7 +211,7 @@ def test_check_cv_nested_objects(self):
netcdf_file_action=cmor.CMOR_REPLACE,
logfile=self.tmpfile)

with open("TestTables/CMIP7_CV.json", "r") as cv_infile:
with open(CV_PATH, "r") as cv_infile:
cv = json.load(cv_infile)
cv["CV"]["nested_attr"] = {}
cv["CV"]["nested_attr"]["nested_value"] = {
Expand Down
22 changes: 10 additions & 12 deletions Test/test_cmor_chunking.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import pyfive

CMIP7_TABLES_PATH = "cmip7-cmor-tables/tables"
CV_PATH = "TestTables/CMIP7_CV.json"
CV_PATH = "cmip7-cmor-tables/tables-cvs/cmor-cvs.json"

USER_INPUT = {
"_AXIS_ENTRY_FILE": "CMIP7_coordinate.json",
Expand All @@ -19,19 +19,17 @@
"activity_id": "CMIP",
"calendar": "360_day",
"cv_version": "6.2.19.0",
"drs_specs": "MIP-DRS7",
"experiment_id": "piControl",
"forcing_index": "f30",
"grid_label": "gn",
"initialization_index": "i000001d",
"institution_id": "PCMDI",
"license_id": "CC BY 4.0",
"nominal_resolution": "250 km",
"experiment_id": "amip",
"forcing_index": "f3",
"grid_label": "g999",
"initialization_index": "i1",
"institution_id": "CCCma",
"license_id": "CC-BY-4.0",
"nominal_resolution": "100 km",
"outpath": ".",
"physics_index": "p1",
"realization_index": "r009",
"source_id": "PCMDI-test-1-0",
"tracking_prefix": "hdl:21.14100",
"realization_index": "r9",
"source_id": "DUMMY-MODEL",
"host_collection": "CMIP7",
"frequency": "day",
"region": "glb",
Expand Down
37 changes: 17 additions & 20 deletions Test/test_cmor_cv_root_string_attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from netCDF4 import Dataset

CMIP7_TABLES_PATH = "cmip7-cmor-tables/tables"
CV_PATH = Path("TestTables/CMIP7_CV.json")
CV_PATH = Path("cmip7-cmor-tables/tables-cvs/cmor-cvs.json")

USER_INPUT = {
"_AXIS_ENTRY_FILE": "CMIP7_coordinate.json",
Expand All @@ -19,17 +19,17 @@
"activity_id": "CMIP",
"calendar": "360_day",
"cv_version": "6.2.19.0",
"experiment_id": "piControl",
"forcing_index": "f30",
"grid_label": "gn",
"initialization_index": "i000001d",
"institution_id": "PCMDI",
"license_id": "CC BY 4.0",
"nominal_resolution": "250 km",
"experiment_id": "amip",
"forcing_index": "f3",
"grid_label": "g999",
"initialization_index": "i1",
"institution_id": "CCCma",
"license_id": "CC-BY-4.0",
"nominal_resolution": "100 km",
"outpath": ".",
"physics_index": "p1",
"realization_index": "r009",
"source_id": "PCMDI-test-1-0",
"realization_index": "r9",
"source_id": "DUMMY-MODEL",
"host_collection": "CMIP7",
"frequency": "mon",
"region": "glb",
Expand All @@ -40,11 +40,9 @@
class TestCVRootStringAttributes(unittest.TestCase):
def setUp(self):
self.tmpdir = Path(tempfile.mkdtemp(dir=str(Path("Test").resolve())))
self.cv_path = self.tmpdir / "CMIP7_CV_root_strings.json"
self.input_path = self.tmpdir / "input.json"
self.output_dir = self.tmpdir / "output"
self.output_dir.mkdir()
self.cv_relpath = self.cv_path.relative_to(Path.cwd())
self.input_relpath = self.input_path.relative_to(Path.cwd())
self.output_relpath = self.output_dir.relative_to(Path.cwd())

Expand All @@ -55,14 +53,11 @@ def test_sets_drs_specs_and_tracking_prefix_from_cv_root_strings(self):
with CV_PATH.open() as cv_infile:
cv = json.load(cv_infile)

cv["CV"]["drs_specs"] = "MIP-DRS7"
cv["CV"]["tracking_prefix"] = "hdl:21.14100"

with self.cv_path.open("w") as cv_outfile:
json.dump(cv, cv_outfile, sort_keys=True, indent=4)
expected_drs_specs = cv["CV"]["drs_specs"]
expected_tracking_prefix = cv["CV"]["tracking_prefix"]

user_input = USER_INPUT.copy()
user_input["_controlled_vocabulary_file"] = str(self.cv_relpath)
user_input["_controlled_vocabulary_file"] = str(CV_PATH)
user_input["outpath"] = str(self.output_relpath)

with self.input_path.open("w") as input_file:
Expand Down Expand Up @@ -109,8 +104,10 @@ def test_sets_drs_specs_and_tracking_prefix_from_cv_root_strings(self):

ds = Dataset(filename)
self.assertNotIn("tracking_prefix", ds.ncattrs())
self.assertEqual(ds.getncattr("drs_specs"), "MIP-DRS7")
self.assertTrue(ds.getncattr("tracking_id").startswith("hdl:21.14100/"))
self.assertEqual(ds.getncattr("drs_specs"), expected_drs_specs)
self.assertTrue(
ds.getncattr("tracking_id").startswith(f"{expected_tracking_prefix}/")
)
ds.close()

filename.unlink(missing_ok=True)
Expand Down
17 changes: 11 additions & 6 deletions Test/test_cmor_frequency_required.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from base_CMIP6_CV import BaseCVsTest

CMIP7_TABLES_PATH = "cmip7-cmor-tables/tables"
CV_PATH = "TestTables/CMIP7_CV.json"
CV_PATH = "cmip7-cmor-tables/tables-cvs/cmor-cvs.json"


def run():
Expand All @@ -21,13 +21,18 @@ def _create_cmip7_json(self, frequency=None, extra_fields=None):
"_cmip7_option": 1,
"_controlled_vocabulary_file": CV_PATH,
"mip_era": "CMIP7",
"institution_id": "PCMDI",
"source_id": "PCMDI-test-1-0",
"experiment_id": "piControl",
"forcing_index": "f3",
"grid_label": "g999",
"initialization_index": "i1",
"institution_id": "CCCma",
"license_id": "CC-BY-4.0",
"nominal_resolution": "100 km",
"physics_index": "p1",
"realization_index": "r9",
"source_id": "DUMMY-MODEL",
"experiment_id": "amip",
"activity_id": "CMIP",
"source_type": "AOGCM",
"grid_label": "gn",
"nominal_resolution": "250 km",
"calendar": "360_day",
"region": "glb",
"outpath": ".",
Expand Down
31 changes: 15 additions & 16 deletions Test/test_cmor_license_attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from netCDF4 import Dataset

CMIP7_TABLES_PATH = "cmip7-cmor-tables/tables"
CV_PATH = "TestTables/CMIP7_CV.json"
CV_PATH = "cmip7-cmor-tables/tables-cvs/cmor-cvs.json"

USER_INPUT = {
"_AXIS_ENTRY_FILE": "CMIP7_coordinate.json",
Expand All @@ -17,19 +17,17 @@
"activity_id": "CMIP",
"calendar": "360_day",
"cv_version": "6.2.19.0",
"drs_specs": "MIP-DRS7",
"experiment_id": "piControl",
"forcing_index": "f30",
"grid_label": "gn",
"initialization_index": "i000001d",
"institution_id": "PCMDI",
"license_id": "CC BY 4.0",
"nominal_resolution": "250 km",
"experiment_id": "amip",
"forcing_index": "f3",
"grid_label": "g999",
"initialization_index": "i1",
"institution_id": "CCCma",
"license_id": "CC-BY-4.0",
"nominal_resolution": "100 km",
"outpath": ".",
"physics_index": "p1",
"realization_index": "r009",
"source_id": "PCMDI-test-1-0",
"tracking_prefix": "hdl:21.14100",
"realization_index": "r9",
"source_id": "DUMMY-MODEL",
"host_collection": "CMIP7",
"frequency": "mon",
"region": "glb",
Expand Down Expand Up @@ -122,22 +120,23 @@ def test_cmip7_with_license_id_and_url(self):
'frequency': 'mon',
'archive_id': 'WCRP',
'mip_era': 'CMIP7',
'data_specs_version': 'CMIP-7.0.0.0',
'data_specs_version': 'MIP-DS7.1.0.0',
'host_collection': 'CMIP7',
}

for attr, val in test_attrs.items():
self.assertTrue(attr in attrs)
self.assertEqual(val, ds.getncattr(attr))
institution_id = USER_INPUT["institution_id"]
license_id = "CC BY 4.0"
license_id = "CC-BY-4.0"
license_type = "Creative Commons Attribution 4.0 International"
license_url = "https://creativecommons.org/licenses/by/4.0/"
license_url = "https://creativecommons.org/licenses/by/4.0"
license = \
(f"{license_id}; CMIP7 data produced by {institution_id} is "
f"licensed under a {license_type} License ({license_url}). "
"Consult https://wcrp-cmip.github.io/cmip7-guidance/docs/CMIP7/"
"Guidance_for_users for terms of "
"Guidance_for_users/#2-terms-of-use-and-citations-requirements "
"for terms of "
"use governing CMIP7 output, including citation requirements and "
"proper acknowledgment. The data producers and data providers "
"make no warranty, either express or implied, including, but not "
Expand Down
Loading
Loading