scikit-hep / histbook

Versatile, high-performance histogram toolkit for Numpy.
BSD 3-Clause "New" or "Revised" License
109 stars 9 forks source link

Another error #29

Closed imandr closed 6 years ago

imandr commented 6 years ago

I have this fragment, which is not working:

h_muon_kinematics = Hist(
    bin("mu_phi", 10, -180, 180),
    bin("mu_theta", 10, -90, 90),
    bin("mu_p3", 10, 0, 1000),
    bin("mu_e", 10, 0, 1000),
    bin("mu_pt", 10, 0, 1000)
)

h_muon_kinematics.fill(
    mu_phi = np.random.random((100,)),
    mu_theta = np.random.random((100,)),
    mu_p3 = np.random.random((100,))*1000,
    mu_e = np.random.random((100,))*1000,
    mu_pt = np.random.random((100,))*1000
)

grid(2,
        h_muon_kinematics.step("mu_phi"),
        h_muon_kinematics.step("mu_theta"),
        h_muon_kinematics.step("mu_p3"),
        h_muon_kinematics.step("mu_pt"),
        h_muon_kinematics.step("mu_e")
).to(canvas)

Error is:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-10-e8fa35fd32f6> in <module>()
     21         h_muon_kinematics.step("mu_pt"),
     22         h_muon_kinematics.step("mu_e")
---> 23 ).to(canvas)

/home/ivm/anaconda2/lib/python2.7/site-packages/histbook-1.1.0-py2.7.egg/histbook/vega.pyc in to(self, fcn)
    453     def to(self, fcn):
    454         """Call ``fcn`` on the Vega-Lite JSON for this plot."""
--> 455         return fcn(self.vegalite())
    456 
    457     def ipyvega(self):

/home/ivm/anaconda2/lib/python2.7/site-packages/histbook-1.1.0-py2.7.egg/histbook/vega.pyc in vegalite(self)
   1087                "vconcat": [{"hconcat": []}]}
   1088 
-> 1089         self._fill(0, allaxis, alldomains, out["vconcat"])
   1090         return out

/home/ivm/anaconda2/lib/python2.7/site-packages/histbook-1.1.0-py2.7.egg/histbook/vega.pyc in _fill(self, i, allaxis, alldomains, tofill)
   1069             else:
   1070                 varname = self._varname(i)
-> 1071                 marks, encodings, transforms = plotable._vegalite(allaxis[i], alldomains[i], varname)
   1072                 thislayer = [{"filter": {"field": "id", "equal": varname}}]
   1073 

/home/ivm/anaconda2/lib/python2.7/site-packages/histbook-1.1.0-py2.7.egg/histbook/vega.pyc in _vegalite(self, axis, domains, varname)
    628                 raise AssertionError(values)
    629 
--> 630         encoding = {"x": {"field": varname + str(axis.index(self._last.axis)), "type": xtype, "scale": {"zero": False}, "axis": {"title": xtitle}},
    631                     "y": {"field": varname + str(len(axis)), "type": "quantitative", "axis": {"title": ytitle}}}
    632         for channel in self._chain[:-1]:

ValueError: bin('mu_theta', 10, -90.0, 90.0) is not in list
imandr commented 6 years ago

I think is it something with grid(). When I change grid(n,...) to beside(...) it works

jpivarski commented 6 years ago

You're right. I tested grid and then later made all of the Combinations composable. In doing so, I missed a i += 1 in grid.

I need to find a way to put plotting in deployment tests. Possibly through Altair (which checks the generated Vega against a schema). It would be hard to do unit tests on images...