API

oemoflex.model.datapackage

class oemoflex.model.datapackage.EnergyDataPackage(*args, **kwargs)
classmethod from_csv_dir(dir)

Initialize a DataFramePackage from a csv directory

Parameters

dir (str) – Path to csv directory

classmethod from_metadata(json_file_path)

Initialize a DataFramePackage from the metadata string, usually named datapackage.json

Parameters

json_file_path (str) – Path to metadata

infer_metadata(foreign_keys_update=None)

Infers metadata of the EnergyDataPackage and save it in basepath as datapackage.json.

Parameters

foreign_keys_update

parametrize(frame, column, values)

Sets the values of parameters.

Parameters
  • frame (str) – Name of the DataFrame in the Package.

  • column – Name of the columns within the DataFrame

  • values (str or numeric) – Values with the correct index to be set to the DataFrame

classmethod setup_default(name, basepath, datetimeindex, components, busses, regions, links, **kwargs)

Initializes an EnergyDataPackage with a specific structure, but without the values of parameters being set.

Parameters
  • name (str) – Name of the EnergyDataPackage

  • basepath (str) – Path where EnergyDataPackage is stored

  • datetimeindex (pandas.DatetimeIndex) – A valid timeindex

  • components (list) – List of components

  • busses (list) – List of busses

  • regions (list) – List of regions

  • links (list) – List of links between regions

  • bus_attrs_update (dict) – Update with custom-defined busses

  • component_attrs_update (dict) – Update with custom-defined components

stack_components()

Stacks the component DataFrames into a single DataFrame.

to_csv_dir(destination, overwrite=False)

Save the DataFramePackage to csv files. Warns if overwrite is False and the destination is not empty. If overwrite is True, all existing contents in destination will be deleted.

Parameters
  • destination (str) – Path to store data to

  • overwrite (bool) – Decides if any existing files will be overwritten.

unstack_components()

Unstacks a single component DataFrame into separate DataFrames for each component.

class oemoflex.model.datapackage.ResultsDataPackage(*args, **kwargs)
classmethod from_csv_dir(dir)

Initialize a DataFramePackage from a csv directory

Parameters

dir (str) – Path to csv directory

classmethod from_energysytem(es)

Initializes a ResultsDataPackage from an EnergySystem with optimization results.

Parameters

es (oemof.solph.EnergySystem) – EnergySystem with results.

set_scenario_name(scenario_name)

Prepends the given scenario name to the scalar results’ index.

Parameters

scenario_name (str) – Name of the scenario

to_csv_dir(destination, overwrite=False)

Save the DataFramePackage to csv files. Warns if overwrite is False and the destination is not empty. If overwrite is True, all existing contents in destination will be deleted.

Parameters
  • destination (str) – Path to store data to

  • overwrite (bool) – Decides if any existing files will be overwritten.

to_element_dfs()

Separates scalar results such that each component is represented by one DataFrame.

to_stacked_scalars()

Stacks all scalar results such into a single DataFrame named ‘scalars’.

oemoflex.tools.plots

oemoflex.tools.plots.map_labels(df, labels_dict=None)

Renames columns according to the specifications in the label_dict. The data has multilevel column names. Thus, the labels_dict needs a tuple as key. The value is used as the new column name.

Parameters
  • df (pandas.DataFrame) – Dataframe with data.

  • labels_dict (dictionary) – Contains old and new column names. The new column names are used for the labels in the plot.

Returns

df – Edited dataframe with new column names.

Return type

pandas.DataFrame

oemoflex.tools.plots.prepare_dispatch_data(df, bus_name, demand_name, labels_dict=None)

The data in df is split into a DataFrame with consumers and generators and a DataFrame which only contains the demand data. Consumer data is made negative. The multilevel column names are replaced by more simple names. Columns the same name are grouped together. Really small numerical values which are practically zero are replaced with 0.0.

Parameters
  • df (pandas.DataFrame) – Dataframe with data.

  • bus_name (string) – name of the main bus to which all other are connected, e.g. the “BB-electricity” bus.

  • demand_name (string) – Name of the bus representing the demand.

  • labels_dict (dict) – Dictionary to map the column labels.

Returns

  • df (pandas.DataFrame) – DataFrame with prepared data for dispatch plotting of consumers and generators.

  • df_demand (pandas.DataFrame) – DataFrame with prepared data for dispatch plotting of demand.

oemoflex.tools.plots.filter_timeseries(df, start_date=None, end_date=None)

Filters a dataframe with a timeseries from a start date to an end date. If start_date or end_date are not given, filtering is done from the first available date or to the last available date.

Parameters
  • df (pandas.DataFrame) – Dataframe with timeseries.

  • start_date (string) – String with the start date for filtering in the format ‘YYYY-MM-DD hh:mm:ss’.

  • end_date (string) – String with the end date for filtering in the format ‘YYYY-MM-DD hh:mm:ss’.

Returns

df_filtered – Filtered dataframe.

Return type

pandas.DataFrame

oemoflex.tools.plots.stackplot(ax, df, colors_odict)

Plots data as a stackplot. The stacking order is determined by the order of labels in the colors_odict. It is stacked beginning with the x-axis as the bottom.

Parameters
  • ax (matplotlib.AxesSubplot) – Axis on which data is plotted.

  • df (pandas.DataFrame) – Dataframe with data.

  • colors_odict (collections.OrderedDictionary) – Ordered dictionary with labels as keys and colourcodes as values.

oemoflex.tools.plots.lineplot(ax, df, colors_odict)

Plots data as a lineplot.

Parameters
  • ax (matplotlib.AxesSubplot) – Axis on which data is plotted.

  • df (pandas.DataFrame) – Dataframe with data.

  • colors_odict (collections.OrderedDictionary) – Ordered dictionary with labels as keys and colourcodes as values.

oemoflex.tools.plots.plot_dispatch(ax, df, df_demand, unit, colors_odict=None)

Plots data as a dispatch plot. The demand is plotted as a line plot and suppliers and other consumers are plotted with a stackplot. Columns with negative vlaues are stacked below the x axis and columns with positive values above.

Parameters
  • ax (matplotlib.AxesSubplot) – Axis on which data is plotted.

  • df (pandas.DataFrame) – Dataframe with data except demand.

  • df_demand (pandas.DataFrame) – Dataframe with demand data.

  • unit (string) – String with unit sign of plotted data on y-axis.

  • colors_odict (collections.OrderedDictionary) – Ordered dictionary with labels as keys and colourcodes as values.

oemoflex.tools.plots.plot_dispatch_plotly(df, df_demand, unit, colors_odict=None)

Plots data as a dispatch plot in an interactive plotly plot. The demand is plotted as a line plot and suppliers and other consumers are plotted with a stackplot.

Parameters
  • df (pandas.DataFrame) – Dataframe with data except demand.

  • df_demand (pandas.DataFrame) – Dataframe with demand data.

  • unit (string) – String with unit sign of plotted data on y-axis.

  • colors_odict (collections.OrderedDictionary) – Ordered dictionary with labels as keys and colourcodes as values.

Returns

fig – Interactive plotly dispatch plot

Return type

plotly.graph_objs._figure.Figure