|
5 | 5 |
|
6 | 6 | import pandas as pd |
7 | 7 |
|
| 8 | +from message_ix_models.model.material.data_power_sector import gen_data_power_sector |
| 9 | +from message_ix_models.util import add_par_data |
| 10 | + |
8 | 11 | if TYPE_CHECKING: |
9 | 12 | from message_ix import Scenario |
10 | 13 |
|
@@ -236,3 +239,49 @@ def subtract_material_demand( |
236 | 239 | raise ValueError(f"Unknown method: {method}") |
237 | 240 |
|
238 | 241 | return mat_demand |
| 242 | + |
| 243 | + |
| 244 | +def build_PM(context, scenario: "Scenario", **kwargs) -> "Scenario": |
| 245 | + """Build the material intensity for power capacities. |
| 246 | +
|
| 247 | + This function adds power sector material intensity parameters (input_cap_new, |
| 248 | + input_cap_ret, output_cap_new, output_cap_ret) to the scenario if they do not |
| 249 | + already exist. |
| 250 | +
|
| 251 | + Parameters |
| 252 | + ---------- |
| 253 | + context |
| 254 | + The context of the scenario to be add intensity data to. |
| 255 | + scenario : message_ix.Scenario |
| 256 | + The scenario to add material-power sector linkages to. |
| 257 | + **kwargs |
| 258 | + Additional keyword arguments (ignored, for workflow compatibility). |
| 259 | + """ |
| 260 | + # Check if power sector material data already exists |
| 261 | + if scenario.has_par("input_cap_new"): |
| 262 | + try: |
| 263 | + existing_data = scenario.par("input_cap_new") |
| 264 | + if ( |
| 265 | + not existing_data.empty |
| 266 | + and "cement" in existing_data.get("commodity", pd.Series()).values |
| 267 | + ): |
| 268 | + log.info( |
| 269 | + "Power sector material intensity data already exists " |
| 270 | + "(found cement in input_cap_new). Skipping build_pm." |
| 271 | + ) |
| 272 | + return scenario |
| 273 | + except Exception as e: |
| 274 | + log.warning(f"Could not check existing input_cap_new data: {e}") |
| 275 | + |
| 276 | + log.info("Adding material intensity for power capacities...") |
| 277 | + scenario.check_out() |
| 278 | + try: |
| 279 | + power_data = gen_data_power_sector(scenario, dry_run=False) |
| 280 | + add_par_data(scenario, power_data, dry_run=False) |
| 281 | + # but actually do not know how to provide log info while adding those parameters |
| 282 | + log.info("Successfully added power sector material intensity data.") |
| 283 | + except Exception as e: |
| 284 | + log.error(f"Error adding power sector material data: {e}") |
| 285 | + raise |
| 286 | + |
| 287 | + return scenario |
0 commit comments