Spherical Kernel Density Estimation
These packages allow you to do rudimentary kernel density estimation on a sphere. Suggestions for improvements/extensions welcome.
The fundamental principle is to replace the traditional Gaussian function used in kernel density estimation with the Von Mises-Fisher distribution.
Bandwidth estimation is still rough-and-ready.
Example Usage
import numpy
from spherical_kde import SphericalKDE
import matplotlib.pyplot as plt
import cartopy.crs
from matplotlib.gridspec import GridSpec, GridSpecFromSubplotSpec
# Choose a seed for deterministic plot
numpy.random.seed(seed=0)
# Set up a grid of figures
fig = plt.figure(figsize=(10, 10))
gs_vert = GridSpec(3, 1)
gs_lower = GridSpecFromSubplotSpec(1, 2, subplot_spec=gs_vert[1])
fig.add_subplot(gs_vert[0], projection=cartopy.crs.Mollweide())
fig.add_subplot(gs_lower[0], projection=cartopy.crs.Orthographic())
fig.add_subplot(gs_lower[1], projection=cartopy.crs.Orthographic(-10, 45))
fig.add_subplot(gs_vert[2], projection=cartopy.crs.PlateCarree())
# Choose parameters for samples
nsamples = 100
pi = numpy.pi
# Generate some samples centered on (1,1) +/- 0.3 radians
theta_samples = numpy.random.normal(loc=1, scale=0.3, size=nsamples)
phi_samples = numpy.random.normal(loc=1, scale=0.3, size=nsamples)
phi_samples = numpy.mod(phi_samples, pi*2)
kde_green = SphericalKDE(phi_samples, theta_samples)
# Generate some samples centered on (-1,1) +/- 0.4 radians
theta_samples = numpy.random.normal(loc=1, scale=0.4, size=nsamples)
phi_samples = numpy.random.normal(loc=-1, scale=0.4, size=nsamples)
phi_samples = numpy.mod(phi_samples, pi*2)
kde_red = SphericalKDE(phi_samples, theta_samples)
# Generate a spread of samples along latitude 2, height 0.1
theta_samples = numpy.random.normal(loc=2, scale=0.1, size=nsamples)
phi_samples = numpy.random.uniform(low=-pi/2, high=pi/2, size=nsamples)
phi_samples = numpy.mod(phi_samples, pi*2)
kde_blue = SphericalKDE(phi_samples, theta_samples, bandwidth=0.1)
for ax in fig.axes:
ax.set_global()
ax.gridlines()
ax.coastlines(linewidth=0.1)
kde_green.plot(ax, 'g')
kde_green.plot_samples(ax)
kde_red.plot(ax, 'r')
kde_blue.plot(ax, 'b')
# Save to plot
fig.tight_layout()
fig.savefig('plot.png')
Metadata
Release files for spherical_kde 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| spherical_kde-0.1.2.tar.gz | 8.1 kB | Without provenance | Details for spherical_kde-0.1.2.tar.gz |
Release files / spherical_kde-0.1.2.tar.gz
| Download URL | spherical_kde-0.1.2.tar.gz |
|---|---|
| Size | 8.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3d87d7d7ca8a55ff61b01459aefbc76c26d0bb4e9d846cda1d243c61d72bb621
|
|
BLAKE2b-256 checksum How to use checksums |
dcbceac61d967e359fcb61c4b16db023a7b78239e6ddf677d809a54102f1910d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
Python-urllib/3.8
|
Security for spherical_kde 0.1.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.