omegalpes.general.utils package
Submodules
omegalpes.general.utils.input_data module
This module includes the following utils for input data management
- It contains the following methods:
select_csv_file_between_dates() : select data in a .csv file between two dates
read_enedis_data_csv_file() : select and rearrange the data in a .csv file of Enedis (the French Distribion System Operator company), possibly between two dates
- omegalpes.general.utils.input_data.read_enedis_data_csv_file(file_path=None, start=None, end=None)[source]
Rearrange the Enedis data in cvs file in oder to have a Dataframe of the following form
DD MM YYYY HH:00 ; a DD MM YYYY HH:30 ; b …
- Parameters:
file_path – path of the file to rearrange
start – DD MM YYYY HH:00 : first date which should be considered
end – DD MM YYYY HH:00 : last date which should be considered
- Returns:
df_list: the data as a list
- omegalpes.general.utils.input_data.resample_data(input_list=None, dt_origin=1.0, dt_final=1.0, fill_config='ffill', pick_config='mean')[source]
Changing data set in a dt_origin time step into data set in a dt_final time step :param input_list: list to be resample (list or dict) :param dt_origin: the time step of the input dataset (in hours) :param dt_final: the wanted time step for the output dataset (in hours) :param fill_config: choose the configuration of filling when dt_origin > dt_final by default: ffil, keeping the same data over the time steps other way: interpolate, taking into account the time steps) :param pick_config: choose the configuration of picking when dt_origin < dt_final by default: “mean” which determines the mean value of the time steps to be reduced :return: output_list: resampled list (pandas Series)
- omegalpes.general.utils.input_data.select_csv_file_between_dates(file_path=None, start='DD/MM/YYYY HH:MM', end='DD/MM/YYYY HH:MM', v_cols=[], sep=';')[source]
Select data in a .csv file between two dates
- Parameters:
file_path – path of the file to rearrange
start – DD MM YYYY HH:00 : first date which should be considered
end – DD MM YYYY HH:00 : last date which should be considered
v_cols – columns which should be considered
- Returns:
df: a dataframe considering the dates
omegalpes.general.utils.maths module
This module includes the following maths utils
- It contains the following methods:
def_abs_value() : Define easily absolute value for quantity
- omegalpes.general.utils.maths.def_abs_value(quantity, q_min, q_max)[source]
- Parameters:
quantity – Quantity whose absolute value is wanted
q_min – Minimal value of the quantity (negative value)
q_max – Maximal value of the quantity (positive value)
- Returns:
A new Quantity whose values equal absolute values of the initial Quantity
omegalpes.general.utils.output_data module
This module includes the following utils for output data management
- It contains the following methods:
save_energy_flows() : Save the optimisation results in a .csv file
- omegalpes.general.utils.output_data.save_energy_flows(*nodes, file_name=None, sep='\t', decimal_sep='.')[source]
Save the optimisation results in a .csv file
- Parameters:
nodes – one or several nodes from which should be collected the data
file_name – name of the file to save the data
sep – separator for the data
decimal_sep – separator dor the decimals of the data
omegalpes.general.utils.plots module
This module includes the following display utils:
plot_node_energy_flows() : enables one to plot the energy flows through an EnergyNode
plot_energy_mix() : enables one to plot the energy flows connected to a node
plot_pareto2D() : enables one to plot a pareto front based on two quantities
plot_quantity() : enables one to plot easily a Quantity
plot_quantity_bar() : enables one to plot easily a Quantity as a bar
sum_quantities_in_quantity() : enables one to to plot several quantities in one once the optimisation is done
- class omegalpes.general.utils.plots.Backend(*values)[source]
Bases:
str,EnumSupported rendering backends.
- MATPLOTLIB = 'matplotlib'
- PLOTLY = 'plotly'
- class omegalpes.general.utils.plots.FigureOptions(figsize: Tuple[float, float] | None = None, save_png: bool = False, save_path: str | Path | None = None, fontsize: int | None = None, dpi: int = 96)[source]
Bases:
objectPortable figure size and PNG export settings accepted by every plotting functions in this module
- Parameters:
figsize –
(width, height)in inches.Matplotlib – passed directly to
plt.subplots(figsize=...).Plotly – converted to pixels at dpi and applied via
fig.update_layout(width=..., height=...).
Nonekeeps each backend’s own default size.save_png – When
Truethe finished figure is written to disk as a PNG. Requires save_path to be provided.save_path – Destination file path for the PNG. The
.pngextension is appended automatically if absent. Parent directories are created on demand.dpi –
Dots-per-inch used when saving the figure (both backends) and when converting figsize inches → Plotly pixels. Defaults to
150for crisp exports.Note
Plotly PNG export requires the
kaleidopackage:pip install kaleido
Examples
>>> opts = FigureOptions(figsize=(12, 4), save_png=True, ... save_path="out/flows.png", dpi=200) >>> fig = plot_node_energy_flows(node, fig_opts=opts) >>> fig.show()
- dpi: int = 96
- figsize: Tuple[float, float] | None = None
- fontsize: int | None = None
- property mpl_figsize: Tuple[float, float] | None
figsizeready forplt.subplots(figsize=...), orNone.
- property plotly_wh: Tuple[int | None, int | None]
(width_px, height_px)for Plotly, or(None, None).
- property resolved_save_path: Path | None
Resolved
Pathwith.pngsuffix, orNone.
- save_path: str | Path | None = None
- save_png: bool = False
- omegalpes.general.utils.plots.plot_energy_mix(node: EnergyNode, interactive: bool = False, fig_opts: FigureOptions = FigureOptions(figsize=None, save_png=False, save_path=None, fontsize=None, dpi=96))[source]
Description
This function allows to plot the energy flows through an EnergyNode
The display is realized :
with stacked bars for production and storage flow
with dotted lines for consumption and export flow
- Parameters:
node (EnergyNode) – The node whose flows are to be visualised.
interactive (bool) – When True, uses Plotly; otherwise Matplotlib.
- Raises:
TypeError – If node is not an EnergyNode.
ValueError – If no production units are connected to node.
Examples:
opts = FigureOptions(figsize=(14, 5), save_png=True, save_path="results/flows.png", dpi=200) fig = plot_energy_mix(node, interactive=True, fig_opts=opts) fig.show()
- omegalpes.general.utils.plots.plot_node_energy_flows(node: EnergyNode, interactive: bool = False, fig_opts: FigureOptions = FigureOptions(figsize=None, save_png=False, save_path=None, fontsize=None, dpi=96))[source]
Description
This function allows to plot the energy flows through an EnergyNode
The display is realized :
with stacked bars for production and storage flow
with dotted lines for consumption and export flow
- Parameters:
node (EnergyNode) – The node whose flows are to be visualised.
interactive (bool) – When True, uses Plotly; otherwise Matplotlib.
- Raises:
TypeError – If node is not an EnergyNode.
Examples:
opts = FigureOptions(figsize=(14, 5), save_png=True, save_path="results/flows.png", dpi=200) fig = plot_node_energy_flows(node, interactive=True, fig_opts=opts) fig.show()
- omegalpes.general.utils.plots.plot_pareto2D(model, quantity_1, quantity_2, title=None, legend_on=True, interactive=False, fig_opts=FigureOptions(figsize=None, save_png=False, save_path=None, fontsize=None, dpi=96))[source]
Description
Plot a Pareto front for two quantities. Before using it, you should have added in your model two objectives with the pareto parameter activated (pareto=True)
Parameters
- Parameters:
model
quantity_1 – the first quantity for the pareto front
quantity_2 – the second quantity for the pareto front
title – Optional figure title; auto-generated when
Nonelegend_on – Whether to annotate each Pareto point with its run index.
interactive – Selects the Plotly backend when
True.fig_opts – FigureOptions controlling figure size and PNG export
- omegalpes.general.utils.plots.plot_quantity(time, quantity, fig=None, ax=None, color=None, label=None, xlabel=None, ylabel=None, title=None, interactive=False, fig_opts=FigureOptions(figsize=None, save_png=False, save_path=None, fontsize=None, dpi=96))[source]
Description
Function that plots a OMEGAlpes.general.optimisation.elements.Quantity
Parameters
time: TimeUnit for the studied horizon as defined in general.time
quantity: OMEGAlpes.general.optimisation.elements.Quantity
fig: Figure as defined in matplotlib.pyplot.Figure
ax: axes as defined in matplotlib.pyplot.Axes
color: color of the plot
label: label for the quantity
title: title of the plot
interactive: Boolean for interactive plot
fig_opts: FigureOptions controlling figure size and PNG export
Returns
arg1 the matplotlib.pyplot.Figure handle object
arg2 the matplotlib.pyplot.Axes handle object
arg3 the matplotlib.pyplot.Line2D handle object
- omegalpes.general.utils.plots.plot_quantity_bar(time, quantity, fig=None, ax=None, color=None, label=None, xlabel=None, ylabel=None, title=None, interactive=False, fig_opts=FigureOptions(figsize=None, save_png=False, save_path=None, fontsize=None, dpi=96))[source]
Description
Function that plots a OMEGALPES.general.optimisation.elements.Quantity as a bar
Attributes
time: TimeUnit for the studied horizon as defined in general.time
quantity: OMEGAlpes.general.optimisation.elements.Quantity
fig: Existing figure to draw into; backend is inferred from its type.
ax: Existing Matplotlib
Axes(ignored for the Plotly backend).color: color of the plot
label: label for the quantity
title: title of the plot
interactive: Boolean for interactive plot
fig_opts: FigureOptions controlling figure size and PNG export
Returns
arg1 the matplotlib.pyplot.Figure handle object
arg2 the matplotlib.pyplot.Axes handle object
arg3 the matplotlib.pyplot.Line2D handle object
- omegalpes.general.utils.plots.sum_quantities_in_quantity(quantities_list=[], tot_quantity_name='sum_quantity')[source]
Description
Function that creates a new quantity gathering several values of quantities Should be used in order to plot several quantities in one once the optimisation is done
- Attributes
quantities_list: a list of Quantities (OMEGALPES.general.optimisation.elements.Quantity)
tot_quantity_name: string : name of the new quantity
- Returns
tot_quantity: the new quantity created and filled
- Raises
ValueError: If quantities_list is empty, or units / lengths are inconsistent.
TypeError: If an element is not a
Quantity.