Skip to main content

Fast histogramming in python built on pybind11 and OpenMP.

Project description

pygram11

Actions 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 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 need NumPy pre-installed and 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

When installing from source you'll need NumPy pre-installed 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'll probably want to install libomp from Homebrew.

pip install numpy
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, staterr = 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 (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)

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)
>>> 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

This version

0.7.0

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

Uploaded Source

Built Distributions

pygram11-0.7.0-cp38-cp38-manylinux2014_x86_64.whl (384.6 kB view details)

Uploaded CPython 3.8

pygram11-0.7.0-cp38-cp38-manylinux2010_x86_64.whl (360.5 kB view details)

Uploaded CPython 3.8 manylinux: glibc 2.12+ x86-64

pygram11-0.7.0-cp38-cp38-macosx_10_9_x86_64.whl (453.9 kB view details)

Uploaded CPython 3.8 macOS 10.9+ x86-64

pygram11-0.7.0-cp37-cp37m-manylinux2014_x86_64.whl (386.3 kB view details)

Uploaded CPython 3.7m

pygram11-0.7.0-cp37-cp37m-manylinux2010_x86_64.whl (362.1 kB view details)

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

pygram11-0.7.0-cp37-cp37m-macosx_10_9_x86_64.whl (449.5 kB view details)

Uploaded CPython 3.7m macOS 10.9+ x86-64

pygram11-0.7.0-cp36-cp36m-manylinux2014_x86_64.whl (386.3 kB view details)

Uploaded CPython 3.6m

pygram11-0.7.0-cp36-cp36m-manylinux2010_x86_64.whl (362.0 kB view details)

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

pygram11-0.7.0-cp36-cp36m-macosx_10_9_x86_64.whl (449.6 kB view details)

Uploaded CPython 3.6m macOS 10.9+ x86-64

File details

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

File metadata

  • Download URL: pygram11-0.7.0.tar.gz
  • Upload date:
  • Size: 532.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.1.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.8.1

File hashes

Hashes for pygram11-0.7.0.tar.gz
Algorithm Hash digest
SHA256 477e2b3eb77f51a3b985ee21d69a5772c2d2b5d05c1a018df7ecd4b91955a53a
MD5 b511a0c71dfa264fe3be848ba4ad5456
BLAKE2b-256 7a42deb0ce62845e0a63543216eb0c67f5ca612be514574cc9d10aaf6e3ffb7f

See more details on using hashes here.

File details

Details for the file pygram11-0.7.0-cp38-cp38-manylinux2014_x86_64.whl.

File metadata

  • Download URL: pygram11-0.7.0-cp38-cp38-manylinux2014_x86_64.whl
  • Upload date:
  • Size: 384.6 kB
  • Tags: CPython 3.8
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.1.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.8.1

File hashes

Hashes for pygram11-0.7.0-cp38-cp38-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d50467aeaaee304f771d3e85bb2524cd79c27e709dab502dd30782885faa5d43
MD5 d9749647f5eee95e9618dd1316b74a8b
BLAKE2b-256 758c0bd02c80d86a51845a9153bed95019e5507bbdf9ccfc8cd9c4de5f198112

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pygram11-0.7.0-cp38-cp38-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 360.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.22.0 setuptools/45.1.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.8.1

File hashes

Hashes for pygram11-0.7.0-cp38-cp38-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 dd409b3f1866b23241061a38e123dade7a84c02561c208473b57ab2b6460a726
MD5 b9cb96b169557bb0081ad00fa052a5a8
BLAKE2b-256 4ce949f205fb6da27d0d371b87aace6af96f6ef246513a34457cd0798027f785

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pygram11-0.7.0-cp38-cp38-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 453.9 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.22.0 setuptools/45.1.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.8.1

File hashes

Hashes for pygram11-0.7.0-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 c5809bdc7a2f0a6eccb3db2394005c10788884b7dd4800cbd1781c837a150882
MD5 1d4db3c3fc179963adc0b6dd5043d67c
BLAKE2b-256 79815999e9d14a99771ef406bdaad35a806c1cde5357b160cdfef41ab235ebd6

See more details on using hashes here.

File details

Details for the file pygram11-0.7.0-cp37-cp37m-manylinux2014_x86_64.whl.

File metadata

  • Download URL: pygram11-0.7.0-cp37-cp37m-manylinux2014_x86_64.whl
  • Upload date:
  • Size: 386.3 kB
  • Tags: CPython 3.7m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.1.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.8.1

File hashes

Hashes for pygram11-0.7.0-cp37-cp37m-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 9950245ca61ce30359d55d0fbec0828656c84b45a002c46a64b740eee6ed9e42
MD5 b05290cea564c8e5d490af6dd16f1dac
BLAKE2b-256 784f73343dc98997692d2c4cd00fd585bd390169d5d89cfc547cd1d579e9a635

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pygram11-0.7.0-cp37-cp37m-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 362.1 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.22.0 setuptools/45.1.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.8.1

File hashes

Hashes for pygram11-0.7.0-cp37-cp37m-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 c090a307b04fc4b69e70e9c4213fb553506af05c217268373290445487bfdab5
MD5 488694606ee81c716e5c930b39fb0299
BLAKE2b-256 7224292510b2759e2a822ff42a8991cbc10f4560d91d0af96a2386a8cbcc08fe

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pygram11-0.7.0-cp37-cp37m-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 449.5 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.22.0 setuptools/45.1.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.8.1

File hashes

Hashes for pygram11-0.7.0-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 ea6af8bdb229e8db3ca0e20b953f5b686d8df7ad2e1c7f35010a338f7442c7ac
MD5 888e1d4702576589cf671641b28cb26e
BLAKE2b-256 31345780ba49a637dd19ac18e4f49a846f893678d9652eb5a795948125349cbd

See more details on using hashes here.

File details

Details for the file pygram11-0.7.0-cp36-cp36m-manylinux2014_x86_64.whl.

File metadata

  • Download URL: pygram11-0.7.0-cp36-cp36m-manylinux2014_x86_64.whl
  • Upload date:
  • Size: 386.3 kB
  • Tags: CPython 3.6m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.1.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.8.1

File hashes

Hashes for pygram11-0.7.0-cp36-cp36m-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c3dbfd07a542d5cfe7ffbd53dacd6e4634d9941076a4de77b543f9dc7587948b
MD5 87ca97406795af6618323e20d1433329
BLAKE2b-256 7f3a7a03a635a7d9425586a3349a5829a7b78cd32547c180ef4c46cd757cdc11

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pygram11-0.7.0-cp36-cp36m-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 362.0 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.22.0 setuptools/45.1.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.8.1

File hashes

Hashes for pygram11-0.7.0-cp36-cp36m-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 822ba8175da5bf3824024613bd7cd324811437556feabbffe815db1d487a4e97
MD5 83a86e1eaa60a452e7ca0626cf37c842
BLAKE2b-256 7f9328925b65468699d579d098592dba97353fe748a0dae93dd76ad258b52599

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pygram11-0.7.0-cp36-cp36m-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 449.6 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.22.0 setuptools/45.1.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.8.1

File hashes

Hashes for pygram11-0.7.0-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 60ad0c71e0da3b5e7f8fe22b1a2fba5dfff3e0c5b97eaabb382710725eb099e4
MD5 8cafe10e5bdb912a6fb1f63789ac45f8
BLAKE2b-256 0c998a7c6d1c4f07513b94c6332cda2c877d7f3a5bad9758d084b2b0d74137ed

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