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
[WIP] histogram heart surgery #432
Conversation
Heh, don't do it for me because I'm not using it any more. Beware messing with lots of code in production. Maybe try and gauge how many people this will affect by making a really simple email which solicits complaints. |
Yeah, it was more of a joke. Maybe I could lure you back to HEP :) That's a good plan. I will send an email out to the users and dev lists when this PR is ready. |
@schmitts you mind taking a peek at this? |
I'll have a look. |
👍 |
@pwaller thanks for having a look! |
I'll be merging this PR in soon. Last chance for comments :) |
Addresses #227
Bins are 0-indexed at the underflow bin like ROOT
This PR changes the histogram indexing so that index 0 refers to the underflow bin and index
nbins(axis) + 1
is the overflow bin. In the end this seemed like the best option. Allowing the user to decide the indexing scheme at init would just be a mess. Note though, that the methods that return a generator if index is None allow the option of excluding or including the overflow bins.So with this change, rootpy's indexing scheme will be identical to ROOT's. rootpy just defines the centers, edges and widths of the overflow bins as (+/-)infinity, where ROOT gives you bogus values.
We will advertise this in BIG BOLD TEXT in the WHATSNEW.md and mail list. I'll start updating the WHATSNEW.md in this PR.
Full slicing support
Histogram
__getitem__
and__setitem__
methods now accept slicing by global bin index or along each axis separately.Access contents and errors:
__setitem__
with a slice and a single value just repeats that value over the sliced view:If a single index is requested then a BinProxy is returned:
If a slice is requested, then a HistIndexView or Hist[2D|3D]View is returned. You may iterate over the BinProxies in these views.
You can then construct a new histogram using a view of another. The step member of a slice translates to a rebinning along the associated axis.
Example: reverse the bin contents and errors:
Summary of changes
len(hist)
is now the same ash.GetSize()
(so includes overflow bins):h.nbins(axis) + 1
is the overflow bin.[]
operator returns a BinProxy if a single bin is selected or a view if a slice is selected: