API¶
oemoflex.model.datapackage¶
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, linewidth=1)¶
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.
linewidth (float) – Width of the line - set by default to 1.
- oemoflex.tools.plots.plot_dispatch(ax, df, df_demand, unit, colors_odict=None, linewidth=1)¶
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.
linewidth (float) – Width of the line - set by default to 1.
- 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
- oemoflex.tools.plots.plot_grouped_bar(ax, df, color_dict, unit, stacked=False)¶
This function plots scalar data as grouped bar plot. The index of the DataFrame will be interpreted as groups (e.g. regions), the columns as different categories (e.g. energy carriers) within the groups which will be plotted in different colors.
- Parameters
ax (matplotlib Axes object) – Axes to draw the plot.
df (pd.DataFrame) – DataFrame with an index defining the groups and columns defining the bars of different color within the group.
color_dict (dict) – Dictionary defining colors of the categories
unit (str) – Unit of the variables.
stacked (boolean) – Stack bars of a group. False by default.