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
feat: conversion of ROOT histograms to PlottableHistogram #27
Conversation
This is awesome, thanks! Bug me if I don't review it by the end of the week. |
PS: Sourcery (c34d809) recommends using "guard" style, which has the short-circuit branch come first. It's easier to read with less action at a distance, and avoids excessive indentation. |
I was just wondering if this was already in, would be great to have by PyHEP :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! A couple of optional ideas:
- We could either make type aliases to improve readability for the ROOT types (TAxis = Any), or maybe even make them Protocols (TAxis would have GetNbins, etc). But it's really not any different from "Any".
- It's optional and beyond the strict protocol, but maybe we could promote fName to
.name
?
Thanks for the review!
I'm not familiar enough with the type annotations, protocols etc. yet to tackle that, sorry, but feel free to add it.
Good idea, done |
bb9249b
to
f9ede8b
Compare
I've added a ROOT test system (you can even run it locally with nox, though it will be a bit slow until wntrblm/nox#444, and it will be a little harder to maintain unless wntrblm/nox#447 gets addressed). Could you add a test converting a ROOT histogram to the mostly-empty test file I've added? |
c4e89b3
to
032d59e
Compare
[pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci
032d59e
to
0a6e022
Compare
Sourcery Code Quality Report✅ Merging this PR will increase code quality in the affected files by 2.63%.
Here are some functions in these files that still need a tune-up:
Legend and ExplanationThe emojis denote the absolute quality of the code:
The 👍 and 👎 indicate whether the quality has improved or gotten worse with this pull request. Please see our documentation here for details on how these metrics are calculated. We are actively working on this report - lots more documentation and extra metrics to come! Help us improve this quality report! |
Beautiful, thank you! |
Tested for TH1F by comparing as follows:
The conversion to numpy exploits the fact that TH1 inherits from TArray (which can directly be converted to a numpy array) for storing the counts, and the sums of squared weights is stored as another TArray (so most could be replaced by equivalent PyROOT pythonizations in the future).
For more-dimensional histograms I put
order="F"
in the reshape such that.values()[i,j]
equals.GetBinContent(i+1, j+1)
, but didn't test beyond that. Overflow bins are dropped.CC @andrzejnovak