Automatic calculation of emissions for batches of reservoirs

Input data is defined in JSON file whilst outputs data configuration is specified in YAML config file.

This notebook demonstrates how to:

  1. Read input data in JSON format and output configuration YAML file

  2. Instantiate the emission model object from input data output configuration file

  3. Calculate emissions

  4. Display model ouptputs

Import the required libraries and RE-Emission classes

[1]:
from os.path import exists
import pathlib
import gdown
import pprint
# Import reemission
try:
    import reemission
except ImportError:
    %pip install git+https://github.com/tomjanus/reemission.git --quiet
# Import package file loader
from reemission.utils import get_package_file
# Import from the model module
from reemission.model import EmissionModel
# Import from the input module
from reemission.input import Inputs
# Import from the presenter module
from reemission.presenter import LatexWriter, JSONWriter

1. Read input data and output configuration YAML file

[2]:
if not exists(pathlib.Path('./inputs.json')):
    # Download the required input file from an external link
    !gdown 1T9Pal8h9Ce6phw1qdPM5AkuZM_hnvBGT
input_data = Inputs.fromfile('inputs.json')
output_config = get_package_file('config', 'outputs.yaml').as_posix()

2. Instantiate the emission model object from input data output configuration file

[3]:
model = EmissionModel(inputs=input_data, presenter_config=output_config, p_model='g-res')

3. Calculate emissions

[4]:
model.calculate()

4. Display outputs dictionary

[5]:
pprint.pprint(model.outputs)
{'Reservoir 1': {'ch4_degassing': 4247.529844440521,
                 'ch4_diffusion': 229.50728895021928,
                 'ch4_ebullition': 321.2319562880549,
                 'ch4_net': 4798.269089678795,
                 'ch4_preimp': 0.0,
                 'ch4_profile': [15037.538803908017,
                                 13234.917873312756,
                                 11288.903866240284,
                                 8232.44194734772,
                                 6027.752360164751,
                                 4437.463880888554,
                                 3290.355706291948,
                                 2140.182925317766,
                                 1435.5616063934115,
                                 901.0218112214025],
                 'ch4_total_lifetime': 769.6423619844787,
                 'ch4_total_per_year': 7696.423619844788,
                 'co2_diffusion': 572.7646642529623,
                 'co2_diffusion_nonanthro': 393.12744599578104,
                 'co2_minus_nonanthro': 179.6372182571813,
                 'co2_net': 311.6372182571813,
                 'co2_preimp': -132.00000000000003,
                 'co2_profile': [1535.8116797855287,
                                 795.3817060605891,
                                 579.3641298860341,
                                 407.51426690686856,
                                 323.7748832811502,
                                 270.8014311786585,
                                 233.03901151252305,
                                 192.05382930950483,
                                 162.0413825592751,
                                 132.00000000000003],
                 'co2_total_lifetime': 49.98660980845189,
                 'co2_total_per_year': 499.86609808451885,
                 'n2o_mean': 0.04569849137014073,
                 'n2o_methodA': 0.043280912406044016,
                 'n2o_methodB': 0.048116070334237454,
                 'n2o_profile': [0.043280912406044016,
                                 0.043280912406044016,
                                 0.043280912406044016,
                                 0.043280912406044016,
                                 0.043280912406044016,
                                 0.043280912406044016,
                                 0.043280912406044016,
                                 0.043280912406044016,
                                 0.043280912406044016,
                                 0.043280912406044016],
                 'n2o_total_lifetime': 0.00694225834992946,
                 'n2o_total_per_year': 0.0694225834992946},
 'Reservoir 2': {'ch4_degassing': 827.4542257275465,
                 'ch4_diffusion': 136.10915204619948,
                 'ch4_ebullition': 90.94433704616341,
                 'ch4_net': 1054.5077148199093,
                 'ch4_preimp': 0.0,
                 'ch4_profile': [3258.2891678085275,
                                 2870.3097742242635,
                                 2451.4689517569577,
                                 1793.6292798288143,
                                 1319.1187852130984,
                                 976.8466188494463,
                                 729.9601173612991,
                                 482.4159071534167,
                                 330.7662555693782,
                                 215.72302098425348],
                 'ch4_total_lifetime': 1832.5235068140385,
                 'ch4_total_per_year': 18325.235068140384,
                 'co2_diffusion': 796.9654854957547,
                 'co2_diffusion_nonanthro': 547.0117579064897,
                 'co2_minus_nonanthro': 249.953727589265,
                 'co2_net': 378.8003942559317,
                 'co2_preimp': -128.8466666666667,
                 'co2_profile': [2082.161049955455,
                                 1051.8999840865445,
                                 751.3253096762252,
                                 512.2071900900598,
                                 395.68918070233053,
                                 321.98000203239394,
                                 269.43600446933124,
                                 212.40773846209936,
                                 170.6473337304127,
                                 128.8466666666667],
                 'co2_total_lifetime': 658.279325137958,
                 'co2_total_per_year': 6582.79325137958,
                 'n2o_mean': 0.3184910807620064,
                 'n2o_methodA': 0.35553527541406443,
                 'n2o_methodB': 0.2814468861099484,
                 'n2o_profile': [0.35553527541406443,
                                 0.35553527541406443,
                                 0.35553527541406443,
                                 0.35553527541406443,
                                 0.35553527541406443,
                                 0.35553527541406443,
                                 0.35553527541406443,
                                 0.35553527541406443,
                                 0.35553527541406443,
                                 0.35553527541406443],
                 'n2o_total_lifetime': 0.6178492016145611,
                 'n2o_total_per_year': 6.178492016145611},
 'Reservoir 3': {'ch4_degassing': 847.6508199549853,
                 'ch4_diffusion': 238.65463850593412,
                 'ch4_ebullition': 210.60761679419937,
                 'ch4_net': 1296.9130752551187,
                 'ch4_preimp': 0.0,
                 'ch4_profile': [3781.469556760416,
                                 3344.0551177505276,
                                 2871.8481344638835,
                                 2130.1934484630237,
                                 1595.228714997142,
                                 1209.352010260699,
                                 931.0143515978866,
                                 651.9370369875498,
                                 480.97107687442974,
                                 351.2754567775871],
                 'ch4_total_lifetime': 5731.577644782472,
                 'ch4_total_per_year': 57315.77644782472,
                 'co2_diffusion': 1001.8691408378094,
                 'co2_diffusion_nonanthro': 687.6511089825283,
                 'co2_minus_nonanthro': 314.2180318552811,
                 'co2_net': 701.7846985219478,
                 'co2_preimp': -387.5666666666667,
                 'co2_profile': [2843.0875625989893,
                                 1547.941426805347,
                                 1170.087559492952,
                                 869.4910225180519,
                                 723.0156731059005,
                                 630.3555104641342,
                                 564.302198679944,
                                 492.6116914899196,
                                 440.11448606382885,
                                 387.5666666666667],
                 'co2_total_lifetime': 3101.4672966478965,
                 'co2_total_per_year': 31014.672966478964,
                 'n2o_mean': 2.929791544898492,
                 'n2o_methodA': 3.6100903829982802,
                 'n2o_methodB': 2.2494927067987036,
                 'n2o_profile': [3.6100903829982802,
                                 3.6100903829982802,
                                 3.6100903829982802,
                                 3.6100903829982802,
                                 3.6100903829982802,
                                 3.6100903829982802,
                                 3.6100903829982802,
                                 3.6100903829982802,
                                 3.6100903829982802,
                                 3.6100903829982802],
                 'n2o_total_lifetime': 15.954433438622601,
                 'n2o_total_per_year': 159.544334386226},
 'Reservoir 4': {'ch4_degassing': 485.87517473985247,
                 'ch4_diffusion': 114.55798902807442,
                 'ch4_ebullition': 35.770362020378734,
                 'ch4_net': 636.2035257883056,
                 'ch4_preimp': 0.0,
                 'ch4_profile': [2009.4812892531536,
                                 1767.7120096789718,
                                 1506.711836827945,
                                 1096.7808317473907,
                                 801.0919176227009,
                                 587.807406529236,
                                 433.9623330994227,
                                 279.70805642717863,
                                 185.20983637711493,
                                 113.5227771377119],
                 'ch4_total_lifetime': 16810.087660141504,
                 'ch4_total_per_year': 168100.87660141505,
                 'co2_diffusion': 556.5994481893181,
                 'co2_diffusion_nonanthro': 382.0321559024945,
                 'co2_minus_nonanthro': 174.5672922868236,
                 'co2_net': 347.15729228682363,
                 'co2_preimp': -172.59000000000003,
                 'co2_profile': [1536.7817092588934,
                                 817.248992736217,
                                 607.3281103878444,
                                 440.3283897776909,
                                 358.95239431788053,
                                 307.47401925543494,
                                 270.77737356434943,
                                 230.94892180765413,
                                 201.78352047868628,
                                 172.59000000000003],
                 'co2_total_lifetime': 9172.763555448599,
                 'co2_total_per_year': 91727.63555448598,
                 'n2o_mean': 0.0035568256933053745,
                 'n2o_methodA': 0.003956510851593258,
                 'n2o_methodB': 0.0031571405350174914,
                 'n2o_profile': [0.003956510851593258,
                                 0.003956510851593258,
                                 0.003956510851593258,
                                 0.003956510851593258,
                                 0.003956510851593258,
                                 0.003956510851593258,
                                 0.003956510851593258,
                                 0.003956510851593258,
                                 0.003956510851593258,
                                 0.003956510851593258],
                 'n2o_total_lifetime': 0.10454090797622287,
                 'n2o_total_per_year': 1.0454090797622286}}

Open in Colab