This is the main repository of notebooks which demonstrate the usage of dam-emission
This notebook demonstrates how to:
Read input data and output configuration YAML file and instantiate the emission model
Add LaTeX model presenter, calculate emissions and save results to TEX and PDF files
Open the generated PDF document
Import the required libraries and RE-Emission classes
[1]:
import os
import pathlib
import gdown
import webbrowser
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, 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:
print(f"File: {pdf_file} does not exist.")
File: outputs/output.pdf does not exist.