Skip to content

Commit

Permalink
mplhep lowerbound version (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
APN-Pucky authored Nov 13, 2024
1 parent 8d43d59 commit 17a1219
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 24 deletions.
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ classifiers = [
"Topic :: Scientific/Engineering",
]
dependencies = [
"numpy"
"numpy",
"mplhep>=0.3.35"
]
[project.optional-dependencies]
lint = [
Expand Down
3 changes: 1 addition & 2 deletions src/babyyoda/histo1d.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import sys
from typing import Any, Optional, Union

import mplhep as hep
import numpy as np

import babyyoda
Expand Down Expand Up @@ -349,8 +350,6 @@ def project(self) -> Any:
return p

def plot(self, *args: Any, binwnorm: float = 1.0, **kwargs: Any) -> None:
import mplhep as hep

hep.histplot(
self,
*args,
Expand Down
25 changes: 4 additions & 21 deletions src/babyyoda/histo2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import sys
from typing import Any, Optional, Union

import mplhep as hep
import numpy as np

from babyyoda.analysisobject import UHIAnalysisObject
Expand Down Expand Up @@ -402,8 +403,8 @@ def project(self, axis: int = 0) -> Any:
def to_string(self) -> str:
return str(self.to_grogu_v3().to_string())

def plot(self, *args: Any, binwnorm: bool = True, **kwargs: Any) -> None:
# # TODO should use histplot
def plot(self, *args: Any, binwnorm: float = 1.0, **kwargs: Any) -> None:
# # TODO should use histplot?
# import mplhep as hep

# hep.histplot(
Expand All @@ -414,25 +415,7 @@ def plot(self, *args: Any, binwnorm: bool = True, **kwargs: Any) -> None:
# binwnorm=binwnorm,
# **kwargs,
# )
import mplhep as hep

if binwnorm:
# Hack in the temporary division by dVol
saved_values = self.values

def temp_values() -> np.ndarray:
return (
np.array(
[b.sumW() / vol for b, vol in zip(self.bins(), self.dVols())]
)
.reshape((len(self.axes[1]), len(self.axes[0])))
.T
)

self.values = temp_values # type: ignore[method-assign]
hep.hist2dplot(self, *args, **kwargs)
if binwnorm:
self.values = saved_values # type: ignore[method-assign]
hep.hist2dplot(self, *args, binwnorm=binwnorm, **kwargs)

def _ipython_display_(self) -> "UHIHisto2D":
with contextlib.suppress(ImportError):
Expand Down

0 comments on commit 17a1219

Please sign in to comment.