diff --git a/config/cmip6.yaml b/config/cmip6.yaml index 5af7bd5..0ea165d 100644 --- a/config/cmip6.yaml +++ b/config/cmip6.yaml @@ -10,8 +10,4 @@ sources: - metadata_yaml: /g/data/xp65/admin/access-nri-intake-catalog/config/metadata_sources/cmip6-oi10/metadata.yaml path: - - /g/data/oi10/catalog/v2/esm/catalog.json - - - metadata_yaml: /g/data/xp65/admin/intake/metadata/cmip6_ig45/metadata.yaml - path: - - /g/data/ig45/catalog/v2/esm/catalog.json \ No newline at end of file + - /g/data/oi10/catalog/v2/esm/catalog.json \ No newline at end of file diff --git a/config/experiments/cmip6_ig45/metadata.yaml b/config/experiments/cmip6_ig45/metadata.yaml deleted file mode 100644 index 8046f73..0000000 --- a/config/experiments/cmip6_ig45/metadata.yaml +++ /dev/null @@ -1,26 +0,0 @@ -name: cmip6_ig45 -experiment_uuid: c7021d1e-7ba2-11ef-beb5-000007d3fe80 -description: 20km regional projections for CORDEX-CMIP6 from the Queensland Future Climate Science Program -long_description: >- - This dataset includes projections at 20km, formatted to meet the CORDEX-CMIP6 data standards. - The 20km projections were derived from the 10km projections. -model: -- CMIP6 -frequency: -- -variable: -- -nominal_resolution: -- -version: -contact: NCI -email: help@nci.org.au -reference: -license: -url: https://geonetwork.nci.org.au/geonetwork/srv/eng/catalog.search#/metadata/f7465_8388_5100_7022 -parent_experiment: -related_experiments: -- -notes: -keywords: -- cmip \ No newline at end of file diff --git a/config/metadata_sources/cordex-ig45/metadata.yaml b/config/metadata_sources/cordex-ig45/metadata.yaml index c118c40..1d013e6 100644 --- a/config/metadata_sources/cordex-ig45/metadata.yaml +++ b/config/metadata_sources/cordex-ig45/metadata.yaml @@ -121,7 +121,6 @@ license: url: https://geonetwork.nci.org.au/geonetwork/srv/eng/catalog.search#/metadata/f7465_8388_5100_7022 parent_experiment: related_experiments: -- notes: keywords: - cmip \ No newline at end of file diff --git a/src/access_nri_intake/catalog/translators.py b/src/access_nri_intake/catalog/translators.py index e547296..fb8fb5a 100644 --- a/src/access_nri_intake/catalog/translators.py +++ b/src/access_nri_intake/catalog/translators.py @@ -211,8 +211,8 @@ def set_dispatch( The function to translate the column """ if core_colname not in ["model", "realm", "frequency", "variable"]: - raise ValueError( - "'flag' must be one of 'model', 'realm', 'frequency', 'variable'" + raise TranslatorError( + f"'core_colname' must be one of 'model', 'realm', 'frequency', 'variable', not {core_colname}" ) self._dispatch[core_colname] = func setattr(self._dispatch_keys, core_colname, input_name) diff --git a/tests/test_translators.py b/tests/test_translators.py index 29b422b..91ee588 100644 --- a/tests/test_translators.py +++ b/tests/test_translators.py @@ -17,6 +17,7 @@ TranslatorError, _cmip_realm_translator, _to_tuple, + tuplify_series, ) @@ -189,6 +190,29 @@ def test_DefaultTranslator_error(test_data): assert "Could not translate" in str(excinfo.value) +@pytest.mark.parametrize( + "colname, should_raise", + [ + ("model", False), + ("realm", False), + ("frequency", False), + ("variable", False), + ("random_string", True), + ], +) +def test_DefaultTranslator_set_dispatch(test_data, colname, should_raise): + """Test that only valid translation setups are allowed""" + esmds = intake.open_esm_datastore(test_data / "esm_datastore/cmip5-al33.json") + dtrans = DefaultTranslator(esmds, CORE_COLUMNS) + if should_raise: + with pytest.raises(TranslatorError) as excinfo: + dtrans.set_dispatch(colname, dtrans._model_translator, "model") + assert "'core_colname' must be one of" in str(excinfo.value) + else: + dtrans.set_dispatch(colname, dtrans._model_translator, colname) + assert dtrans._dispatch[colname] == dtrans._model_translator + + @pytest.mark.parametrize( "groupby, n_entries", [ @@ -280,3 +304,26 @@ def test_CordexTranslator(test_data, groupby, n_entries): esmds.description = "description" df = CordexTranslator(esmds, CORE_COLUMNS).translate(groupby) assert len(df) == n_entries + + +@pytest.mark.parametrize( + "input_series, expected_output", + [ + (pd.Series([1, 2, 3]), pd.Series([(1,), (2,), (3,)])), + (pd.Series([(1,), 2, 3]), pd.Series([(1,), (2,), (3,)])), + ], +) +def test_tuplify_series(input_series, expected_output): + """Test the _tuplify_series function""" + + @tuplify_series + def tuplify_func(series): + return series + + class TestSeries: + @tuplify_series + def method(self, series): + return series + + assert all(tuplify_func(input_series) == expected_output) + assert all(TestSeries().method(input_series) == expected_output)