pynbody.plot.util.fast_kde#
- pynbody.plot.util.fast_kde(x, y, kern_nx=None, kern_ny=None, gridsize=(100, 100), extents=None, nocorrelation=False, weights=None, norm=False, **kwargs)[source]#
Gaussian kernel density estimation (KDE)
This function is typically several orders of magnitude faster than scipy.stats.kde.gaussian_kde for large (>1e7) numbers of points and produces an essentially identical result. Unlike the scipy original, however, it is limited to using a regular grid.
- Parameters:
x (array) – The x-coords of the input data points
y (array) – The y-coords of the input data points
kern_nx (float) – size (in units of x) of the kernel. If None, the size is determined automatically based on the Scott’s factor.
kern_ny (float) – size (in units of y) of the kernel. If None, the size is determined automatically based on the Scott’s factor.
gridsize (tuple) – Size of the output grid (default 100x100)
extents (tuple) – Extents of the output grid as (xmin, xmax, ymin, ymax). Default: extent of input data
nocorrelation (bool) – If True, the correlation between the x and y coords will be ignored when preforming the KDE.
weights (array) – An array of the same shape as x & y that weighs each sample (x_i, y_i) by each value in weights (w_i). Defaults to an array of ones the same size as x & y.
norm (bool) – If False, the output is only corrected for the kernel. If True, the result is normalized such that the integral over the area yields 1.
- Return type:
A gridded 2D kernel density estimate of the input points.
- Authors:
Joe Kington
- License:
MIT License <http://www.opensource.org/licenses/mit-license.php>