FBMCΒΆ

This notebook

[1]:
import os
import numpy as np
from pyltmapi import LtmSession, LtmPlot, LtmTable

import logging
logging.basicConfig(level=logging.ERROR)

from pathlib import Path

ltm_core_path =  os.environ.get("LTM_CORE_PATH", str(Path("~").expanduser().joinpath("ltm/release/bin/")))
license_file = os.environ.get("LTM_CORE_LICENSE_FILE", str(Path("~").expanduser().joinpath("ltm/ltm-license.dat")))
[2]:
from IPython.display import HTML, display, display_markdown

ltmapi_version = LtmSession.version()
display(f"pyltm version {ltmapi_version}")
'pyltm version PyLTM version: 0.21.0'
[3]:
def usercallback(program_info: dict, userdata: any):

    print(userdata)
    print(program_info)

    return True


def generate_plots(ltm):

    for dc_line in ltm.model.dclines():
        if(dc_line.have_transmission_results()):
            LtmPlot.make_generic_plot(dc_line.transmission_results(),name="Exchange " + '"'+dc_line.name+'"')

    LtmTable.make_table_cnes(ltm)
    for cne in ltm.model.cnes():
        LtmPlot.make_generic_plot(cne.get_dual_values(),name="Dual values " + '"'+cne.name+'"')
        LtmPlot.make_generic_plot(cne.get_flow_values(),name="Flow values " + '"'+cne.name+'"')


    for busbar in ltm.model.busbars():
        print(busbar)

        time, busbar_prices = busbar.market_result_price()
        LtmPlot.plot_price_series(time, busbar_prices, busbar.name)

        if(busbar.have_aggregated_hydro_results()):
            time, aggregated_hydro_production = busbar.sum_hydro_production()
            LtmPlot.generic_plot(time, aggregated_hydro_production,name="Area Production " + '"'+busbar.name+'"')

            time, aggregated_energy = busbar.sum_reservoir()
            LtmPlot.generic_plot(time, aggregated_energy, name=f'Aggregated energy "{busbar.name}"')

        # Water values
        if (busbar.have_water_value_results()):
            LtmPlot.make_water_value_plot(busbar.water_value_results(), busbar.name)

        if(busbar.have_battery_results()):
            time, battery_production = busbar.sum_hydro_production()
            LtmPlot.generic_plot(time, battery_production, name=f'Battery (dis)charge "{busbar.name}"')

            time, battery_energy = busbar.sum_reservoir()
            LtmPlot.generic_plot(time, battery_energy, name="Battery stored energy "  + '"'+busbar.name+'"')

            time, water_values = busbar.water_value_results()
            water_values_np = np.array(water_values, copy=False)
            wv_for_plotting = water_values_np[:, 0, 0, :]
            max_reservoir_level = 100
            filling = np.linspace(max_reservoir_level, 0, wv_for_plotting.shape[1])
            week = np.arange(wv_for_plotting.shape[0])

            X, Y = np.meshgrid(filling, week)
            LtmPlot.plot_water_values(time, X, Y, wv_for_plotting, name=busbar.name)

        # Busbar reservoirs
        if(busbar.have_detailed_hydro_results()):
            for rsv in busbar.reservoirs():
                display("Reservoir")
                LtmPlot.make_generic_plot(rsv.reservoir(), f"Reservoir '{rsv.name}'")
                LtmPlot.make_generic_plot(rsv.discharge(), f"Discharge '{rsv.name}'")
                LtmPlot.make_generic_plot(rsv.inflow(), f"Inflow '{rsv.name}'")
                LtmPlot.make_generic_plot(rsv.production(), f"Production '{rsv.name}'")


[4]:

from pyltmapi import LtmDot def open_and_write_model(filename: str): session = LtmSession("ikernel", ltm_core_path=ltm_core_path) # Explicitly set license file session.model.global_settings.ltm_license_file_path = license_file with session: try: # Load model from file. session.load(filename=filename) # Write model to disk, and automatically generate an output directory. session.write_model() LtmDot.display_dot_image(session.build_busbar_graph()) # Execute/run LTM/EMPS on the model last_rc, results = session.execute_model() #print(f"python pid: {os.getpid()}") # for debugging # If last return code is not 0, then there was an error. if last_rc != 0: err = results[0]["log_file_contents"] display_markdown(err) else: # Make plots from the results generate_plots(session) except Exception as e: print(e) raise(e)

[5]:
open_and_write_model("fbmc_with_cnes.json") # json-file model containts cnes
# open_and_write_model("fbmc_cnes_from_jao.json") # cnes are read from separate file
../../../_images/ltm-api_guides_fbmc_fbmc-notebook_5_0.svg
../../../_images/ltm-api_guides_fbmc_fbmc-notebook_5_1.png
../../../_images/ltm-api_guides_fbmc_fbmc-notebook_5_2.png
../../../_images/ltm-api_guides_fbmc_fbmc-notebook_5_3.png
../../../_images/ltm-api_guides_fbmc_fbmc-notebook_5_4.png
../../../_images/ltm-api_guides_fbmc_fbmc-notebook_5_5.png
../../../_images/ltm-api_guides_fbmc_fbmc-notebook_5_6.png
../../../_images/ltm-api_guides_fbmc_fbmc-notebook_5_7.png
../../../_images/ltm-api_guides_fbmc_fbmc-notebook_5_8.png
../../../_images/ltm-api_guides_fbmc_fbmc-notebook_5_9.png
../../../_images/ltm-api_guides_fbmc_fbmc-notebook_5_10.png
../../../_images/ltm-api_guides_fbmc_fbmc-notebook_5_11.png
../../../_images/ltm-api_guides_fbmc_fbmc-notebook_5_12.png
../../../_images/ltm-api_guides_fbmc_fbmc-notebook_5_13.png
../../../_images/ltm-api_guides_fbmc_fbmc-notebook_5_14.png
busbar/numedal
../../../_images/ltm-api_guides_fbmc_fbmc-notebook_5_16.png
../../../_images/ltm-api_guides_fbmc_fbmc-notebook_5_17.png
../../../_images/ltm-api_guides_fbmc_fbmc-notebook_5_18.png
../../../_images/ltm-api_guides_fbmc_fbmc-notebook_5_19.png
'Reservoir'
../../../_images/ltm-api_guides_fbmc_fbmc-notebook_5_21.png
../../../_images/ltm-api_guides_fbmc_fbmc-notebook_5_22.png
../../../_images/ltm-api_guides_fbmc_fbmc-notebook_5_23.png
../../../_images/ltm-api_guides_fbmc_fbmc-notebook_5_24.png
'Reservoir'
../../../_images/ltm-api_guides_fbmc_fbmc-notebook_5_26.png
../../../_images/ltm-api_guides_fbmc_fbmc-notebook_5_27.png
../../../_images/ltm-api_guides_fbmc_fbmc-notebook_5_28.png
../../../_images/ltm-api_guides_fbmc_fbmc-notebook_5_29.png
busbar/tev
../../../_images/ltm-api_guides_fbmc_fbmc-notebook_5_31.png
../../../_images/ltm-api_guides_fbmc_fbmc-notebook_5_32.png
../../../_images/ltm-api_guides_fbmc_fbmc-notebook_5_33.png
../../../_images/ltm-api_guides_fbmc_fbmc-notebook_5_34.png
busbar/otra
../../../_images/ltm-api_guides_fbmc_fbmc-notebook_5_36.png
../../../_images/ltm-api_guides_fbmc_fbmc-notebook_5_37.png
../../../_images/ltm-api_guides_fbmc_fbmc-notebook_5_38.png
../../../_images/ltm-api_guides_fbmc_fbmc-notebook_5_39.png
busbar/term
../../../_images/ltm-api_guides_fbmc_fbmc-notebook_5_41.png
busbar/battery_busbar
../../../_images/ltm-api_guides_fbmc_fbmc-notebook_5_43.png
../../../_images/ltm-api_guides_fbmc_fbmc-notebook_5_44.png
../../../_images/ltm-api_guides_fbmc_fbmc-notebook_5_45.png
../../../_images/ltm-api_guides_fbmc_fbmc-notebook_5_46.png
../../../_images/ltm-api_guides_fbmc_fbmc-notebook_5_47.png
busbar/numedal_hvdc
../../../_images/ltm-api_guides_fbmc_fbmc-notebook_5_49.png
busbar/otra_hvdc
../../../_images/ltm-api_guides_fbmc_fbmc-notebook_5_51.png
busbar/tev_hvdc
../../../_images/ltm-api_guides_fbmc_fbmc-notebook_5_53.png