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

Uploaded Source

Built Distributions

pygram11-0.10.0-cp38-cp38-manylinux2010_x86_64.whl (267.5 kB view details)

Uploaded CPython 3.8 manylinux: glibc 2.12+ x86-64

pygram11-0.10.0-cp38-cp38-manylinux1_x86_64.whl (204.5 kB view details)

Uploaded CPython 3.8

pygram11-0.10.0-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.0-cp37-cp37m-manylinux2010_x86_64.whl (266.0 kB view details)

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

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

Uploaded CPython 3.7m

pygram11-0.10.0-cp37-cp37m-macosx_10_9_x86_64.whl (397.8 kB view details)

Uploaded CPython 3.7m macOS 10.9+ x86-64

pygram11-0.10.0-cp36-cp36m-manylinux2010_x86_64.whl (265.8 kB view details)

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

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

Uploaded CPython 3.6m

pygram11-0.10.0-cp36-cp36m-macosx_10_9_x86_64.whl (397.8 kB view details)

Uploaded CPython 3.6m macOS 10.9+ x86-64

File details

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

File metadata

  • Download URL: pygram11-0.10.0.tar.gz
  • Upload date:
  • Size: 530.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 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.10.0.tar.gz
Algorithm Hash digest
SHA256 0303de5bb5723c2297522a23fcf62b4b5a72ed0111329a0c2def5c36dbc9591b
MD5 8affd0bd73810159c01e11ff0b76908c
BLAKE2b-256 ed449ecdf38d8ed071c64fa2cbe7486fd8ff99c8877031f46229b4d89d1cc717

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pygram11-0.10.0-cp38-cp38-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 267.5 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.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.10.0-cp38-cp38-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 449b91b67c7bf3fbbe9ee77111ec8f83438a551f50d854e4b76bc037360363e0
MD5 bc1e73e19d856bb3cc80602d20310065
BLAKE2b-256 a5f598d8ce577857d465a0d0879a5e2a302dcdd96475589bdfe6e618e772f9cf

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pygram11-0.10.0-cp38-cp38-manylinux1_x86_64.whl
  • Upload date:
  • Size: 204.5 kB
  • Tags: CPython 3.8
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 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.10.0-cp38-cp38-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 621456a425c29ebe86ceaea4d01d49f5021cd271073f9eb40b72a42eb113f4f8
MD5 c387a65807d453d3e84c585963277243
BLAKE2b-256 969a6a430c538750e8ae7df644bf5c69070e2159d25a784d441f2ded8740c2ad

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pygram11-0.10.0-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/47.3.1 requests-toolbelt/0.9.1 tqdm/4.33.0 CPython/3.7.4

File hashes

Hashes for pygram11-0.10.0-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 6f0fb61025c3408e633a0d298233edacee4e6ec151e8462d4539a71af7c9a1b7
MD5 acb13069b5e2e0f54f56a101e602008f
BLAKE2b-256 159c3c1643ff0c3104b56876bc794ff7a59ceaf1eaca4ce43928c0e0cf554b83

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pygram11-0.10.0-cp37-cp37m-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 266.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.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.10.0-cp37-cp37m-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 23b77285d588e9a7b409b5c630897bdefc50076bc47e327b5b6e2e85607861df
MD5 c90df03eadb6577c1eedc0a462f99bbd
BLAKE2b-256 b793e7839656e68482fd568e1ef25866ecdd92568feeb2ad1bb3f4919e8efa0c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pygram11-0.10.0-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.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.10.0-cp37-cp37m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 c88a10b714e16217173affb39e2157240dc504e2ce9d5d166a67b33b54164708
MD5 2b0bca50d954b5c1959073b9d1600b0b
BLAKE2b-256 972751716b03cdb9cf55b7773d1d87755584f04b6a11d171af3d4390b9b42949

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pygram11-0.10.0-cp37-cp37m-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 397.8 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/47.3.1 requests-toolbelt/0.9.1 tqdm/4.33.0 CPython/3.7.4

File hashes

Hashes for pygram11-0.10.0-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 50f72968c81611d174a2669ea48b7e52ec9cf3427722a0242bd5b4dac2564013
MD5 6d99acf06a4a18222fdb8e013dd2fcf8
BLAKE2b-256 16264494f78c5e679248fd839e84be2e1c45f7bf32b1aafd5a98225a093c5927

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pygram11-0.10.0-cp36-cp36m-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 265.8 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.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.10.0-cp36-cp36m-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 ea5a43b2153e6ec4ac0dafa4a493dc85fe8f2221f9b76eeb5b39c1edf79ed376
MD5 cea3b522f2a03384bb37ec35d4ed753a
BLAKE2b-256 ad4020bd7485f09b5816a21ff719e594c1c159421aab69de4986a2a6dd30500b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pygram11-0.10.0-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.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.10.0-cp36-cp36m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 48561292a0bc05e6d6944bfcd3665609fbd95d448ec422e8e31e7e664282cc56
MD5 28f2c785607cd62e75672abb849cbe59
BLAKE2b-256 dc8a1c19fa6d7369af4ce130a4ea8273f7481b6db3458451a4b5f20c6009430a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pygram11-0.10.0-cp36-cp36m-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 397.8 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/47.3.1 requests-toolbelt/0.9.1 tqdm/4.33.0 CPython/3.7.4

File hashes

Hashes for pygram11-0.10.0-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 01cee55d00dcf708fc51dccbe50839666bb77b38c3a3c14e796ad6d8ac670b93
MD5 a47061ecad079131faeef05e8ae66ab9
BLAKE2b-256 5edf1965691dbcd27c04dd70f7b281cb2a39a9152c2f85290329ee8bb73970a1

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