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

This version

0.7.1

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

Uploaded Source

Built Distributions

pygram11-0.7.1-cp38-cp38-manylinux2014_x86_64.whl (384.5 kB view details)

Uploaded CPython 3.8

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

Uploaded CPython 3.8 manylinux: glibc 2.12+ x86-64

pygram11-0.7.1-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.1-cp37-cp37m-manylinux2014_x86_64.whl (386.3 kB view details)

Uploaded CPython 3.7m

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

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

pygram11-0.7.1-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.1-cp36-cp36m-manylinux2014_x86_64.whl (386.2 kB view details)

Uploaded CPython 3.6m

pygram11-0.7.1-cp36-cp36m-manylinux2010_x86_64.whl (361.9 kB view details)

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

pygram11-0.7.1-cp36-cp36m-macosx_10_9_x86_64.whl (449.5 kB view details)

Uploaded CPython 3.6m macOS 10.9+ x86-64

File details

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

File metadata

  • Download URL: pygram11-0.7.1.tar.gz
  • Upload date:
  • Size: 531.9 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.1.tar.gz
Algorithm Hash digest
SHA256 def008922cad642f4823749e90a80e79e5ca97e91e8b5a3c67e3239c3cdd87c5
MD5 dfd5c7d9f28b07771283888a4a8364b4
BLAKE2b-256 40bbc95f89912b455b0491ec9d6c39ca557a1fa8670f9c3c84849f56b05ea1f1

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pygram11-0.7.1-cp38-cp38-manylinux2014_x86_64.whl
  • Upload date:
  • Size: 384.5 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.1-cp38-cp38-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e4e1cfcfa78a6c03de194135df65b9164f77e1dd70f58c78d63906d6c097b227
MD5 2a9992d87f8450ee368261ac779a1dcd
BLAKE2b-256 0b33da4e77858ff300d0f50774d780ccd3c315148de8751f4ae04779f5b7ce57

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pygram11-0.7.1-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.1-cp38-cp38-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 bb26f223009ff05d95e525b0fa35ae3678a32d9e74b61ba489de6c44b043bd40
MD5 f2f32f8b6657c80e77d162491affa0fa
BLAKE2b-256 4e3cde80808e253cb82becf27443db318b415640deaa5ebb3663dc45b8743b12

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pygram11-0.7.1-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.1-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 4097e47bc61fea8821e8c5edaa45ede2ec25107bdd975a09e1b81388533adcdd
MD5 54df5931ba78140aefd2d07992f113ef
BLAKE2b-256 c6ee90cd62011fd0a22edcf18ec1030eb5ec2d141523d6684cae1ed6a9412438

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pygram11-0.7.1-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.1-cp37-cp37m-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 82da207b393f60254d17776fc96fd5d5bad6ffa24675cbb837c0f4c73969f2e8
MD5 1e50c5ac5e9ef87693c10098553cc2f4
BLAKE2b-256 29aea4e153a912b29d0a90c46e387386505a4e362f9056e567125644a6ab90bb

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pygram11-0.7.1-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.1-cp37-cp37m-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 961c4d279500d40002b3712a5ed8229f21e88a901e745f9ad0e6cd48ca7cc917
MD5 819f38f6c9a2b469d090763135114f1c
BLAKE2b-256 fefda7d353de9fe39e00024f0d8b58a3d9bc9aceef184eb5ea15b67b3bf6f439

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pygram11-0.7.1-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.1-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 884ecf72595f29c91872dc8dd88350fbf2b81e6ca0a1b01c9440b25a8b638a26
MD5 c50962e0879f4a44c931b65f26267e89
BLAKE2b-256 25de4f10bdaccd615cacbdf4c761759c82fe9eeaa6a3d77f697c2021206fa4bb

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pygram11-0.7.1-cp36-cp36m-manylinux2014_x86_64.whl
  • Upload date:
  • Size: 386.2 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.1-cp36-cp36m-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 9efcf9da192150db21bac6de4b6931575567d2298c0445bcaaf64455bea0a306
MD5 0b79d777e6f80181021ae61ec6da851c
BLAKE2b-256 ccf52b0810b16acc24f75b17d5f5a4963cfe3a54eab771153fa496e7cccae379

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pygram11-0.7.1-cp36-cp36m-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 361.9 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.1-cp36-cp36m-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 f42049f19d31e7f00125f8a43eb11fb2eab9eddac78311840b4256a51379d931
MD5 f10c435f9cbe0caf57162b24a9ce84fb
BLAKE2b-256 306e12cfa00de20d288bcad3b8143f7ce92c6a9e89a25311278ae210c01dcfa0

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pygram11-0.7.1-cp36-cp36m-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 449.5 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.1-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 cc4747883c9ae1dbfe3ef5ba0658185a7ab22fcad25f940a2b50a72505f8b7a3
MD5 e7d530069933b043149984f776eebe81
BLAKE2b-256 3183b3c0de1739714082cae173656f480afd3d3eb1b463836ebd57f157662dac

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