meteodatalab.operators.lateral_operators¶
Lateral operators.
Functions
|
Compute the conditional mask for which the convolution results are valid. |
|
Compute weights for a convolution kernel. |
|
Compute disk average. |
|
Fill undefined values. |
- meteodatalab.operators.lateral_operators.compute_cond_mask(windows: DataArray, weights: DataArray, frac_val: float, nx: int, ny: int) DataArray [source]¶
Compute the conditional mask for which the convolution results are valid.
The function computes the ratio of undefined values to the total number values in the convolution window. The computational domain and the window shape are both taken into account. The mask is true for locations where the ratio is above the given threshold.
- Parameters:
windows (xarray.DataArray) – Values of the constructed windows for the application of the convolution.
weights (xarray.DataArray) – Weights of the convolution kernel.
frac_val (float) – Threshold on the ratio of undefined values.
nx (int) – Size of the field in the x dimension.
ny (int) – Size of the field in the y dimension.
- Returns:
Boolean mask indicating where the undefined value ratio in the convolution kernel is within the acceptable threshold.
- Return type:
xarray.DataArray
- meteodatalab.operators.lateral_operators.compute_weights(window_size: int, window_type: Literal['exp', 'const'], window_shape: Literal['disk', 'square']) DataArray [source]¶
Compute weights for a convolution kernel.
- Parameters:
window_size (int) – Number of grid cells the kernel. Must be an odd number.
window_type ({"exp", "const"}) –
The window type.
- Supported types:
exp: Exponential drop from the center of the window.
const: All weights are set to 1.
window_shape ({"disk", "square"}) –
The window shape.
- Supported shapes:
disk: The kernel is confined to the circle inscribing the window.
square: The kernel is defined on the entire window.
- Raises:
ValueError – if window_size is not an odd number.
- Returns:
Weights corresponding to the window_type within the given window_shape and zero outside of the shape.
- Return type:
xarray.DataArray
- meteodatalab.operators.lateral_operators.disk_avg(field: DataArray, radius: int) DataArray [source]¶
Compute disk average.
- Parameters:
field (xarray.DataArray) – Input field.
radius (int) – Radius of the convolution window.
- Return type:
xarray.DataArray
- meteodatalab.operators.lateral_operators.fill_undef(field: DataArray, radius: int, frac_val: float) DataArray [source]¶
Fill undefined values.
Replace undefined values with a value derived from neighbourhood. The values are obtained by applying a Gaussian filter to the field around the undefined elements.
- Parameters:
field (xarray.DataArray) – Input field.
radius (int) – Radius of the convolution window.
frac_val (float) – Threshold of acceptable ratio of undefined values in window. If the ratio of undefined to total elements in the window is below the threshold then the output value remains undefined.
- Returns:
Input field with undefined values replaced by values derived from neighbourhood.
- Return type:
xarray.DataArray