aptapy 0.3.1__py3-none-any.whl → 0.3.2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- aptapy/_version.py +1 -1
- aptapy/hist.py +52 -7
- aptapy/modeling.py +3 -3
- {aptapy-0.3.1.dist-info → aptapy-0.3.2.dist-info}/METADATA +1 -1
- aptapy-0.3.2.dist-info/RECORD +12 -0
- aptapy-0.3.1.dist-info/RECORD +0 -12
- {aptapy-0.3.1.dist-info → aptapy-0.3.2.dist-info}/WHEEL +0 -0
- {aptapy-0.3.1.dist-info → aptapy-0.3.2.dist-info}/licenses/LICENSE +0 -0
aptapy/_version.py
CHANGED
@@ -1 +1 @@
|
|
1
|
-
__version__ = "0.3.
|
1
|
+
__version__ = "0.3.2"
|
aptapy/hist.py
CHANGED
@@ -17,7 +17,7 @@
|
|
17
17
|
"""
|
18
18
|
|
19
19
|
from abc import ABC, abstractmethod
|
20
|
-
from typing import List, Sequence
|
20
|
+
from typing import List, Sequence, Tuple
|
21
21
|
|
22
22
|
import numpy as np
|
23
23
|
|
@@ -93,6 +93,43 @@ class AbstractHistogram(ABC):
|
|
93
93
|
"""
|
94
94
|
return np.diff(self._edges[axis])
|
95
95
|
|
96
|
+
def binned_statistics(self, axis: int = 0) -> Tuple[float, float]:
|
97
|
+
"""Return the mean and standard deviation along a specific axis, based
|
98
|
+
on the binned data.
|
99
|
+
|
100
|
+
.. note::
|
101
|
+
|
102
|
+
This is a crude estimate of the underlying statistics that might be
|
103
|
+
useful for monitoring purposes, but should not be relied upon for
|
104
|
+
quantitative analysis.
|
105
|
+
|
106
|
+
This is not the same as computing the mean and standard deviation of
|
107
|
+
the unbinned data that filled the histogram, as some information is
|
108
|
+
lost in the binning process.
|
109
|
+
|
110
|
+
In addition, note that we are not applying any bias correction to
|
111
|
+
the standard deviation, as we are assuming that the histogram is
|
112
|
+
filled with a sufficiently large number of entries. (In most circumstances
|
113
|
+
the effect should be smaller than that of the binning itself.)
|
114
|
+
|
115
|
+
Arguments
|
116
|
+
---------
|
117
|
+
axis : int
|
118
|
+
the axis along which to compute the statistics.
|
119
|
+
|
120
|
+
Returns
|
121
|
+
-------
|
122
|
+
mean : float
|
123
|
+
the mean value along the specified axis.
|
124
|
+
stddev : float
|
125
|
+
the standard deviation along the specified axis.
|
126
|
+
"""
|
127
|
+
values = self.bin_centers(axis)
|
128
|
+
weights = self.content.sum(axis=tuple(i for i in range(self.content.ndim) if i != axis))
|
129
|
+
mean = np.average(values, weights=weights)
|
130
|
+
variance = np.average((values - mean)**2, weights=weights)
|
131
|
+
return float(mean), float(np.sqrt(variance))
|
132
|
+
|
96
133
|
def fill(self, *values: ArrayLike, weights: ArrayLike = None) -> "AbstractHistogram":
|
97
134
|
"""Fill the histogram from unbinned data.
|
98
135
|
|
@@ -229,10 +266,18 @@ class Histogram1d(AbstractHistogram):
|
|
229
266
|
"""
|
230
267
|
# If we are not explicitly providing a label at plotting time, use
|
231
268
|
# the one attached to the histogram, if any.
|
232
|
-
kwargs.setdefault(
|
269
|
+
kwargs.setdefault("label", f"{self}")
|
233
270
|
axes.hist(self.bin_centers(0), self._edges[0], weights=self.content, **kwargs)
|
234
271
|
setup_axes(axes, xlabel=self.axis_labels[0], ylabel=self.axis_labels[1])
|
235
272
|
|
273
|
+
def __str__(self) -> str:
|
274
|
+
"""String formatting.
|
275
|
+
"""
|
276
|
+
mean, rms = self.binned_statistics()
|
277
|
+
text = self.label or self.__class__.__name__
|
278
|
+
text = f"{text}\nMean: {mean:g}\nRMS: {rms:g}"
|
279
|
+
return text
|
280
|
+
|
236
281
|
|
237
282
|
class Histogram2d(AbstractHistogram):
|
238
283
|
|
@@ -259,10 +304,10 @@ class Histogram2d(AbstractHistogram):
|
|
259
304
|
the text label for the z axis (default: "Entries/bin").
|
260
305
|
"""
|
261
306
|
|
262
|
-
DEFAULT_PLOT_OPTIONS = dict(cmap=plt.get_cmap(
|
307
|
+
DEFAULT_PLOT_OPTIONS = dict(cmap=plt.get_cmap("hot"))
|
263
308
|
|
264
309
|
def __init__(self, xedges, yedges, label: str = None, xlabel: str = None,
|
265
|
-
ylabel: str = None, zlabel: str =
|
310
|
+
ylabel: str = None, zlabel: str = "Entries/bin") -> None:
|
266
311
|
"""Constructor.
|
267
312
|
"""
|
268
313
|
super().__init__((xedges, yedges), label, [xlabel, ylabel, zlabel])
|
@@ -272,9 +317,9 @@ class Histogram2d(AbstractHistogram):
|
|
272
317
|
"""
|
273
318
|
# pylint: disable=arguments-differ
|
274
319
|
if logz:
|
275
|
-
vmin = kwargs.pop(
|
276
|
-
vmax = kwargs.pop(
|
277
|
-
kwargs.setdefault(
|
320
|
+
vmin = kwargs.pop("vmin", None)
|
321
|
+
vmax = kwargs.pop("vmax", None)
|
322
|
+
kwargs.setdefault("norm", matplotlib.colors.LogNorm(vmin, vmax))
|
278
323
|
mappable = axes.pcolormesh(*self._edges, self.content.T, **kwargs)
|
279
324
|
plt.colorbar(mappable, ax=axes, label=self.axis_labels[2])
|
280
325
|
setup_axes(axes, xlabel=self.axis_labels[0], ylabel=self.axis_labels[1])
|
aptapy/modeling.py
CHANGED
@@ -316,10 +316,10 @@ class FitStatus:
|
|
316
316
|
if self.chisquare is None:
|
317
317
|
return "N/A"
|
318
318
|
if spec.endswith(Format.LATEX):
|
319
|
-
return f"$\\chi^2
|
319
|
+
return f"$\\chi^2$: {self.chisquare:.2f} / {self.dof} dof"
|
320
320
|
if spec.endswith(Format.PRETTY):
|
321
|
-
return f"
|
322
|
-
return f"chisquare
|
321
|
+
return f"χ²: {self.chisquare:.2f} / {self.dof} dof"
|
322
|
+
return f"chisquare: {self.chisquare:.2f} / {self.dof} dof"
|
323
323
|
|
324
324
|
def __str__(self) -> str:
|
325
325
|
"""String formatting.
|
@@ -0,0 +1,12 @@
|
|
1
|
+
aptapy/__init__.py,sha256=a7Au1ukdeJbjiIZ-UL-qZE1xk-d2WnKKkoqjg_0SzqA,1707
|
2
|
+
aptapy/_version.py,sha256=vNiWJ14r_cw5t_7UDqDQIVZvladKFGyHH2avsLpN7Vg,22
|
3
|
+
aptapy/hist.py,sha256=ZY9Yfqr4ImtUTxKirprSS6FEGKkSj3q7EsXKpTiIs6U,11534
|
4
|
+
aptapy/modeling.py,sha256=PK5OSVeQZAizlLBwg67oqt_MfKAbc5P3y0K_WVL0yCs,32563
|
5
|
+
aptapy/plotting.py,sha256=p9YNdrcFcTimRCtoXcV3zORaEd4EfMtsDd4ETxGKKHM,27483
|
6
|
+
aptapy/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
7
|
+
aptapy/strip.py,sha256=qGsVXWp-Dz-lz7KQxktMifUTNkSxh8ZQwYme8_bealQ,3026
|
8
|
+
aptapy/typing_.py,sha256=JIbEqKI8kn_fd90yDt0JmI1AojjmLhAEB_1RfMFxLx4,807
|
9
|
+
aptapy-0.3.2.dist-info/METADATA,sha256=Cc2Ct3DH0htSAiNpwC5OWuVywtTijpaboUepUUGWq9g,42796
|
10
|
+
aptapy-0.3.2.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
11
|
+
aptapy-0.3.2.dist-info/licenses/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
|
12
|
+
aptapy-0.3.2.dist-info/RECORD,,
|
aptapy-0.3.1.dist-info/RECORD
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
aptapy/__init__.py,sha256=a7Au1ukdeJbjiIZ-UL-qZE1xk-d2WnKKkoqjg_0SzqA,1707
|
2
|
-
aptapy/_version.py,sha256=r4xAFihOf72W9TD-lpMi6ntWSTKTP2SlzKP1ytkjRbI,22
|
3
|
-
aptapy/hist.py,sha256=jvHULR2lW_gyoemNaRI-vpqhFqmLLCB319CaKjwU69E,9752
|
4
|
-
aptapy/modeling.py,sha256=mHHHFMYmMuXTRQD2yR1XLM6E4KaBk8md7Z7dDp5ReD8,32566
|
5
|
-
aptapy/plotting.py,sha256=p9YNdrcFcTimRCtoXcV3zORaEd4EfMtsDd4ETxGKKHM,27483
|
6
|
-
aptapy/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
7
|
-
aptapy/strip.py,sha256=qGsVXWp-Dz-lz7KQxktMifUTNkSxh8ZQwYme8_bealQ,3026
|
8
|
-
aptapy/typing_.py,sha256=JIbEqKI8kn_fd90yDt0JmI1AojjmLhAEB_1RfMFxLx4,807
|
9
|
-
aptapy-0.3.1.dist-info/METADATA,sha256=KZP-aljwTsIKUi-1nE-X9ZfIxc44ijFhKCkoyK0EXjY,42796
|
10
|
-
aptapy-0.3.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
11
|
-
aptapy-0.3.1.dist-info/licenses/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
|
12
|
-
aptapy-0.3.1.dist-info/RECORD,,
|
File without changes
|
File without changes
|