Utilities
General-purpose utilities for TopFarm.
- class topfarm.utils.LogSumExpMax(base=1)[source]
Bases:
SmoothMaxLogSumExp
Overpredict the maximum of similar values
- class topfarm.utils.LogSumExpMin(base=1)[source]
Bases:
LogSumExpMax
- class topfarm.utils.SmoothMax(base=1)[source]
Bases:
AggregationFunction
- class topfarm.utils.StrictMax[source]
Bases:
AggregationFunctionNormal max with discontinous gradient
- topfarm.utils.regular_generic_layout(n_wt, sx, sy, stagger, rotation, x0=0, y0=0, ratio=1.0)[source]
- Parameters:
n_wt (int) – number of wind turbines
sx (float) – spacing (in turbine diameters or meters) between turbines in x direction
sy (float) – spacing (in turbine diameters or meters) between turbines in y direction
stagger (float) – stagger (in turbine diameters or meters) distance every other turbine column
rotation (float) – rotational angle of the grid in degrees
ratio (float) – ratio between number of columns and number of rows (1.0)
- Returns:
xy – 2D array of x- and y-coordinates (in turbine diameters or meters)
- Return type:
array
- topfarm.utils.regular_generic_layout_gradients(n_wt, sx, sy, stagger, rotation, x0=0, y0=0, ratio=1.0)[source]
- Parameters:
n_wt (int) – number of wind turbines
sx (float) – spacing (in turbine diameters or meters) between turbines in x direction
sy (float) – spacing (in turbine diameters or meters) between turbines in y direction
stagger (float) – stagger (in turbine diameters or meters) distance every other turbine column
rotation (float) – rotational angle of the grid in degrees
ratio (float) – ratio between number of columns and number of rows (1.0)
- Returns:
dx_dsx, dy_dsx, dx_dsy, dy_dsy, dx_dr, dy_dr – tuple of gradients of x and y with respect to x-spacing, y-spacing and grid rotation
- Return type:
- topfarm.utils.smart_start(XX, YY, ZZ, N_WT, min_space, radius=None, random_pct=0, plot=False, seed=None, types=None, show_progress=True)[source]
Selects the a number of gridpoints (N_WT) in the grid defined by x and y, where ZZ has the maximum value, while chosen points spacing (min_space) is respected.
- Parameters:
XX (array_like) – x coordinates
YY (array_like) – y coordinates
ZZ (array_like) – Values at (XX, YY) of the desired variable in the grid points. This could be e.g. the AEP or wind speed.
N_WT (integer) – number of wind turbines
min_space (float) – minimum space between turbines
random_pct (float) – select by random position of the <random_pct> best points
plot (boolean) – if True, each step is plotted in new figure
types (array_like of integers or None) – list of turbine type numbers e.g. types = [0, 1, 2, 3] for 4 different types. ZZ, min_space and optionally also radius should also have type dimension. if ZZ is callable it should be callable with type argument.
- Returns:
Positions where the aep or wsp is highest, while
respecting the minimum spacing requirement.
Notes
XX, YY and ZZ can be 1D or 2D, but must have same size. If multiple turbine types ZZ must have the shape (n_types, shape_like_XX)
- topfarm.utils.smooth_max(X, alpha, axis=0)[source]
Returns the smooth maximum of a matrix for positive values of alpha and smoth minimum for negative values of alpha :param X: Matrix of which the smooth maximum is calculated. :type X: ndarray :param alpha: smoothness parameter. :type alpha: float :param axis: Axis along which the smooth maximum is calculated. The default is 0. :type axis: int, optional
- Returns:
Matrix of smooth maximum values.
- Return type:
ndarray
- topfarm.utils.smooth_max_gradient(X, alpha, axis=0)[source]
- Parameters:
- Returns:
Matrix of smooth maximum derivatives.
- Return type:
ndarray
- topfarm.utils.smooth_zero(X, alpha=1, axis=0)[source]
Function that from an array approximates the value cloest to zero. A differentiable alternative to min(abs(X)). :param X: Matrix of which the smooth zero is calculated. :type X: ndarray :param alpha: smoothness parameter. :type alpha: float :param axis: Axis along which the smooth zero is calculated. The default is 0. :type axis: int, optional
- Returns:
Matrix of smooth zero.
- Return type:
ndarray
- topfarm.utils.smooth_zero_gradient(X, alpha=1, axis=0)[source]
Gradients of the smooth_zero function. :param X: Matrix of which the smooth zero derivative is calculated. :type X: ndarray :param alpha: smoothness parameter. :type alpha: float :param axis: Axis along which the smooth zero is calculated. The default is 0. :type axis: int, optional
- Returns:
Matrix of smooth zero derivatives.
- Return type:
ndarray