Source code for pywasp.lincom.wind

"""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
import xarray as xr

from windkit.metadata import ALL_VARS_META, update_history
from windkit.spatial import create_dataset, get_latitude
from windkit.sector import create_direction_coords


_lincom_wind_type = {
    "geostrophic": 1,
    "generalized": 2,
    "observed": 3,
}


[docs] def create_wind(wind_type, speed, w_height, z0, we, sn, srs, direction=None, nsec=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 w_height: float Height of the wind z0: float Roughness length for the wind we, sn: float Location for the wind srs : 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 nsec will be used otherwise direction is use. nsec: 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(nsec) else: sec = create_direction_coords(direction=direction) ############################### # Get latitude by reprojection ############################### # Always either raster or stacked point wind_ds = create_dataset(we, sn, 0, srs, "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": z0, "wind_height": w_height, "type": _lincom_wind_type[wind_type], "type_str": wind_type, "latitude": lat, } return update_history(wind_ds)