Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
8ef7d85
WIP
mzecc Mar 4, 2026
a9c6dc2
Country gridding + infilling
mzecc Mar 12, 2026
76ccade
Country gridding + infilling
mzecc Mar 12, 2026
75c5269
infilling and global harmonisation
mzecc Mar 13, 2026
4e51f95
cleaned how-to-run-the-cmip7-scenariomip-workflow
mzecc Mar 13, 2026
286487d
Failing tests/integration/harmonisation/test_integration_harmonisation
mzecc Mar 13, 2026
4064581
Tests passing locally
mzecc Mar 13, 2026
6856041
Added pandas-indexing into pyproject
mzecc Mar 14, 2026
9744763
Resolve merge conflicts with main
mzecc Mar 17, 2026
49c2027
Updated test files
mzecc Mar 17, 2026
c82cab3
Splitted get_pre_industrial_aware_direct_scaling_infiller out
mzecc Mar 17, 2026
a761134
mypy: 1
mzecc Mar 18, 2026
a5c26d7
mypy: 2
mzecc Mar 18, 2026
555b5bf
mypy: 3
mzecc Mar 18, 2026
558371e
mypy: 4
mzecc Mar 18, 2026
9dd8723
mypy: 5
mzecc Mar 18, 2026
e0e3bb7
mypy: 5
mzecc Mar 18, 2026
4164a01
mypy: 7
mzecc Mar 18, 2026
50f6e85
mypy: 9
mzecc Mar 18, 2026
9003906
mypy: 11
mzecc Mar 18, 2026
025a523
mypy:11
mzecc Mar 18, 2026
cf5ce7f
mypy :11
mzecc Mar 18, 2026
1ae66fd
mypy :14
mzecc Mar 18, 2026
51eaac7
mypy :16
mzecc Mar 18, 2026
830a2dc
mypy :17
mzecc Mar 18, 2026
b7ee45a
mypy :18
mzecc Mar 18, 2026
2b586e2
Implemented Corrections
mzecc Mar 19, 2026
3cf1cb4
Added class for infilling
mzecc Mar 19, 2026
9421466
tests passing
mzecc Mar 20, 2026
416f76e
moved complete_index_gcages_names into infilling.py
mzecc Mar 20, 2026
760a76c
removed scm_runnig.py
mzecc Mar 20, 2026
504affd
cleaned common.py
mzecc Mar 20, 2026
18ad33d
Updated how-to-run-the-cmip7-scenariomip-workflow
mzecc Mar 20, 2026
611ee19
Revert changes to pyproject.toml
mzecc Mar 20, 2026
b5dd418
Corrected how-to-run-the-cmip7-scenariomip-workflow.py
mzecc Mar 20, 2026
8df4528
Small errors mypy
mzecc Mar 20, 2026
b2ca0b9
Removed year column form get_cmip7_scenariomip_harmonised_emissions
mzecc Mar 20, 2026
eed1e31
Removed year column form get_cmip7_scenariomip_infilled_emissions
mzecc Mar 20, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 57 additions & 38 deletions docs/how-to-guides/how-to-run-the-cmip7-scenariomip-workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
from gcages.cmip7_scenariomip.harmonisation import (
create_cmip7_scenariomip_global_harmoniser,
)
from gcages.cmip7_scenariomip.infilling import CMIP7ScenarioMIPInfiller
from gcages.cmip7_scenariomip.pre_processing import CMIP7ScenarioMIPPreProcessor
from gcages.index_manipulation import split_sectors

Expand Down Expand Up @@ -105,9 +106,8 @@
EXAMPLE_INPUT_FILE,
index_columns=["model", "scenario", "region", "variable", "unit"],
out_columns_type=int,
out_columns_name="year",
)
start.columns.name = "year"
start

# %% editable=true slideshow={"slide_type": ""}
relplot_in_emms = partial(
Expand Down Expand Up @@ -319,9 +319,6 @@
# (Lots of assumptions are not an issue,
# we simply include this for clarity and transparency.)

# %% editable=true slideshow={"slide_type": ""}
res_pre_processed.assumed_zero_emissions

# %% [markdown] editable=true slideshow={"slide_type": ""}
# ## Harmonisation
#
Expand All @@ -345,8 +342,6 @@
CMIP7_SCENARIOMIP_GLOBAL_HISTORICAL_EMISSIONS_FILE = Path(
"tests/regression/cmip7-scenariomip/cmip7-scenariomip-workflow-inputs/history_cmip7_scenariomip.csv"
)
# TODO: move this file to inputs
# (yes, we derived it as part of the process, but it's an input now)
ANERIS_GLOBAL_OVERRIDES_FILE = Path(
"tests/regression/cmip7-scenariomip/cmip7-scenariomip-workflow-inputs/aneris-overrides-global.csv"
)
Expand Down Expand Up @@ -377,11 +372,11 @@
harmonised_global = harmoniser_global(res_pre_processed.global_workflow_emissions)
harmonised_global

# %% [markdown] editable=true slideshow={"slide_type": ""}
# You can see the modification to the pathways
# as a result of the harmonisation in the plot below.
# %% [markdown]
# You can see the modification to the pathways as a result of
# the harmonisation in the plot below.

# %% editable=true slideshow={"slide_type": ""}
# %%
pdf = (
pix.concat(
[
Expand Down Expand Up @@ -477,19 +472,37 @@
# [silicone](https://github.com/GranthamImperial/silicone) package.

# %%
# TBD - download infiller db
BASE_DIR = Path("tests/regression/cmip7-scenariomip/cmip7-scenariomip-workflow-inputs")
CMIP7_SCENARIOMIP_INFILLING_FILE = BASE_DIR / "infilling_db_cmip7_scenariomip.csv"
GHG_INVERSION_FILE = BASE_DIR / "cmip7_ghg_inversions.csv"

# %% editable=true slideshow={"slide_type": ""} tags=["remove_input"]
if not CMIP7_SCENARIOMIP_INFILLING_FILE.exists():
CMIP7_SCENARIOMIP_INFILLING_FILE = Path("../..") / CMIP7_SCENARIOMIP_INFILLING_FILE
if not CMIP7_SCENARIOMIP_INFILLING_FILE.exists():
raise AssertionError

if not GHG_INVERSION_FILE.exists():
GHG_INVERSION_FILE = Path("../..") / GHG_INVERSION_FILE
if not GHG_INVERSION_FILE.exists():
raise AssertionError

# %% [markdown]
# With the infilling databases, we can initialise our infiller.

# %%
# TBD
infiller = CMIP7ScenarioMIPInfiller.from_cmip7_scenariomip_config(
cmip7_scenariomip_infilling_leader_emissions_file=CMIP7_SCENARIOMIP_INFILLING_FILE,
cmip7_ghg_inversions_file=GHG_INVERSION_FILE,
cmip7_scenariomip_global_historical_emissions_file=CMIP7_SCENARIOMIP_GLOBAL_HISTORICAL_EMISSIONS_FILE,
)

# %% [markdown]
# And infill

# %%
# TBD
infilled = infiller(harmonised_global)
infilled

# %% [markdown]
# You can see infilled pathways compared to raw pathways in the below.
Expand All @@ -499,32 +512,38 @@
# see [Lamboll et al., 2020](https://doi.org/10.5194/gmd-13-5259-2020).

# %%
# pdf = (
# pix.concat(
# [
# pre_processed.pix.assign(stage="pre_processed"),
# harmonised.pix.assign(stage="harmonised"),
# infilled.pix.assign(stage="infilled"),
# ]
# )
# .loc[pix.ismatch(variable=["**CO2|Fossil", "**CH4", "**N2O", "**SOx"])]
# .melt(ignore_index=False, var_name="year")
# .reset_index()
# )
pdf = (
pix.concat(
[
res_pre_processed.global_workflow_emissions.loc[:, 2023:].pix.assign(
stage="pre_processed"
),
harmonised_global.pix.assign(stage="harmonised"),
infilled.pix.assign(stage="infilled"),
]
)
.loc[
pix.ismatch(
variable=["**CO2|Energy and Industrial Processes", "**CH4", "**N2O", "**CO"]
)
]
.melt(ignore_index=False, var_name="year")
.reset_index()
)

# fg = relplot_in_emms(
# data=pdf,
# hue="scenario",
# style="stage",
# dashes={
# "pre_processed": (3, 3),
# "harmonised": "",
# "infilled": (1, 1),
# },
# )
fg = relplot_in_emms(
data=pdf,
hue="scenario",
style="stage",
dashes={
"pre_processed": (3, 3),
"harmonised": "",
"infilled": (1, 1),
},
)

# fg.axes.flatten()[0].axhline(0.0, linestyle="--", color="gray")
# fg.axes.flatten()[1].set_ylim(ymin=0.0)
fg.axes.flatten()[0].axhline(0.0, linestyle="--", color="gray")
fg.axes.flatten()[1].set_ylim(ymin=0.0)

# %% [markdown]
# ## SCM Running
Expand Down
4 changes: 4 additions & 0 deletions src/gcages/cmip7_scenariomip/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
from gcages.cmip7_scenariomip.harmonisation import (
create_cmip7_scenariomip_global_harmoniser,
)
from gcages.cmip7_scenariomip.infilling import (
CMIP7ScenarioMIPInfiller,
)
from gcages.cmip7_scenariomip.pre_processing import (
CMIP7ScenarioMIPPreProcessingResult,
CMIP7ScenarioMIPPreProcessor,
Expand All @@ -15,6 +18,7 @@
)

__all__ = [
"CMIP7ScenarioMIPInfiller",
"CMIP7ScenarioMIPPreProcessingResult",
"CMIP7ScenarioMIPPreProcessor",
"ReaggregatorBasic",
Expand Down
11 changes: 9 additions & 2 deletions src/gcages/cmip7_scenariomip/harmonisation.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ def load_cmip7_scenariomip_historical_emissions(
index_columns=["model", "scenario", "region", "variable", "unit"],
out_columns_type=int,
)
res.columns.name = "year"

return res

Expand All @@ -83,7 +84,13 @@ def load_aneris_overrides_file(filepath: Path) -> pd.Series[str]:
Aneris overrides
"""
raw = pd.read_csv(filepath)
res = raw.set_index(list(raw.columns.difference(["method"])))["method"]

# TODO: better function for validating our overrides will work with the data
if "method" not in raw.columns:
msg = "'method' column is required in the overrides CSV"
raise KeyError(msg)

res = raw.set_index(list(raw.columns.difference(["method"])))["method"].astype(str)

return res

Expand All @@ -96,7 +103,7 @@ def create_cmip7_scenariomip_global_harmoniser(
n_processes: int | None = multiprocessing.cpu_count(),
) -> AnerisHarmoniser:
"""
Create an a harmoniser configured for CMIP7 ScenarioMIP's global workflow.
Create an Aneris harmoniser configured for CMIP7 ScenarioMIP global emissions.

Parameters
----------
Expand Down
Loading
Loading