Skip to content

Commit

Permalink
Version 0.1.0 now in beta
Browse files Browse the repository at this point in the history
  • Loading branch information
williamjameshandley committed Mar 26, 2018
1 parent b487eb6 commit a819a28
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 18 deletions.
19 changes: 11 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
[![Build Status](https://travis-ci.org/williamjameshandley/spherical_kde.svg?branch=master)](https://travis-ci.org/williamjameshandley/spherical_kde)
[![codecov](https://codecov.io/gh/williamjameshandley/spherical_kde/branch/master/graph/badge.svg)](https://codecov.io/gh/williamjameshandley/spherical_kde)
[![PyPI version](https://badge.fury.io/py/spherical_kde.svg)](https://badge.fury.io/py/spherical_kde)
[![Documentation Status](https://readthedocs.org/projects/pip/badge/?version=stable)](http://pip.pypa.io/en/stable/?badge=stable)
[![Documentation Status](https://readthedocs.org/projects/spherical-kde/badge/?version=latest)](http://spherical-kde.readthedocs.io/en/latest/?badge=latest)




Spherical Kernel Density Estimation
===================================

These packages allow you to do rudimentary kernel density estimation on a
sphere. Extreme alpha development status.
sphere. Suggestions for improvements/extensions welcome.

The fundamental principle is to replace the traditional Gaussian function used
in
[kernel density estimation](https://en.wikipedia.org/wiki/Kernel_density_estimation)
with the
[Von Mises-Fisher distribution](https://en.wikipedia.org/wiki/Von_Mises-Fisher_distribution).

Bandwidth estimation is still rough-and-ready.

![](https://raw.github.com/williamjameshandley/spherical_kde/master/plot.png)

Example Usage
Expand All @@ -26,7 +29,7 @@ Example Usage
import numpy
from spherical_kde import SphericalKDE
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
import cartopy.crs
from matplotlib.gridspec import GridSpec, GridSpecFromSubplotSpec

# Choose a seed for deterministic plot
Expand All @@ -37,10 +40,10 @@ 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=ccrs.Mollweide())
fig.add_subplot(gs_lower[0], projection=ccrs.Orthographic())
fig.add_subplot(gs_lower[1], projection=ccrs.Orthographic(-10, 45))
fig.add_subplot(gs_vert[2], projection=ccrs.PlateCarree())
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
Expand Down Expand Up @@ -69,7 +72,7 @@ for ax in fig.axes:
ax.gridlines()
ax.coastlines(linewidth=0.1)
kde_green.plot(ax, 'g')
kde_green.plot_decra_samples(ax)
kde_green.plot_samples(ax)
kde_red.plot(ax, 'r')
kde_blue.plot(ax, 'b')

Expand Down
5 changes: 4 additions & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,11 @@
# The short X.Y version
version = ''
# The full version, including alpha/beta/rc tags
release = '0.0.6'
release = '0.1.0'

import sys
import os
sys.path.append(os.path.abspath('../../'))

# -- General configuration ---------------------------------------------------

Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
long_description = ''

setup(name='spherical_kde',
version='0.0.6',
version='0.1.0',
author='Will Handley',
author_email='[email protected]',
url='https://github.com/williamjameshandley/spherical_kde',
Expand All @@ -17,7 +17,7 @@
install_requires=['cartopy', 'pytest', 'numpy', 'scipy', 'matplotlib', 'pypandoc', 'numpydoc'],
license='MIT',
classifiers=[
'Development Status :: 3 - Alpha',
'Development Status :: 4 - Beta',
'Intended Audience :: Developers',
'Natural Language :: English',
'License :: OSI Approved :: MIT License',
Expand Down
10 changes: 7 additions & 3 deletions spherical_kde/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
""" The spherical kernel density estimator class. """

import matplotlib
import numpy
import cartopy.crs
Expand Down Expand Up @@ -93,6 +95,7 @@ def plot(self, ax, colour='g', **kwargs):
ax : matplotlib.axes.Axes
matplotlib axis to plot on. This must be constructed with a
`cartopy.crs.projection`:
>>> import cartopy
>>> import matplotlib.pyplot as plt
>>> fig = plt.subplots()
Expand Down Expand Up @@ -139,13 +142,14 @@ def plot(self, ax, colour='g', **kwargs):
transform=cartopy.crs.PlateCarree(), *kwargs)

def plot_samples(self, ax, nsamples=None, **kwargs):
""" Plot equally weighted samples on an axis.
""" Plot equally weighted samples on an axis.
Parameters
----------
ax : matplotlib.axes.Axes
matplotlib axis to plot on. This must be constructed with a
`cartopy.crs.projection`:
>>> import cartopy
>>> import matplotlib.pyplot as plt
>>> fig = plt.subplots()
Expand All @@ -158,7 +162,7 @@ def plot_samples(self, ax, nsamples=None, **kwargs):
Keywords
--------
Any other keywords are passed to `matplotlib.axes.Axes.plot`
"""
ra, dec = self._samples(nsamples)
ax.plot(ra, dec, 'k.', transform=cartopy.crs.PlateCarree(), *kwargs)
Expand Down
14 changes: 10 additions & 4 deletions spherical_kde/distributions.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
""" Module containing the kernel function for the spherical KDE.
For more detail, see:
https://en.wikipedia.org/wiki/Von_Mises-Fisher_distribution
"""

import numpy
import scipy.optimize
from spherical_kde.utils import (cartesian_from_polar,
Expand Down Expand Up @@ -106,12 +112,12 @@ def VonMises_std(phi, theta):
Returns
-------
solution for
solution for
..math:: 1/tanh(x) - 1/x = R,
where
where
..math:: R = || \sum_i^N x_i || / N
Notes
Expand Down
8 changes: 8 additions & 0 deletions spherical_kde/utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
""" Utilities
* General stable functions
* Transforming coordinates
* Computing rotations
* Performing spherical integrals
"""

import numpy
from scipy.integrate import dblquad

Expand Down

0 comments on commit a819a28

Please sign in to comment.