Skip to content
ReEmission 1.0.0 documentation
⌘ K
ReEmission 1.0.0 documentation

Contents:

  • About the Library
  • Theoretical Background
  • Configuration
  • Installation
    • Installing RE-Emission
    • About Docker
    • Building the ReEmission Docker Image
    • Using the ReEmission Docker Image
  • Usage
  • Running the ReEmission Docker Container
  • Tutorials
  • Demo
  • JSON file format description
  • Configuration
  • Reporting Calculation Outputs
  • Visualisation
  • Integration with GeoCARET
  • Python API reference
    • Model (Main)
    • Input Model
    • Reservoir Model
    • Catchment Model
    • Post-impoundment catchment
    • Emissions
    • Emission Profile Calculator
    • MonthlyTemperature
    • Biogenic Factors
    • Presenter
    • Utility functions
    • Auxiliary functions
    • Constants
    • Mixins
    • Document \(\LaTeX\) Compiler
    • Custom Exceptions
    • App Logger
    • External Data Downloader
    • Global variables
    • Main
    • SALib Integration
    • Postprocessing
  • License
ReEmission 1.0.0 documentation
/
Import the required libraries and RE-Emission classes

b5209d3f4ff94cb7b8bcb3a5c69211dd

This is the main repository of notebooks which demonstrate the usage of dam-emission

This notebook demonstrates how to:

  1. Read input data and output configuration YAML file and instantiate the emission model

  2. Add LaTeX model presenter, calculate emissions and save results to TEX and PDF files

  3. Open the generated PDF document

< Saving Results To JSON | Contents | Modifying configuration parameters >

Open in Colab

Import the required libraries and RE-Emission classes

[1]:
import os
import pathlib
import gdown
import webbrowser
from rich import print as rprint
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

1. Read input data and output configuration YAML file and instantiate the emission model

[2]:
if not os.path.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()
model = EmissionModel(inputs=input_data, presenter_config=output_config, author="Guest")

2. Add LaTeX model presenter, calculate emissions and save results to TEX and PDF files

[3]:
# Recent changes force the input data to contain a unique reservoir 'id' field
# We are dynamically adding ids so that the input data conforms to the schema.
for index, (res_name, res_inputs) in enumerate(input_data.inputs.items()):
    res_inputs.data['id'] = index
[4]:
os.makedirs('outputs', exist_ok=True)
model.add_presenter(
    writers=[LatexWriter],
    output_files=[pathlib.Path('outputs/output.tex')])
model.calculate()
model.save_results()
ERROR:reemission.presenter:LaTeX compiler cannot be found in your environment.'.tex' and '.pdf' files could not be created.

3. Open the generated PDF document

[5]:
# os.getcwd(),
pdf_file = pathlib.Path('outputs/output.pdf').as_posix()
if os.path.exists(pdf_file):
    webbrowser.open_new(pdf_file)
else:
    rprint(f"File: {pdf_file} does not exist.")
File: outputs/output.pdf does not exist.

Open in Colab

On this page

  • 1. Read input data and output configuration YAML file and instantiate the emission model
  • 2. Add LaTeX model presenter, calculate emissions and save results to TEX and PDF files
  • 3. Open the generated PDF document

© 2024, Tomasz Janus, University of Manchester, United Kingdom Built with Sphinx 8.1.3