Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement a square root binning function #280

Merged
merged 4 commits into from
Aug 4, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 15 additions & 0 deletions becquerel/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,18 @@ def bin_centers_from_edges(edges_kev):
edges_kev = np.array(edges_kev)
centers_kev = (edges_kev[:-1] + edges_kev[1:]) / 2
return centers_kev


def sqrt_bins(bin_min, bin_max, nbins):
"""
Square root binning

Args:
bin_min (float): Minimum bin edge (must be greater than 0)
jvavrek marked this conversation as resolved.
Show resolved Hide resolved
bin_max (float): Maximum bin edge (must be greater than bin_min)
nbins (int): Number of bins

Returns:
np.array of bin edges (length = nbins + 1)
"""
return np.linspace(np.sqrt(bin_min), np.sqrt(bin_max), nbins + 1) ** 2