turboflow.plot_functions module

turboflow.plot_functions.NURBS(P, p, U, u, W)[source]
turboflow.plot_functions.combine_multiple_figures(figures, labels=None, markers=None, linestyles=None, colors=None, y_labels=None)[source]

Combine multiple matplotlib figures into a single figure with custom labels, markers, linestyles, and colors.

This function extracts the lines from all axes of the given figures and plots them onto a new figure. The resulting figure contains the plots from all corresponding axes in the input figures, with custom labels, markers, linestyles, and colors applied to each line.

Parameters:
figureslist of matplotlib.figure.Figure

The list of figures to be combined.

labelslist of str, optional

The list of labels. If not provided, default labels ‘fig1’, ‘fig2’, etc. will be used.

markerslist of str, optional

The list of markers to use for the lines from each figure. If not provided, default markers will be used.

linestyleslist of str, optional

The list of linestyles to use for the lines from each figure. If not provided, default linestyles will be used.

colorslist of str, optional

The list of colors to use for the lines from each figure. If not provided, default colors will be used.

Returns:
figmatplotlib.figure.Figure

The new figure containing the combined plots.

axeslist of matplotlib.axes.Axes

The list of axes objects in the new figure.

turboflow.plot_functions.find_column(performance_data, column_name)[source]

Find the sheet containing the specified column in performance_data.

This function searches through all sheets in performance_data to find the one containing the specified column. If the column is found, it returns the name of the sheet. If the column is not found, it raises an exception.

Parameters:
performance_datadict

A dictionary containing sheets of performance data, where keys are sheet names and values are DataFrames.

column_namestr

The name of the column to find.

Returns:
str

The name of the sheet containing the specified column.

Raises:
Exception

If the specified column is not found in any sheet of performance_data.

turboflow.plot_functions.get_column(performance_data, column_name)[source]

Retrieve a column of data from performance_data.

This function retrieves the specified column of data from performance_data by finding the sheet containing the column using the find_column function. It then returns the column as a pandas Series.

Parameters:
performance_datadict

A dictionary containing sheets of performance data, where keys are sheet names and values are DataFrames.

column_namestr

The name of the column to retrieve.

Returns:
pandas.Series

The column of data corresponding to column_name.

turboflow.plot_functions.get_lines(performance_data, column_name, subsets=None)[source]

Retrieve lines of data from the specified column in performance_data.

This function returns a list of array from the specified column(s) of the performance data. If no subset is specified, it returns lines covering all rows in performance_data. If a subset is specified, it returns lines covering only the rows that match the specified subset.

Parameters:
performance_dataDataFrame

The DataFrame containing the performance data.

column_namestr or list of str

The name(s) of the column(s) from which to retrieve data.

subsetslist, optional

Name and value of subsets to get data from performance_data. First instance should be a string representing the column name, while the remaining elemnts represet the values defining the subset. Default is None.

Returns:
list

A list of arrays from the specified column(s) of performance_data.

turboflow.plot_functions.get_subset(performance_data, column_name, row_value)[source]

Retrieve the index of rows in performance_data where column_name equals row_value.

This function retrieves the index of rows in performance_data where the specified column (column_name) equals the specified value (row_value). It first finds the sheet containing the column using the find_column function, then returns the index of rows where the column has the specified value.

Parameters:
performance_datadict

A dictionary containing sheets of performance data, where keys are sheet names and values are DataFrames.

column_namestr

The name of the column to search for row_value.

row_valueobject

The value to match in column_name.

Returns:
pandas.Index

The index of rows where column_name equals row_value.

turboflow.plot_functions.load_data(filename, sheet_names=None)[source]

Load performance data from an Excel file.

This function imports an Excel file containing performance parameters. It reads the data into a dictionary named ‘performance_data’ where each key corresponds to a sheet name in the Excel file, and each value is a pandas DataFrame containing the data from that sheet. The data is rounded to avoid precision loss when loading from Excel.

Parameters:
filenamestr

The name of the Excel file containing performance parameters.

sheet_nameslist

List of the sheets to be exported. Default None extract all worksheets.

Returns:
dict

A dictionary containing performance data, where keys are sheet names and values are DataFrames.

turboflow.plot_functions.plot_axial_radial_plane(geometry)[source]

Plot the turbine geometry in an axial-radial plane.

This function plots the turbine geometry in an axial-radial plane. It takes the turbine geometry data as input, including the radii at the inner and outer hub and tip, the number of cascades, and the axial chord lengths. It then constructs and displays the plot, which represents the turbine blades in the axial-radial plane.

Parameters:
geometrydict

A dictionary containing turbine geometry data including:

  • radius_hub_in (array-like) : Inner hub radii at each cascade.

  • radius_hub_out (array-like) : Outer hub radii at each cascade.

  • radius_tip_in (array-like) : Inner tip radii at each cascade.

  • radius_tip_out (array-like) : Outer tip radii at each cascade.

  • number_of_cascades (int) : Number of cascades in the turbine.

  • axial_chord (array-like) : Axial chord lengths at each cascade.

Returns:
matplotlib.figure.Figure

The generated figure.

matplotlib.axes.Axes

The generated axes.

turboflow.plot_functions.plot_blade_profile(blade_parameters)[source]

Python version of the MATLAB function [x, y] = plot_blade_profile(blade_parameters).

Given a dictionary blade_parameters with:

chord, stagger, theta_in, theta_out, wedge_in, wedge_out, radius_in, radius_out, d1, d2, d3, d4

it computes the shape of a 2D blade profile (x, y) by connecting four NURBS segments:

  1. Leading edge arc (between points 1 and 2)

  2. Spline from point 2 to point 3

  3. Trailing edge arc (between points 3 and 4)

  4. Spline from point 4 back to point 1

turboflow.plot_functions.plot_convergence_process(data, plot_together=True, colors=None, linestyles=None, labels=None, linewidth=1.5, fontsize=12)[source]

Plots the convergence process for multiple optimization algorithms.

Parameters:
datadict

A dictionary where each key is the algorithm name and the value is another dictionary with the following keys: - ‘objective’ : list

List of objective values at each iteration.

  • ‘constraint_violation’list

    List of constraint violations at each iteration.

  • ‘iterations’list

    List of iteration counts corresponding to the objective values and constraint violations.

plot_togetherbool, optional

If True, plots the objective value and constraint violation in separate subplots in the same figure. If False, plots them in separate figures. Default is True.

colorslist, optional

List of colors for the lines, one for each algorithm. If None, default colors are used.

linestyleslist, optional

List of linestyles for the lines, one for each algorithm. If None, default linestyles are used.

labelslist, optional

List of labels for the legend, one for each algorithm. If None, the dictionary keys are used as labels.

Returns:
figmatplotlib.figure.Figure

The figure object containing the plots.

axmatplotlib.axes.Axes or list of Axes

The axes object(s) containing the plots. If plot_together=True, a list of two axes is returned. Otherwise, a single axes object is returned.

Notes

The function creates either one or two subplots depending on the plot_together parameter. It also customizes the plots using the provided colors, linestyles, and labels.

turboflow.plot_functions.plot_lines(performance_data, x_key, y_keys, subsets=None, fig=None, ax=None, xlabel='', ylabel='', title='', labels=None, filename=None, outdir='figures', stack=False, color_map='viridis', colors=None, close_fig=False, save_figs=False, linestyles=None, markers=None, save_formats=['.png'], legend_loc='best')[source]

Plot lines from performance data.

This function plots lines from performance data. It supports plotting multiple lines on the same axes with customizable labels, colors, and linestyles. The resulting plot can be saved to a file if desired.

Parameters:
performance_dataDataFrame

The performance data to plot.

x_keystr

Name of the column in performance_data to be used as x-axis values.

y_keyslist of str

Names of the columns in performance_data to be plotted.

subsetslist, optional

Name and value of subsets to plot from performance_data. First instance should be a string representing the column name, while the remaining elemnts represet the values defining the subset. Default is None.

figmatplotlib.figure.Figure, optional

An existing figure object. If None, a new figure is created.

axmatplotlib.axes.Axes, optional

An existing axes object. If None, a new axes is created.

xlabelstr, optional

The label for the x-axis.

ylabelstr, optional

The label for the y-axis.

titlestr, optional

The title of the plot.

labelslist of str, optional

Labels for the plotted lines. Default is None.

filenamestr, optional

The filename for saving the figure. Default is None.

outdirstr, optional

The directory where figures should be saved. Default is ‘figures’.

stackbool, optional

Whether to stack the plotted lines. Default is False.

color_mapstr, optional

The colormap used for the lines. Default is ‘viridis’.

colorslist of str or colors, optional

Colors for the plotted lines. Default is None.

close_figbool, optional

Whether to close the figure after plotting. Default is False.

save_figsbool, optional

Whether to save the figure. Default is False.

linestyleslist of str, optional

Linestyles for the plotted lines. Default is None.

save_formatslist of str, optional

File formats for saving the figure. Default is [‘.png’].

legend_locstr, optional

Location for the legend. Default is ‘best’.

Returns:
matplotlib.figure.Figure

The figure object.

matplotlib.axes.Axes

The axes object.

turboflow.plot_functions.plot_optimization_results(initial_guess, lower_bounds, upper_bounds, final_solutions, markers=None, colors=None, fig=None, ax=None, labels=None, variable_names=None, fontsize=12, markersizes=6)[source]

Plots the relative change from the initial guess for each variable, along with the bounds as an error bar style plot.

Parameters:
initial_guessnp.ndarray

Array of initial guesses for the design variables.

lower_boundslist of float

List of lower bounds for each design variable.

upper_boundslist of float

List of upper bounds for each design variable.

final_solutionslist of np.ndarray

List of arrays where each array represents a set of final optimized design variables.

markerslist of str, optional

List of markers to use for each set of final solutions. Default is ‘o’.

colorslist of str, optional

List of colors to use for each set of final solutions. Default is ‘b’, ‘g’, ‘r’, etc.

figmatplotlib.figure.Figure, optional

Matplotlib Figure object. If not provided, a new figure will be created.

axmatplotlib.axes.Axes, optional

Matplotlib Axes object. If not provided, a new axes will be created.

Returns:
figmatplotlib.figure.Figure

The Figure object containing the plot.

axmatplotlib.axes.Axes

The Axes object containing the plot.

Examples

>>> initial_guess = np.array([1.0, 2.0, 3.0])
>>> lower_bounds = [0.5, 1.0, 2.0]
>>> upper_bounds = [1.5, 3.0, 4.0]
>>> final_solutions = [np.array([1.1, 2.5, 2.8]), np.array([0.9, 2.1, 3.2])]
>>> fig, ax = plot_optimization_results(initial_guess, lower_bounds, upper_bounds, final_solutions)
>>> plt.show()
turboflow.plot_functions.plot_velocity_triangle(fig, ax, start_x, start_y, w_t, v_t, v_m, w_m, hs=10, fontsize=12, lines='all', color=None, linestyle=None, cascade='', label='')[source]
turboflow.plot_functions.plot_velocity_triangle_stage(plane, fig=None, ax=None, color=None, linestyle=None, label='', fontsize=12, hs=15, start_y=0, start_x=0, dy=0.1, dx=0)[source]

Plot velocity triangles for each stage of a turbine.

Parameters:
planepandas.DataFrame

A DataFrame containing velocity components for each plane of the turbine. The DataFrame should have the following keys: - ‘v_m’: Meridional velocities. - ‘v_t’: Tangential velocities. - ‘w_m’: Meridional velocities of relative motion. - ‘w_t’: Tangential velocities of relative motion.

Returns:
matplotlib.figure.Figure

The matplotlib figure object containing the velocity triangle plot.

matplotlib.axes._subplots.AxesSubplot

The matplotlib axis object containing the velocity triangle plot.

turboflow.plot_functions.plot_velocity_triangles_planes(plane)[source]

Plot velocity triangles for each plane of a turbine.

Parameters:
planepandas.DataFrame

A DataFrame containing velocity components for each plane of the turbine. The DataFrame should have the following keys: - ‘v_m’: Meridional velocities. - ‘v_t’: Tangential velocities. - ‘w_m’: Meridional velocities of relative motion. - ‘w_t’: Tangential velocities of relative motion.

Returns:
matplotlib.figure.Figure

The matplotlib figure object containing the velocity triangle plot.

matplotlib.axes._subplots.AxesSubplot

The matplotlib axis object containing the velocity triangle plot.

turboflow.plot_functions.plot_view_axial_tangential(problem_structure, fig=None, ax=None, repeats=3, color='k', linestyle='-', label='')[source]

Optional: Python version of the MATLAB function plot_view_axial_tangential. Demonstrates how a multi-stage turbine might be visualized in an axial-tangential view, using repeated calls to plot_blade_profile for rotor/stator rows.

turbine_data is a dictionary expected to have structure:
turbine_data[‘cascade’] = list of dicts, each with
{

‘s’: …, # pitch ‘cs’: …, # spacing between cascades ‘c’: …, # chord ‘b’: …, # axial spacing ‘stagger’: …, ‘theta_in’: …, ‘theta_out’: …, ‘t_max’: …, ‘t_te’: …,

}

turbine_data[‘overall’] = {

‘axial_length’: …, ‘n_stages’: …,

} turbine_data[‘stage’] = {

‘R’: [reaction_values],

}

This function is included mainly to show how one might replicate the high-level plotting. It references internal design logic that is specific to your original MATLAB code.

turboflow.plot_functions.savefig_in_formats(fig, path_without_extension, formats=['.png', '.svg', '.pdf', '.eps'])[source]

Save a given matplotlib figure in multiple file formats.

Parameters:
figmatplotlib.figure.Figure

The figure object to be saved.

path_without_extensionstr

The full path to save the figure excluding the file extension.

formatslist of str, optional

A list of string file extensions to specify which formats the figure should be saved in. Default is [‘.png’, ‘.svg’, ‘.pdf’, “.eps”].

Examples

>>> import matplotlib.pyplot as plt
>>> fig, ax = plt.subplots()
>>> ax.plot([0, 1], [0, 1])
>>> save_fig_in_formats(fig, "/path/to/figure/filename")

This will save the figure as “filename.png”, “filename.svg”, and “filename.pdf” in the “/path/to/figure/” directory.