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,
)
Metadata
Release files for binning-utils-sebastian-achim-mueller 0.0.20
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| binning_utils_sebastian_achim_mueller-0.0.20.tar.gz | 10.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| binning_utils_sebastian_achim_mueller-0.0.20-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 21.3 kB
Release files / binning_utils_sebastian_achim_mueller-0.0.20.tar.gz
| Download URL | binning_utils_sebastian_achim_mueller-0.0.20.tar.gz |
|---|---|
| Size | 10.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7e48aa6a61c4379625ed31d1e062250f026227af721f93b9eec6580a22b23c01
|
|
BLAKE2b-256 checksum How to use checksums |
069c3e78eebe1e776cbec1a7fc07fb600923213613a63225a04657c648c11b08
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.11.5
|
Release files / binning_utils_sebastian_achim_mueller-0.0.20-py3-none-any.whl
| Download URL | binning_utils_sebastian_achim_mueller-0.0.20-py3-none-any.whl |
|---|---|
| Size | 10.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c5f1d885d713990bf0bfd6620bdb82bea21922119f453630e8f8cf6564036208
|
|
BLAKE2b-256 checksum How to use checksums |
088841ae464413b67d88c28d171e850022174f938f98a2fdc2bd2c45ddd7d577
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.11.5
|