From 77e2992d9032cce2379107c773d73b0ad7c17bb7 Mon Sep 17 00:00:00 2001 From: Paul Natsuo Kishimoto Date: Wed, 13 Sep 2023 15:24:40 +0200 Subject: [PATCH] Fall back to synthetic test data for SSPUpdate --- message_ix_models/project/ssp/data.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/message_ix_models/project/ssp/data.py b/message_ix_models/project/ssp/data.py index 8f4a81ae26..7f47a45d6b 100644 --- a/message_ix_models/project/ssp/data.py +++ b/message_ix_models/project/ssp/data.py @@ -1,9 +1,14 @@ +import logging +from copy import copy + from message_ix_models.tools.exo_data import ( ExoDataSource, iamc_like_data_for_query, register_source, ) -from message_ix_models.util import private_data_path +from message_ix_models.util import package_data_path, private_data_path + +log = logging.getLogger(__name__) @register_source @@ -20,16 +25,17 @@ def __init__(self, source, source_kw): *parts, self.ssp_number = source.partition(s) # Map the `measure` keyword to a string appearing in the data + _kw = copy(source_kw) self.measure = { "GDP": "GDP|PPP", "POP": "Population", - }[source_kw.pop("measure")] + }[_kw.pop("measure")] # Store the model ID, if any - self.model = source_kw.pop("model", None) + self.model = _kw.pop("model", None) - if len(source_kw): - raise ValueError(source_kw) + if len(_kw): + raise ValueError(_kw) def __call__(self): # Assemble a query string @@ -42,6 +48,8 @@ def __call__(self): ) path = private_data_path("ssp", "SSP-Review-Phase-1.csv.gz") - assert path.exists(), "TODO handle the case where message_data is not insalled" + if not path.exists(): + log.warning(f"Cannot find (private) path {path}; reading random data") + path = package_data_path("test", *path.parts[-2:]) return iamc_like_data_for_query(path, query)