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

Uploaded Source

Built Distributions

pygram11-0.8.1-cp38-cp38-manylinux2010_x86_64.whl (266.4 kB view details)

Uploaded CPython 3.8 manylinux: glibc 2.12+ x86-64

pygram11-0.8.1-cp38-cp38-manylinux1_x86_64.whl (203.4 kB view details)

Uploaded CPython 3.8

pygram11-0.8.1-cp38-cp38-macosx_10_9_x86_64.whl (401.0 kB view details)

Uploaded CPython 3.8 macOS 10.9+ x86-64

pygram11-0.8.1-cp37-cp37m-manylinux2010_x86_64.whl (264.9 kB view details)

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

pygram11-0.8.1-cp37-cp37m-manylinux1_x86_64.whl (205.8 kB view details)

Uploaded CPython 3.7m

pygram11-0.8.1-cp37-cp37m-macosx_10_9_x86_64.whl (396.7 kB view details)

Uploaded CPython 3.7m macOS 10.9+ x86-64

pygram11-0.8.1-cp36-cp36m-manylinux2010_x86_64.whl (264.7 kB view details)

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

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

Uploaded CPython 3.6m

pygram11-0.8.1-cp36-cp36m-macosx_10_9_x86_64.whl (396.7 kB view details)

Uploaded CPython 3.6m macOS 10.9+ x86-64

File details

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

File metadata

  • Download URL: pygram11-0.8.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.22.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.8.2

File hashes

Hashes for pygram11-0.8.1.tar.gz
Algorithm Hash digest
SHA256 7ac8136ef5ce5cba0d55160f65d627de4d46fcac306aee51c170fa2888d1c348
MD5 ba65d13ce52d8ee605b1be4d687ff4d5
BLAKE2b-256 5859fa559d67d6e07941aac265641ff346b3838f1d68bcf286b4bbda655c1eae

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pygram11-0.8.1-cp38-cp38-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 266.4 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.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.2

File hashes

Hashes for pygram11-0.8.1-cp38-cp38-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 824abd4fa3c7a06078eaa7ed0431601393864042d6726e83932a086437771b9f
MD5 824819ff767f700b6894f049b009c1cf
BLAKE2b-256 8a8301bc4ab8386a184b3dcc72fc8d3f5d032cb35b36952fd64c8d58cc561f3e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pygram11-0.8.1-cp38-cp38-manylinux1_x86_64.whl
  • Upload date:
  • Size: 203.4 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.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.2

File hashes

Hashes for pygram11-0.8.1-cp38-cp38-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 dcfac2413d28c2f4868be2a99dd93b50e33bd093aceb9a67c22fad5fb1840ac0
MD5 e26c50d9b0b2b6e8c423971e2ce4ac85
BLAKE2b-256 13106f2b5f13cb77c3dce9e0dd0fe24a1214769dd4d7238a49e3286e0457e5b2

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pygram11-0.8.1-cp38-cp38-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 401.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.22.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.8.2

File hashes

Hashes for pygram11-0.8.1-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 56c49b4b360589ba31fb2ae88f365ea505ae3575c0f957259f7c80fa3f1c1650
MD5 0ddea8c4b8f16c86e2d28698854fe3d5
BLAKE2b-256 a86fdc7b429409e59cdb4bea9372a944d099c447dbc8f7c549a24bb97797b0ca

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pygram11-0.8.1-cp37-cp37m-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 264.9 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.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.2

File hashes

Hashes for pygram11-0.8.1-cp37-cp37m-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 b56bf590af9000dd2205039fe362023f10fb716f97107474e3347cbbd99d586b
MD5 fd5c7afb1c7a774549889425f4778a00
BLAKE2b-256 ed0911846d4183ce198023a17fef1b035edb47338bcdcc6e5a8ebf053e3045e6

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pygram11-0.8.1-cp37-cp37m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 205.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.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.2

File hashes

Hashes for pygram11-0.8.1-cp37-cp37m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 c8dfe2fab8e7a247bd1bf6ea3c3e223d214a555895ab23c9300205b3649ddfdd
MD5 9422b1e78021eac783ebcd2a99567bf5
BLAKE2b-256 971261aec86d1f0f850cf5dda4beed9a82de52f68deaee41e15c8973f639dd76

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pygram11-0.8.1-cp37-cp37m-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 396.7 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/46.1.3 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.8.2

File hashes

Hashes for pygram11-0.8.1-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 60cd654c24618795a4c7427fbebed06a30c6193b08da3c594dc81a57ade753f7
MD5 5c25bf46a45a55294d0a3db5a89e2ac8
BLAKE2b-256 8dedd3cdc94d3da3d78cd41809d5100fa79b0983b46300a5bed9af29c645ab5a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pygram11-0.8.1-cp36-cp36m-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 264.7 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.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.2

File hashes

Hashes for pygram11-0.8.1-cp36-cp36m-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 00881fefee823813600fbe6f0bb3ebd78a858a9be438814d827c9a92cb152e03
MD5 fc00150a2b6a6825cbf6cfad3e7d9150
BLAKE2b-256 9fca58d14acd208f84a4c8e8e2dd318fd0cafcae7dd1909aff0ba6d40e88b844

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pygram11-0.8.1-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.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.2

File hashes

Hashes for pygram11-0.8.1-cp36-cp36m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 648756d203d1c7d2a61f2f7795eb9a54551444a3e4b1d9641397ed1a17938767
MD5 eadf6268edcf7c6f3fd3e46efda58785
BLAKE2b-256 3a81047081400098da76c8e4e414614cd14cf68675354a05635eea367f626bd4

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pygram11-0.8.1-cp36-cp36m-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 396.7 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/46.1.3 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.8.2

File hashes

Hashes for pygram11-0.8.1-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 911c1e42551ff5056a7e54467a0a39510b91b9f1e41e45d3ee15d277f9480bbc
MD5 d9110fa98612c7d1bb3a90492fb69a15
BLAKE2b-256 13ed5eb7cfe2e0f340668b754cf983cd510ee299bedd82e5395cd51c66442987

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