Skip to content

Commit

Permalink
Fall back to synthetic test data for SSPUpdate
Browse files Browse the repository at this point in the history
  • Loading branch information
khaeru committed Sep 13, 2023
1 parent e1c67fa commit 77e2992
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions message_ix_models/project/ssp/data.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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)

0 comments on commit 77e2992

Please sign in to comment.