Skip to content

Commit

Permalink
Merge branch 'nexus-upd' of https://github.com/iiasa/message-ix-models
Browse files Browse the repository at this point in the history
…into nexus-upd
  • Loading branch information
awais307 committed Apr 7, 2024
2 parents 18b3648 + c404225 commit 826cbaf
Show file tree
Hide file tree
Showing 7 changed files with 170 additions and 81 deletions.
184 changes: 115 additions & 69 deletions doc/data.rst

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions doc/whatsnew.rst
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
What's new
**********

.. Next release
.. ============
Next release
============

- Expand :doc:`data` (:pull:`161`).

v2024.4.2
=========
Expand Down
Git LFS file not shown
2 changes: 2 additions & 0 deletions message_ix_models/model/water/data/irrigation.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

from typing import TYPE_CHECKING

from typing import TYPE_CHECKING

import pandas as pd
from message_ix import make_df

Expand Down
16 changes: 11 additions & 5 deletions message_ix_models/project/ssp/data.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import logging

from platformdirs import user_cache_path

from message_ix_models.tools.exo_data import (
ExoDataSource,
iamc_like_data_for_query,
Expand Down Expand Up @@ -122,7 +124,7 @@ class SSPUpdate(ExoDataSource):
- `source`: Any value from :data:`.SSP_2024` or equivalent string, for instance
"ICONICS:SSP(2024).2".
- `release`: One of "3.0" or "preview".
- `release`: One of "3.0.1", "3.0", or "preview".
Example
-------
Expand All @@ -140,6 +142,7 @@ class SSPUpdate(ExoDataSource):
#: File names containing the data, according to the release.
filename = {
"3.0": "1706548837040-ssp_basic_drivers_release_3.0_full.csv.gz",
"3.0.1": "1710759470883-ssp_basic_drivers_release_3.0.1_full.csv.gz",
"preview": "SSP-Review-Phase-1.csv.gz",
}

Expand Down Expand Up @@ -171,10 +174,12 @@ def __init__(self, source, source_kw):
models = []
scenarios = []

if release == "3.0":
# Directories in which to locate `self.filename`; stored directly within
# message_ix_models
dirs = [package_data_path("ssp")]
if release in ("3.0.1", "3.0"):
# Directories in which to locate `self.filename`:
# - User's local cache (retrieved with "mix-models fetch" or equivalent).
# - Stored directly within message_ix_models (editable install from a clone
# of the git repository).
dirs = [user_cache_path("message-ix-models"), package_data_path("ssp")]

scenarios.append(f"SSP{ssp_id}")

Expand All @@ -191,6 +196,7 @@ def __init__(self, source, source_kw):
# Look first in message_data, then in message_ix_models test data
dirs = [private_data_path("ssp"), package_data_path("test", "ssp")]

models.extend([model] if model is not None else [])
scenarios.append(f"SSP{ssp_id} - Review Phase 1")
else:
log.error(
Expand Down
9 changes: 8 additions & 1 deletion message_ix_models/tests/project/test_ssp.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from copy import copy

import pytest
from genno import Computer

Expand Down Expand Up @@ -155,11 +157,16 @@ class TestSSPUpdate:
),
),
)
def test_prepare_computer(self, test_context, source, source_kw):
@pytest.mark.parametrize("release", ("preview", "3.0", "3.0.1"))
def test_prepare_computer(self, test_context, source, source_kw, release):
# FIXME The following should be redundant, but appears mutable on GHA linux and
# Windows runners.
test_context.model.regions = "R14"

# Set the release
source_kw = copy(source_kw)
source_kw.update(release=release)

c = Computer()

keys = prepare_computer(test_context, c, source, source_kw)
Expand Down
31 changes: 27 additions & 4 deletions message_ix_models/util/pooch.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import logging
from pathlib import Path
from typing import Tuple
from typing import Any, Mapping, Tuple

import click
import pooch
Expand Down Expand Up @@ -73,8 +73,11 @@ def __call__(self, fname, action, pooch):
return path


#: Base URL portion for files stored in the message-ix-models GitHub repository.
GH_MAIN = "https://github.com/iiasa/message-ix-models/raw/main/message_ix_models/data"

#: Supported remote sources of data.
SOURCE = {
SOURCE: Mapping[str, Mapping[str, Any]] = {
"PRIMAP": dict(
pooch_args=dict(
base_url="ftp://datapub.gfz-potsdam.de/download/10.5880.PIK.2019.001/",
Expand All @@ -88,8 +91,7 @@ def __call__(self, fname, action, pooch):
),
"MESSAGEix-Nexus": dict(
pooch_args=dict(
base_url="https://github.com/iiasa/message-ix-models/raw/enh/2023-W44/"
"message_ix_models/data/water/",
base_url=f"{GH_MAIN}/water/",
registry={"water.tar.xz": "sha1:ec9e0655af90ca844c0158968bb03a194b8fa6c6"},
),
processor=Extract(extract_dir="water"),
Expand All @@ -105,6 +107,27 @@ def __call__(self, fname, action, pooch):
),
processor=UnpackSnapshot(),
),
"SSP-Update-3.0": dict(
pooch_args=dict(
base_url=f"{GH_MAIN}/ssp/",
registry={
"1706548837040-ssp_basic_drivers_release_3.0_full.csv.gz": (
"sha1:e2af7a88aeed7d0e44ceaf2dff60f891cf551517"
),
},
),
),
"SSP-Update-3.0.1": dict(
pooch_args=dict(
base_url="https://github.com/iiasa/message-ix-models/raw/fix/ssp-pooch/"
"message_ix_models/data/ssp/",
registry={
"1710759470883-ssp_basic_drivers_release_3.0.1_full.csv.gz": (
"sha1:e5c24c27ee743e79dac5a578235b35a68cd64183"
),
},
),
),
}


Expand Down

0 comments on commit 826cbaf

Please sign in to comment.