Skip to content

Commit f42a502

Browse files
committed
added support for forecasts with single magnitude bin
fixes #140
1 parent 732733b commit f42a502

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

csep/utils/calc.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,12 @@ def bin1d_vec(p, bins, tol=None, right_continuous=False):
7272
bins = numpy.array(bins)
7373
p = numpy.array(p)
7474
a0 = numpy.min(bins)
75-
h = bins[1] - bins[0]
75+
# if user supplies only a single bin, do 2 things: 1) fix right continuous to true, and use of h is arbitrary
76+
if bins.size == 1:
77+
right_continuous = True
78+
h = 1
79+
else:
80+
h = bins[1] - bins[0]
7681

7782
a0_tol = numpy.abs(a0) * numpy.finfo(numpy.float).eps
7883
h_tol = numpy.abs(h) * numpy.finfo(numpy.float).eps

tests/test_calc.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,14 @@ def test_bin1d_vec_int(self):
9898
expected = [0, 0, 0, 1, 2]
9999
self.assertListEqual(test.tolist(), expected)
100100

101+
def test_bin1d_single_bin1(self):
102+
data = [0, 2, 3, 1, 1.5, 1.0, 0.99]
103+
bin_edges = [1]
104+
# purposely leaving right_continous flag=False bc it should be forced in the bin1d_vec function
105+
test = bin1d_vec(data, bin_edges)
106+
expected = [-1, 0, 0, 0, 0, 0, -1]
107+
self.assertListEqual(test.tolist(), expected)
108+
101109
def test_upper_limit_right_continuous(self):
102110
data = [40, 40, 40]
103111
bin_edges = [0, 10, 20, 30]

0 commit comments

Comments
 (0)