"""LINCOM wind class
Here we define a structure for defining the input wind to LINCOM. This is typically the
first step in creating a LINCOM study.
"""
import numpy as np
from windkit.xarray_structures.metadata import _update_history, _ALL_VARS_META
from windkit.spatial import create_dataset, _get_latitude
from windkit import _create_direction_coords
_lincom_wind_type = {
"geostrophic": 1,
"generalized": 2,
"observed": 3,
}
[docs]
def create_wind(
wind_type,
speed,
height,
roughness,
west_east,
south_north,
crs,
direction=None,
n_sectors=12,
):
"""Creates an xarray object defining the input wind for a LINCOM simulation
.. warning::
This function is experimental and its signature may change.
Parameters
----------
wind_type: str
Type of LINCOM wind to create, can be one of "geostropic", "generalized", or
"observed"
speed: float
The wind speed to store at each location
height: float
Height of the wind
roughness: float
Roughness length for the wind
west_east, south_north: float
Location for the wind
crs : int, dict, str or CRS
Value to create pyproj.CRS object or an existing pyproj.CRS object
direction: float, optional
Direction of the wind (degrees), by default None. If None, then n_sectors will be
used otherwise direction is use.
n_sectors: int, optional
Number of sectors to apply the wind to, by default 12. Only used if direction is
None.
Returns
-------
xarray.Dataset
Dataset containing a representation of the wind
"""
########################
# Define wind direction
########################
if direction is None:
sec = _create_direction_coords(n_sectors)
else:
sec = _create_direction_coords(directions=direction)
###############################
# Get latitude by reprojection
###############################
# Always either raster or stacked point
wind_ds = create_dataset(west_east, south_north, 0, crs, "stacked_point").drop_dims(
"height"
)
wind_ds = wind_ds.assign_coords({**sec.coords})
lat = _get_latitude(wind_ds)
wind_ds["wind_speed"] = (
("sector"),
np.full(sec.size, speed),
_ALL_VARS_META["wind_speed"],
)
wind_ds.attrs = {
**wind_ds.attrs,
"title": "LINCOM input wind",
"z0": roughness,
"wind_height": height,
"type": _lincom_wind_type[wind_type],
"type_str": wind_type,
"latitude": lat,
}
return _update_history(wind_ds)