pylawr.transform.spatial#
Filter to apply/remove the beam expansion effect to/from a reflectivity field. |
|
This class can be used to fill holes within a radar field with given remapping algorithm. |
pylawr.transform.spatial.BeamExpansion#
- class pylawr.transform.spatial.BeamExpansion[source]#
Bases:
TransformerFilter to apply/remove the beam expansion effect to/from a reflectivity field. See radartutorial.eu for reference.
This filter basically just does
\[input \cdot R ^ 2\]in the forward direction and
\[\frac{input}{R ^ 2}\]in the inverse direction.
- _abc_impl = <_abc._abc_data object>#
- static _determine_inv(array)[source]#
Method to determine the transform direction if no inverse is given.
- Parameters
array (
xarray.DataArray) – The linear reflectivity array to operate on.- Returns
inverse – The direction of the transformation with apply if False or removed if True.
- Return type
- transform(array, grid=None, inverse=None, *args, **kwargs)[source]#
Apply (or remove if
inverse=True) the beam expansion effect from a givenarray.Tag the array with
TAG_BEAM_EXPANSION_CORRorTAG_BEAM_EXPANSION_UNCORRaccordingly.- Parameters
array (
xarray.DataArray) – The linear reflectivity array to operate on.grid (child of
pylawr.grid.base.BaseGridor None) – This grid is used to determine the distance to the radar. If no grid is given it will be determined from the array.inverse (bool or None, optional) – Invert the transformation? Defaults to
None, which means to try to determine the direction automatically by checking the array’stags. If that fails,inversedefaults toFalse.
- Returns
transformed_array – The array with the beam expansion effect applied/removed
- Return type
- Raises
AttributeError – An AttributeError is raised if no grid was specified and no grid is set for the array.
TypeError – A TypeError is raised if the given grid is not a valid grid.
ValueError – A ValueError is raised if the given grid does not have the same shape as the given array.
pylawr.transform.spatial.Interpolator#
- class pylawr.transform.spatial.Interpolator(threshold=0.75, algorithm=None, polar=True, cov_thres=4, zero_field=(11, 11), zero_thres=0.34)[source]#
Bases:
TransformerThis class can be used to fill holes within a radar field with given remapping algorithm. For the interpolation temporary
UnstructuredGridis used.- Parameters
threshold (float) – If more values are nan than field size * threshold, then no interpolation is possible. Default is 0.75.
algorithm (child of
pylawr.remap.base.BaseRemapor None) – This initialized algorithm is used for hole filling. If this is None,NearestNeighborwith one nearest neighbor is used as algorithm. Default is None.polar (boolean, optional) – If the given reflectivity is in polar coordinates or in other coordinates. If polar coordinates are used, the padding for the masks is calculated with polar padding, else a reflect padding is used.
cov_thres (float, optional) – If this interpolation covariance (uncertainty) above this threshold ( default \(= 4~ ext{dbz}^{2}), then the value is not interpolated. If given interpolation algorithm has no uncertainty estimation, this step is skipped. To use no thresholding this values can be set to :py:class:\).
zero_field (tuple(int)) – The size of the local receptive field to search for valid values, which have rain. If the number of rain values is below a given threshold, the missing values are set to zero. Default is (11, 11).
zero_thres (float, optional) – If the number of rain values within a local receptive field is below this threshold, the missing values are set to zero. Default is 0.34.
Warning
The algorithm is refitted every time such that old fits are overwritten.
- _abc_impl = <_abc._abc_data object>#
- _get_source_mask(reflectivity)[source]#
Get a mask for all source points based on given reflectivity. Two different conditions are necessary such that a value is declared as source value:
the value is not nan
the value has no surrounding nan value or is below 5 dBZ
- Parameters
reflectivity (
xarray.DataArray) – This reflectivity array is used to create the source mask.- Returns
source_mask – All source values are True, all other are False.
- Return type
numpy.ndarray(bool)
- static _get_target_mask(reflectivity)[source]#
Mask all values, which should be interpolated. Currently, only
numpy.nanare set to True, while all other are set to False.- Parameters
reflectivity (
xarray.DataArray) – This reflectivity array is used to create the target mask. All nan- values are used as target.- Returns
target_mask – The inferred boolean target mask with the same shape as the given reflectivity.
- Return type
numpy.ndarray(bool)
- _get_valid_mask(reflectivity)[source]#
Get a mask for all valid values. A value is declared as valid value, if the number of rain values (> 5 dBZ) within a local receptive field is larger than a set threshold.
- Parameters
reflectivity (
xarray.DataArray) – This reflectivity array is used to create the valid mask.- Returns
valid_mask – All valid values are True, all other are False.
- Return type
numpy.ndarray(bool)
- _prefill_noninterp_vals(reflectivity)[source]#
All missing and not valid values within a given array are set to -32.5 dBZ.
- Parameters
reflectivity (
xarray.DataArray) – This reflectivity array is used to fill non valid values- Returns
filled_values – In this array all missing and not valid values are replaced with -32.5 dBZ.
- Return type
- _repl_uncertain_interpolation(refl_array, repl_value=nan)[source]#
This method replaces values in a given interpolation array, where the interpolation covariance are above a set threshold.
- property algorithm#
- transform(refl_array, grid=None, *args, **kwargs)[source]#
Interpolate holes within given array.
- Parameters
refl_array (
xarray.DataArray) – This array is used as input array. This array is handled as single reflectivity array such that only one time step at a time can be processed.grid (child of
pylawr.grid.base.BaseGridor None) – This grid is used for the interpolation. If this grid is None, the grid from given array is used. Default is None.
- Returns
filled_array – In this interpolated array all nan-values are replaced by their interpolated value. The interpolated array will be returned as logarithmic reflectivity in dBZ.
- Return type
Warning
For interpolation of missing values a grid is needed.