Skip to main content

Fast histogramming in python built on pybind11 and OpenMP.

Project description

pygram11

Build Status builds.sr.ht status Documentation Status PyPI version Conda Forge

Simple and fast histogramming in Python and accelerated with OpenMP (built using pybind11).

pygram11 provides fast functions for calculating histograms (and their statistical uncertainties). The API is very simple, documentation found here (you'll also find some benchmarks there). I also wrote a blog post with some simple examples.

Installing

pygram11 only requires NumPy. To build from source you'll need a C++ compiler with C++11 support.

From PyPI

Binary wheels are provided for Linux (starting with version 0.5.0) and macOS (starting with version 0.5.1), they can be installed from PyPI via pip.

pip install pygram11

From conda-forge

For a simple installation process via the conda package manager pygram11 is part of conda-forge.

conda install pygram11 -c conda-forge

Please note that on macOS the OpenMP library from LLVM (libomp) and Intel (libiomp) can clash if your Anaconda environment includes the Intel Math Kernel Library (MKL) package distributed by Anaconda. You may need to install the nomkl package to prevent the clash (Intel MKL accelerates many linear algebra operations, but does not impact pygram11; for pure conda-forge environments this is probably not necessary):

conda install nomkl ## sometimes necessary fix on (macOS only)

From Source

pip install git+https://github.com/douglasdavis/pygram11.git@master

To ensure OpenMP acceleration in a build from source, read the OpenMP section of the docs. If you have a modern GCC verion on Linux, you probably don't have to worry about anything. If you are on macOS, you'll probably want to install libomp from Homebrew.

Note: For releases older than v0.5, when building from source or PyPI, pybind11 was required to be explicitly installed before pygram11 (because setup.py used pybind11 to determine include directories). Starting with v0.5 pybind11 is bundled with the source for non-binary (conda-forge or wheel) installations.

In Action

A histogram (with fixed bin width) of weighted data in one dimension, accelerated with OpenMP:

>>> x = np.random.randn(10000)
>>> w = np.random.uniform(0.8, 1.2, 10000)
>>> h, staterr = pygram11.histogram(x, bins=40, range=(-4, 4), weights=w, omp=True)

A histogram with fixed bin width which saves the under and overflow in the first and last bins (using __ to catch the None returned due to the absence of weights):

>>> x = np.random.randn(1000000)
>>> h, __ = pygram11.histogram(x, bins=20, range=(-3, 3), flow=True, omp=True)

A histogram in two dimensions with variable width bins:

>>> x = np.random.randn(10000)
>>> y = np.random.randn(10000)
>>> xbins = [-2.0, -1.0, -0.5, 1.5, 2.0]
>>> ybins = [-3.0, -1.5, -0.1, 0.8, 2.0]
>>> h, __ = pygram11.histogram2d(x, y, bins=[xbins, ybins])

Histogramming multiple weight variations for the same data, then putting the result in a DataFrame (the input pandas DataFrame will be interpreted as a NumPy array):

>>> weights = pd.DataFrame({"weight_a" : np.abs(np.random.randn(10000)),
...                         "weight_b" : np.random.uniform(0.5, 0.8, 10000),
...                         "weight_c" : np.random.rand(10000)})
>>> data = np.random.randn(10000)
>>> count, err = pygram11.histogram(data, bins=20, range=(-3, 3),
...                                 weights=weights, flow=True, omp=True)
>>> count_df = pd.DataFrame(count, columns=weights.columns)
>>> err_df = pd.DataFrame(err, columns=weights.columns)

Other Libraries

  • There is an effort to develop an object oriented histogramming library for Python called boost-histogram. This library will be feature complete w.r.t. everything a physicist needs with histograms.
  • Simple and fast histogramming in Python using the NumPy C API: fast-histogram. No weights or overflow).
  • If you want to calculate histograms on a GPU in Python, check out cupy.histogram. They only have 1D histograms (no weights or overflow).

If there is something you'd like to see in pygram11, please open an issue or pull request.

Project details


Release history Release notifications | RSS feed

Download files

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

Source Distribution

pygram11-0.5.2.dev0.tar.gz (147.3 kB view details)

Uploaded Source

Built Distributions

pygram11-0.5.2.dev0-cp37-cp37m-macosx_10_9_x86_64.whl (317.5 kB view details)

Uploaded CPython 3.7m macOS 10.9+ x86-64

pygram11-0.5.2.dev0-cp36-cp36m-macosx_10_9_x86_64.whl (317.5 kB view details)

Uploaded CPython 3.6m macOS 10.9+ x86-64

pygram11-0.5.2.dev0-cp27-cp27m-macosx_10_9_x86_64.whl (313.3 kB view details)

Uploaded CPython 2.7m macOS 10.9+ x86-64

File details

Details for the file pygram11-0.5.2.dev0.tar.gz.

File metadata

  • Download URL: pygram11-0.5.2.dev0.tar.gz
  • Upload date:
  • Size: 147.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.33.0 CPython/3.7.4

File hashes

Hashes for pygram11-0.5.2.dev0.tar.gz
Algorithm Hash digest
SHA256 35892f75a3703c342da8c0c6fbe5732609ce289809e40525cf8a5a59482858c9
MD5 274b3913d013e8c0d445ecb3c98da667
BLAKE2b-256 252ea72fdb6ef15f4c42ad9942b020e462ff758ecdf09919f07879768ccc9527

See more details on using hashes here.

File details

Details for the file pygram11-0.5.2.dev0-cp37-cp37m-macosx_10_9_x86_64.whl.

File metadata

  • Download URL: pygram11-0.5.2.dev0-cp37-cp37m-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 317.5 kB
  • Tags: CPython 3.7m, macOS 10.9+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.33.0 CPython/3.7.4

File hashes

Hashes for pygram11-0.5.2.dev0-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 fbca4091d0a52762630eaa80a209fb48a9a27fd267e1f4704e2e14a3f6c80b90
MD5 da781817d823db4b08689b7ddde2a303
BLAKE2b-256 02562334e20a33feec7413124f27255c18f2d01f563dfd6927fbd85455d501e3

See more details on using hashes here.

File details

Details for the file pygram11-0.5.2.dev0-cp36-cp36m-macosx_10_9_x86_64.whl.

File metadata

  • Download URL: pygram11-0.5.2.dev0-cp36-cp36m-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 317.5 kB
  • Tags: CPython 3.6m, macOS 10.9+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.33.0 CPython/3.7.4

File hashes

Hashes for pygram11-0.5.2.dev0-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 1276a6a60b63227d0f3776a5cf990ff10e4f9f19331122ce90870aa8c9096b22
MD5 76151d8f6b6af6446c5013ec1e83a215
BLAKE2b-256 24d3e1253409dc5c10dbc141f88bf2462dc7f4703cbedf6757d71458be6fbf74

See more details on using hashes here.

File details

Details for the file pygram11-0.5.2.dev0-cp27-cp27m-macosx_10_9_x86_64.whl.

File metadata

  • Download URL: pygram11-0.5.2.dev0-cp27-cp27m-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 313.3 kB
  • Tags: CPython 2.7m, macOS 10.9+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.33.0 CPython/3.7.4

File hashes

Hashes for pygram11-0.5.2.dev0-cp27-cp27m-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 3572880ceed3190fa407ade4de782c443ee3f1187d7535f480eace0713d1d773
MD5 9012c5ce8453c0accf5151fa1e6cbcb1
BLAKE2b-256 00ea8e9fa3303204cdce9f69f9678f61c449ed8a982b20c7ff1555518f20d718

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page