Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
    Henry Schreiner
    @henryiii
    Currently pickeling is well supported, and quite fast. There’s a plan in the very near future to offer something specific that will even work across boost-histogram for Python and Boost.Histogram C++, but that’s still in planning phase. There also might be Hist-specific support for some other formats, and uproot 4 writing should support boost-histograms.
    Jim Pivarski
    @jpivarski

    In this talk, https://indico.cern.ch/event/1028381/#6-pythonic-data-science, I pointed out that this is an area that needs improvement: serialization of boost-histograms and interoperability with ROOT. One avenue is to use ROOT histograms as the serialization format, which takes advantage of the predominance of that format, but would lose some of the boost-histogram features, like mixed categorical/continuous axes. Uproot writing should do those conversions in either case.

    Beyond that, there ought to be a lossless way to save and load boost-histograms.

    5 replies
    Oh, one of the other ideas was just for Boost.Histograms (in C++) to use ROOT's streamer-generation macros, so that they can be serialized to ROOT files without conversion into and out of TH*.
    Henry Schreiner
    @henryiii
    Hmm, using underflow/overflow in a slice to pick looks like a possible bug. Underflow/overflow is special in slicing, and since we don’t have a single-element pick, it uses slicing in the backend.
    Andrzej Novak
    @andrzejnovak
    Is there a possible workaround?
    Henry Schreiner
    @henryiii
    Just really hacky ones, like using .view()
    Fixing it likely will be hacky too unless we get a “pick_one” command of some sort.
    Andrzej Novak
    @andrzejnovak
    ah, that's a bummer, I've actually stumbled into this while trying to investigate some other sus flow related behaviour
    Henry Schreiner
    @henryiii
    It will be fixable, I think, just will be a little messy on the backend until/unless we get a one-element "pick”.
    Hans Dembinski
    @HDembinski
    I suggested a non-hacky solution in the PR that can be implemented in pure Python
    1 reply
    Jim Pivarski
    @jpivarski

    This is likely a very easy question, but I haven't found the answer. What's a quick way to h.plot(...) with a logarithmic y-axis? I've tried ylog=True, logy=True, and yscale="log".

    I could follow the example given in scikit-hep/hist#198 and extract the ax object out of the output, but I'm writing a tutorial and I want to show how easy this is. (It's for the Uproot tutorial, but I'm trying to include related libraries.)

    @henryiii (The above question is for hist, not necessarily boost-histogram.)
    Henry Schreiner
    @henryiii
    I think we currently just expect users use the existing mpl tools to do this, rather than trying to shortcut it - but it’s likely common enough to provide a shortcut. I’ll check in a little bit - we pass on to mplhep, so if mplhep already provides a shortcut, then that “just works”.
    Though, what’s wrong with plt.yscale(“log”)?
    Jim Pivarski
    @jpivarski
    I haven't imported matplotlib.pyplot as plt yet, but I could do that.
    Henry Schreiner
    @henryiii
    That way, you don’t have to look up anything, and it works everwhere, rather than being hist-specific.
    Jim Pivarski
    @jpivarski
    It just seems like something that should be part of a one-liner, just as it is in Pandas.
    Hist.plot is sending some properties downstream (i.e. nothing to look up: they're defined by Matplotlib), in the StepPatch object it turns out.
    Henry Schreiner
    @henryiii
    We could match pandas.
    Jim Pivarski
    @jpivarski

    https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.plot.html

    • ax
    • figsize
    • title
    • grid
    • legend
    • logx
    • logy
    • loglog
    • xticks
    • yticks
    • xticks
    • yticks
    • xlim
    • ylim
    • xlabel
    • ylabel
    • rot
    • fontsize
    • colormap
    • colorbar

    ?

    Henry Schreiner
    @henryiii
    We could add some of those to Hist - I think mplhep should remain like mpl and use the normal, composible functions and calls.
    But I’m not against adding logy to hist. Not sure if logx makes much sense, or several of the others.
    Jim Pivarski
    @jpivarski
    That's true. This is a superset of what I think would be reasonable.
    ax is definitely good. That's saved me a few times (in Pandas).
    Henry Schreiner
    @henryiii
    We have ax
    Jim Pivarski
    @jpivarski
    Oh, good. When it's not a super-quick plot, I always start with fig, ax = plt.subplots(...).
    Henry Schreiner
    @henryiii
    Yes, as one should. :)
    Hans Dembinski
    @HDembinski
    I think it is really bad to duplicate matplotlib interface
    Wrapping a popular library like matplotlib behind your own interface is doing more harm than good, because now someone has to learn the matplotlib api and this additional api
    Andrzej Novak
    @andrzejnovak
    I agree with Hans here, though given how ubiquitous pandas is having similar shortcuts is not too far out of left field. While I also get a little annoyed by how long matplotlib.pyplot as plt is, duplicating the interface is not the way. For faster access I could see 2 options 1) have a shortcut to pyplot with hist.plt/mplhep.plt2) .plot()returning the ax object. I think Henry is very pro returning the artists, but the tuple with the artists could quite easily contain the ax as well. Then you could do h_obj.plot().ax.semilogy()if you really wanted a one-liner
    Henry Schreiner
    @henryiii
    I thought about that one liner, but it only works exactly once, you can’t make two changes that way (and you can easily get the axis from an artist). Is “pyplot” a required import, though? I seem tho remember that you can actually avoid that import, and just import the parts you need (though I’m prety sure we don’t do that)
    The point of hist.plot is to have a quick way to make a plot. If you want to import stuff, you can make figures/axes with plt, use mplhep.histplot, etc. Just like pandas, “.plot” is intended to be a shortcut for exploration, so mimicking the pandas API for quick-plotting isn’t unreasonable.
    Henry Schreiner
    @henryiii
    But I don’t want this to balloon, either, and skills you learn for matplotlib are composable / work anywhere, including other matplotlib plots, such as from pandas
    Supporing the pandas plot API might be something we could make a bit more formal. Will look into it.
    Matthew Feickert
    @matthewfeickert

    This isn't directly related, but this is reminding me of when I learned about how to use interactive vs. non-interactive matploltlib backends earlier this year and how that relates between using the matplotlib.pyplot.subplots vs. matplotlib.figure.Figure APIs

    https://gist.github.com/matthewfeickert/84245837f09673b2e7afea929c016904

    1 reply
    Henry Schreiner
    @henryiii
    Looks like plothist from mplhep already duplicates / provides a lot of this. I’d think keeping that simple and only having the shortcuts .plot would have been better.
    veprbl
    @veprbl:matrix.org
    [m]
    Hey! I have a question: Is there a file format that allows interop between C++ and python boost-histogram?
    Henry Schreiner
    @henryiii
    It’s planned. I think you can find a dissussion of it little while back in this(?) channel.
    veprbl
    @veprbl:matrix.org
    [m]
    I see. Thanks!
    Henry Schreiner
    @henryiii
    Shiny new versions of boost-histogram and hist are out, just in time for the talk at PyHEP. Watch the talk in 6.5 hours on Zoom or YouTube LiveStream (I think) to see what’s new!
    Angus Hollands
    @agoose77:matrix.org
    [m]
    I misread that as a 6.5 hour talk 😂 looking forward to it!
    Raghav Kansal
    @rkansal47
    Hi, i was wondering if there's a recommended way of keeping track of errors, e.g. when dividing two hists?
    Henry Schreiner
    @henryiii:matrix.org
    [m]
    I think views handle this correctly (and if not, it's likely a bug 😉) - h.view() / h2.view()
    Raghav Kansal
    @rkansal47
    oh sorry i meant errors as in confidence intervals but i think i found what i was looking for https://hist.readthedocs.io/en/latest/reference/hist.html#module-hist.intervals :)
    Henry Schreiner
    @henryiii
    Hist is now Python 3.7+ only following NEP 29 (3.6 users will still get Hist 2.4)
    Andrzej Novak
    @andrzejnovak
    yay
    Matthew Feickert
    @matthewfeickert
    @henryiii @LovelyBuggies If you have a hist.hist.Hist object that someone else made and serialized to give to you, and upon deserializing realize that the name and label field for the axes has information that should have been put in metadata placed in them (e.g., hist_1.axes[0].name gives wjets instead of something like pt) is there a way to update the name and label in a copy of the histogram? name and label are read only in boost-histogram, so is there any way to get around this other then manually making new histogram objects and filling them with the old histogram contents?
    Henry Schreiner
    @henryiii
    Well, label is easy, it's not read-only. Only name is, because we validate that it doesn't get duplicated inside a histogram. You can set it via a secret method (hist_1.axes[0]._ax.metadata, IIRC), but I've intended to allow it to be set in bulk, that is, hist.axes.name = ("name1", "name2"), as that we can validate. I'll open an issue for that.
    Ethan Simpson
    @ethansimpson285
    Hi there, thanks for the great work on PyHEP histogram infrastructure. Apologies in advance, I feel this is a common question concerning bin errors and ratio plots. My main question is if there is a boost-histogram method to access the bin error, something that does the computation np.sqrt(h.values()))automatically? For generating ratio plots I understand I can use the hist.intervalsmodule, is this the current "best practice"?
    Henry Schreiner
    @henryiii
    np.sqrt(h.variances()) is better (though you need to be a tiny bit careful if the variances is None, which can happen for non-weighted storages if you fill with a weight)