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

Uploaded Source

Built Distributions

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

Uploaded CPython 3.8 manylinux: glibc 2.12+ x86-64

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

Uploaded CPython 3.8

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

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

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

Uploaded CPython 3.7m

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

Uploaded CPython 3.7m macOS 10.9+ x86-64

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

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

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

Uploaded CPython 3.6m

pygram11-0.9.1-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.9.1.tar.gz.

File metadata

  • Download URL: pygram11-0.9.1.tar.gz
  • Upload date:
  • Size: 530.3 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.46.0 CPython/3.8.2

File hashes

Hashes for pygram11-0.9.1.tar.gz
Algorithm Hash digest
SHA256 5475366eb773dd76dac929b0d8e0fe9614165e737aca2ef61a744d737b4acca3
MD5 24de2379779118a06516db87d979d92b
BLAKE2b-256 9c6e36ab2be628df76837bdce2de5727cdcdf73ba91682b4daeb0d8906e7c85f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pygram11-0.9.1-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.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.9.1-cp38-cp38-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 375442b804ff6c5ab65de2866c2feb5e293f458c81f6eac31b593b5b3691f676
MD5 aee5845e1ce10fce2e0ef7453eb6c392
BLAKE2b-256 4b1d38ec40f8b57c32e38c1377de06d5f55b3c198702d51d1a2b493309124789

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pygram11-0.9.1-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.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.9.1-cp38-cp38-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 d3d08ef752d951016d80c690346f806f574febb9b77d3487893388ccca82c326
MD5 ba067c97442e4d816033b3d72e9db617
BLAKE2b-256 3999ddb1c14116138e0757955e23647c0ce240b42ac0de0c9ebdece35f6bdbf9

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pygram11-0.9.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.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.9.1-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 e9620e118bbdc1ef9403946ba08dcdaca71f7ade3777d97fa803c756324a734f
MD5 a9bde34de0b3f5de8286cb8d9fc1eb47
BLAKE2b-256 5601bad4466470bcd40c569b77d191f03fae72b74c3a1fab5025bece2f66d65d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pygram11-0.9.1-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.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.9.1-cp37-cp37m-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 2b5050b2d494ed074e6fabfce54d12cc975d98449f3f8136f373de6db53eacd1
MD5 9a9bfe8a9527a626bf9201b455eb6c53
BLAKE2b-256 bdccfcdafa9832751a2272b7ca5332bb8cb5de4e776fb8e8798da36a6ea376c6

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pygram11-0.9.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.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.9.1-cp37-cp37m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 9ee0617a13a49ee64707f93a7fe2da94b13b5edaf36efbf3a3f269ed7c614ed3
MD5 e668f39ef462a33c33303ad5f6071a6c
BLAKE2b-256 531964643a4602bbc9596727827f7ef6b14ae0c5016cb6bc94537b5df2311228

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pygram11-0.9.1-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.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.9.1-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 53b92c5e6a96008c50726414a8c4fb940b8b6e001c65df612720290a29cfabb7
MD5 7fe45c1c513a7e24ad8758298cce6b29
BLAKE2b-256 411271e14ce2bd2225c50754bdcfe3bf0e410f82e5e838c22aa97e44f7c38274

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pygram11-0.9.1-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.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.9.1-cp36-cp36m-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 abe72baff229b38505ad752c56aefabba5e3896042356f95fb18ce62b723e95b
MD5 4d3e76bb450ddfaa1d10eaab8e37a9eb
BLAKE2b-256 a9d96bc3db65f888ee9d4b22854df13912411b0d2e4c5c42fbdc6580931af40d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pygram11-0.9.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.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.9.1-cp36-cp36m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 acfc49a17b46490d4502ba8e12ba9c88132777fa3d6a82ac804735b45e8b10c7
MD5 66ed30083496448109fa0a8387c6b662
BLAKE2b-256 bb1e3078880fe073517209b8d2199f2d4898773fbbf2b6ea0c0629742b0c68df

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pygram11-0.9.1-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.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.9.1-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 487b7434fa11d032a9d4257f92d8ad35d31063509712fbb65d6961d639d9d9db
MD5 a130d4874f0f3e2fdc1b811b2716e2b5
BLAKE2b-256 6ad92204e3309c59b8ba2715ef9f69f78eec4f5f2645a78bdc6113ed7b388085

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