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 accelerated with OpenMP (with help from 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 libraries from LLVM (libomp) and Intel (libiomp) can clash if your conda 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):

conda install nomkl ## sometimes necessary fix (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.tar.gz (147.0 kB view details)

Uploaded Source

Built Distributions

pygram11-0.5.2-cp38-cp38-manylinux2010_x86_64.whl (1.3 MB view details)

Uploaded CPython 3.8 manylinux: glibc 2.12+ x86-64

pygram11-0.5.2-cp38-cp38-macosx_10_9_x86_64.whl (324.7 kB view details)

Uploaded CPython 3.8 macOS 10.9+ x86-64

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

Uploaded CPython 3.7m

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

Uploaded CPython 3.7m macOS 10.9+ x86-64

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

Uploaded CPython 3.6m

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

Uploaded CPython 3.6m macOS 10.9+ x86-64

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

Uploaded CPython 2.7m

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

Uploaded CPython 2.7m macOS 10.9+ x86-64

File details

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

File metadata

  • Download URL: pygram11-0.5.2.tar.gz
  • Upload date:
  • Size: 147.0 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.0.0 requests-toolbelt/0.9.1 tqdm/4.34.0 CPython/3.7.0

File hashes

Hashes for pygram11-0.5.2.tar.gz
Algorithm Hash digest
SHA256 3a89224a35f0c68099f2c0f6bd8dc0d1b505a689dcefa0138ef20d94a1c2b573
MD5 d4e254af4e33d18caa16b9721e7bc33b
BLAKE2b-256 78a6d09e072e412139953df80f074712f156c4d8d09cf106dfbdff97c9919af5

See more details on using hashes here.

File details

Details for the file pygram11-0.5.2-cp38-cp38-manylinux2010_x86_64.whl.

File metadata

  • Download URL: pygram11-0.5.2-cp38-cp38-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 1.3 MB
  • Tags: CPython 3.8, manylinux: glibc 2.12+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.8.0

File hashes

Hashes for pygram11-0.5.2-cp38-cp38-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 d3c5b7a155f2821e113946b03b76a8ad37e11bb0d0e8c44aa2a6ba64155c2e4c
MD5 bf38f21726b3c68d42f13a915f930a39
BLAKE2b-256 2ef2ffd71315168b0094b78a3e1d5b716529759e387055d8d77c24507d9875ce

See more details on using hashes here.

File details

Details for the file pygram11-0.5.2-cp38-cp38-macosx_10_9_x86_64.whl.

File metadata

  • Download URL: pygram11-0.5.2-cp38-cp38-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 324.7 kB
  • Tags: CPython 3.8, macOS 10.9+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.8.0

File hashes

Hashes for pygram11-0.5.2-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 426147312409f5d15398a9b9c3167ad25d1f09bb6a73004338ed622ca0dcf74c
MD5 a1e1132939fe954df97b60405093eb33
BLAKE2b-256 430de385b323b7739c8bc816c2fecf216e04266059be54605e6741083d84e394

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pygram11-0.5.2-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.0.0 requests-toolbelt/0.9.1 tqdm/4.34.0 CPython/3.7.0

File hashes

Hashes for pygram11-0.5.2-cp37-cp37m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 748b9b337b4aa3bd98683140a1e05b5ba91dd094d939661c5d5abd2d82fe9c80
MD5 4a7dcba8d68f5780a9c1d78aef505ddc
BLAKE2b-256 ac5b57c452fa496a80a2ff5965687df8d1b13c58cfd77389ff6e1a47ad90ea67

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pygram11-0.5.2-cp37-cp37m-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 318.7 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-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 bdc1885e23c4d5be03553b52970b2e23bc0f99192ec84b1aa85357d5e7abe64f
MD5 41ed4e6ec57fb0af558f1acc8e865859
BLAKE2b-256 bdcfc86bbd14655d5e17014660493786dd7752602d23eeda19aace6116f32d34

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pygram11-0.5.2-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.0.0 requests-toolbelt/0.9.1 tqdm/4.34.0 CPython/3.7.0

File hashes

Hashes for pygram11-0.5.2-cp36-cp36m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 655150bbfb021d61da6425f05f4dc74bab08c50d80f73e4f3ba66968fe3194cc
MD5 0956e699cccc655b995e015fb939f9e5
BLAKE2b-256 9b31f423b2f5db84d42c96f434365d04420592d931f874d39cd88e9782807c78

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pygram11-0.5.2-cp36-cp36m-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 318.7 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-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 beeec6d8727546c31579820bb5a6f6887fcc340df81a74924da17460273337a0
MD5 83090a0095a0997a6502c054ec5bafdd
BLAKE2b-256 627cc06ba2f166d3c501c01bbe53459579daa422ca4934a07566256cf6c3fecf

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pygram11-0.5.2-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.0.0 requests-toolbelt/0.9.1 tqdm/4.34.0 CPython/3.7.0

File hashes

Hashes for pygram11-0.5.2-cp27-cp27m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 43b2a1f042c338376c2717c4bf306714fed9427166a2d0d82b55553ed7fe5b2e
MD5 7e7e63baa0471d1349785555bd32835a
BLAKE2b-256 66d0a8839ff1ebdd132418ab876dcc7e6c146c937e65c02903c6df121f867358

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pygram11-0.5.2-cp27-cp27m-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 314.1 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-cp27-cp27m-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 c7453eeb030a27d07bd55f5385f45b48464dc8a6e1019a40e6dfa5493729c55e
MD5 54549e35ddeb1af35930aa0987066d06
BLAKE2b-256 d3608b58e26569136f1385cd39d7fb7d05f0d587e9a8ed1e81df92130c1a1c18

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