|
23 | 23 | prepare_ds_and_get_frequency, |
24 | 24 | ) |
25 | 25 | from input4mips_validation.inference.from_data import BoundsInfo |
26 | | -from input4mips_validation.testing import get_valid_ds_min_metadata_example |
| 26 | +from input4mips_validation.testing import ( |
| 27 | + get_valid_ds_min_metadata_example, |
| 28 | + get_valid_ds_min_metadata_example_climatology, |
| 29 | +) |
27 | 30 | from input4mips_validation.validation.tree import get_validate_tree_result |
28 | 31 |
|
29 | 32 | UR = pint.get_application_registry() |
@@ -96,3 +99,65 @@ def test_basic(tmp_path): |
96 | 99 | result = runner.invoke(app, ["validate-tree", str(tmp_path)]) |
97 | 100 |
|
98 | 101 | assert result.exit_code == 0, result.exc_info |
| 102 | + |
| 103 | + |
| 104 | +def test_climatology(tmp_path): |
| 105 | + """ |
| 106 | + Write a climatology file in a tree, then make sure we can validate the tree |
| 107 | + """ |
| 108 | + cvs = load_cvs(cv_source=DEFAULT_TEST_INPUT4MIPS_CV_SOURCE) |
| 109 | + |
| 110 | + # Create ourselves a tree |
| 111 | + written_files = [] |
| 112 | + for variable_id, units in ( |
| 113 | + ("mole_fraction_of_carbon_dioxide_in_air", "ppm"), |
| 114 | + # ("mole_fraction_of_methane_in_air", "ppb"), |
| 115 | + ): |
| 116 | + ds, metadata_minimum = get_valid_ds_min_metadata_example_climatology( |
| 117 | + variable_id=variable_id, units=units |
| 118 | + ) |
| 119 | + |
| 120 | + ds["time"].encoding = { |
| 121 | + "calendar": "proleptic_gregorian", |
| 122 | + "units": "days since 1850-01-01 00:00:00", |
| 123 | + # Time has to be encoded as float |
| 124 | + # to ensure that half-days etc. are handled. |
| 125 | + "dtype": np.dtypes.Float32DType, |
| 126 | + } |
| 127 | + |
| 128 | + input4mips_ds = Input4MIPsDataset.from_data_producer_minimum_information( |
| 129 | + data=ds, |
| 130 | + metadata_minimum=metadata_minimum, |
| 131 | + cvs=cvs, |
| 132 | + dataset_category="GHGConcentrations", |
| 133 | + realm="atmos", |
| 134 | + prepare_func=partial( |
| 135 | + prepare_ds_and_get_frequency, |
| 136 | + standard_and_or_long_names={ |
| 137 | + variable_id: {"standard_name": variable_id} |
| 138 | + }, |
| 139 | + ), |
| 140 | + ) |
| 141 | + |
| 142 | + written_file = input4mips_ds.write(root_data_dir=tmp_path) |
| 143 | + |
| 144 | + written_files.append(written_file) |
| 145 | + |
| 146 | + # Test the function directly first (helps with debugging) |
| 147 | + get_validate_tree_result( |
| 148 | + tmp_path, |
| 149 | + cv_source=DEFAULT_TEST_INPUT4MIPS_CV_SOURCE, |
| 150 | + bounds_info=BoundsInfo( |
| 151 | + time_bounds="time_bnds", |
| 152 | + bounds_dim="bnds", |
| 153 | + ), |
| 154 | + ).raise_if_errors() |
| 155 | + |
| 156 | + # Then test the CLI |
| 157 | + with patch.dict( |
| 158 | + os.environ, |
| 159 | + {"INPUT4MIPS_VALIDATION_CV_SOURCE": str(DEFAULT_TEST_INPUT4MIPS_CV_SOURCE)}, |
| 160 | + ): |
| 161 | + result = runner.invoke(app, ["validate-tree", str(tmp_path)]) |
| 162 | + |
| 163 | + assert result.exit_code == 0, result.exc_info |
0 commit comments