# floris.utilities#

Functions

 `check_and_identify_step_size`(wind_directions) This function identifies the step size in a series of wind directions. `cosd`(angle) Cosine of an angle with the angle given in degrees. `load_yaml`(filename[, loader]) `make_wind_directions_adjacent`(wind_directions) This function reorders the wind directions so that they are adjacent. `nested_get`(d, keys) Get a value from a nested dictionary using a list of keys. `nested_set`(d, keys, value[, idx]) Set a value in a nested dictionary using a list of keys. `print_nested_dict`(dictionary[, indent]) Print a nested dictionary with indentation. `pshape`(array[, label]) This function reverses the rotation of the given grid so that the coordinates are aligned with the original wind direction. `rotate_coordinates_rel_west`(wind_directions, ...) This function rotates the given coordinates so that they are aligned with West (270) rather than North (0). `round_nearest`(x[, base]) Rounds a number (with a 0.5 buffer) up to the nearest integer divisible by 5. Rounds a number (with a 0.5 buffer) up to the nearest integer divisible by 2 or 5. `sind`(angle) Sine of an angle with the angle given in degrees. `tand`(angle) Tangent of an angle with the angle given in degrees. `wind_delta`(wind_directions) This function calculates the deviation from West (270) for a given wind direction or series of wind directions. Shift the given values to within the range (-180, 180]. Shift the given values to within the range (0, 360].

Classes

 `Loader`(stream)
floris.utilities.pshape(array, label='')[source]#
Parameters:
• array (ndarray)

• label (str)

floris.utilities.cosd(angle)[source]#

Cosine of an angle with the angle given in degrees.

Args:

angle (float): Angle in degrees.

Returns:

float

floris.utilities.sind(angle)[source]#

Sine of an angle with the angle given in degrees.

Args:

angle (float): Angle in degrees.

Returns:

float

floris.utilities.tand(angle)[source]#

Tangent of an angle with the angle given in degrees.

Args:

angle (float): Angle in degrees.

Returns:

float

floris.utilities.wrap_180(x)[source]#

Shift the given values to within the range (-180, 180].

Args:

x (numeric or np.array): Scalar value or np.array of values to shift.

Returns:

np.ndarray | float | int: Shifted values.

floris.utilities.wrap_360(x)[source]#

Shift the given values to within the range (0, 360].

Args:

x (numeric or np.array): Scalar value or np.array of values to shift.

Returns:

np.ndarray | float | int: Shifted values.

floris.utilities.check_and_identify_step_size(wind_directions)[source]#

This function identifies the step size in a series of wind directions. The function will return the step size if the wind directions are evenly spaced, otherwise it will raise an error.

Args:

wind_directions (np.ndarray): Array of wind directions.

Returns:

float: The step size of the wind directions.

This function reorders the wind directions so that they are adjacent. The function will return the reordered wind directions if the wind directions are not adjacent, otherwise it will return the input wind directions

Return type:

`ndarray`[`Any`, `dtype`[`float64`]]

Parameters:

wind_directions (ndarray[Any, dtype[float64]])

Args:

wind_directions (NDArrayFloat): Array of wind directions.

Returns:

NDArrayFloat: The reordered wind directions to be adjacent.

floris.utilities.wind_delta(wind_directions)[source]#

This function calculates the deviation from West (270) for a given wind direction or series of wind directions. First, 270 is subtracted from the input wind direction, and then the remainder after dividing by 360 is retained (modulo). The table below lists examples of results.

Input | Result |
----- | ------ |
270.0 | 0.0 |
280.0 | 10.0 |
360.0 | 90.0 |
180.0 | 270.0 |
-10.0 | 80.0 |

|-100.0 | 350.0 |

Args:

wind_directions (NDArrayFloat | float): A single or series of wind directions. They can be any number, negative or positive, but it is typically between 0 and 360.

Returns:

NDArrayFloat | float: The delta between the given wind direction and 270 in positive quantities between 0 and 360. The returned type is the same as wind_directions.

Parameters:

wind_directions (ndarray[Any, dtype[float64]] | float)

floris.utilities.rotate_coordinates_rel_west(wind_directions, coordinates, x_center_of_rotation=None, y_center_of_rotation=None)[source]#

This function rotates the given coordinates so that they are aligned with West (270) rather than North (0). The rotation happens about the centroid of the coordinates.

Args:

wind_directions (NDArrayFloat): Series of wind directions to base the rotation. coordinates (NDArrayFloat): Series of coordinates to rotate with shape (N coordinates, 3)

so that each element of the array coordinates[i] yields a three-component coordinate.

x_center_of_rotation (float, optional): The x-coordinate for the rotation center of the

input coordinates. Defaults to None.

y_center_of_rotation (float, optional): The y-coordinate for the rotational center of the

input coordinates. Defaults to None.

floris.utilities.reverse_rotate_coordinates_rel_west(wind_directions, grid_x, grid_y, grid_z, x_center_of_rotation, y_center_of_rotation)[source]#

This function reverses the rotation of the given grid so that the coordinates are aligned with the original wind direction. The rotation happens about the centroid of the coordinates.

Args:

wind_directions (NDArrayFloat): Series of wind directions to base the rotation. grid_x (NDArrayFloat): X-coordinates to be rotated. grid_y (NDArrayFloat): Y-coordinates to be rotated. grid_z (NDArrayFloat): Z-coordinates to be rotated. x_center_of_rotation (float): The x-coordinate for the rotation center of the

input coordinates.

y_center_of_rotation (float): The y-coordinate for the rotational center of the

input coordinates.

Parameters:
• wind_directions (ndarray[Any, dtype[float64]])

• grid_x (ndarray[Any, dtype[float64]])

• grid_y (ndarray[Any, dtype[float64]])

• grid_z (ndarray[Any, dtype[float64]])

• x_center_of_rotation (float)

• y_center_of_rotation (float)

include(node)[source]#
yaml_constructors = {'!include': <function Loader.include>, 'tag:yaml.org,2002:binary': <function SafeConstructor.construct_yaml_binary>, 'tag:yaml.org,2002:bool': <function SafeConstructor.construct_yaml_bool>, 'tag:yaml.org,2002:float': <function SafeConstructor.construct_yaml_float>, 'tag:yaml.org,2002:int': <function SafeConstructor.construct_yaml_int>, 'tag:yaml.org,2002:map': <function SafeConstructor.construct_yaml_map>, 'tag:yaml.org,2002:null': <function SafeConstructor.construct_yaml_null>, 'tag:yaml.org,2002:omap': <function SafeConstructor.construct_yaml_omap>, 'tag:yaml.org,2002:pairs': <function SafeConstructor.construct_yaml_pairs>, 'tag:yaml.org,2002:seq': <function SafeConstructor.construct_yaml_seq>, 'tag:yaml.org,2002:set': <function SafeConstructor.construct_yaml_set>, 'tag:yaml.org,2002:str': <function SafeConstructor.construct_yaml_str>, 'tag:yaml.org,2002:timestamp': <function SafeConstructor.construct_yaml_timestamp>, None: <function SafeConstructor.construct_undefined>}#
floris.utilities.round_nearest_2_or_5(x)[source]#

Rounds a number (with a 0.5 buffer) up to the nearest integer divisible by 2 or 5.

Return type:

`int`

Parameters:

x (int | float)

Args:

x (int | float): The number to be rounded.

Returns:

int: The rounded number.

floris.utilities.round_nearest(x, base=5)[source]#

Rounds a number (with a 0.5 buffer) up to the nearest integer divisible by 5.

Return type:

`int`

Parameters:
• x (int | float)

• base (int)

Args:

x (int | float): The number to be rounded.

Returns:

int: The rounded number.

floris.utilities.nested_get(d, keys)[source]#

Get a value from a nested dictionary using a list of keys. Based on: https://stackoverflow.com/questions/14692690/access-nested-dictionary-items-via-a-list-of-keys

Return type:

`Any`

Parameters:
• d (Dict[str, Any])

• keys (List[str])

Args:

d (Dict[str, Any]): The dictionary to get the value from. keys (List[str]): A list of keys to traverse the dictionary.

Returns:

Any: The value at the end of the key traversal.

floris.utilities.nested_set(d, keys, value, idx=None)[source]#

Set a value in a nested dictionary using a list of keys. Based on: https://stackoverflow.com/questions/14692690/access-nested-dictionary-items-via-a-list-of-keys

Return type:

`None`

Parameters:
• d (Dict[str, Any])

• keys (List[str])

• value (Any)

• idx (int | None)

Args:

dic (Dict[str, Any]): The dictionary to set the value in. keys (List[str]): A list of keys to traverse the dictionary. value (Any): The value to set. idx (Optional[int], optional): If the value is an list, the index to change.

Defaults to None.

floris.utilities.print_nested_dict(dictionary, indent=0)[source]#

Print a nested dictionary with indentation.

Return type:

`None`

Parameters:
• dictionary (Dict[str, Any])

• indent (int)

Args:

dictionary (Dict[str, Any]): The dictionary to print. indent (int, optional): The number of spaces to indent. Defaults to 0.