Skip to content

Commit

Permalink
Renames
Browse files Browse the repository at this point in the history
  • Loading branch information
APN-Pucky committed Oct 9, 2024
1 parent 459d2a9 commit 13077f5
Show file tree
Hide file tree
Showing 16 changed files with 191 additions and 82 deletions.
6 changes: 3 additions & 3 deletions debug/.ipynb_checkpoints/histo1d-checkpoint.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
}
],
"source": [
"hists = grogu.read_grogu(\"../tests/test1d.yoda\")\n",
"hists = grogu.read_grogu(\"../tests/test_histo1d_v2.yoda\")\n",
"hists[\"/\"]"
]
},
Expand All @@ -50,7 +50,7 @@
}
],
"source": [
"hists = grogu.read_yoda(\"../tests/test1d.yoda\")\n",
"hists = grogu.read_yoda(\"../tests/test_histo1d_v2.yoda\")\n",
"hists[\"/\"]"
]
},
Expand Down Expand Up @@ -187,7 +187,7 @@
"metadata": {},
"outputs": [],
"source": [
"hists = yd.read(\"../tests/test1d.yoda\")"
"hists = yd.read(\"../tests/test_histo1d_v2.yoda\")"
]
},
{
Expand Down
8 changes: 4 additions & 4 deletions debug/.ipynb_checkpoints/histo2d-checkpoint.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
}
],
"source": [
"hists = grogu.read_grogu(\"../tests/test2d.yoda\")\n",
"hists = grogu.read_grogu(\"../tests/test_histo2d_v2.yoda\")\n",
"h=hists['/ALICE_2020_I1797621/GGPdfXQ']\n",
"h"
]
Expand Down Expand Up @@ -2586,7 +2586,7 @@
}
],
"source": [
"hists = grogu.read_grogu(\"../tests/test2d.yoda\")\n",
"hists = grogu.read_grogu(\"../tests/test_histo2d_v2.yoda\")\n",
"h=hists['/ALICE_2020_I1797621/GGPdfXQ']\n",
"h.bins()[0]\n",
"print(len(h.bins()))\n",
Expand Down Expand Up @@ -2619,7 +2619,7 @@
}
],
"source": [
"hists = grogu.read_yoda(\"../tests/test2d.yoda\")\n",
"hists = grogu.read_yoda(\"../tests/test_histo2d_v2.yoda\")\n",
"h=hists['/ALICE_2020_I1797621/GGPdfXQ']\n",
"h"
]
Expand Down Expand Up @@ -5119,7 +5119,7 @@
}
],
"source": [
"hists = grogu.read_yoda(\"../tests/test2d.yoda\")\n",
"hists = grogu.read_yoda(\"../tests/test_histo2d_v2.yoda\")\n",
"h=hists['/ALICE_2020_I1797621/GGPdfXQ']\n",
"print(len(h.bins()))\n",
"for b in h.bins():\n",
Expand Down
53 changes: 25 additions & 28 deletions debug/histo1d.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
}
],
"source": [
"hists = grogu.read_grogu(\"../tests/test1d.yoda\")\n",
"hists = grogu.read_grogu(\"../tests/test_histo1d_v2.yoda\")\n",
"hists[\"/\"]"
]
},
Expand All @@ -50,7 +50,7 @@
}
],
"source": [
"hists = grogu.read_yoda(\"../tests/test1d.yoda\")\n",
"hists = grogu.read_yoda(\"../tests/test_histo1d_v2.yoda\")\n",
"hists[\"/\"]"
]
},
Expand All @@ -72,7 +72,7 @@
}
],
"source": [
"hists[\"/\"][grogu.loc(3.5)+1]"
"hists[\"/\"][grogu.loc(3.5) + 1]"
]
},
{
Expand Down Expand Up @@ -101,44 +101,54 @@
"outputs": [],
"source": [
"import numpy as np\n",
"\n",
"\n",
"class GH1D:\n",
" \n",
" def __init__(self, target):\n",
" # Store the target object where calls and attributes will be forwarded\n",
" super().__setattr__('target', target)\n",
" \n",
" super().__setattr__(\"target\", target)\n",
"\n",
" @property\n",
" def axes(self):\n",
" return [list(zip(self.xMins(), self.xMaxs()))]\n",
"\n",
" @property\n",
" def kind(self):\n",
" return \"COUNT\"\n",
"\n",
" def values(self):\n",
" return self.sumWs()\n",
"\n",
" def variances(self):\n",
" return np.array([b.sumW2() for b in self.bins()])\n",
"\n",
" def counts(self):\n",
" return np.array([b.effNumEntries() for b in self.bins()])\n",
"\n",
" def xMins(self):\n",
" return np.array([b.xMin() for b in self.bins()])\n",
"\n",
" def xMaxs(self):\n",
" return np.array([b.xMax() for b in self.bins()])\n",
"\n",
" def sumWs(self):\n",
" return np.array([b.sumW() for b in self.bins()])\n",
"\n",
" def plot(self, *args, w2method=\"sqrt\", **kwargs):\n",
" import mplhep as hep\n",
"\n",
" hep.histplot(self, w2=self.variances(), *args, w2method=w2method, **kwargs)\n",
"\n",
"\n",
" def __getattr__(self, name):\n",
" # First, check if the Forwarder object itself has the attribute\n",
" if name in self.__dict__ or hasattr(type(self), name):\n",
" return object.__getattribute__(self, name)\n",
" # If not, forward attribute access to the target\n",
" elif hasattr(self.target, name):\n",
" return getattr(self.target, name)\n",
" raise AttributeError(f\"'{type(self).__name__}' object and target have no attribute '{name}'\")\n",
" raise AttributeError(\n",
" f\"'{type(self).__name__}' object and target have no attribute '{name}'\"\n",
" )\n",
"\n",
" def __setattr__(self, name, value):\n",
" # First, check if the attribute belongs to the Forwarder itself\n",
Expand All @@ -148,7 +158,9 @@
" elif hasattr(self.target, name):\n",
" setattr(self.target, name, value)\n",
" else:\n",
" raise AttributeError(f\"Cannot set attribute '{name}'; it does not exist in target or Forwarder.\")\n",
" raise AttributeError(\n",
" f\"Cannot set attribute '{name}'; it does not exist in target or Forwarder.\"\n",
" )\n",
"\n",
" def __call__(self, *args, **kwargs):\n",
" # If the target is callable, forward the call, otherwise raise an error\n",
Expand All @@ -163,22 +175,7 @@
"id": "c830b5c7-9d5f-45a3-b986-12fb928b46c6",
"metadata": {},
"outputs": [],
"source": [
"def grogify(hist):\n",
" def axes():\n",
" return [list(zip(self.xMins(), self.xMaxs()))]\n",
" def values(self):\n",
" return self.sumWs()\n",
" def variances(self):\n",
" return np.array([b.sumW2() for b in self.bins()])\n",
" def counts(self):\n",
" return np.array([b.effNumEntries() for b in self.bins()])\n",
" setattr(hist, 'axes', property(axes))\n",
" hist.kind = \"COUNT\"\n",
" hist.values = values\n",
" hist.variance = variances\n",
" hist.counts = counts"
]
"source": []
},
{
"cell_type": "code",
Expand All @@ -187,7 +184,7 @@
"metadata": {},
"outputs": [],
"source": [
"hists = yd.read(\"../tests/test1d.yoda\")"
"hists = yd.read(\"../tests/test_histo1d_v2.yoda\")"
]
},
{
Expand Down Expand Up @@ -218,7 +215,7 @@
"metadata": {},
"outputs": [],
"source": [
"h=hists['/']"
"h = hists[\"/\"]"
]
},
{
Expand All @@ -236,7 +233,7 @@
"metadata": {},
"outputs": [],
"source": [
"g = GH1D(hists['/'])"
"g = GH1D(hists[\"/\"])"
]
},
{
Expand Down
32 changes: 16 additions & 16 deletions debug/histo2d.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
}
],
"source": [
"hists = grogu.read_grogu(\"../tests/test2d.yoda\")\n",
"h=hists['/ALICE_2020_I1797621/GGPdfXQ']\n",
"hists = grogu.read_grogu(\"../tests/test_histo2d_v2.yoda\")\n",
"h = hists[\"/ALICE_2020_I1797621/GGPdfXQ\"]\n",
"h"
]
},
Expand Down Expand Up @@ -66,9 +66,9 @@
}
],
"source": [
"hists['/ALICE_2020_I1797621/GGPdfXQ'].plot()\n",
"plot.yscale('log')\n",
"plot.xscale('log')"
"hists[\"/ALICE_2020_I1797621/GGPdfXQ\"].plot()\n",
"plot.yscale(\"log\")\n",
"plot.xscale(\"log\")"
]
},
{
Expand Down Expand Up @@ -2586,12 +2586,12 @@
}
],
"source": [
"hists = grogu.read_grogu(\"../tests/test2d.yoda\")\n",
"h=hists['/ALICE_2020_I1797621/GGPdfXQ']\n",
"hists = grogu.read_grogu(\"../tests/test_histo2d_v2.yoda\")\n",
"h = hists[\"/ALICE_2020_I1797621/GGPdfXQ\"]\n",
"h.bins()[0]\n",
"print(len(h.bins()))\n",
"for b in h.bins():\n",
" print(b.xMin(),b.xMax(),b.yMin(),b.yMax())\n"
" print(b.xMin(), b.xMax(), b.yMin(), b.yMax())"
]
},
{
Expand Down Expand Up @@ -2619,8 +2619,8 @@
}
],
"source": [
"hists = grogu.read_yoda(\"../tests/test2d.yoda\")\n",
"h=hists['/ALICE_2020_I1797621/GGPdfXQ']\n",
"hists = grogu.read_yoda(\"../tests/test_histo2d_v2.yoda\")\n",
"h = hists[\"/ALICE_2020_I1797621/GGPdfXQ\"]\n",
"h"
]
},
Expand Down Expand Up @@ -2649,9 +2649,9 @@
}
],
"source": [
"hists['/ALICE_2020_I1797621/GGPdfXQ'].plot()\n",
"plot.yscale('log')\n",
"plot.xscale('log')"
"hists[\"/ALICE_2020_I1797621/GGPdfXQ\"].plot()\n",
"plot.yscale(\"log\")\n",
"plot.xscale(\"log\")"
]
},
{
Expand Down Expand Up @@ -5119,11 +5119,11 @@
}
],
"source": [
"hists = grogu.read_yoda(\"../tests/test2d.yoda\")\n",
"h=hists['/ALICE_2020_I1797621/GGPdfXQ']\n",
"hists = grogu.read_yoda(\"../tests/test_histo2d_v2.yoda\")\n",
"h = hists[\"/ALICE_2020_I1797621/GGPdfXQ\"]\n",
"print(len(h.bins()))\n",
"for b in h.bins():\n",
" print(b.xMin(),b.xMax(),b.yMin(),b.yMax())"
" print(b.xMin(), b.xMax(), b.yMin(), b.yMax())"
]
},
{
Expand Down
26 changes: 26 additions & 0 deletions tests/babyyoda/uhi/test_by_histo1d_plot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import babyyoda as by
import uhi.typing.plottable as uhit


def load_histos():
g2 = next(iter(by.read("tests/test_histo1d_v2.yoda").values()))
return g2


def test_plottable():
h2 = load_histos()
assert isinstance(h2, uhit.PlottableHistogram)


def test_plottable_histoprint():
from histoprint import print_hist

h2 = load_histos()
print_hist(h2)


def test_plottable_mplhep():
import mplhep as hep

h2 = load_histos()
hep.histplot(h2)
26 changes: 26 additions & 0 deletions tests/babyyoda/uhi/test_by_histo2d_plot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import babyyoda as by
import uhi.typing.plottable as uhit


def load_histos():
h2 = next(iter(by.read("tests/test_histo2d_v2.yoda").values()))
return h2


def test_plottable():
h2 = load_histos()
assert isinstance(h2, uhit.PlottableHistogram)


def test_plottable_histoprint():
from histoprint import print_hist

h2 = load_histos()
print_hist(h2)


def test_plottable_mplhep():
import mplhep as hep

h2 = load_histos()
hep.hist2dplot(h2)
26 changes: 26 additions & 0 deletions tests/grogu/uhi/test_gg_histo1d_plot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import babyyoda as by
import uhi.typing.plottable as uhit


def load_histos():
g2 = next(iter(by.read_grogu("tests/test_histo1d_v2.yoda").values()))
return g2


def test_plottable():
h2 = load_histos()
assert isinstance(h2, uhit.PlottableHistogram)


def test_plottable_histoprint():
from histoprint import print_hist

h2 = load_histos()
print_hist(h2)


def test_plottable_mplhep():
import mplhep as hep

h2 = load_histos()
hep.histplot(h2)
Loading

0 comments on commit 13077f5

Please sign in to comment.