Model Data

Model Data input and output is handled by the mapping2es and the es2mapping modules inside the transform subpackage. Following sections provide detailed information on how to use them as well as consequential links for more detailed information.

Note

The current support of the various data transformation capabilities can be gauged and expanded using the tessif.transform module.

Parsed Data

Data parsing is usually the first step in a series of steps for conducting energy supply system simulations. The section about data input gives detailed information on how tessif helps in reading in data.

Handling the parsed data comes second. This usually involves creating a set of equations formulating an optimization problem. This mathematical formulation process however is often interfaced by an energy system object trying to make the problem description process more intuitive for engineers. Examples for such interfaces would be tessif.model.energy_system, oemof.energy_system, and pypsa.Network.

Consequentially handling the parsed data comes down to creating such energy system objects. Since tessif's purpose is to simplify using various different simulation tools most often the first energy system object created is of type tessif.model.energy_system.AbstractEnergySystem. Which can then be simulated directly and or transformed into other energy system model objects for performing simulations.

Tessif also helps with parsing and handling data specificly designed for a single model. This is often the case when tessif's generalization approach reduces a model’s accuracy or straight up ingores and or oversimplifies it’s parts of it by not providing appropriate parameters.

Note

When aiming to perform large scale investigations, involving many different kinds of parameterized energy systems it is much more convenient to use the simulate wrappers. They perform:

  • parsing the read-in data

  • handling it appropriately

  • performing the simulation

with a single call.

The Steps of reading in and parsing data as creating an energy system object out of it are examplified in following sections. The example shown uses a set of config files storing energy system data found in tessif's example hub.

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

    >>> from tessif.frused import configurations
    >>> configurations.spellings_logging_level = 'debug'
    
  2. Reading in the data:

    >>> from tessif import parse
    >>> from tessif.frused.paths import example_dir
    >>> import os
    >>> folder = os.path.join(example_dir,
    ...     'data', 'tsf', 'cfg', 'flat', 'basic')
    >>> energy_system_mapping = parse.flat_config_folder(folder)
    

    Print the the sorted mappings keys for checking succesfull reading:

    >>> keys = list(energy_system_mapping.keys())
    >>> for key in sorted(keys):
    ...     print(key)
    bus
    global_constraints
    sink
    source
    storage
    timeframe
    transformer
    
  3. Transform the parsed data into an energy system object:

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

Simulated Data

As identified in Introduction providing a common interface for various different energy supply system simulation models is one of tessif's goals. The interface’s implementation can be found in the tessif.transform.es2mapping subpackage. It consists of a collection of small classes extracting specific results from the optimized energy system an transforming them into dictionairies keyed by the unique identifiers of the components present in the energy system. These ‘mini-classes’ are called Resultiers (as in ‘Portier’ for the results).

Following sections demonstrate how tessif can be used to extract data out of energy systems simulated by oemof. (The conceptual syntax accross different models remains the same. Only the es2mapping submodule needs to be adjusted to the model used).

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

    >>> from tessif.frused import configurations
    >>> configurations.spellings_logging_level = 'debug'
    
  2. Import all the essentials to use the simulation wrapper:

    >>> import tessif.simulate as simulate
    >>> import tessif.transform.es2mapping.omf as transform_oemof
    >>> from tessif.frused.paths import example_dir
    >>> from tessif import parse
    >>> import os
    >>> import functools
    
  3. Perform simulation :

    >>> es = simulate.omf(
    ...     path=os.path.join(
    ...         example_dir, 'data', 'omf', 'xlsx', 'generic_storage.ods'),
    ...     parser=functools.partial(parse.xl_like, sheet_name=None,
    ...                              engine='odf'),
    ...     solver='glpk')
    
  4. Transform the energy system into objects that can convienently be accessed for the results (load results in this case. See tessif.transform.es2mapping.omf for a complete listing of available Resultiers):

    >>> resultier = transform_oemof.LoadResultier(es)
    >>> print(resultier.node_data().keys())
    dict_keys(['node_inflows', 'node_load', 'node_outflows', 'node_summed_loads'])
    
  5. Query arbitrary energy system components for their load data:

    >>> for node in es.nodes:
    ...     print(node.label)
    Power Grid
    Onshore
    Power
    Power Demand
    Storage
    
    >>> print(resultier.node_inflows['Power Grid'])
    Power Grid           Onshore  Power  Storage
    2016-01-01 00:00:00    250.0    0.0      0.0
    2016-01-01 01:00:00    250.0    0.0      0.0
    2016-01-01 02:00:00    250.0    0.0      0.0
    2016-01-01 03:00:00    250.0    0.0      0.0
    2016-01-01 04:00:00    250.0    0.0      0.0
    
    >>> print(resultier.node_load['Power Grid'])
    Power Grid           Onshore  Power  Storage  Power Demand  Storage
    2016-01-01 00:00:00   -250.0   -0.0     -0.0         200.0     50.0
    2016-01-01 01:00:00   -250.0   -0.0     -0.0         200.0     50.0
    2016-01-01 02:00:00   -250.0   -0.0     -0.0         140.0    110.0
    2016-01-01 03:00:00   -250.0   -0.0     -0.0         200.0     50.0
    2016-01-01 04:00:00   -250.0   -0.0     -0.0         200.0     50.0
    
    >>> print(resultier.node_outflows['Power Demand'])
    Empty DataFrame
    Columns: []
    Index: []
    
    >>> print(resultier.node_summed_loads['Power Grid'])
    2016-01-01 00:00:00    250.0
    2016-01-01 01:00:00    250.0
    2016-01-01 02:00:00    250.0
    2016-01-01 03:00:00    250.0
    2016-01-01 04:00:00    250.0
    Freq: H, dtype: float64
    

Model Specific Data

Tessif’s parsing capabilities can also be used to provide data directly to the model. This however requires a respective submodule to be implemented inside mapping2es transforming the parsed in data to actual energy system objects. Following section shows how this is done using oemof.

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

    >>> from tessif.frused import configurations
    >>> configurations.spellings_logging_level = 'debug'
    
  2. Import all the essentials to use the parsing wrapper:

    >>> from tessif.parse import xl_like
    >>> from tessif.frused.paths import example_dir
    >>> import os
    
  3. Parsing the data:

    >>> p = os.path.join(example_dir, 'data', 'omf', 'xlsx', 'energy_system.xls')
    >>> energy_system_mapping = xl_like(p, engine='xlrd')
    >>> for key in energy_system_mapping.keys():
    ...     print(key)
    Info
    Grid
    Renewable
    Demand
    Commodity
    mimo_transformers
    global_constraints
    timeframe
    
  4. Tansforming the parsed data:

    >>> from tessif.transform.mapping2es.omf import transform
    >>> es = transform(energy_system_mapping)
    >>> for node in es.nodes:
    ...     print(node.label.name)
    Power Grid
    Gas Grid
    Heat Grid
    Coal Grid
    PV
    Onshore
    Offshore
    Gas
    Coal
    Power Demand
    Heat Demand
    Gas_CHP
    Coal_PP
    Gas_HP