py_mapping

Fully Parameteized Working Example

Note

Original code file can be found in: tessif/examples/data/tsf/py_mapping/fpwe.py

Reading the Data

Setting spellings.get_from's logging level to debug for decluttering doctest output:

>>> from tessif.frused import configurations
>>> configurations.spellings_logging_level = 'debug'

Reading in the data:

>>> from tessif.parse import python_mapping
>>> from tessif.examples.data.tsf.py_mapping import fpwe
>>> energy_system_mapping = python_mapping(fpwe.mapping)
>>> for key in energy_system_mapping.keys():
...    print(key)
sources
transformers
sinks
storages
busses
timeframe
global_constraints

Transforming the Read-In Data

>>> from tessif.transform.mapping2es.tsf import transform
>>> es = transform(energy_system_mapping)
>>> for node in es.nodes:
...     print(node.uid.name)
Pipeline
Power Line
Gas Station
Demand
Generator
Battery

Using the Simulate Wrapper

Automatically do the steps from above utilizing the tessif.simulate.tsf_from_es() wrapper:

Warning

Not yet implemented!

Original Data – The Complete Mapping

import tessif.frused.namedtuples as nts
import numpy as np
import pandas as pd

mapping = {
    'sources': {
        'gas_station': {
            'name': 'Gas Station',
            'outputs': ('fuel',),
            # Minimum number of arguments required
            'latitude': 42,
            'longitude': 42,
            'region': 'Here',
            'sector': 'Power',
            'carrier': 'Fuel',
            'node_type': 'hub',
            'accumulated_amounts': {
                'fuel': nts.MinMax(min=0, max=float('+inf'))},
            'flow_rates': {'fuel': nts.MinMax(min=0, max=22)},
            'flow_costs': {'fuel': 0},
            'flow_emissions': {'fuel': 0},
            'flow_gradients': {
                'fuel': nts.PositiveNegative(positive=42, negative=42)},
            'gradient_costs': {
                'fuel': nts.PositiveNegative(positive=1, negative=1)},
            'timeseries': {
                'fuel': nts.MinMax(min=0, max=np.array([10, 22, 22]))},
            'expandable': {'fuel': False},
            'expansion_costs': {'fuel': 0},
            'expansion_limits': {'fuel': nts.MinMax(min=0, max=float('+inf'))},
            'milp': {'fuel': False},
            'initial_status': True,
            'status_inertia': nts.OnOff(on=1, off=1),
            'status_changing_costs': nts.OnOff(on=0, off=0),
            'number_of_status_changes': nts.OnOff(on=float('+inf'), off=10),
            'costs_for_being_active': 0,
            # Total number of arguments to specify source object
        },
    },
    'transformers': {
        'generator': {
            'name': 'Generator',
            'inputs': ('fuel',),
            'outputs': ('electricity',),
            'conversions': {('fuel', 'electricity'): 0.42},
            # Minimum number of arguments required
            'latitude': 42,
            'longitude': 42,
            'region': 'Here',
            'sector': 'Power',
            'carrier': 'Force',
            'node_type': 'hub',
            'flow_rates': {
                'fuel': nts.MinMax(min=0, max=50),
                'electricity': nts.MinMax(min=5, max=15)},
            'flow_costs': {'fuel': 0, 'electricity': 0},
            'flow_emissions': {'fuel': 0, 'electricity': 0},
            'flow_gradients': {
                'fuel': nts.PositiveNegative(positive=50, negative=50),
                'electricity': nts.PositiveNegative(positive=10, negative=10)},
            'gradient_costs': {
                'fuel': nts.PositiveNegative(positive=0, negative=0),
                'electricity': nts.PositiveNegative(positive=0, negative=0)},
            'timeseries': {'electricity': nts.MinMax(
                min=0, max=np.array([10, 22, 22]))},
            'expandable': {'fuel': False, 'electricity': False},
            'expansion_costs': {'fuel': 0, 'electricity': 0},
            'expansion_limits': {
                'fuel': nts.MinMax(min=0, max=float('+inf')),
                'electricity': nts.MinMax(min=0, max=float('+inf'))},
            'milp': {'electricity': True, 'fuel': False},
            'initial_status': True,
            'status_inertia': nts.OnOff(on=0, off=2),
            'status_changing_costs': nts.OnOff(on=0, off=0),
            'number_of_status_changes': nts.OnOff(on=float('+inf'), off=9),
            'costs_for_being_active': 0,
            # Total number of arguments to specify transformer object
        },
    },
    'sinks': {
        'demand': {
            'name': 'Demand',
            'inputs': ('electricity',),
            # Minimum number of arguments required
            'latitude': 42,
            'longitude': 42,
            'region': 'Here',
            'sector': 'Power',
            'carrier': 'Force',
            'node_type': 'hub',
            'accumulated_amounts': {
                'electricity': nts.MinMax(min=0, max=float('+inf'))},
            'flow_rates': {'electricity': nts.MinMax(min=8, max=11)},
            'flow_costs': {'electricity': 0},
            'flow_emissions': {'electricity': 0},
            'flow_gradients': {
                'electricity': nts.PositiveNegative(positive=11, negative=11)},
            'gradient_costs': {
                'electricity': nts.PositiveNegative(positive=0, negative=0)},
            'timeseries': None,
            'expandable': {'electricity': False},
            'expansion_costs': {'electricity': 0},
            'expansion_limits': {
                'electricity': nts.MinMax(min=0, max=float('+inf'))},
            'milp': {'electricity': False},
            'initial_status': True,
            'status_inertia': nts.OnOff(on=2, off=1),
            'status_changing_costs': nts.OnOff(on=0, off=0),
            'number_of_status_changes': nts.OnOff(on=float('+inf'), off=8),
            'costs_for_being_active': 0,
            # Total number of arguments to specify sink object
        },
    },
    'storages': {
        'battery': {
            'name': 'Battery',
            'input': 'electricity',
            'output': 'electricity',
            'capacity': 100,
            'initial_soc': 10,
            # Minimum number of arguments required
            'latitude': 42,
            'longitude': 42,
            'region': 'Here',
            'sector': 'Power',
            'carrier': 'Force',
            'node_type': 'hub',
            'idle_changes': nts.PositiveNegative(positive=0, negative=1),
            'flow_rates': {'electricity': nts.MinMax(min=0, max=10)},
            'flow_efficiencies': {
                'electricity': nts.InOut(inflow=0.95, outflow=0.98)},
            'flow_costs': {'electricity': 0},
            'flow_emissions': {'electricity': 0},
            'flow_gradients': {
                'electricity': nts.PositiveNegative(positive=10, negative=10)},
            'gradient_costs': {
                'electricity': nts.PositiveNegative(positive=0, negative=0)},
            'timeseries': None,
            'expandable': {'electricity': False},
            'expansion_costs': {'electricity': 0},
            'expansion_limits': {
                'electricity': nts.MinMax(min=0, max=float('+inf'))},
            'milp': {'electricity': False},
            'initial_status': True,
            'status_inertia': nts.OnOff(on=0, off=2),
            'status_changing_costs': nts.OnOff(on=0, off=0),
            'number_of_status_changes': nts.OnOff(on=float('+inf'), off=42),
            'costs_for_being_active': 0,
            # Total number of arguments to specify storage object
        },
    },
    'busses': {
        'fuel_supply_line': {
            'name': 'Pipeline',
            'inputs': ('Gas Station.fuel',),
            'outputs': ('Generator.fuel',),
            # Minimum number of arguments required
            'latitude': 42,
            'longitude': 42,
            'region': 'Here',
            'sector': 'Power',
            'carrier': 'fuel',
            'node_type': 'fuel_line',
            # Total number of arguments to specify bus object
        },
        'power_line': {
            'name': 'Power Line',
            'inputs': ('Generator.electricity', 'Battery.electricity'),
            'outputs': ('Demand.electricity', 'Battery.electricity'),
            # Minimum number of arguments required
            'latitude': 42,
            'longitude': 42,
            'region': 'Here',
            'sector': 'Power',
            'carrier': 'Force',
            'node_type': 'hub',
            # Total number of arguments to specify bus object
        },
    },
    'timeframe': {
        'primary': pd.date_range('7/13/1990', periods=3, freq='H'),
        'secondary': pd.date_range('10/03/2019', periods=3, freq='H'),
    },
    'global_constraints': {
        'primary': {'name': 'default',
                    'emissions': float('+inf'),
                    'resources': float('+inf')},
        'secondary': {'name': '80% reduction',
                      'emissions': 1000,
                      'resources': float('+inf')},
    },
}

Transhipment Problem Example

Note

Original code file can be found in: tessif/examples/data/tsf/py_mapping/fpwe.py

A similar example can be found in tessif.examples.data.tsf.py_hard.create_connected_es

Reading the Data

Setting spellings.get_from's logging level to debug for decluttering doctest output:

>>> from tessif.frused import configurations
>>> configurations.spellings_logging_level = 'debug'

Reading in the data:

>>> from tessif.parse import python_mapping
>>> from tessif.examples.data.tsf.py_mapping import transshipment
>>> energy_system_mapping = python_mapping(transshipment.mapping)
>>> for key in energy_system_mapping.keys():
...    print(key)
sources
transformers
sinks
storages
busses
connectors
timeframe
global_constraints

Transforming the Read-In Data into a Tessif Energy System

>>> from tessif.transform.mapping2es.tsf import transform
>>> es = transform(energy_system_mapping)
>>> for node in es.nodes:
...     print(node.uid.name)
bus-01
bus-02
source-01
source-02
sink-01
sink-02
connector

Transforming the Tessif Energy System into an Oemof Energy System

>>> import tessif.transform.es2es.omf as tsf2omf
>>> omf_es = tsf2omf.transform(es)
>>> for node in omf_es.nodes:
...     print(str(node.label))
bus-01
bus-02
connector
source-01
source-02
sink-01
sink-02

Simulating and Post Processing the Oemof Energy System

Handle the imports first:

>>> import tessif.simulate
>>> import tessif.transform.es2mapping.omf as post_process_omf
>>> optimized_omf_es = tessif.simulate.omf_from_es(omf_es)

Postprocess the results:

>>> load_results = post_process_omf.LoadResultier(optimized_omf_es)

Show some results:

>>> print(load_results.node_load['connector'])
connector              bus-01  bus-02  bus-01  bus-02
1990-07-13 00:00:00 -5.555556   -0.00     0.0     5.0
1990-07-13 01:00:00 -0.000000   -6.25     5.0     0.0
1990-07-13 02:00:00 -0.000000   -0.00     0.0     0.0
>>> print(load_results.node_load['bus-01'])
bus-01               connector  source-01  connector  sink-01
1990-07-13 00:00:00       -0.0  -5.555556   5.555556      0.0
1990-07-13 01:00:00       -5.0 -10.000000   0.000000     15.0
1990-07-13 02:00:00       -0.0 -10.000000   0.000000     10.0
>>> print(load_results.node_load['bus-02'])
bus-02               connector  source-02  connector  sink-02
1990-07-13 00:00:00       -5.0     -10.00       0.00     15.0
1990-07-13 01:00:00       -0.0      -6.25       6.25      0.0
1990-07-13 02:00:00       -0.0     -10.00       0.00     10.0

Original Data – The Complete Mapping

import tessif.frused.namedtuples as nts
import numpy as np
import pandas as pd

mapping = {
    'sources': {
        'so1': {
            'name': 'source-01',
            'outputs': ('electricity',),
            'flow_rates': {'electricity': nts.MinMax(min=0, max=10)},
            'flow_costs': {'electricity': 1},
        },
        'so2': {
            'name': 'source-02',
            'outputs': ('electricity',),
            'flow_rates': {'electricity': nts.MinMax(min=0, max=10)},
            'flow_costs': {'electricity': 1},
        },
    },
    'transformers': {
    },
    'sinks': {
        's1': {
            'name': 'sink-01',
            'inputs': ('electricity',),
            'flow_rates': {'electricity': nts.MinMax(min=0, max=15)},
            'flow_costs': {'electricity': 1},
            'timeseries': {
                'electricity': nts.MinMax(
                    min=np.array([0, 15, 10]), max=np.array([0, 15, 10]))}
        },
        's2': {
            'name': 'sink-02',
            'inputs': ('electricity',),
            'flow_rates': {'electricity': nts.MinMax(min=0, max=15)},
            'flow_costs': {'electricity': 1},
            'timeseries': {'electricity': nts.MinMax(
                min=np.array([15, 0, 10]), max=np.array([15, 0, 10]))}
        },
    },
    'storages': {
    },
    'busses': {
        'b1': {
            'name': 'bus-01',
            'inputs': ('source-01.electricity',),
            'outputs': ('sink-01.electricity',),
        },
        'b2': {
            'name': 'bus-02',
            'inputs': ('source-02.electricity',),
            'outputs': ('sink-02.electricity',),
        },
    },
    'connectors': {
        'c': {
            'name': 'connector',
            'interfaces': ('bus-01', 'bus-02'),
            'conversions': {
                ('bus-01', 'bus-02'): 0.9,
                ('bus-02', 'bus-01'): 0.8
            },
        },
    },
    'timeframe': {
        'primary': pd.date_range('7/13/1990', periods=3, freq='H'),
        'secondary': pd.date_range('10/03/2019', periods=3, freq='H'),
    },
    'global_constraints': {
        'primary': {'name': 'default',
                    'emissions': float('+inf'),
                    'resources': float('+inf')},
        'secondary': {'name': '80% reduction',
                      'emissions': 1000,
                      'resources': float('+inf')},
    },
}