Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions message_ix_models/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ def _log_threads(k: int, n: int):
"message_ix_models.testing.cli",
"message_ix_models.util.pooch",
"message_ix_models.util.slurm",
"message_ix_models.model.bmt.cli",
]

try:
Expand Down
4 changes: 2 additions & 2 deletions message_ix_models/data/buildings/set.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,13 @@ relation:
# Relations for which data should be adapted
require:
- BCA_Emission
- CH4_Emission
# - CH4_Emission
- CO2_r_c
- CO_Emission
- HFC_Emission
- HFC_foam_red
- HFC_rescom_red
- N2O_Emission
#- N2O_Emission
- NH3_Emission
- NOx_Emission
- OCA_Emission
Expand Down
8 changes: 8 additions & 0 deletions message_ix_models/data/technology.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2896,6 +2896,14 @@ sp_el_RC:
input: [electr, final]
output: [rc_spec, useful]

sp_el_RC_RT:
name: sp_el_RC
description: Specific use of electricity in residential/commercial from rooftop PV
type: useful
sector: residential/commercial
input: [electr, final]
output: [rc_spec, useful]

h2_fc_RC:
name: h2_fc_RC
description: Specific use of hydrogen fuel cell cogeneration system in res/comm
Expand Down
5 changes: 5 additions & 0 deletions message_ix_models/model/bmt/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
"""BMT runs."""

from .utils import build_PM, subtract_material_demand

__all__ = ["build_PM", "subtract_material_demand"]
75 changes: 75 additions & 0 deletions message_ix_models/model/bmt/cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
"""Command-line tools specific to MESSAGEix-BMT runs."""

import logging
import re

import click

from message_ix_models.util.click import common_params

log = logging.getLogger(__name__)

# Define a command-line option for BMT-run scenarios
_SCENARIO = click.Option(
["--scenario", "bmt_scenario"],
default="baseline",
help="The scenario ID of the specific step in the bmt workflow.",
)


# Define a Click command group for BMT-related commands
@click.group("bmt", params=[_SCENARIO])
@click.pass_obj
def cli(context, bmt_scenario):
"""MESSAGEix-BMT runs."""
# Store the scenario in the context for use in commands
context.bmt = bmt_scenario
pass


# Define run command
@cli.command("run")
@common_params("dry_run")
@click.option("--from", "truncate_step", help="Run workflow from this step.")
@click.argument("target_step", metavar="TARGET")
@click.pass_obj
def run(context, truncate_step, target_step):
"""Run the BMT workflow up to step TARGET.

--from is interpreted as a regular expression, and the workflow is truncated at
every point matching this expression.
"""
from . import workflow

wf = workflow.generate(context)

# Compile the regular expression for truncating the workflow
try:
expr = re.compile(truncate_step.replace("\\", ""))
except AttributeError:
pass # truncate_step is None
else:
# Truncate the workflow at steps matching the expression
for step in filter(expr.fullmatch, wf.keys()):
log.info(f"Truncate workflow at {step!r}")
wf.truncate(step)

# Compile the regular expression for the target step
target_expr = re.compile(target_step)
target_steps = sorted(filter(lambda k: target_expr.fullmatch(k), wf.keys()))
if len(target_steps) > 1:
# If multiple target steps match, create a composite target
target_step = "cli-targets"
wf.add(target_step, target_steps)

log.info(f"Execute workflow:\n{wf.describe(target_step)}")

# If dry_run is enabled, visualize the workflow instead of executing it
if context.dry_run:
path = context.get_local_path("bmt-workflow.svg")
wf.visualize(str(path))
log.info(f"Workflow diagram written to {path}")
return

# Run the workflow up to the specified target step
wf.run(target_step)
Loading
Loading