Skip to content

Commit 67e61e5

Browse files
Create documentation tools-bilateralize
This removes the NEWPATHWAYS project version of documentation (same content)
1 parent 3282202 commit 67e61e5

File tree

1 file changed

+35
-41
lines changed

1 file changed

+35
-41
lines changed
Lines changed: 35 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,39 @@
1-
NEWPATHWAYS-TRADE
2-
#################
3-
4-
- Project lead: :gh-user:`volker-krey`
5-
- Lead modeler: :gh-user:`shepard`
6-
7-
8-
Introduction
9-
************
10-
NEWPATHWAYS-TRADE covers Task 3.5 (Resilience of the Energy System Transformation Towards the Paris Goal) in Work Product 3 (Sector Transitions Including Land and Energy) in the 2024-2027 NEWPATHWAYS project. This task includes the bilateralization of trade networks in MESSAGEix.
11-
1+
.. currentmodule:: mesage_ix_models.tools.bilateralize
2+
Bilateralize (:mod:`.tools.bilateralize`)
3+
#########################################
4+
5+
.. contents::
6+
:local:
7+
8+
Overview
9+
========
1210
This documentation will outline how to bilateralize trade flows in MESSAGEix. By default, trade flows are based on a “global pool” approach, wherein all exporters export energy/commodities to a pool from which importers import based on regionally resolved demands.
1311

1412
By “bilateralizing” trade, we specify exporter and importer flows and can therefore represent trade flows as networks.
1513

1614
The bilateralization tool, **bilateralize**, is generalized for any traded commodity, whether that is a fuel (e.g., LNG), or a material (e.g., steel). It also explicitly represents bilateral trade “flows”, or how a fuel/commodity is transported from exporter to importer. These flow technologies are user defined and flexible; the most common are pipelines (e.g., gas pipelines), maritime shipping (e.g., LNG tanker), and transmission lines.
1715

18-
Tool
19-
****
2016
The ``bilateralize`` tool is a Python script that can be used to bilateralize trade flows in MESSAGEix. It is located in the ``message-ix-models/tools/bilateralize`` directory.
2117

2218
The tool follows the following steps, which are also available in ``tool/bilateralize/workflow.py``:
2319

24-
1. Edit (``tools/bilateralize/prepare_edit.py``)
25-
=======
26-
The first step is to generate empty (or default valued) parameters that are required for bilateralization, specified by commodity. This step requires updates to a configuration file (``config.yaml``) that should be housed in a project directory (e.g., ``message-ix-models/projects/newpathways-trade/config.yaml``). A template configuration file is provided at ``message-ix-models/data/bilateralize/configs/base_config.yaml``. Once the configuration is updated, the user can run ``message_ix_models.tools.bilateralize.bilateralize.generate_bare_sheets(log, message_regions)`` to produce empty (or default valued) parameters as CSV files. These CSV files will populate in ``message-ix-models/data/[your_trade_commodity]/edit_files``.
20+
Step 1 | Edit (``tools/bilateralize/prepare_edit.py``)
21+
=============
22+
The first step is to generate empty (or default valued) parameters that are required for bilateralization, specified by commodity. This step requires updates to a configuration file (``config.yaml``) that should be housed in a project directory (e.g., ``message-ix-models/projects/newpathways-trade/config.yaml``). A template configuration file is provided at ``message-ix-models/data/bilateralize/configs/base_config.yaml``.
23+
24+
Once the configuration is updated, the user can run ``message_ix_models.tools.bilateralize.prepare_edit.generate_edit_files(log, project_name, config_name, message_regions)`` to produce empty (or default valued) parameters as CSV files. These CSV files will populate in ``message-ix-models/data/[your_trade_commodity]/edit_files``.
2725

2826
The tools may stop if the user specifies in their config that they want to specify a trade network (i.e., specify which regions can trade with regions). In this case, a file called ``specify_trade_network.csv`` will appear in ``message-ix-models/data/bilateralize/[your_trade_commodity]/speciy_network_[your_trade_commodity].csv``.
2927

30-
Additional functions here include:
31-
- ``message_ix_models.tools.bilateralize.bilateralize.import_gem(input_file, input_sheet, trade_technology, flow_technology, project_name, config_name)``: This function pulls in pre-downloaded raw data from the Global Energy Monitor in oil and gas infrastructure and can be used to calibrate the flow technology for moving oil and gas via pipeline.
32-
- ``message_ix_models.tools.bilateralize.bilateralize.calibrate_mariteam(covered_tec, message_regions)``: This function pulls in MariTEAM output to calibrate maritime shipping (flow technologies).
28+
Additional functions used here include:
29+
- ``message_ix_models.tools.bilateralize.calculate_distance(message_regions)``: Calculates the great-circle distance between regions (TODO: update this to use explicit maritime routes)
30+
- ``message_ix_models.tools.bilateralize.historical_calibration.build_historical_price(message_regions)``: Builds historical price dataframes
31+
- ``message_ix_models.tools.bilateralize.mariteam_calibration.calibrate_mariteam(covered_tec, message_regions)``: Calibrates maritime shipping (flow technologies) using MariTEAM output.
32+
- ``message_ix_models.tools.bilateralize.pull_gem.import_gem(input_file, input_sheet, trade_technology, flow_technology, project_name, config_name)``: Imports pre-downloaded raw data from the Global Energy Monitor which is used to calibrate the flow technology piped oil and gas
3333

34-
**This step is not necessary for the following commodities (they are already defined):**
34+
**This step is not necessary for the following commodities (they are already defined in ``scenario_parameters.pkl`` in ``message-ix-models/data/bilateralize/configs/``):**
3535
- Biomass (``biomass_shipped``)
36-
- Coal (``coal_shipped``
36+
- Coal (``coal_shipped``)
3737
- Crude Oil (``crude_shipped`` and ``crude_piped``): Note that the global pool version of MESSAGEix names this ``oil_exp`` and ``oil_imp`` and combines shipped and piped trade.
3838
- Ethanol (``eth_shipped``)
3939
- Fuel Oil (``foil_shipped`` and ``foil_piped``): Note that this uses the same oil pipeline infrastructure as crude oil and light oil.
@@ -43,8 +43,8 @@ Additional functions here include:
4343
- Methanol (``meth_shipped``)
4444
- Piped gas (``gas_piped``)
4545

46-
2. Bare (``tools/bilateralize/bare_to_scenario``)
47-
=======
46+
Step 2 | Bare (``tools/bilateralize/bare_to_scenario``)
47+
==============
4848
The second step is to review, edit, and transfer the files in ``message-ix-models/data/bilateralize/[your_trade_commodity]/edit_files/``.
4949

5050
The user should then review all files in ``message-ix-models/data/bilateralize/[your_trade_commodity]/edit_files/`` and transfer these files to ``message-ix-models/data/bilateralize/[your_trade_commodity]/bare_files/``.
@@ -66,24 +66,24 @@ By default, the following parameters are transfered automatically with default v
6666
The user can call ``message_ix_models.tools.bilateralize.bilateralize.build_parameter_sheets(log)`` to pull parameters from ``message-ix-models/data/bilateralize/[your_trade_commodity]/bare_files/`` into a dictionary of parameter dataframes that will be used to build a scenario. Note that this function pulls from ``bare_files`` and not ``edit_files``, so the user should ensure that the right files are transferred in the previous step.
6767

6868
Additional functions here include:
69-
- ``message_ix_models.tools.bilateralize.bilateralize.build_historical_activity(message_regions)``: This function pulls raw IEA World Energy Balances/Natural Gas Flow data to build historical activity in the regionality specified.
69+
- ``message_ix_models.tools.bilateralize.historical_calibration.build_hist_new_capacity_flow(message_regions)``: Builds new capacity dataframes for historical activity of flow technologies (e.g., pipelines)
70+
- ``message_ix_models.tools.bilateralize.historical_calibration.build_hist_new_capacity_trade(message_regions)``: Builds new capacity dataframes for historical activity of trade technologies (e.g., piped gas)
71+
- ``message_ix_models.tools.bilateralize.historical_calibration.build_historical_activity(message_regions)``: Builds historical activity dataframes
7072

71-
3. Build (``tools/bilateralize/load_and_solve.py``)
72-
========
73+
Step 3 | Build (``tools/bilateralize/load_and_solve.py``)
74+
===============
7375
This step builds a scenario.
7476

75-
The user should use the function ``message_ix_models.tools.bilateralize.bilateralize.clone_and_update(trade_dict, log, to_gdx, solve)``. This will pull the base model/scenario, clone it, remove specified trade technologies, add them back as bilateralized versions, and export to a GDX file (if specifed- the default is to not export) and/or solve the scenario (default is to solve). Note that exporting to GDX means that it is not stored in the ixmp database.
76-
77-
4. Solve
78-
========
79-
Solve can be completed using the ``message_ix_models.tools.bilateralize.bilateralize.clone_and_update(trade_dict, log, to_gdx, solve)`` function above. By default scenario will be run.
77+
The user should use the function ``message_ix_models.tools.bilateralize.load_and_solve.load_and_solve(project_name, config_name, scenario_parameter_name, p_drive_access)``.
78+
This will pull the base model/scenario, clone it, remove specified trade technologies, add them back as bilateralized versions, and export to a GDX file (if specifed- the default is to not export) and/or solve the scenario (default is to solve). Note that exporting to GDX means that it is not stored in the ixmp database.
79+
This will also optionally solve the scenario.
8080

81-
5. Report
81+
Reporting
8282
=========
8383
This code is in progress.
8484

8585
To add a new commodity
86-
***********************
86+
======================
8787
To add a new commodity:
8888

8989
- Create a new configuration file for the commodity in ``data/bilateralize/configs/`` (see examples from existing configurations or use ``template.yaml``)
@@ -92,12 +92,6 @@ To add a new commodity:
9292

9393
- Run the workflow from ``prepare_edit``, then ``bare_to_scenario``, then ``load_and_solve``
9494

95-
Scenario Identifier
96-
*******************
97-
- Model: ``NP-SSP2`` (We are basing this framework on SSP2 by default)
98-
- Scenario (default bilateralization): ``default_bilat``
99-
100-
10195
Data
102-
****
103-
All raw data required are currently stored in ``P:/ene_model/MESSAGE_trade``.
96+
====
97+
All raw data required for a MESSAGEix-GLOBIOM update are currently stored in ``P:/ene_model/MESSAGE_trade``.

0 commit comments

Comments
 (0)