Skip to content

Commit

Permalink
Merge pull request #219 from iiasa/costs/ssp-fix
Browse files Browse the repository at this point in the history
Fix naming of GDP and population columns in SSP data aggregation within `tools.costs`
  • Loading branch information
khaeru authored Sep 2, 2024
2 parents cf687da + 33aa238 commit 5fe36ca
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 14 deletions.
7 changes: 5 additions & 2 deletions doc/whatsnew.rst
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
What's new
**********

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

- Fix and update :doc:`/api/tools-costs` (:pull:`219`)
- Fix naming of GDP and population columns in SSP data aggregation (:pull:`219`).

v2024.8.6
=========
Expand Down
21 changes: 11 additions & 10 deletions message_ix_models/tools/costs/gdp.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@ def process_raw_ssp_data(context: Context, config: Config) -> pd.DataFrame:
pandas.DataFrame
with the columns:
- scenario_version
- scenario
- region
- year
- total_gdp
- total_population
- gdp_ppp_per_capita
- gdp_ratio_reg_to_reference
- scenario_version: version of SSP scenario data
- scenario: scenario (SSP1-5, LED)
- region: region name
- year: year of data
- total_population: total population aggregated to the regional level
- total_gdp: total GDP aggregated to the regional level
- gdp_ppp_per_capita: regional GDP per capita in PPP
- gdp_ratio_reg_to_reference: ratio of regional GDP per capita to \
reference region's GDP per capita
"""
from collections import defaultdict

Expand Down Expand Up @@ -97,8 +98,8 @@ def merge(*dfs: pd.DataFrame) -> pd.DataFrame:
return (
pd.concat(
[
dfs[0].to_series().rename("total_gdp"),
dfs[1].to_series().rename("total_population"),
dfs[0].to_series().rename("total_population"),
dfs[1].to_series().rename("total_gdp"),
dfs[2].to_series().rename("gdp_ppp_per_capita"),
dfs[3].to_series().rename("gdp_ratio_reg_to_reference"),
],
Expand Down
8 changes: 6 additions & 2 deletions message_ix_models/tools/wb.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,12 @@ def get_weight(code: "sdmx.model.common.Code") -> float:
return 1.0

elif method == "population":
# Work around khaeru/sdmx#191: ensure the HTTPS URL is used
client = sdmx.Client("WB_WDI")
client.source.url = client.source.url.replace("http://", "https://")

# Retrieve WB_WDI data for SERIES=SP_POP_TOTAL (Population, total)
dm = sdmx.Client("WB_WDI").data(
dm = client.data(
"WDI", key="A.SP_POP_TOTL.", params=dict(startPeriod=2020, endPeriod=2020)
)

Expand Down Expand Up @@ -154,7 +158,7 @@ def fetch_codelist(id: str) -> "sdmx.model.common.Codelist":
import sdmx

file = pooch.retrieve(
url="http://api.worldbank.org/v2/sdmx/rest/codelist/WB/", known_hash=None
url="https://api.worldbank.org/v2/sdmx/rest/codelist/WB/", known_hash=None
)
# Read the retrieved SDMX StructureMessage and extract the code list
sm = sdmx.read_sdmx(file)
Expand Down

0 comments on commit 5fe36ca

Please sign in to comment.