pylawr.functions.fit#
- pylawr.functions.fit.extrapolate_offline(refl_array, pre_refl_array, time_extra, grid_extrapolation=<pylawr.grid.cartesian.CartesianGrid object>, remapper=<pylawr.remap.nearest.NearestNeighbor object>, *args, **kwargs)[source]#
Fits an extrapolator for temporal interpolation between two given arrays. The extrapolator is applied to both fields and then the weighted average is returned as extrapolated field. The weights are based on a linear dynamics assumptions and anti-proportional from array time to
time_extra.- Parameters
refl_array (
DataArray) – This reflectivity array is handled as last available reflectivity.pre_refl_path (str, file or xarray.backends.*DataStore) – This path is passed to
xarray.open_dataarray(). Stored array should be a processed array bypylawr.grid_extrapolation (
CartesianGrid) – This grid is passed tofit(). If no grid is given, the grid fromrefl_arrayis used. Default is None.args – list of additional arguments, which are passed to
Extrapolatorduring initialization.kwargs – dictionary of additional keyword arguments, which are passed to
Extrapolatorduring initialization.
- Returns
ExtrapolatorThis extrapolator was fitted to given array and previous array with given grid.- Return type
extrapolated_field
- pylawr.functions.fit.fit_extrapolator(refl_array, pre_refl_path, grid_extrapolation=<pylawr.grid.cartesian.CartesianGrid object>, remapper=<pylawr.remap.nearest.NearestNeighbor object>, *args, **kwargs)[source]#
Fits an extrapolator with given reflectivity and path to old reflectivity.
- Parameters
refl_array (
DataArray) – This reflectivity array is handled as last available reflectivity.pre_refl_path (str, file or xarray.backends.*DataStore) – This path is passed to
xarray.open_dataarray(). Stored array should be a processed array bypylawr.grid_extrapolation (
CartesianGrid) – This grid is passed tofit(). If no grid is given, the grid fromrefl_arrayis used. Default is None.args – list of additional arguments, which are passed to
Extrapolatorduring initialization.kwargs – dictionary of additional keyword arguments, which are passed to
Extrapolatorduring initialization.
- Returns
ExtrapolatorThis extrapolator was fitted to given array and previous array with given grid.- Return type
extrapolator
- pylawr.functions.fit.fit_kriging(refl_array, samples=10000, iterations=1, particle_filter=None, kriging=None, bins=50, rnd=None, ens_size=100, ens_threshold=10)[source]#
This function fits kriging instances with particle filters and a stochastic variogram matching.
- Parameters
refl_array (
xarray.DataArray) – The kriging instance is fitted to this reflectivity array. This reflectivity array needs a set grid to determine the distances between different grid points.samples (int, optional) – This number of samples are drawn from given reflectivity data during each iteration for the stochastic variogram matching (default = 10000).
iterations (int, optional) – This number of iterations is used to fit the kriging instance to given reflectivity data. The default number of one iteration is recommended in an online setting, while more than 100 iterations should be used if kriging is fitted from scratch.
particle_filter (
SIRParticleFilter) –None (or) – This initialized particle filter is used to fit kriging to given reflectivity. If no particle filter (default) is given, a new sequential importance resampling particle filter is constructed and used.
optional – This initialized particle filter is used to fit kriging to given reflectivity. If no particle filter (default) is given, a new sequential importance resampling particle filter is constructed and used.
kriging (child of
SimpleKrigingor None, optional) – This kriging instance is fitted and returned by this function. If no kriging instance is given (default), then a new ordinary kriging instance with a RBF and white noise kernel is fitted.bins (int, optional) – This number of bins (default=50) is used to construct the stochastic variogram. A large number of bins, increases the resolution of the variogram, but also increases the observational uncertainty.
rnd (
RandomState, int or None, optional) – This random state is used to sample the stochastic variogram. If no random state is given, a new one is initialized with given random seed (int) or with processor clock time (None, default).ens_size (int, optional) – This number of ensemble members (default=100) is used for the particle filter to fit the kriging instance.
ens_threshold (int, optional) – If the number of effective ensemble members in particle filter is below this threshold (default=10), then the ensemble is resampled.
- Returns
kriging (child of
SimpleKriging) – The fitted kriging instance with the weighted and averaged parameters estimated with returned particle filter. This kriging instance is ready to remap data.particle_filter (
SIRParticleFilter) – This particle filter instance was used to infer the parameters for returned kriging instance.
Notes
In its default settings, this function iterates only once over given radar data. To fit kriging instances from scratch, it is recommended to set the number of iterations at least to 100.
- pylawr.functions.fit.sample_sq_diff(refl_array, samples=10000, rnd=None)[source]#
Function to sample squared differences between different grid point and their reflectivities. This function can be used to construct an empirical variogram. Only reflectivites larger than 5 dBZ are sampled. These squared differences are based on a stochastic assumption for improved performance.
- Parameters
refl_array (
xarray.DataArray) – This reflectivity array is used to sample the grid points and their values. This reflectivity array needs a grid.samples (int, optional) – This number of samples is drawn from given array. Default is 10000.
rnd (
numpy.random.RandomState, int or None, optional) – This random state is used to generate the samples. If no random state is given a new one is created with either given seed (int) or the cpu time (None). Default is None.
- Returns
grid_dist (
numpy.ndarray) – This is the grid distance in meters between the compared points. The length of this array equals the specified number of samples.squared_diff (
numpy.ndarray) – This is the squared difference between two random sampled points. The length of this array equals the specified number of samples.
- pylawr.functions.fit.sample_variogram(refl_array, samples=10000, bins=50, rnd=None)[source]#
This function samples a variogram from given reflectivity field. A variogram specifies the spatial correlation within a reflectivity. This variogram can be used to optimize the parameters for interpolation or remapping. This variogram sampling is based on a stochstic approximation, where a given number of grid points are sampled and used to create the variogram. This increases the performance of the variogram creation and could improve the optimization like stochastic gradient descent. This function uses
sample_sq_diff()to sample the squared differences between grid points. Afterwards they are binned withbinned_statistics()and a median value.- Parameters
refl_array (
xarray.DataArray) – This reflectivity array is used to sample the grid points and their values. This reflectivity array needs a grid.samples (int, optional) – This number of samples is drawn from given array. Default is 10000.
bins (int or sequence of scalars, optional) – This specifies the number of bins within the variogram. For further information please see:
binned_statistics(). Default is 50.rnd (
numpy.random.RandomState, int or None, optional) – This random state is used to generate the samples. If no random state is given a new one is created with either given seed (int) or the cpu time (None). Default is None.
- Returns
bin_center (
numpy.ndarray) – These are the center points of the bins. The length of this array equals the number of specified bins.bin_vario (
numpy.ndarray) – These are the binned and sampled variogram values. The length of this array equals the number of specified bins.