Skip to main content

Fast histogramming in Python build on pybind11 and OpenMP.

Project description

pygram11

Documentation Status Actions Status builds.sr.ht 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 the variance in each bin). The API is very simple; documentation can be found here (you'll also find some benchmarks there).

Installing

Using pygram11 only requires NumPy. To build and install from source you'll just need a compiler with support for C++11 and OpenMP.

From PyPI

Binary wheels are provided for Linux and macOS. They can be installed from PyPI via pip.

pip install pygram11

From conda-forge

For installation 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) may 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

All you need is a C++11 compiler and OpenMP. If you are using a relatively modern GCC release on Linux then you probably don't have to worry about the OpenMP dependency. If you are on macOS, you can install libomp from Homebrew. With those dependencies met, simply run:

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

In Action

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

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

A histogram with fixed bin width which saves the under and overflow in the first and last bins:

>>> x = np.random.randn(1000000)
>>> h, err = pygram11.histogram(x, bins=20, range=(-3, 3), flow=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, err = 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)
>>> count_df = pd.DataFrame(count, columns=weights.columns)
>>> err_df = pd.DataFrame(err, columns=weights.columns)

I also wrote a blog post with some simple examples.

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 variance or overflow support).
  • 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.10.1.tar.gz (804.7 kB view details)

Uploaded Source

Built Distributions

pygram11-0.10.1-cp38-cp38-manylinux2010_x86_64.whl (219.7 kB view details)

Uploaded CPython 3.8 manylinux: glibc 2.12+ x86-64

pygram11-0.10.1-cp38-cp38-manylinux1_x86_64.whl (204.4 kB view details)

Uploaded CPython 3.8

pygram11-0.10.1-cp38-cp38-macosx_10_9_x86_64.whl (402.0 kB view details)

Uploaded CPython 3.8 macOS 10.9+ x86-64

pygram11-0.10.1-cp37-cp37m-manylinux2010_x86_64.whl (222.0 kB view details)

Uploaded CPython 3.7m manylinux: glibc 2.12+ x86-64

pygram11-0.10.1-cp37-cp37m-manylinux1_x86_64.whl (206.8 kB view details)

Uploaded CPython 3.7m

pygram11-0.10.1-cp37-cp37m-macosx_10_9_x86_64.whl (397.7 kB view details)

Uploaded CPython 3.7m macOS 10.9+ x86-64

pygram11-0.10.1-cp36-cp36m-manylinux2010_x86_64.whl (221.5 kB view details)

Uploaded CPython 3.6m manylinux: glibc 2.12+ x86-64

pygram11-0.10.1-cp36-cp36m-manylinux1_x86_64.whl (206.3 kB view details)

Uploaded CPython 3.6m

pygram11-0.10.1-cp36-cp36m-macosx_10_9_x86_64.whl (397.7 kB view details)

Uploaded CPython 3.6m macOS 10.9+ x86-64

File details

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

File metadata

  • Download URL: pygram11-0.10.1.tar.gz
  • Upload date:
  • Size: 804.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.2.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5

File hashes

Hashes for pygram11-0.10.1.tar.gz
Algorithm Hash digest
SHA256 bc154cc0775fee91b07157b3b4c522a09c347b84a5e0c0e35c8f86e3e5e6cad4
MD5 39fb5bc636a9dd168563fc25a55ffe69
BLAKE2b-256 9180429c75570651471b66e3edeba94d617b71dd5cc0cf229508c624f6782921

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pygram11-0.10.1-cp38-cp38-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 219.7 kB
  • Tags: CPython 3.8, manylinux: glibc 2.12+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.6.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5

File hashes

Hashes for pygram11-0.10.1-cp38-cp38-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 e5ffafd58f784119342f78f9be67316742379a2da958059832767a2a7d2c8c66
MD5 180bf201e8f85b320f04a54b7dbe7b71
BLAKE2b-256 93b94fca5464044ff87ea3ed95895a50c10eb83ccb6ea6d6000776ed1a7d271b

See more details on using hashes here.

File details

Details for the file pygram11-0.10.1-cp38-cp38-manylinux1_x86_64.whl.

File metadata

  • Download URL: pygram11-0.10.1-cp38-cp38-manylinux1_x86_64.whl
  • Upload date:
  • Size: 204.4 kB
  • Tags: CPython 3.8
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.6.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5

File hashes

Hashes for pygram11-0.10.1-cp38-cp38-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 5d1d7cdf9cf7dc0f4e27785cecb06f9ca22f05ea6dbe1a66e7d493e3b570d3b0
MD5 8c98591201cc6761c0476422bf0854f9
BLAKE2b-256 1d9a36fde5d3a1cb21d0779abeac3c81936934d33e2f28e2aa2678c66d77a01e

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for pygram11-0.10.1-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 7067ac91be9070eee107785f908c09a5e40ec5e0bb7dfe20eb9202f31aa33a12
MD5 b3909b56d5ec6ac4c33fe63679bfd383
BLAKE2b-256 c4486afabadc3f9cf45ae87fad056a4f0605a6a9ce640be4b17ca9be43709f77

See more details on using hashes here.

File details

Details for the file pygram11-0.10.1-cp37-cp37m-manylinux2010_x86_64.whl.

File metadata

  • Download URL: pygram11-0.10.1-cp37-cp37m-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 222.0 kB
  • Tags: CPython 3.7m, manylinux: glibc 2.12+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.6.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5

File hashes

Hashes for pygram11-0.10.1-cp37-cp37m-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 89647befa6366e2084cdcd74fef99749f5d3bc613194ba89df8746304df38f06
MD5 069cd69619ca7a9f8ee2ba7263de77b0
BLAKE2b-256 6c56c01c2153464f573d423389d8740ea5101338cb8e9e5efc2fa42b374ad8c0

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pygram11-0.10.1-cp37-cp37m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 206.8 kB
  • Tags: CPython 3.7m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.6.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5

File hashes

Hashes for pygram11-0.10.1-cp37-cp37m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 afff5ee069408172d57abaaefc88ded6066b49e56229194b08a95945a8b81f08
MD5 f66500d72facf64d5a043e630e4f64f1
BLAKE2b-256 154bfff803b3d0210efdc9f8626b3841760387c188c2c439866485f089f91b49

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pygram11-0.10.1-cp37-cp37m-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 397.7 kB
  • Tags: CPython 3.7m, macOS 10.9+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/50.2.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.8.5

File hashes

Hashes for pygram11-0.10.1-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 7d717f9be820cefdfc835bb9792a01c223ea1a0d15a30b657bb4bc47f36ca526
MD5 5b895047516f9907acf0c969519b0e92
BLAKE2b-256 92c02753fa94f2a08a8dc4d364d66e38a581e226ae99d1911112e909273b8fef

See more details on using hashes here.

File details

Details for the file pygram11-0.10.1-cp36-cp36m-manylinux2010_x86_64.whl.

File metadata

  • Download URL: pygram11-0.10.1-cp36-cp36m-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 221.5 kB
  • Tags: CPython 3.6m, manylinux: glibc 2.12+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.6.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5

File hashes

Hashes for pygram11-0.10.1-cp36-cp36m-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 7e31d0e3d1f922cc88df4923ba1fcdb1b22fe1cc2abc2b7f2c288aad541dbd53
MD5 4cc9c0f5af448373ce4ad3c0c7651ff4
BLAKE2b-256 6a223b1e71554f2ec62e83abaa49536bd0e25bc7698fbeab90978215b11d5549

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pygram11-0.10.1-cp36-cp36m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 206.3 kB
  • Tags: CPython 3.6m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.6.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5

File hashes

Hashes for pygram11-0.10.1-cp36-cp36m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 6a65cbef14648f4698936af0b8d95f10e0020fbaf9c1487d1332e7b6b812ea28
MD5 69a3c9aba1ff085fad1f60868aa75f3a
BLAKE2b-256 4ab9b44cae27e649208a2ca02e367a68ab1a538d62bdbfb770e03317fc0bea20

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pygram11-0.10.1-cp36-cp36m-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 397.7 kB
  • Tags: CPython 3.6m, macOS 10.9+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/50.2.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.8.5

File hashes

Hashes for pygram11-0.10.1-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 3a3f39dea1c411cbbea3eb340e2de66062eeb49522b605c327ef3f63033dba10
MD5 f1eeeb967aa8436f72669fd28e7bab0b
BLAKE2b-256 43f4dcedded8fb67e42b6624e73f19b1f6a66ad7d7fadaff41a7ed4f79e8b96f

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