Skip to main content

Fast histogramming in python built on pybind11 and OpenMP.

Project description

pygram11

builds.sr.ht status Documentation Status PyPI version Conda Forge Code style: black

Simple and fast histogramming in Python via pybind11 and accelerated with OpenMP.

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 at runtime. To build from source, you'll just need a C++ compiler with C++11 support.

From PyPI

Binary wheels are provided for Linux and macOS, they can be installed from PyPI via pip. These builds include OpenMP acceleration.

pip install pygram11

From conda-forge

For a simple installation process via the conda package manager pygram11 is part of conda-forge. These builds include OpenMP acceleration.

conda install pygram11 -c conda-forge

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.

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=["a", "b", "c"])
>>> err_df = pd.DataFrame(err, columns=["a", "b", "c"])

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.1.tar.gz (146.5 kB view details)

Uploaded Source

Built Distributions

pygram11-0.5.1-cp37-cp37m-manylinux1_x86_64.whl (1.6 MB view details)

Uploaded CPython 3.7m

pygram11-0.5.1-cp37-cp37m-macosx_10_9_x86_64.whl (316.4 kB view details)

Uploaded CPython 3.7m macOS 10.9+ x86-64

pygram11-0.5.1-cp36-cp36m-manylinux1_x86_64.whl (1.6 MB view details)

Uploaded CPython 3.6m

pygram11-0.5.1-cp36-cp36m-macosx_10_9_x86_64.whl (316.4 kB view details)

Uploaded CPython 3.6m macOS 10.9+ x86-64

pygram11-0.5.1-cp27-cp27m-manylinux1_x86_64.whl (1.5 MB view details)

Uploaded CPython 2.7m

pygram11-0.5.1-cp27-cp27m-macosx_10_9_x86_64.whl (312.4 kB view details)

Uploaded CPython 2.7m macOS 10.9+ x86-64

File details

Details for the file pygram11-0.5.1.tar.gz.

File metadata

  • Download URL: pygram11-0.5.1.tar.gz
  • Upload date:
  • Size: 146.5 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.3

File hashes

Hashes for pygram11-0.5.1.tar.gz
Algorithm Hash digest
SHA256 717cebae7c6719ec4bc7f0b8090e2855033c71454395056ed06fd366655e7f8e
MD5 fe9cceef30e819152d5c10a2084ce8f4
BLAKE2b-256 823b0127e8565615c738cd9731855a85d57cb8319a6178aaf36b3e9d4f0c2dd3

See more details on using hashes here.

File details

Details for the file pygram11-0.5.1-cp37-cp37m-manylinux1_x86_64.whl.

File metadata

  • Download URL: pygram11-0.5.1-cp37-cp37m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 1.6 MB
  • Tags: CPython 3.7m
  • 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.3

File hashes

Hashes for pygram11-0.5.1-cp37-cp37m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 fda88b9d70e29f8895d92aedc12430d921c39f0140e99914ef648975545000ec
MD5 accaa64f142158ba75f41365b92c7c3d
BLAKE2b-256 295a3f478b6abdf841174720c7066128c4b354cebbe5dbd14264589404d60691

See more details on using hashes here.

File details

Details for the file pygram11-0.5.1-cp37-cp37m-macosx_10_9_x86_64.whl.

File metadata

  • Download URL: pygram11-0.5.1-cp37-cp37m-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 316.4 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.3

File hashes

Hashes for pygram11-0.5.1-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 6f27cdfdcf64ef0657ce561a286cf7fed8a8941b2414ba932a80a0b9054a085f
MD5 0ef70ad0263b9523721e3fe268eb03b6
BLAKE2b-256 679dae14c20a7bf33b3ec15ac985b97f929e2a31b5b110b307fae8d5bf3558a1

See more details on using hashes here.

File details

Details for the file pygram11-0.5.1-cp36-cp36m-manylinux1_x86_64.whl.

File metadata

  • Download URL: pygram11-0.5.1-cp36-cp36m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 1.6 MB
  • Tags: CPython 3.6m
  • 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.3

File hashes

Hashes for pygram11-0.5.1-cp36-cp36m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 9f7aeefc16eb732fecc8df7688b6a49d4469afe8ebc9f47d7c4afd05adb60eba
MD5 29a353b33de5b1c36710643617cfdac7
BLAKE2b-256 1793fdd976214ab258a64642c29ce8405ad61731352e886acb02dca8b5469bdf

See more details on using hashes here.

File details

Details for the file pygram11-0.5.1-cp36-cp36m-macosx_10_9_x86_64.whl.

File metadata

  • Download URL: pygram11-0.5.1-cp36-cp36m-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 316.4 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.3

File hashes

Hashes for pygram11-0.5.1-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 7e79e18dfd6b274adf31d964dcf574cda03568c71d7ef97c8c6891d9f2a442fc
MD5 6a3a51d08704be83e238de4e74cbb3d9
BLAKE2b-256 01c9ddd9b78f982c1eaf5db434ba5195d02bb81d2457f4628f8708f0e9aa9cd2

See more details on using hashes here.

File details

Details for the file pygram11-0.5.1-cp27-cp27m-manylinux1_x86_64.whl.

File metadata

  • Download URL: pygram11-0.5.1-cp27-cp27m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 1.5 MB
  • Tags: CPython 2.7m
  • 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.3

File hashes

Hashes for pygram11-0.5.1-cp27-cp27m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 59d43079aaa6d5d02c05d03f7ee982cebf521d58c9f7ceeb9f9b564ae240b82a
MD5 37f9dc55638ef3dcc601bd0acc1af474
BLAKE2b-256 d01aceeb17a1d545f0f55027244e65c279b19df9406a89bdb8b1c1b79bfb0f47

See more details on using hashes here.

File details

Details for the file pygram11-0.5.1-cp27-cp27m-macosx_10_9_x86_64.whl.

File metadata

  • Download URL: pygram11-0.5.1-cp27-cp27m-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 312.4 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.3

File hashes

Hashes for pygram11-0.5.1-cp27-cp27m-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 dad61a733b9e15a49728322b32fbdfaea4c106cd8160a94b4638943244d7fc8e
MD5 752ea49bad34b8b269a675afc7932fdc
BLAKE2b-256 9cbfcadbecbf4e8bd8881a64b5551c58b77aa1d284ffc7204b7e6a16e2927c80

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