Skip to main content

Implementation of FB8, a generalization of the Kent (1982) and Bingham-Mardia (1978) distributions on a sphere

Project description

PyPI version Build Status Python versions

Getting started

pip install fb8

import numpy as np
from matplotlib import pyplot as plt
from matplotlib import cm
from mpl_toolkits.mplot3d import Axes3D
from sphere.distribution import fb8

def grid(npts):
    return [_.flatten() for _ in np.meshgrid(np.linspace(0, np.pi, npts), np.linspace(0,2*np.pi, npts))]

def plot_fb8(fb8, npts):
    Plot fb8 on 3D sphere
    xs = fb8.spherical_coordinates_to_nu(*grid(npts))
    pdfs = fb8.pdf(xs)
    z,x,y = xs.T #!!! Note the ordering for xs here is used consistently throughout. Follows Kent's 1982 paper.

    fig = plt.figure(figsize=plt.figaspect(1.))
    ax = fig.add_subplot(111, projection='3d')
    ax.plot_surface(x.reshape(npts, npts),
                    y.reshape(npts, npts),
                    z.reshape(npts, npts),
                    rstride=1, cstride=1,
                    facecolors=cm.plasma(pdfs.reshape(npts, npts)/pdfs.max()))

plot_fb8(fb8(np.pi/16,-np.pi/3,0,10,10,-1,0.5,0.3), 200)

Basic information

Implements the FB8 distribution on a sphere, which is a generalization of the FB6, FB5 (Kent), and FB4 (Bingham-Mardia) distributions described below.

Implements the FB6 distribution that is first introduced in Rivest (1984).

Implements calculation of the density and fitting (using maximum likelihood estimate) of the Kent distribution based on Kent (1982). A unittest is performed if is called from the command line.

Implements the Bingham-Mardia distribution whose mode is a small-circle on the sphere based on Bingham, Mardia (1978).

Also calculates directional, percentile levels which can be used to indicate the N% highest-posterior-density regions in the sky.


Additional references

Kent, Hussein, Jah, Directional distributions in tracking of space debris

Terdik, Jammalamadaka, Wainwright, Simulation and visualization of spherical distributions

Mardia, Jupp, Directional statistics


Currently the scipy.special.hyp2f1 is used and may exhibit inaccuracies for large parameters. See github issues.


This project was originally developed for the FB5 (Kent) distribution here.

Tianlu Yuan

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for fb8, version 1.0.1
Filename, size File type Python version Upload date Hashes
Filename, size fb8-1.0.1-py3-none-any.whl (22.9 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size fb8-1.0.1.tar.gz (21.2 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page