Skip to main content

Helps you with bin-edges, -centers, and more.

Project description

TestStatus PyPiStatus BlackStyle BlackPackStyle MITLicenseBadge

A collection of tools to help with binning.

Binning

The Binning is powerful dict which contains many bin related quantities and is soley constructed from the edges of a binning.

import numpy as np
import binning_utils
binning_utils.Binning(bin_edges=np.linspace(0, 1, 9))

{'num': 4,
 'edges': array([0.  , 0.25, 0.5 , 0.75, 1.  ]),
 'centers': array([0.125, 0.375, 0.625, 0.875]),
 'widths': array([0.25, 0.25, 0.25, 0.25]),
 'start': 0.0,
 'stop': 1.0,
 'limits': array([0., 1.])}

random drawing

Draw the bin to which a sample is randomly assigned to. This assumes that the distribution of samples is uniform over the entire range of the binning. You can provide the aperture of the bins though. (This is the widths of the bins if the binning is one dimensional).

import numpy as np
import binning_utils
prng = np.random.Generator(np.random.PCG64(19))

assignment = binning_utils.draw_random_bin(
    prng=prng,
    bin_apertures=[1000, 4000, 2000, 3000],
    size=10000,
)

print(np.unique(assignment, return_counts=True))

(array([0, 1, 2, 3]), array([ 974, 3950, 2060, 3016]))

power10

Create binning in geomspace which is aligned to decades.

import binning_utils
binning_utils.power10.space(
    start_decade=0,
    start_bin=0,
    stop_decade=2,
    stop_bin=1,
    num_bins_per_decade=3,
)
array([ 1., 2.15, 4.64, 10., 21.54, 46.41, 100.])

powerspace

To make bin edges for distributions occuring in power laws. For example to histogram the energies of cosmic rays which occur in a power law with slope -2.7

import binning_utils
binning_utils.powerspace(
    start=1,
    stop=10,
    power_slope=-2.7,
    size=10,
)
array([ 1.        ,  1.07017144,  1.15544801,  1.26196439,  1.39995703,
    1.58808152,  1.86493297,  2.32807878,  3.33799855, 10.        ])

sphere

Make tiles of roughly same areas on the surface of a sphere using a Fibonacci spacing.

import binning_utils
vertices_on_sphere = binning_utils.sphere.fibonacci_space(
    size=100,
    max_zenith_distance_rad=0.5,
)

Project details


Download files

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

Source Distribution

Built Distribution

File details

Details for the file binning_utils_sebastian_achim_mueller-0.0.19.tar.gz.

File metadata

File hashes

Hashes for binning_utils_sebastian_achim_mueller-0.0.19.tar.gz
Algorithm Hash digest
SHA256 9ff9fd4c2023201db07ed6476d87948b3bacb612cc1e4e501e0974f594268462
MD5 cccf4c4679040e64058827f4a1278ca8
BLAKE2b-256 8b7d7422cb4b171b247a8ffd5e57b6ff5f1b932a94fe282d9fabf9a50662b4d1

See more details on using hashes here.

File details

Details for the file binning_utils_sebastian_achim_mueller-0.0.19-py3-none-any.whl.

File metadata

File hashes

Hashes for binning_utils_sebastian_achim_mueller-0.0.19-py3-none-any.whl
Algorithm Hash digest
SHA256 41d587241af54d3d056c9772cb598f885a9e72fdcb251dc2c3bc794c923db162
MD5 9ad9ab169e961cfd429164825d5a2bd5
BLAKE2b-256 db91258b332821e704716a6915a371eac9a6966437461f67a68f43385d61da76

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