Skip to main content

The Boost::Histogram Python wrapper.

Project description

boost-histogram logo

boost-histogram for Python

Gitter Build Status Actions Status Documentation Status DOI Code style: black PyPI version Conda-Forge

Python bindings for Boost::Histogram (source), a C++14 library. This should become one of the fastest libraries for histogramming, while still providing the power of a full histogram object.

Version 0.6.0: Public beta

Please feel free to try out boost-histogram and give feedback. Join the discussion on gitter or open an issue!

Installation

You can install this library from PyPI with pip:

python -m pip install boost-histogram

or you can use Conda through conda-forge:

conda install -c conda-forge boost-histogram

All the normal best-practices for Python apply; you should be in a virtual environment, etc.

Usage

import boost_histogram as bh

# Compose axis however you like; this is a 2D histogram
hist = bh.Histogram(bh.axis.Regular(2, 0, 1),
                    bh.axis.Regular(4, 0.0, 1.0))

# Filling can be done with arrays, one per dimension
hist.fill([.3, .5, .2],
          [.1, .4, .9])

# Numpy array view into histogram counts, no overflow bins
counts = hist.view()

Features

  • Many axis types (all support metadata=...)

    • bh.axis.Regular(n, start, stop, ...): Make a regular axis. Options listed below.
      • overflow=False: Turn off overflow bin
      • underflow=False: Turn off underflow bin
      • growth=True: Turn on growing axis, bins added when out-of-range items added
      • circular=True: Turn on wrapping, so that out-of-range values wrap around into the axis
      • transform=bh.axis.transform.Log: Log spacing
      • transform=bh.axis.transform.Sqrt: Square root spacing
      • transform=bh.axis.transform.Pow(v): Power spacing
      • See also the flexible Function transform
    • bh.axis.Integer(start, stop, underflow=True, overflow=True, growth=False): Special high-speed version of regular for evenly spaced bins of width 1
    • bh.axis.Variable([start, edge1, edge2, ..., stop], underflow=True, overflow=True): Uneven bin spacing
    • bh.axis.Category([...], growth=False): Integer or string categories
  • Axis features:

    • .index(values): The index at a point (or points) on the axis
    • .value(indexes): The value for a fractional bin in the axis
    • .bin(i): The bin edges or a bin value (categories)
    • .centers: The N bin centers (if continuous)
    • .edges: The N+1 bin edges (if continuous)
    • .extent: The number of bins (including under/overflow)
    • .metadata: Anything a user wants to store
    • .options: The options set on the axis (bh.axis.options)
    • .size: The number of bins (not including under/overflow)
    • .widths: The N bin widths
  • Many storage types

    • bh.storage.Double(): Doubles for weighted values (default)
    • bh.storage.Int64(): 64-bit unsigned integers
    • bh.storage.Unlimited(): Starts small, but can go up to unlimited precision ints or doubles.
    • bh.storage.AtomicInt64(): Threadsafe filling, experimental. Does not support growing axis in threads.
    • bh.storage.Weight(): Stores a weight and sum of weights squared.
    • bh.storage.Mean(): Accepts a sample and computes the mean of the samples (profile).
    • bh.storage.WeightedMean(): Accepts a sample and a weight. It computes the weighted mean of the samples.
  • Accumulators

    • bh.accumulator.Sum: High accuracy sum (Neumaier) - used by the sum method when summing a numerical histogram
    • bh.accumulator.WeightedSum: Tracks a weighted sum and variance
    • bh.accumulator.Mean: Running count, mean, and variance (Welfords's incremental algorithm)
    • bh.accumulator.WeightedMean: Tracks a weighted sum, mean, and variance (West's incremental algorithm)
  • Histogram operations

    • h.fill(arr, ..., weight=...) Fill with N arrays or single values
    • h.rank: The number of dimensions
    • h.size or len(h): The number of bins
    • .reset(): Set counters to 0
    • +: Add two histograms
    • *=: Multiply by a scaler (not all storages) (hist * scalar and scalar * hist supported too)
    • /=: Divide by a scaler (not all storages) (hist / scalar supported too)
    • .to_numpy(flow=False): Convert to a numpy style tuple (with or without under/overflow bins)
    • .view(flow=False): Get a view on the bin contents (with or without under/overflow bins)
    • .axes: Get the axes
      • .axes[0]: Get the 0th axis
      • .axes.edges: The lower values as a broadcasting-ready array
      • All other properties of axes available here, too
    • .sum(flow=False): The total count of all bins
    • .project(ax1, ax2, ...): Project down to listed axis (numbers)
    • .reduce(ax, reduce_option, ...): shrink, rebin, or slice, or any combination
  • Indexing - Supports the Unified Histogram Indexing (UHI) proposal

  • Details

    • Use bh.Histogram(..., storage=...) to make a histogram (there are several different types)

Supported platforms

Binaries available:

The easiest way to get boost-histogram is to use a binary wheel, which happens when you run:

python -m pip install boost-histogram

These are the supported platforms for which wheels are produced:

System Arch Python versions
ManyLinux1 (custom GCC 9.2) 64 & 32-bit 2.7, 3.5, 3.6, 3.7, 3.8
ManyLinux2010 64-bit 2.7, 3.5, 3.6, 3.7, 3.8
macOS 10.9+ 64-bit 2.7, 3.6, 3.7, 3.8
Windows 64 & 32-bit 2.7, 3.6, 3.7, 3.8
  • Linux: I'm not supporting 3.4 because I have to build the Numpy wheels to do so.
  • manylinux1: Using a custom docker container with GCC 9.2; should work but can't be called directly other compiled extensions unless they do the same thing (think that's the main caveat). Supporting 32 bits because it's there.
  • manylinux2010: Requires pip 10+ and a version of Linux newer than 2010. This is very new technology.
  • MacOS: Uses the dedicated 64 bit 10.9+ Python.org builds. We are not supporting 3.5 because those no longer provide binaries (could add a 32+64 fat 10.6+ that really was 10.9+, but not worth it unless there is a need for it).
  • Windows: PyBind11 requires compilation with a newer copy of Visual Studio than Python 2.7's Visual Studio 2008; you need to have the Visual Studio 2015 distributable installed (the dll is included in 2017 and 2019, as well).

If you are on a Linux system that is not part of the "many" in manylinux, such as Alpine or ClearLinux, building from source is usually fine, since the compilers on those systems are often quite new. It will just take a little longer to install when it's using the sdist instead of a wheel.

Conda-Forge

The boost-histogram package is available on Conda-Forge, as well. All supported versions are available with the exception of Windows + Python 2.7, which cannot built due to the age of the compiler. Please use Pip if you really need Python 2.7 on Windows. You will also need the VS 2015 distributable, as described above.

conda install -c conda-forge boost-histogram

Source builds

For a source build, for example from an "sdist" package, the only requirements are a C++14 compatible compiler. The compiler requirements are dictated by Boost.Histogram's C++ requirements: gcc >= 5.5, clang >= 3.8, msvc >= 14.1.

If you are using Python 2.7 on Windows, you will need to use a recent version of Visual studio and force distutils to use it, or just upgrade to Python 3.6 or newer. Check the PyBind11 documentation for more help. On some Linux systems, you may need to use a newer compiler than the one your distribution ships with.

Having Numpy before building is recommended (enables multithreaded builds). Boost is not required or needed (this only depends on included header-only dependencies).This library is under active development; you can install directly from GitHub if you would like.

python -m pip install git+https://github.com/scikit-hep/boost-histogram.git@develop

For the moment, you need to uninstall and reinstall to ensure you have the latest version - pip will not rebuild if it thinks the version number has not changed. In the future, this may be addressed differently in boost-histogram.

Developing

See CONTRIBUTING.md for details on how to set up a development environment.

Talks and other documentation/tutorial sources

The official documentation is here, and includes a quickstart.


Acknowledgements

This library was primarily developed by Henry Schreiner and Hans Dembinski.

Support for this work was provided by the National Science Foundation cooperative agreement OAC-1836650 (IRIS-HEP) and OAC-1450377 (DIANA/HEP). Any opinions, findings, conclusions or recommendations expressed in this material are those of the authors and do not necessarily reflect the views of the National Science Foundation.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for boost-histogram, version 0.6.0
Filename, size File type Python version Upload date Hashes
Filename, size boost_histogram-0.6.0-cp27-cp27m-macosx_10_9_x86_64.whl (1.3 MB) File type Wheel Python version cp27 Upload date Hashes View hashes
Filename, size boost_histogram-0.6.0-cp27-cp27m-manylinux1_i686.whl (1.8 MB) File type Wheel Python version cp27 Upload date Hashes View hashes
Filename, size boost_histogram-0.6.0-cp27-cp27m-manylinux1_x86_64.whl (1.7 MB) File type Wheel Python version cp27 Upload date Hashes View hashes
Filename, size boost_histogram-0.6.0-cp27-cp27m-manylinux2010_x86_64.whl (1.3 MB) File type Wheel Python version cp27 Upload date Hashes View hashes
Filename, size boost_histogram-0.6.0-cp27-cp27mu-manylinux1_i686.whl (1.8 MB) File type Wheel Python version cp27 Upload date Hashes View hashes
Filename, size boost_histogram-0.6.0-cp27-cp27mu-manylinux1_x86_64.whl (1.7 MB) File type Wheel Python version cp27 Upload date Hashes View hashes
Filename, size boost_histogram-0.6.0-cp27-cp27mu-manylinux2010_x86_64.whl (1.3 MB) File type Wheel Python version cp27 Upload date Hashes View hashes
Filename, size boost_histogram-0.6.0-cp27-cp27m-win32.whl (537.6 kB) File type Wheel Python version cp27 Upload date Hashes View hashes
Filename, size boost_histogram-0.6.0-cp27-cp27m-win_amd64.whl (719.9 kB) File type Wheel Python version cp27 Upload date Hashes View hashes
Filename, size boost_histogram-0.6.0-cp35-cp35m-manylinux1_i686.whl (1.8 MB) File type Wheel Python version cp35 Upload date Hashes View hashes
Filename, size boost_histogram-0.6.0-cp35-cp35m-manylinux1_x86_64.whl (1.7 MB) File type Wheel Python version cp35 Upload date Hashes View hashes
Filename, size boost_histogram-0.6.0-cp35-cp35m-manylinux2010_x86_64.whl (1.2 MB) File type Wheel Python version cp35 Upload date Hashes View hashes
Filename, size boost_histogram-0.6.0-cp36-cp36m-macosx_10_9_x86_64.whl (1.3 MB) File type Wheel Python version cp36 Upload date Hashes View hashes
Filename, size boost_histogram-0.6.0-cp36-cp36m-manylinux1_i686.whl (1.8 MB) File type Wheel Python version cp36 Upload date Hashes View hashes
Filename, size boost_histogram-0.6.0-cp36-cp36m-manylinux1_x86_64.whl (1.7 MB) File type Wheel Python version cp36 Upload date Hashes View hashes
Filename, size boost_histogram-0.6.0-cp36-cp36m-manylinux2010_x86_64.whl (1.2 MB) File type Wheel Python version cp36 Upload date Hashes View hashes
Filename, size boost_histogram-0.6.0-cp36-cp36m-win32.whl (503.8 kB) File type Wheel Python version cp36 Upload date Hashes View hashes
Filename, size boost_histogram-0.6.0-cp36-cp36m-win_amd64.whl (651.3 kB) File type Wheel Python version cp36 Upload date Hashes View hashes
Filename, size boost_histogram-0.6.0-cp37-cp37m-macosx_10_9_x86_64.whl (1.3 MB) File type Wheel Python version cp37 Upload date Hashes View hashes
Filename, size boost_histogram-0.6.0-cp37-cp37m-manylinux1_i686.whl (1.8 MB) File type Wheel Python version cp37 Upload date Hashes View hashes
Filename, size boost_histogram-0.6.0-cp37-cp37m-manylinux1_x86_64.whl (1.7 MB) File type Wheel Python version cp37 Upload date Hashes View hashes
Filename, size boost_histogram-0.6.0-cp37-cp37m-manylinux2010_x86_64.whl (1.2 MB) File type Wheel Python version cp37 Upload date Hashes View hashes
Filename, size boost_histogram-0.6.0-cp37-cp37m-win32.whl (503.9 kB) File type Wheel Python version cp37 Upload date Hashes View hashes
Filename, size boost_histogram-0.6.0-cp37-cp37m-win_amd64.whl (651.4 kB) File type Wheel Python version cp37 Upload date Hashes View hashes
Filename, size boost_histogram-0.6.0-cp38-cp38-macosx_10_9_x86_64.whl (1.3 MB) File type Wheel Python version cp38 Upload date Hashes View hashes
Filename, size boost_histogram-0.6.0-cp38-cp38-manylinux1_i686.whl (1.7 MB) File type Wheel Python version cp38 Upload date Hashes View hashes
Filename, size boost_histogram-0.6.0-cp38-cp38-manylinux1_x86_64.whl (1.7 MB) File type Wheel Python version cp38 Upload date Hashes View hashes
Filename, size boost_histogram-0.6.0-cp38-cp38-manylinux2010_x86_64.whl (1.3 MB) File type Wheel Python version cp38 Upload date Hashes View hashes
Filename, size boost_histogram-0.6.0-cp38-cp38-win32.whl (500.3 kB) File type Wheel Python version cp38 Upload date Hashes View hashes
Filename, size boost_histogram-0.6.0-cp38-cp38-win_amd64.whl (648.8 kB) File type Wheel Python version cp38 Upload date Hashes View hashes
Filename, size boost-histogram-0.6.0.tar.gz (591.2 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page