diff --git a/grib_processor/grib.py b/grib_processor/grib.py index 473986be4bcbffa533df3e6a4390202fd50f8d89..7abd23561a6485ca21cb2a5b7fa8290d138ef352 100644 --- a/grib_processor/grib.py +++ b/grib_processor/grib.py @@ -42,7 +42,7 @@ else: # Loaded using load_xcd_models() _XCD_MODELS = None -# default model_name, model_id when +# default model_name, model_id _XCD_MISSING = ("UNKWN", "UNKWN") @@ -96,10 +96,11 @@ def load_xcd_models( ) -> None: """Load the xcd models from the package.""" global _XCD_MODELS - # This MUST match name of xcd file in grib_processor.data - data_path = resources.files(data) / "xcd_model_info.json" - with data_path.open("r") as xcd_data: - _XCD_MODELS = json.load(xcd_data) + if _XCD_MODELS is None: + # This MUST match name of xcd file in grib_processor.data + data_path = resources.files(data) / "xcd_model_info.json" + with data_path.open("r") as xcd_data: + _XCD_MODELS = json.load(xcd_data) for addtnl in addtnl_models: _XCD_MODELS.update(addtnl) diff --git a/tests/test_grib.py b/tests/test_grib.py new file mode 100644 index 0000000000000000000000000000000000000000..351289ccf7e15c2a65347000184504556880d489 --- /dev/null +++ b/tests/test_grib.py @@ -0,0 +1,20 @@ +from grib_processor.grib import xcd_lookup, load_xcd_models + + +def test_custom_loading(): + """Test that loading a custom xcd model works with xcd_lookup. + + Note: This is a leaky test, the custom model will be in following tests. + """ + f_lat = 123 + f_lon = 456 + rows = 1 + cols = 5 + g_id = 6 + m_name = "custom_name" + m_id = "custom_id" + c_model = { + str(f_lat): {str(f_lon): {str(rows): {str(cols): {str(g_id): [m_name, m_id]}}}} + } + load_xcd_models(c_model) + assert xcd_lookup(f_lat, f_lon, rows, cols, g_id) == (m_name, m_id)