You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was wondering if it is possible to implement a rebinning algorithm that uses a new bh.axis or list of new edges object to complement the rebin-by-factor method that exists? Maybe one can start by an implementation that asserts the new edges lie on the boundaries of the old ones and then work on adding some interpolation algorithms to handle other cases. I have had a simple implementation of the re-binning which looks like :
def rebin(hist, new_axis, axis = 0):
# Need to match storage of incoming histogram
hnew = bh.Histogram(new_axis, storage=bh.storage.Weight())
new_edges = new_axis.edges
sw = np.array(hist.values())
sw2 = np.array(hist.variances())
assert all(e in hist.axes[axis].edges for e in new_edges)
binmap = np.digitize(hist.axes[axis].centers, new_edges)
new_sw, new_sw2 = [], []
for bin_num in sorted(set(binmap)):
old_bins_in_this_bin = np.where(binmap == bin_num)[0]
w_slice = sw[old_bins_in_this_bin].sum()
sw2_slice = sw2[old_bins_in_this_bin].sum()
new_sw.append(w_slice)
new_sw2.append(sw2_slice)
hnew[...] = np.stack([new_sw, new_sw2], axis=-1)
return hnew
Or, it would be simpler if one can slice with an array of bh.loc(new_edges) for example.
Has there been any discussion/issues created on this?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi experts,
I was wondering if it is possible to implement a rebinning algorithm that uses a new
bh.axis
or list of new edges object to complement the rebin-by-factor method that exists? Maybe one can start by an implementation that asserts the new edges lie on the boundaries of the old ones and then work on adding some interpolation algorithms to handle other cases. I have had a simple implementation of the re-binning which looks like :Or, it would be simpler if one can slice with an array of
bh.loc(new_edges)
for example.Has there been any discussion/issues created on this?
Beta Was this translation helpful? Give feedback.
All reactions