-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
plots: Revise plotting function interfaces to return JSON string easily
- Loading branch information
1 parent
3bcc12a
commit 16f9183
Showing
6 changed files
with
126 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,13 @@ | ||
"""Plotting function collection.""" | ||
|
||
from .plots import plot_to_figure, plot_to_file, plot_to_json | ||
from .time_series import ( | ||
der_active_power_time_series, | ||
der_reactive_power_time_series, | ||
der_apparent_power_time_series, | ||
der_aggregated_active_power_time_series, | ||
der_aggregated_reactive_power_time_series, | ||
der_aggregated_apparent_power_time_series, | ||
node_voltage_per_unit_time_series, | ||
der_aggregated_reactive_power_time_series, | ||
der_apparent_power_time_series, | ||
der_reactive_power_time_series, | ||
node_aggregated_voltage_per_unit_time_series, | ||
node_voltage_per_unit_time_series, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
"""Interfaces to plotting functions.""" | ||
|
||
import pathlib | ||
from typing import Callable | ||
|
||
import plotly.graph_objects as go | ||
|
||
from mesmo import data_models | ||
from mesmo.plots import plot_utils | ||
|
||
|
||
def plot_to_figure( | ||
*plot_functions: Callable[[go.Figure, data_models.RunResults], go.Figure], results: data_models.RunResults | ||
) -> go.Figure: | ||
"""Generate new plotly figure and apply given plotting function(s) for given run results. | ||
Args: | ||
Callable: Plotting function | ||
data_models.RunResults: MESMO run results as input for the plotting function | ||
Returns: | ||
go.Figure: Plotly figure containing the generated plot | ||
""" | ||
figure = go.Figure() | ||
for plot_function in plot_functions: | ||
figure = plot_function(figure, results) | ||
return figure | ||
|
||
|
||
def plot_to_json( | ||
*plot_functions: Callable[[go.Figure, data_models.RunResults], go.Figure], results: data_models.RunResults | ||
) -> str: | ||
"""Generate new plotly figure and apply given plotting function(s) for given run results. Output the final figure | ||
as JSON string. | ||
Args: | ||
Callable: Plotting function | ||
data_models.RunResults: MESMO run results as input for the plotting function | ||
Returns: | ||
str: JSON string containing the generated plot | ||
""" | ||
return plot_utils.get_plotly_figure_json(plot_to_figure(*plot_functions, results=results)) | ||
|
||
|
||
def plot_to_file( | ||
*plot_functions: Callable[[go.Figure, data_models.RunResults], go.Figure], | ||
results: data_models.RunResults, | ||
results_path: pathlib.Path, | ||
): | ||
"""Generate new plotly figure and apply given plotting function(s) for given run results. Out put the final figure | ||
to file. | ||
Args: | ||
Callable: Plotting function | ||
data_models.RunResults: MESMO run results as input for the plotting function | ||
pathlib.Path: Results file output path | ||
""" | ||
filename = plot_functions[0].__name__ | ||
plot_utils.write_plotly_figure_file( | ||
plot_to_figure(*plot_functions, results=results), results_path=results_path / filename | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters