aptapy 0.3.0__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 CHANGED
@@ -1 +1 @@
1
- __version__ = "0.3.0"
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('label', self.label)
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('hot'))
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 = 'Entries/bin') -> None:
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('vmin', None)
276
- vmax = kwargs.pop('vmax', None)
277
- kwargs.setdefault('norm', matplotlib.colors.LogNorm(vmin, vmax))
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$ = {self.chisquare:.2f} / {self.dof} dof"
319
+ return f"$\\chi^2$: {self.chisquare:.2f} / {self.dof} dof"
320
320
  if spec.endswith(Format.PRETTY):
321
- return f"χ² = {self.chisquare:.2f} / {self.dof} dof"
322
- return f"chisquare = {self.chisquare:.2f} / {self.dof} dof"
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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: aptapy
3
- Version: 0.3.0
3
+ Version: 0.3.2
4
4
  Summary: Statistical tools for online monitoring and analysis
5
5
  Project-URL: Homepage, https://github.com/lucabaldini/aptapy
6
6
  Project-URL: Issues, https://github.com/lucabaldini/aptapy/issues
@@ -680,6 +680,14 @@ License: GNU GENERAL PUBLIC LICENSE
680
680
  Public License instead of this License. But first, please read
681
681
  <https://www.gnu.org/licenses/why-not-lgpl.html>.
682
682
  License-File: LICENSE
683
+ Classifier: Development Status :: 4 - Beta
684
+ Classifier: Intended Audience :: Science/Research
685
+ Classifier: License :: OSI Approved :: GNU Lesser General Public License v3 or later (LGPLv3+)
686
+ Classifier: Operating System :: OS Independent
687
+ Classifier: Programming Language :: Python
688
+ Classifier: Programming Language :: Python :: 3.7
689
+ Classifier: Programming Language :: Python :: 3.13
690
+ Classifier: Topic :: Scientific/Engineering
683
691
  Requires-Python: >=3.7
684
692
  Requires-Dist: cycler
685
693
  Requires-Dist: loguru
@@ -700,10 +708,14 @@ Description-Content-Type: text/markdown
700
708
 
701
709
  <img src="docs/_static/logo.png" alt="logo" width="175"/>
702
710
 
711
+ [![PyPI](https://img.shields.io/pypi/v/aptapy.svg)](https://pypi.org/project/aptapy/)
712
+ ![Python versions](https://img.shields.io/badge/python-3.7--3.13-blue)
703
713
  ![License](https://img.shields.io/github/license/lucabaldini/aptapy.svg)
704
714
  [![CI](https://github.com/lucabaldini/aptapy/actions/workflows/ci.yml/badge.svg)](https://github.com/lucabaldini/aptapy/actions/workflows/ci.yml)
705
715
  [![Docs](https://github.com/lucabaldini/aptapy/actions/workflows/docs.yml/badge.svg)](https://github.com/lucabaldini/aptapy/actions/workflows/docs.yml)
706
716
  [![Docs](https://img.shields.io/badge/docs-latest-blue.svg)](https://lucabaldini.github.io/aptapy/)
717
+ ![GitHub last commit](https://img.shields.io/github/last-commit/lucabaldini/aptapy)
718
+
707
719
  [![Ceasefire Now](https://badge.techforpalestine.org/default)](https://techforpalestine.org/learn-more)
708
720
 
709
721
  Statistical tools for online monitoring and analysis.
@@ -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,,
@@ -1,12 +0,0 @@
1
- aptapy/__init__.py,sha256=a7Au1ukdeJbjiIZ-UL-qZE1xk-d2WnKKkoqjg_0SzqA,1707
2
- aptapy/_version.py,sha256=VrXpHDu3erkzwl_WXrqINBm9xWkcyUy53IQOj042dOs,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.0.dist-info/METADATA,sha256=ae7Q-HEWZCiZW8QjbAMNqCwZQVTFv52oH2n4J5tMRfg,42131
10
- aptapy-0.3.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
11
- aptapy-0.3.0.dist-info/licenses/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
12
- aptapy-0.3.0.dist-info/RECORD,,
File without changes