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

binning_utils_sebastian_achim_mueller-0.0.20.tar.gz (10.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

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

File metadata

File hashes

Hashes for binning_utils_sebastian_achim_mueller-0.0.20.tar.gz
Algorithm Hash digest
SHA256 7e48aa6a61c4379625ed31d1e062250f026227af721f93b9eec6580a22b23c01
MD5 334826a66aaafd74e41954afa3979bdd
BLAKE2b-256 069c3e78eebe1e776cbec1a7fc07fb600923213613a63225a04657c648c11b08

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for binning_utils_sebastian_achim_mueller-0.0.20-py3-none-any.whl
Algorithm Hash digest
SHA256 c5f1d885d713990bf0bfd6620bdb82bea21922119f453630e8f8cf6564036208
MD5 da82c5dc36361bbfc261081611618f48
BLAKE2b-256 088841ae464413b67d88c28d171e850022174f938f98a2fdc2bd2c45ddd7d577

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page