Skip to main content

Fast histogramming in python built 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 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.8.2.tar.gz (530.5 kB view details)

Uploaded Source

Built Distributions

pygram11-0.8.2-cp38-cp38-manylinux2010_x86_64.whl (266.5 kB view details)

Uploaded CPython 3.8 manylinux: glibc 2.12+ x86-64

pygram11-0.8.2-cp38-cp38-manylinux1_x86_64.whl (203.5 kB view details)

Uploaded CPython 3.8

pygram11-0.8.2-cp38-cp38-macosx_10_9_x86_64.whl (401.1 kB view details)

Uploaded CPython 3.8 macOS 10.9+ x86-64

pygram11-0.8.2-cp37-cp37m-manylinux2010_x86_64.whl (265.0 kB view details)

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

pygram11-0.8.2-cp37-cp37m-manylinux1_x86_64.whl (205.9 kB view details)

Uploaded CPython 3.7m

pygram11-0.8.2-cp37-cp37m-macosx_10_9_x86_64.whl (396.8 kB view details)

Uploaded CPython 3.7m macOS 10.9+ x86-64

pygram11-0.8.2-cp36-cp36m-manylinux2010_x86_64.whl (264.8 kB view details)

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

pygram11-0.8.2-cp36-cp36m-manylinux1_x86_64.whl (205.3 kB view details)

Uploaded CPython 3.6m

pygram11-0.8.2-cp36-cp36m-macosx_10_9_x86_64.whl (396.8 kB view details)

Uploaded CPython 3.6m macOS 10.9+ x86-64

File details

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

File metadata

  • Download URL: pygram11-0.8.2.tar.gz
  • Upload date:
  • Size: 530.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.4.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.2

File hashes

Hashes for pygram11-0.8.2.tar.gz
Algorithm Hash digest
SHA256 677e22a99c72a8494d89b3e3ebe0844115d8caa2eee7636b36f5f0a3865b0d7e
MD5 c05c7276f58992d959989e4522294169
BLAKE2b-256 b812f8a458bd36a0da094ddaeb09f2c689121a6ef1faf701efb0a695a9d49782

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pygram11-0.8.2-cp38-cp38-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 266.5 kB
  • Tags: CPython 3.8, manylinux: glibc 2.12+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.4.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.2

File hashes

Hashes for pygram11-0.8.2-cp38-cp38-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 7fa02d2c3b7fcaf3155cd57c944f716ba444eda438c982a49a2205eb287c095f
MD5 439dafeb7cca2532d1c62f4be5fbfc80
BLAKE2b-256 e8f2c91a03a64dfdf984358a9c2337955804bae7b2d9309607d0f320045ae0de

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pygram11-0.8.2-cp38-cp38-manylinux1_x86_64.whl
  • Upload date:
  • Size: 203.5 kB
  • Tags: CPython 3.8
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.4.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.2

File hashes

Hashes for pygram11-0.8.2-cp38-cp38-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 a238dff713a7ac0f20697d0129285116e91fc67c0f1e2e36c7a32b5bdc495319
MD5 54546cad5b69098132dfde9b394bc733
BLAKE2b-256 a15ce1cfc7a0077903961cae1e4d2f0ee02de94ee89a34b4513d41c6f92d1532

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pygram11-0.8.2-cp38-cp38-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 401.1 kB
  • Tags: CPython 3.8, macOS 10.9+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.4.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.2

File hashes

Hashes for pygram11-0.8.2-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 2f42be0267979322488cddd93cd83b7fe5654050f7902eb9f44a21c1b5551f22
MD5 bfd211d2625522f8996d8943bffb788b
BLAKE2b-256 e9d5ba473dbe5dbd6b1d69ec5a2e618a8ab699f2c1c7fef54a147b9de648756f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pygram11-0.8.2-cp37-cp37m-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 265.0 kB
  • Tags: CPython 3.7m, manylinux: glibc 2.12+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.4.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.2

File hashes

Hashes for pygram11-0.8.2-cp37-cp37m-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 fe587d25fff3dbaec9493fe75a18ca764412d677c38e85d3175b130ac2cd0040
MD5 0437240ac5be44addc9d6c4ec4b2c315
BLAKE2b-256 a014e8fded3c46283516d02e490e09a5b6aa0b6f04e60cae7628f62f4d1d65d7

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pygram11-0.8.2-cp37-cp37m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 205.9 kB
  • Tags: CPython 3.7m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.4.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.2

File hashes

Hashes for pygram11-0.8.2-cp37-cp37m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 7c890228db9b1cb94b276f11dbd9e819aa1ed66655f554827140b7b2d3c3ad7a
MD5 223265304ccf33056b4951d2ab7b2a65
BLAKE2b-256 e3dc0b0f4ff40da3c6127c7f3cb9900d719171c20724bd73d009005921f93fb0

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pygram11-0.8.2-cp37-cp37m-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 396.8 kB
  • Tags: CPython 3.7m, macOS 10.9+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.4.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.2

File hashes

Hashes for pygram11-0.8.2-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 0616b3d7da58e2e25bf01cf75efbaaf4b50af1cb233553a51bc5e887bfc7d6ca
MD5 8ddb0c0a7a446d6ffc27578e668e4726
BLAKE2b-256 dd1b55e8148840b0c8982f11c318b9d8b5499737d279871ebaf0a5a762667dc4

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pygram11-0.8.2-cp36-cp36m-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 264.8 kB
  • Tags: CPython 3.6m, manylinux: glibc 2.12+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.4.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.2

File hashes

Hashes for pygram11-0.8.2-cp36-cp36m-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 4e170cb1cf5bef10e1686e977e071338b9dad761c5967ef5404d32ded78c4768
MD5 fe01cbd18931f4c0029761af5bacb4fe
BLAKE2b-256 64bc519f62d4c960caabf1c27503b85f4aae3f391e7a5426dc07066d8fcaed2e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pygram11-0.8.2-cp36-cp36m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 205.3 kB
  • Tags: CPython 3.6m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.4.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.2

File hashes

Hashes for pygram11-0.8.2-cp36-cp36m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 db5be5981b61fddf450d79978c770ad9088d5a9ea0872fe7514db3b3642e911f
MD5 494ed2d771f7e3bee1efae7790ab1701
BLAKE2b-256 00847ee5d8e0942e592f4c403dbab58332811f59f3584a377c0e69525079873a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pygram11-0.8.2-cp36-cp36m-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 396.8 kB
  • Tags: CPython 3.6m, macOS 10.9+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.4.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.2

File hashes

Hashes for pygram11-0.8.2-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 c73a5bcf0a45479a422a57c7d1bc1675780c2910f8f9e28fe8b8425bb84bdf12
MD5 d18e512c597fef60beddad0af6f75a04
BLAKE2b-256 84f30715e9c30dea25739352ef3374f579e35debbfdbb5ed7198274f7481bd6f

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