Utilities

General-purpose utilities for TopFarm.

class topfarm.utils.AggregationFunction[source]

Bases: ABC

abstract gradient(x, axis=-1)[source]

compute gradients of aggregated value wrt x over axis

class topfarm.utils.LogSumExpMax(base=1)[source]

Bases: SmoothMax

LogSumExp

Overpredict the maximum of similar values

Parameters:

base (float) – smoothing factor ]0;inf[. higher number gives more smooth transition For two numbers, (a,b), the smoothing approximately starts when |a-b| < 4*base

gradient(x, axis=-1)[source]

compute gradients of aggregated value wrt x over axis

class topfarm.utils.LogSumExpMin(base=1)[source]

Bases: LogSumExpMax

class topfarm.utils.SmoothMax(base=1)[source]

Bases: AggregationFunction

gradient(x, axis=-1)[source]

compute gradients of aggregated value wrt x over axis

class topfarm.utils.SmoothMin(base=1)[source]

Bases: SmoothMax

topfarm.utils.SoftMax(x, alpha, axis=-1)[source]

gradient of LogSumExpMax

https://en.wikipedia.org/wiki/Softmax_function

class topfarm.utils.StrictMax[source]

Bases: AggregationFunction

Normal max with discontinous gradient

gradient(x, axis=-1)[source]

compute gradients of aggregated value wrt x over axis

class topfarm.utils.StrictMin[source]

Bases: StrictMax

Normal min with discontinous gradient

topfarm.utils.downsample_ts(ws, wd, timestamps, start=None, end=None, freq='D')[source]
topfarm.utils.fit_sectorwise_weib(ws, wd, n_sectors=12)[source]
topfarm.utils.fit_weib(u)[source]
topfarm.utils.gauss(X)[source]
topfarm.utils.gauss_inv(X)[source]
topfarm.utils.gauss_inv_prime(X)[source]
topfarm.utils.gauss_prime(X)[source]
topfarm.utils.is_number(s)[source]
topfarm.utils.main()[source]
topfarm.utils.plot_list_recorder(recorder, x='counter', dont_plot=[])[source]
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:

tuple

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:
  • X (ndarray) – Matrix of which the smooth maximum derivative is calculated.

  • alpha (float) – smoothness parameter.

  • axis (int, optional) – Axis along which the smooth maximum is calculated. The default is 0. The default is 0.

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