-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #280 from lbl-anp/feature-sqrt-binning
- Loading branch information
Showing
2 changed files
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import pytest | ||
import numpy as np | ||
import becquerel as bq | ||
|
||
|
||
# ---------------------------------------------- | ||
# Test utils | ||
# ---------------------------------------------- | ||
|
||
|
||
def test_sqrt_bins(): | ||
"""Test basic functionality of utils.sqrt_bins.""" | ||
edge_min = 0 | ||
edge_max = 3000 | ||
n_bins = 128 | ||
be = bq.utils.sqrt_bins(edge_min, edge_max, n_bins) | ||
bc = (be[1:] + be[:-1]) / 2 | ||
bw = np.diff(be) | ||
# compute slope of line | ||
m = np.diff(bw ** 2) / np.diff(bc) | ||
# assert that the square of the bin | ||
assert np.allclose(m[0], m) | ||
# negative edge_min | ||
with pytest.raises(AssertionError): | ||
be = bq.utils.sqrt_bins(-10, edge_max, n_bins) | ||
# edge_max < edge_min | ||
with pytest.raises(AssertionError): | ||
be = bq.utils.sqrt_bins(100, 50, n_bins) |