tsf
Api
Transform an |
Internal Functionalities
Generate |
|
Generate |
|
Generate |
|
Generate |
|
Generate |
|
Generate |
tsf is a tessif package to transform
abstract energy system data represented as mapping into
ready to simulate energy system model instances.
Mapping like representations are usually returned by utilities part of the
parse module.
- tessif.transform.mapping2es.tsf._generate_busses(energy_system_dict)[source]
Generate
Busobjects out of theenergy_system_dict.- Parameters:
energy_system_dict¶ (dict) – Dictionary of
pandas.DataFrameobjects keyed by strings. With the key strings representing energy system components. Usually returned by something like thetessif.parsefunctionalities.- Returns:
generated_busses – Generator object yielding the parsed
bus objects.- Return type:
- tessif.transform.mapping2es.tsf._generate_sinks(energy_system_dict)[source]
Generate
Sinkobjects out of theenergy_system_dict.- Parameters:
energy_system_dict¶ (dict) – Dictionairy of
pandas.DataFrameobjects keyed by strings. With the key strings representing energy system components. Usually returned by something like thetessif.parsefunctionalities.- Returns:
generated_sinks – Generator obeject yielding the parsed
sink objects.- Return type:
Examples
Setting
spellings.get_from'slogging level to debug for decluttering doctest output:>>> from tessif.frused import configurations >>> configurations.spellings_logging_level = 'debug'
Using the pure_python energy system mapping example
>>> from tessif.examples.data.tsf.py_mapping.fpwe import mapping as m >>> import tessif.parse as parse >>> import tessif.transform.mapping2es.tsf as ttsf >>> sinks = ttsf._generate_sinks(parse.python_mapping(m)) >>> for s in sinks: ... for name, attr in s.attributes.items(): ... print('{}: {}'.format(name, attr)) accumulated_amounts: {'electricity': MinMax(min=0, max=inf)} costs_for_being_active: 0 expandable: {'electricity': False} expansion_costs: {'electricity': 0} expansion_limits: {'electricity': MinMax(min=0, max=inf)} flow_costs: {'electricity': 0} flow_emissions: {'electricity': 0} flow_gradients: {'electricity': PositiveNegative(positive=11, negative=11)} flow_rates: {'electricity': MinMax(min=8, max=11)} gradient_costs: {'electricity': PositiveNegative(positive=0, negative=0)} initial_status: True inputs: frozenset({'electricity'}) interfaces: frozenset({'electricity'}) milp: {'electricity': False} number_of_status_changes: OnOff(on=2, off=1) status_changing_costs: OnOff(on=2, off=1) status_inertia: OnOff(on=2, off=1) timeseries: None uid: Demand
- tessif.transform.mapping2es.tsf._generate_sources(energy_system_dict)[source]
Generate
Sourceobjects out of theenergy_system_dict.- Parameters:
energy_system_dict¶ (dict) – Dictionairy of
pandas.DataFrameobjects keyed by strings. With the key strings representing energy system components. Usually returned by something like thetessif.parsefunctionalities.- Returns:
generated_sources – Generator obeject yielding the parsed
sourceobjects.- Return type:
Examples
Setting
spellings.get_from'slogging level to debug for decluttering doctest output:>>> from tessif.frused import configurations >>> configurations.spellings_logging_level = 'debug'
Using the pure_python energy system mapping example
>>> from tessif.examples.data.tsf.py_mapping.fpwe import mapping as m >>> import tessif.parse as parse >>> import tessif.transform.mapping2es.tsf as ttsf >>> sources = ttsf._generate_sources(parse.python_mapping(m)) >>> for s in sources: ... for name, attr in s.attributes.items(): ... print('{}: {}'.format(name, attr)) accumulated_amounts: {'fuel': MinMax(min=0, max=inf)} costs_for_being_active: 0 expandable: {'fuel': False} expansion_costs: {'fuel': 0} expansion_limits: {'fuel': MinMax(min=0, max=inf)} flow_costs: {'fuel': 0} flow_emissions: {'fuel': 0} flow_gradients: {'fuel': PositiveNegative(positive=42, negative=42)} flow_rates: {'fuel': MinMax(min=0, max=22)} gradient_costs: {'fuel': PositiveNegative(positive=1, negative=1)} initial_status: True interfaces: frozenset({'fuel'}) milp: {'fuel': False} number_of_status_changes: OnOff(on=1, off=1) outputs: frozenset({'fuel'}) status_changing_costs: OnOff(on=1, off=1) status_inertia: OnOff(on=1, off=1) timeseries: {'fuel': MinMax(min=0, max=array([10, 22, 22]))} uid: Gas Station
- tessif.transform.mapping2es.tsf._generate_transformers(energy_system_dict)[source]
Generate
Transformerobjects out of theenergy_system_dict.- Parameters:
energy_system_dict¶ (dict) – Dictionairy of
pandas.DataFrameobjects keyed by strings. With the key strings representing energy system components. Usually returned by something like thetessif.parsefunctionalities.- Returns:
generated_transformers – Generator obeject yielding the parsed
transformerobjects.- Return type:
Examples
Setting
spellings.get_from'slogging level to debug for decluttering doctest output:>>> from tessif.frused import configurations >>> configurations.spellings_logging_level = 'debug'
Using the pure_python energy system mapping example
>>> from tessif.examples.data.tsf.py_mapping.fpwe import mapping as m >>> import tessif.parse as parse >>> import tessif.transform.mapping2es.tsf as ttsf >>> transformers = ttsf._generate_transformers(parse.python_mapping(m)) >>> for t in transformers: ... for name, atr in t.attributes.items(): ... print('{}: {}'.format( ... name, sorted(atr) if isinstance(atr, frozenset) else atr)) ... # frozensets are printed as sorted lists for doctesting consistency conversions: {('fuel', 'electricity'): 0.42} costs_for_being_active: 0 expandable: {'electricity': False, 'fuel': False} expansion_costs: {'electricity': 0, 'fuel': 0} expansion_limits: {'electricity': MinMax(min=0, max=inf), 'fuel': MinMax(min=0, max=inf)} flow_costs: {'electricity': 0, 'fuel': 0} flow_emissions: {'electricity': 0, 'fuel': 0} flow_gradients: {'electricity': PositiveNegative(positive=10, negative=10), 'fuel': PositiveNegative(positive=50, negative=50)} flow_rates: {'electricity': MinMax(min=5, max=15), 'fuel': MinMax(min=0, max=50)} gradient_costs: {'electricity': PositiveNegative(positive=0, negative=0), 'fuel': PositiveNegative(positive=0, negative=0)} initial_status: True inputs: ['fuel'] interfaces: ['electricity', 'fuel'] milp: {'electricity': True, 'fuel': False} number_of_status_changes: OnOff(on=0, off=2) outputs: ['electricity'] status_changing_costs: OnOff(on=0, off=2) status_inertia: OnOff(on=0, off=2) timeseries: {'electricity': MinMax(min=0, max=array([10, 22, 22]))} uid: Generator
- tessif.transform.mapping2es.tsf._generate_chps(energy_system_dict)[source]
Generate
CHPobjects out of theenergy_system_dict.- Parameters:
energy_system_dict¶ (dict) – Dictionairy of
pandas.DataFrameobjects keyed by strings. With the key strings representing energy system components. Usually returned by something like thetessif.parsefunctionalities.- Returns:
generated_chps – Generator obeject yielding the parsed
chpobjects.- Return type:
Examples
Setting
spellings.get_from'slogging level to debug for decluttering doctest output:>>> from tessif.frused import configurations >>> configurations.spellings_logging_level = 'debug'
Store the create_variable_chp example from the hardcoded examples into a hdf5 file and then parse it into a mapping from which the chps are generated.
>>> import tessif.examples.data.tsf.py_hard as tsf_examples >>> tsf_es = tsf_examples.create_variable_chp() >>> import os >>> from tessif.frused.paths import write_dir >>> output_msg = tsf_es.to_hdf5( ... directory=os.path.join(write_dir, 'tsf'), ... filename='chp_es.hdf5', ... ) >>> import tessif.parse as parse >>> import tessif.transform.mapping2es.tsf as ttsf >>> chps = ttsf._generate_chps(parse.hdf5( ... path=os.path.join(write_dir, 'tsf', 'chp_es.hdf5'),)) >>> for c in chps: ... for name, atr in c.attributes.items(): ... print('{}: {}'.format( ... name, sorted(atr) if isinstance(atr, frozenset) else atr)) ... # frozensets are printed as sorted lists for doctesting consistency back_pressure: nan conversion_factor_full_condensation: {('gas', 'electricity'): 0.5} conversions: {('gas', 'electricity'): 0.3, ('gas', 'heat'): 0.2} costs_for_being_active: 0.0 el_efficiency_wo_dist_heat: MinMax(min=nan, max=nan) enthalpy_loss: MinMax(min=nan, max=nan) expandable: {'electricity': False, 'gas': False, 'heat': False} expansion_costs: {'electricity': 0.0, 'gas': 0.0, 'heat': 0.0} expansion_limits: {'electricity': MinMax(min=0.0, max=inf), 'gas': MinMax(min=0.0, max=inf), 'heat': MinMax(min=0.0, max=inf)} flow_costs: {'electricity': 3, 'gas': 0, 'heat': 2} flow_emissions: {'electricity': 2, 'gas': 0, 'heat': 3} flow_gradients: {'electricity': PositiveNegative(positive=inf, negative=inf), 'gas': PositiveNegative(positive=inf, negative=inf), 'heat': PositiveNegative(positive=inf, negative=inf)} flow_rates: {'electricity': MinMax(min=0, max=9), 'gas': MinMax(min=0.0, max=inf), 'heat': MinMax(min=0, max=6)} gradient_costs: {'electricity': PositiveNegative(positive=0.0, negative=0.0), 'gas': PositiveNegative(positive=0.0, negative=0.0), 'heat': PositiveNegative(positive=0.0, negative=0.0)} initial_status: 1 inputs: ['gas'] interfaces: ['electricity', 'gas', 'heat'] milp: {'electricity': False, 'gas': False, 'heat': False} min_condenser_load: nan number_of_status_changes: OnOff(on=0, off=0) outputs: ['electricity', 'heat'] power_loss_index: nan power_wo_dist_heat: MinMax(min=nan, max=nan) status_changing_costs: OnOff(on=0, off=0) status_inertia: OnOff(on=0, off=0) timeseries: None uid: CHP1 back_pressure: False conversion_factor_full_condensation: {} conversions: {} costs_for_being_active: 0.0 el_efficiency_wo_dist_heat: MinMax(min=[0.43, 0.43, 0.43, 0.43], max=[0.53, 0.53, 0.53, 0.53]) enthalpy_loss: MinMax(min=[1.0, 1.0, 1.0, 1.0], max=[0.18, 0.18, 0.18, 0.18]) expandable: {'electricity': False, 'gas': False, 'heat': False} expansion_costs: {'electricity': 0.0, 'gas': 0.0, 'heat': 0.0} expansion_limits: {'electricity': MinMax(min=0.0, max=inf), 'gas': MinMax(min=0.0, max=inf), 'heat': MinMax(min=0.0, max=inf)} flow_costs: {'electricity': 3, 'gas': 0, 'heat': 2} flow_emissions: {'electricity': 2, 'gas': 0, 'heat': 3} flow_gradients: {'electricity': PositiveNegative(positive=inf, negative=inf), 'gas': PositiveNegative(positive=inf, negative=inf), 'heat': PositiveNegative(positive=inf, negative=inf)} flow_rates: {'electricity': MinMax(min=0.0, max=inf), 'gas': MinMax(min=0.0, max=inf), 'heat': MinMax(min=0.0, max=inf)} gradient_costs: {'electricity': PositiveNegative(positive=0.0, negative=0.0), 'gas': PositiveNegative(positive=0.0, negative=0.0), 'heat': PositiveNegative(positive=0.0, negative=0.0)} initial_status: 1 inputs: ['gas'] interfaces: ['electricity', 'gas', 'heat'] milp: {'electricity': False, 'gas': False, 'heat': False} min_condenser_load: [3, 3, 3, 3] number_of_status_changes: OnOff(on=0, off=0) outputs: ['electricity', 'heat'] power_loss_index: [0.19, 0.19, 0.19, 0.19] power_wo_dist_heat: MinMax(min=[8, 8, 8, 8], max=[20, 20, 20, 20]) status_changing_costs: OnOff(on=0, off=0) status_inertia: OnOff(on=0, off=0) timeseries: None uid: CHP2
- tessif.transform.mapping2es.tsf._generate_storages(energy_system_dict)[source]
Generate
Storageobjects out of theenergy_system_dict.- Parameters:
energy_system_dict¶ (dict) – Dictionairy of
pandas.DataFrameobjects keyed by strings. With the key strings representing energy system components. Usually returned by something like thetessif.parsefunctionalities.- Returns:
generated_storages – Generator obeject yielding the parsed
storageobjects.- Return type:
Examples
Setting
spellings.get_from'slogging level to debug for decluttering doctest output:>>> from tessif.frused import configurations >>> configurations.spellings_logging_level = 'debug'
Using the pure_python energy system mapping example
>>> from tessif.examples.data.tsf.py_mapping.fpwe import mapping as m >>> import tessif.parse as parse >>> import tessif.transform.mapping2es.tsf as ttsf >>> storages = ttsf._generate_storages(parse.python_mapping(m)) >>> for s in storages: ... print(s.uid) ... print(s.input) ... print(s.output) ... for name, atr in s.attributes.items(): ... print('{}: {}'.format( ... name, sorted(atr) if isinstance(atr, frozenset) else atr)) ... # frozensets are printed as sorted lists for doctesting consistency Battery electricity electricity capacity: 100 costs_for_being_active: 0 expandable: {'electricity': False} expansion_costs: {'electricity': 0} expansion_limits: {'electricity': MinMax(min=0, max=inf)} final_soc: None fixed_expansion_ratios: {'electricity': True} flow_costs: {'electricity': 0} flow_efficiencies: {'electricity': InOut(inflow=0.95, outflow=0.98)} flow_emissions: {'electricity': 0} flow_gradients: {'electricity': PositiveNegative(positive=10, negative=10)} flow_rates: {'electricity': MinMax(min=0, max=10)} gradient_costs: {'electricity': PositiveNegative(positive=0, negative=0)} idle_changes: PositiveNegative(positive=0, negative=1) initial_soc: 10 initial_status: True input: electricity interfaces: ['electricity'] milp: {'electricity': False} number_of_status_changes: OnOff(on=0, off=2) output: electricity status_changing_costs: OnOff(on=0, off=2) status_inertia: OnOff(on=0, off=2) timeseries: None uid: Battery
- tessif.transform.mapping2es.tsf._generate_connectors(energy_system_dict)[source]
Generate
Connectorobjects out of theenergy_system_dict.- Parameters:
energy_system_dict¶ (dict) – Dictionairy of
pandas.DataFrameobjects keyed by strings. With the key strings representing energy system components. Usually returned by something like thetessif.parsefunctionalities.- Returns:
generated_connectors – Generator obeject yielding the parsed
connectorobjects.- Return type:
Examples
Setting
spellings.get_from'slogging level to debug for decluttering doctest output:>>> from tessif.frused import configurations >>> configurations.spellings_logging_level = 'debug'
Using the pure_python energy system mapping example
>>> import tessif.examples.data.tsf.py_mapping.transshipment as tship >>> import tessif.parse as parse >>> import tessif.transform.mapping2es.tsf as ttsf >>> connectors = ttsf._generate_connectors( ... parse.python_mapping(tship.mapping)) >>> for c in connectors: ... for name, atr in c.attributes.items(): ... print('{}: {}'.format( ... name, sorted(atr) if isinstance(atr, frozenset) else atr)) ... # frozensets are printed as sorted lists for doctesting consistency conversions: {('bus-01', 'bus-02'): 0.9, ('bus-02', 'bus-01'): 0.8} inputs: ['bus-01', 'bus-02'] interfaces: ['bus-01', 'bus-02'] outputs: ['bus-01', 'bus-02'] timeseries: None uid: connector
- tessif.transform.mapping2es.tsf.infer_timeindex(energy_system_dict)[source]
Try inferring the timeindex from the energy system dictionary. Inferring is done by reading out the
timeindex-like column of thetimeseries-like spreadsheet (DataFrame) and rounding it according to thetemporal resolution.The timeframe to be simulated is here referred to as “timeindex”.
Warning
For inferring to be succesfull, discrete timeframe length has to be at least 3 (after rounding).
- Parameters:
energy_system_dict¶ (dict) – Dictionary containing the energy system data. Typically returned by one of the
tessif.parsefunctionalities- Returns:
timeindex – The time frame inferred from the energy system dictionary.
- Return type:
Example
>>> from tessif.examples.data.tsf.py_mapping.fpwe import mapping as m >>> from tessif.frused.paths import example_dir >>> import tessif.parse as parse >>> import tessif.transform.mapping2es.tsf as ttsf >>> idx = ttsf.infer_timeindex(parse.python_mapping(m)) >>> import pprint >>> pprint.pprint(idx) DatetimeIndex(['1990-07-13 00:00:00', '1990-07-13 01:00:00', '1990-07-13 02:00:00'], dtype='datetime64[ns]', freq='H')
- tessif.transform.mapping2es.tsf.transform(energy_system_mapping, **kwargs)[source]
Transform an
energy system mappingto atessif energy system.- Parameters:
energy_system_mapping¶ (dict) – Dictionairy containing the energy system data. Typically returned by one of the
tessif.parsefunctionalitiestimeframe¶ (pandas.DatetimeIndex) –
Datetime index representing the evaluated timeframe. Explicitly stating:
initial datatime (0th element of the
pandas.DatetimeIndex)number of timesteps (length of
pandas.DatetimeIndex)temporal resolution (
pandas.DatetimeIndex.freq)
For example:
idx = pd.DatetimeIndex( data=pd.date_range( '2016-01-01 00:00:00', periods=11, freq='H'))
Note
If not stated it is tried to be
inferred.global_constraints¶ (dict, default={'emissions': float('+inf')}) –
Dictionairy of
numericvalues mapped to global constraint namingstrings.Recognized constraint keys are:
emissions…
For a more detailed explanation see the user guide’s section: Secondary Objectives
uid¶ (Hashable, default='automatically_transformed') – Hashable unique identifier. Usually a string aka a name.
- Returns:
energy_system – The dictionairy transformed oemof energy system, ready for simulation.
- Return type:
Examples
Using the pure_python energy system mapping example:
>>> from tessif.examples.data.tsf.py_mapping.fpwe import mapping as m >>> import tessif.parse as parse >>> import tessif.transform.mapping2es.tsf as ttsf >>> esys = ttsf.transform(parse.python_mapping(m)) >>> for node in esys.nodes: ... for k, v in node.attributes.items(): ... print('{} = {}'.format( ... k, sorted(v) if isinstance(v, frozenset) else v)) ... # frozensets are printed as sorted lists for doctesting consistency ... print(50*'-') ... print() inputs = ['Gas Station.fuel'] interfaces = ['Gas Station.fuel', 'Generator.fuel'] outputs = ['Generator.fuel'] timeseries = None uid = Pipeline -------------------------------------------------- inputs = ['Battery.electricity', 'Generator.electricity'] interfaces = ['Battery.electricity', 'Demand.electricity', 'Generator.electricity'] outputs = ['Battery.electricity', 'Demand.electricity'] timeseries = None uid = Power Line -------------------------------------------------- accumulated_amounts = {'fuel': MinMax(min=0, max=inf)} costs_for_being_active = 0 expandable = {'fuel': False} expansion_costs = {'fuel': 0} expansion_limits = {'fuel': MinMax(min=0, max=inf)} flow_costs = {'fuel': 0} flow_emissions = {'fuel': 0} flow_gradients = {'fuel': PositiveNegative(positive=42, negative=42)} flow_rates = {'fuel': MinMax(min=0, max=22)} gradient_costs = {'fuel': PositiveNegative(positive=1, negative=1)} initial_status = True interfaces = ['fuel'] milp = {'fuel': False} number_of_status_changes = OnOff(on=1, off=1) outputs = ['fuel'] status_changing_costs = OnOff(on=1, off=1) status_inertia = OnOff(on=1, off=1) timeseries = {'fuel': MinMax(min=0, max=array([10, 22, 22]))} uid = Gas Station -------------------------------------------------- accumulated_amounts = {'electricity': MinMax(min=0, max=inf)} costs_for_being_active = 0 expandable = {'electricity': False} expansion_costs = {'electricity': 0} expansion_limits = {'electricity': MinMax(min=0, max=inf)} flow_costs = {'electricity': 0} flow_emissions = {'electricity': 0} flow_gradients = {'electricity': PositiveNegative(positive=11, negative=11)} flow_rates = {'electricity': MinMax(min=8, max=11)} gradient_costs = {'electricity': PositiveNegative(positive=0, negative=0)} initial_status = True inputs = ['electricity'] interfaces = ['electricity'] milp = {'electricity': False} number_of_status_changes = OnOff(on=2, off=1) status_changing_costs = OnOff(on=2, off=1) status_inertia = OnOff(on=2, off=1) timeseries = None uid = Demand -------------------------------------------------- conversions = {('fuel', 'electricity'): 0.42} costs_for_being_active = 0 expandable = {'electricity': False, 'fuel': False} expansion_costs = {'electricity': 0, 'fuel': 0} expansion_limits = {'electricity': MinMax(min=0, max=inf), 'fuel': MinMax(min=0, max=inf)} flow_costs = {'electricity': 0, 'fuel': 0} flow_emissions = {'electricity': 0, 'fuel': 0} flow_gradients = {'electricity': PositiveNegative(positive=10, negative=10), 'fuel': PositiveNegative(positive=50, negative=50)} flow_rates = {'electricity': MinMax(min=5, max=15), 'fuel': MinMax(min=0, max=50)} gradient_costs = {'electricity': PositiveNegative(positive=0, negative=0), 'fuel': PositiveNegative(positive=0, negative=0)} initial_status = True inputs = ['fuel'] interfaces = ['electricity', 'fuel'] milp = {'electricity': True, 'fuel': False} number_of_status_changes = OnOff(on=0, off=2) outputs = ['electricity'] status_changing_costs = OnOff(on=0, off=2) status_inertia = OnOff(on=0, off=2) timeseries = {'electricity': MinMax(min=0, max=array([10, 22, 22]))} uid = Generator -------------------------------------------------- capacity = 100 costs_for_being_active = 0 expandable = {'electricity': False} expansion_costs = {'electricity': 0} expansion_limits = {'electricity': MinMax(min=0, max=inf)} final_soc = None fixed_expansion_ratios = {'electricity': True} flow_costs = {'electricity': 0} flow_efficiencies = {'electricity': InOut(inflow=0.95, outflow=0.98)} flow_emissions = {'electricity': 0} flow_gradients = {'electricity': PositiveNegative(positive=10, negative=10)} flow_rates = {'electricity': MinMax(min=0, max=10)} gradient_costs = {'electricity': PositiveNegative(positive=0, negative=0)} idle_changes = PositiveNegative(positive=0, negative=1) initial_soc = 10 initial_status = True input = electricity interfaces = ['electricity'] milp = {'electricity': False} number_of_status_changes = OnOff(on=0, off=2) output = electricity status_changing_costs = OnOff(on=0, off=2) status_inertia = OnOff(on=0, off=2) timeseries = None uid = Battery --------------------------------------------------
Get the inspected timeframe:
>>> print(esys.timeframe) DatetimeIndex(['1990-07-13 00:00:00', '1990-07-13 01:00:00', '1990-07-13 02:00:00'], dtype='datetime64[ns]', freq='H')
Use the automatically generated energy system to
transformit into anetworkx.Graphto facilitate plotting:>>> import tessif.visualize.nxgrph as nxv >>> import matplotlib.pyplot as plt >>> grph = esys.to_nxgrph() >>> drawings = nxv.draw_graph( ... grph, node_color='green', edge_color='pink') >>> plt.draw()