heapyx 0.2.3__tar.gz → 0.2.4__tar.gz

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.
Files changed (49) hide show
  1. {heapyx-0.2.3 → heapyx-0.2.4}/PKG-INFO +13 -7
  2. {heapyx-0.2.3 → heapyx-0.2.4}/README.md +12 -6
  3. heapyx-0.2.4/heapy/__info__.py +1 -0
  4. {heapyx-0.2.3 → heapyx-0.2.4}/heapy/auto/signal_utils.py +6 -6
  5. {heapyx-0.2.3 → heapyx-0.2.4}/heapy/pipe/batpipe.py +2 -2
  6. {heapyx-0.2.3 → heapyx-0.2.4}/heapy/pipe/event.py +19 -11
  7. {heapyx-0.2.3 → heapyx-0.2.4}/heapy/pipe/image.py +2 -2
  8. {heapyx-0.2.3 → heapyx-0.2.4}/heapy/temp/txx.py +7 -6
  9. {heapyx-0.2.3 → heapyx-0.2.4}/heapy/util/data.py +102 -0
  10. {heapyx-0.2.3 → heapyx-0.2.4}/heapyx.egg-info/PKG-INFO +13 -7
  11. heapyx-0.2.3/heapy/__info__.py +0 -1
  12. {heapyx-0.2.3 → heapyx-0.2.4}/LICENSE +0 -0
  13. {heapyx-0.2.3 → heapyx-0.2.4}/heapy/__init__.py +0 -0
  14. {heapyx-0.2.3 → heapyx-0.2.4}/heapy/auto/__init__.py +0 -0
  15. {heapyx-0.2.3 → heapyx-0.2.4}/heapy/auto/baseline.py +0 -0
  16. {heapyx-0.2.3 → heapyx-0.2.4}/heapy/auto/polynomial.py +0 -0
  17. {heapyx-0.2.3 → heapyx-0.2.4}/heapy/auto/signal.py +0 -0
  18. {heapyx-0.2.3 → heapyx-0.2.4}/heapy/data/__init__.py +0 -0
  19. {heapyx-0.2.3 → heapyx-0.2.4}/heapy/data/filefinder.py +0 -0
  20. {heapyx-0.2.3 → heapyx-0.2.4}/heapy/data/retrieve.py +0 -0
  21. {heapyx-0.2.3 → heapyx-0.2.4}/heapy/docs/McIlwainL_coeffs/McIlwainL_Coeffs.npy +0 -0
  22. {heapyx-0.2.3 → heapyx-0.2.4}/heapy/docs/psf_model/fxt_psf.cod +0 -0
  23. {heapyx-0.2.3 → heapyx-0.2.4}/heapy/docs/psf_model/fxt_psf.dat +0 -0
  24. {heapyx-0.2.3 → heapyx-0.2.4}/heapy/docs/psf_model/xrt_psf.cod +0 -0
  25. {heapyx-0.2.3 → heapyx-0.2.4}/heapy/geos/__init__.py +0 -0
  26. {heapyx-0.2.3 → heapyx-0.2.4}/heapy/geos/detector.py +0 -0
  27. {heapyx-0.2.3 → heapyx-0.2.4}/heapy/geos/geometry.py +0 -0
  28. {heapyx-0.2.3 → heapyx-0.2.4}/heapy/geos/localization.py +0 -0
  29. {heapyx-0.2.3 → heapyx-0.2.4}/heapy/geos/skymap.py +0 -0
  30. {heapyx-0.2.3 → heapyx-0.2.4}/heapy/pipe/__init__.py +0 -0
  31. {heapyx-0.2.3 → heapyx-0.2.4}/heapy/pipe/filter.py +0 -0
  32. {heapyx-0.2.3 → heapyx-0.2.4}/heapy/temp/__init__.py +0 -0
  33. {heapyx-0.2.3 → heapyx-0.2.4}/heapy/temp/cwt.py +0 -0
  34. {heapyx-0.2.3 → heapyx-0.2.4}/heapy/temp/lag.py +0 -0
  35. {heapyx-0.2.3 → heapyx-0.2.4}/heapy/temp/mvt.py +0 -0
  36. {heapyx-0.2.3 → heapyx-0.2.4}/heapy/temp/temp_utils.py +0 -0
  37. {heapyx-0.2.3 → heapyx-0.2.4}/heapy/util/__init__.py +0 -0
  38. {heapyx-0.2.3 → heapyx-0.2.4}/heapy/util/coord.py +0 -0
  39. {heapyx-0.2.3 → heapyx-0.2.4}/heapy/util/file.py +0 -0
  40. {heapyx-0.2.3 → heapyx-0.2.4}/heapy/util/significance.py +0 -0
  41. {heapyx-0.2.3 → heapyx-0.2.4}/heapy/util/time.py +0 -0
  42. {heapyx-0.2.3 → heapyx-0.2.4}/heapy/util/tools.py +0 -0
  43. {heapyx-0.2.3 → heapyx-0.2.4}/heapyx.egg-info/SOURCES.txt +0 -0
  44. {heapyx-0.2.3 → heapyx-0.2.4}/heapyx.egg-info/dependency_links.txt +0 -0
  45. {heapyx-0.2.3 → heapyx-0.2.4}/heapyx.egg-info/requires.txt +0 -0
  46. {heapyx-0.2.3 → heapyx-0.2.4}/heapyx.egg-info/top_level.txt +0 -0
  47. {heapyx-0.2.3 → heapyx-0.2.4}/pyproject.toml +0 -0
  48. {heapyx-0.2.3 → heapyx-0.2.4}/setup.cfg +0 -0
  49. {heapyx-0.2.3 → heapyx-0.2.4}/setup.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: heapyx
3
- Version: 0.2.3
3
+ Version: 0.2.4
4
4
  Summary: High-energy (X-ray and gamma-ray) astronomical data analysis tools
5
5
  Home-page: https://github.com/jyangch/heapy
6
6
  Author: Jun Yang
@@ -49,6 +49,7 @@ Dynamic: summary
49
49
 
50
50
  <p align="center">
51
51
  <a href="https://pypi.org/project/heapyx/"><img alt="PyPI" src="https://img.shields.io/pypi/v/heapyx?color=4F46E5&labelColor=1f2937&logo=pypi&logoColor=white"></a>
52
+ <a href="https://doi.org/10.5281/zenodo.23283842"><img alt="DOI" src="https://zenodo.org/badge/DOI/10.5281/zenodo.23283842.svg"></a>
52
53
  <a href="https://github.com/jyangch/heapy/tree/main/examples"><img alt="Examples" src="https://img.shields.io/badge/docs-examples-06B6D4?labelColor=1f2937"></a>
53
54
  <a href="https://www.gnu.org/licenses/gpl-3.0"><img alt="License GPL-3.0" src="https://img.shields.io/badge/license-GPL--3.0-9CA3AF?labelColor=1f2937"></a>
54
55
  </p>
@@ -136,20 +137,25 @@ for typical workflows end to end.
136
137
 
137
138
  If you use `HEAPY` in your research, please include a software citation in
138
139
  your reference list and state the version used in your methods section.
139
- Citation metadata are available in [CITATION.cff](CITATION.cff).
140
+ Citation metadata are available in [CITATION.cff](CITATION.cff), with a
141
+ downloadable BibTeX entry in [CITATION.bib](CITATION.bib).
140
142
 
141
- Until a DOI-backed release is available, the repository can be cited as:
143
+ HEAPY version `0.2.3` is archived on Zenodo and can be cited as:
142
144
 
143
- > Yang, J. HEAPY: A Python toolkit for data reduction, temporal analysis, and
144
- > spectral extraction of X-ray and gamma-ray transients [Computer software].
145
- > https://github.com/jyangch/heapy
145
+ > Yang, J. (2026). HEAPY: A Python toolkit for data reduction, temporal analysis, and
146
+ > spectral extraction of X-ray and gamma-ray transients (v0.2.3) [Computer software].
147
+ > Zenodo. https://doi.org/10.5281/zenodo.23283842
146
148
 
147
149
  ```bibtex
148
150
  @software{heapy,
149
151
  author = {Yang, Jun},
150
152
  title = {{HEAPY}: A Python toolkit for data reduction, temporal analysis, and
151
153
  spectral extraction of X-ray and gamma-ray transients},
152
- url = {https://github.com/jyangch/heapy}
154
+ year = {2026},
155
+ version = {v0.2.3},
156
+ publisher = {Zenodo},
157
+ doi = {10.5281/zenodo.23283842},
158
+ url = {https://doi.org/10.5281/zenodo.23283842}
153
159
  }
154
160
  ```
155
161
 
@@ -6,6 +6,7 @@
6
6
 
7
7
  <p align="center">
8
8
  <a href="https://pypi.org/project/heapyx/"><img alt="PyPI" src="https://img.shields.io/pypi/v/heapyx?color=4F46E5&labelColor=1f2937&logo=pypi&logoColor=white"></a>
9
+ <a href="https://doi.org/10.5281/zenodo.23283842"><img alt="DOI" src="https://zenodo.org/badge/DOI/10.5281/zenodo.23283842.svg"></a>
9
10
  <a href="https://github.com/jyangch/heapy/tree/main/examples"><img alt="Examples" src="https://img.shields.io/badge/docs-examples-06B6D4?labelColor=1f2937"></a>
10
11
  <a href="https://www.gnu.org/licenses/gpl-3.0"><img alt="License GPL-3.0" src="https://img.shields.io/badge/license-GPL--3.0-9CA3AF?labelColor=1f2937"></a>
11
12
  </p>
@@ -93,20 +94,25 @@ for typical workflows end to end.
93
94
 
94
95
  If you use `HEAPY` in your research, please include a software citation in
95
96
  your reference list and state the version used in your methods section.
96
- Citation metadata are available in [CITATION.cff](CITATION.cff).
97
+ Citation metadata are available in [CITATION.cff](CITATION.cff), with a
98
+ downloadable BibTeX entry in [CITATION.bib](CITATION.bib).
97
99
 
98
- Until a DOI-backed release is available, the repository can be cited as:
100
+ HEAPY version `0.2.3` is archived on Zenodo and can be cited as:
99
101
 
100
- > Yang, J. HEAPY: A Python toolkit for data reduction, temporal analysis, and
101
- > spectral extraction of X-ray and gamma-ray transients [Computer software].
102
- > https://github.com/jyangch/heapy
102
+ > Yang, J. (2026). HEAPY: A Python toolkit for data reduction, temporal analysis, and
103
+ > spectral extraction of X-ray and gamma-ray transients (v0.2.3) [Computer software].
104
+ > Zenodo. https://doi.org/10.5281/zenodo.23283842
103
105
 
104
106
  ```bibtex
105
107
  @software{heapy,
106
108
  author = {Yang, Jun},
107
109
  title = {{HEAPY}: A Python toolkit for data reduction, temporal analysis, and
108
110
  spectral extraction of X-ray and gamma-ray transients},
109
- url = {https://github.com/jyangch/heapy}
111
+ year = {2026},
112
+ version = {v0.2.3},
113
+ publisher = {Zenodo},
114
+ doi = {10.5281/zenodo.23283842},
115
+ url = {https://doi.org/10.5281/zenodo.23283842}
110
116
  }
111
117
  ```
112
118
 
@@ -0,0 +1 @@
1
+ __version__ = '0.2.4'
@@ -7,7 +7,7 @@ Bundles four groups of utilities consumed by :mod:`heapy.auto.signal`:
7
7
  :func:`intervals_equal`).
8
8
  - Bayesian-blocks driver :func:`time_rescaling_bblock` that wraps
9
9
  ``astropy.stats.bayesian_blocks`` with optional non-stationary
10
- background correction (Scargle 2013, Appendix B).
10
+ background correction via time rescaling.
11
11
  - One-bin SNR estimators (:func:`pg_snr`, :func:`pp_snr`,
12
12
  :func:`gauss_snr`) wrapping :mod:`heapy.util.significance`.
13
13
  - :class:`SignalPlotter`, the composable two-panel diagnostic figure
@@ -56,11 +56,11 @@ def time_rescaling_bblock(t, cts=None, bkg_integral=None, p0=0.05):
56
56
 
57
57
  When ``bkg_integral`` is supplied, transforms the time axis via
58
58
  ``tau(t) = integral_0^t B(s) ds`` so the inhomogeneous Poisson
59
- process becomes homogeneous (Scargle 2013, Appendix B), runs
60
- ``events`` mode Bayesian blocks in ``tau``-space, then maps the
61
- resulting edges back to the original time axis through cubic
62
- interpolation on the ``(tau, t)`` pairs. Without ``bkg_integral``,
63
- delegates to ``astropy.stats.bayesian_blocks`` unchanged.
59
+ process becomes a homogeneous one with rate 1, runs ``events``
60
+ mode Bayesian blocks (Scargle et al. 2013) in ``tau``-space, then
61
+ maps the resulting edges back to the original time axis by
62
+ Voronoi-midpoint lookup. Without ``bkg_integral``, delegates to
63
+ ``astropy.stats.bayesian_blocks`` unchanged.
64
64
 
65
65
  Args:
66
66
  t: Photon arrival times (``cts=None``, unbinned branch) or
@@ -870,8 +870,8 @@ class batPipe:
870
870
  estimate (e.g. ``0.9`` gives T90).
871
871
  pulse: Manual override for the pulse interval(s). Either a single
872
872
  ``[pstart, pstop]`` pair or a list of such pairs (``[]`` clears
873
- the pulse to "none detected"); ``None`` keeps the existing
874
- ``self.pulse``.
873
+ the pulse to "none detected"); ``None`` uses the pulse detected
874
+ by ``find_pulse``.
875
875
  lbkg: Left background interval as ``[t1, t2]`` in seconds relative
876
876
  to ``timezero``. Auto-selected when ``None``.
877
877
  rbkg: Right background interval as ``[t1, t2]`` in seconds relative
@@ -992,8 +992,8 @@ class Event:
992
992
  xx: Fraction of total counts to enclose; e.g. 0.9 for T90.
993
993
  pulse: Manual override for the pulse interval(s). Either a single
994
994
  ``[pstart, pstop]`` pair or a list of such pairs (``[]`` clears
995
- the pulse to "none detected"); ``None`` keeps the existing
996
- ``self.pulse``.
995
+ the pulse to "none detected"); ``None`` uses the pulse detected
996
+ by ``find_pulse``.
997
997
  lbkg: Left background window ``[t1, t2]``, or ``None`` to use
998
998
  the automatically determined window.
999
999
  rbkg: Right background window ``[t1, t2]``, or ``None`` to use
@@ -1225,11 +1225,12 @@ class Event:
1225
1225
 
1226
1226
  pha_hdu = self._to_pha_fits(
1227
1227
  phaii[i],
1228
- np.sqrt(phaii[i]),
1228
+ None,
1229
1229
  exps[i],
1230
1230
  self.timezero + left,
1231
1231
  self.timezero + right,
1232
1232
  file_name,
1233
+ poisson=True,
1233
1234
  )
1234
1235
 
1235
1236
  if os.path.isfile(savepath + f'/{file_name}'):
@@ -1426,7 +1427,7 @@ class Event:
1426
1427
  self.extract_src_phaii(savepath=savepath)
1427
1428
  self.extract_bkg_phaii(savepath=savepath, poisson_binsize=poisson_binsize, show=show)
1428
1429
 
1429
- def _to_pha_fits(self, pha, pha_err, exp, tstart, tstop, file_name):
1430
+ def _to_pha_fits(self, pha, pha_err, exp, tstart, tstop, file_name, poisson=False):
1430
1431
 
1431
1432
  hdr = fits.Header()
1432
1433
  hdr['HDUCLASS'] = ('ogip', 'Format conforms to OGIP/GSFC conventions')
@@ -1437,24 +1438,31 @@ class Event:
1437
1438
  hdr['DATE'] = (Time.now().isot, 'file generated date')
1438
1439
  primary_hdu = fits.PrimaryHDU(header=hdr)
1439
1440
 
1441
+ # source is raw integer Poisson counts (POISSERR=True); background carries a
1442
+ # fitted Gaussian STAT_ERR column (POISSERR=False)
1440
1443
  channel_field = fits.Column(name='CHANNEL', array=self.channel, format='I')
1441
1444
  counts_field = fits.Column(name='COUNTS', array=pha, format='E', unit='count')
1442
- stat_err_field = fits.Column(name='STAT_ERR', array=pha_err, format='E', unit='count')
1443
- spectrum_hdu = fits.BinTableHDU.from_columns([channel_field, counts_field, stat_err_field])
1445
+ fields = [channel_field, counts_field]
1446
+ if not poisson:
1447
+ stat_err_field = fits.Column(name='STAT_ERR', array=pha_err, format='E', unit='count')
1448
+ fields.append(stat_err_field)
1449
+ spectrum_hdu = fits.BinTableHDU.from_columns(fields)
1444
1450
 
1445
1451
  spectrum_hdu.header['TTYPE1'] = ('CHANNEL', 'label for field 1')
1446
1452
  spectrum_hdu.header['TFORM1'] = ('I', 'data format of field: 2-byte INTEGER')
1447
1453
  spectrum_hdu.header['TTYPE2'] = ('COUNTS', 'label for field 2')
1448
1454
  spectrum_hdu.header['TFORM2'] = ('E', 'data format of field: 32-bit SINGLE FLOAT')
1449
1455
  spectrum_hdu.header['TUNIT2'] = ('count', 'physical unit of field')
1450
- spectrum_hdu.header['TTYPE3'] = ('STAT_ERR', 'label for field 3')
1451
- spectrum_hdu.header['TFORM3'] = ('E', 'data format of field: 32-bit SINGLE FLOAT')
1452
- spectrum_hdu.header['TUNIT3'] = ('count', 'physical unit of field')
1456
+ if not poisson:
1457
+ spectrum_hdu.header['TTYPE3'] = ('STAT_ERR', 'label for field 3')
1458
+ spectrum_hdu.header['TFORM3'] = ('E', 'data format of field: 32-bit SINGLE FLOAT')
1459
+ spectrum_hdu.header['TUNIT3'] = ('count', 'physical unit of field')
1453
1460
  spectrum_hdu.header['EXTNAME'] = ('SPECTRUM', 'name of this binary table extension')
1454
1461
  spectrum_hdu.header['TLMIN1'] = (np.min(self.channel), 'Lowest legal channel number')
1455
1462
  spectrum_hdu.header['TLMAX1'] = (np.max(self.channel), 'Highest legal channel number')
1456
- spectrum_hdu.header['POISSERR'] = (False, 'Poissonian errors to be assumed')
1457
- spectrum_hdu.header['STAT_ERR'] = (0, 'no statisical error specified')
1463
+ spectrum_hdu.header['POISSERR'] = (poisson, 'Poissonian errors to be assumed')
1464
+ if not poisson:
1465
+ spectrum_hdu.header['STAT_ERR'] = (0, 'no statisical error specified')
1458
1466
  spectrum_hdu.header['SYS_ERR'] = (0, 'no systematic error specified')
1459
1467
  spectrum_hdu.header['QUALITY'] = (0, 'no data quality information specified')
1460
1468
  spectrum_hdu.header['GROUPING'] = (0, 'no grouping data has been specified')
@@ -1077,8 +1077,8 @@ class Image:
1077
1077
  xx: Fraction of total counts to enclose; e.g. 0.9 for T90.
1078
1078
  pulse: Manual override for the pulse interval(s). Either a single
1079
1079
  ``[pstart, pstop]`` pair or a list of such pairs (``[]`` clears
1080
- the pulse to "none detected"); ``None`` keeps the existing
1081
- ``self.pulse``.
1080
+ the pulse to "none detected"); ``None`` uses the pulse detected
1081
+ by ``find_pulse``.
1082
1082
  lbkg: Left background window ``[t1, t2]``, or ``None``.
1083
1083
  rbkg: Right background window ``[t1, t2]``, or ``None``.
1084
1084
  savepath: Directory where duration results are written.
@@ -118,6 +118,7 @@ class Txx:
118
118
  if len(pulse) > 0 and not isinstance(pulse[0], (list, tuple, np.ndarray)):
119
119
  pulse = [pulse]
120
120
  self.pulse = [list(p) for p in pulse]
121
+ self.detected_pulse = [list(p) for p in pulse]
121
122
 
122
123
  self.backscale = backscale
123
124
 
@@ -325,10 +326,10 @@ class Txx:
325
326
  Args:
326
327
  xx: Cumulative count fraction defining the duration, e.g. ``0.9``
327
328
  for T90 or ``0.5`` for T50.
328
- pulse: Override pulse interval(s). Either a single ``[pstart,
329
- pstop]`` pair or a list of such pairs (``[]`` clears the
330
- pulse to "none detected"); ``None`` keeps the existing
331
- ``self.pulse``.
329
+ pulse: Override pulse interval(s) for this call only. Either a
330
+ single ``[pstart, pstop]`` pair or a list of such pairs
331
+ (``[]`` clears the pulse to "none detected"); ``None`` uses
332
+ the detected pulse (``self.detected_pulse``).
332
333
  lbkg: Length of the background window to the left of the first
333
334
  pulse, in the same time units as the light curve. ``None``
334
335
  extends to the beginning of the data.
@@ -343,14 +344,14 @@ class Txx:
343
344
 
344
345
  if getattr(self, 'pulse', None) is None:
345
346
  self.find_pulse()
346
- detected_pulse = [list(p) for p in self.pulse]
347
+ detected_pulse = [list(p) for p in self.detected_pulse]
347
348
 
348
349
  user_pulse = None
349
350
  if pulse is not None:
350
351
  if len(pulse) > 0 and not isinstance(pulse[0], (list, tuple, np.ndarray)):
351
352
  pulse = [pulse]
352
353
  user_pulse = [list(p) for p in pulse]
353
- self.pulse = user_pulse
354
+ self.pulse = detected_pulse if user_pulse is None else user_pulse
354
355
 
355
356
  self.pstart = np.sort([p[0] for p in self.pulse])
356
357
  self.pstop = np.sort([p[1] for p in self.pulse])
@@ -596,6 +596,108 @@ def find_peak(dt, mode='unbinned', ts=None, edges=None, counts=None):
596
596
  raise ValueError(f"unsupported mode: {mode!r}; expected 'unbinned' or 'binned'")
597
597
 
598
598
 
599
+ def simulate_peak_rate(dt, edges, counts, bkg_counts=None, counts_err=None):
600
+ """Bootstrap the peak rate on a window width of a binned light curve.
601
+
602
+ The peak rate is the largest rolling sum of net counts over
603
+ ``round(dt / binsize)`` bins divided by ``dt``, as :func:`find_peak` in
604
+ ``'binned'`` mode. Taking the largest window of a noisy light curve
605
+ biases it upwards, more so for a short window with few counts. The light
606
+ curve is resampled 1000 times (seed 450001) with the observed counts as
607
+ the expectation: Poisson total counts minus the fixed background when
608
+ ``bkg_counts`` is given, or Gaussian net counts with ``counts_err``
609
+ (e.g. mask-weighted BAT light curves). Bins with NaN counts (data gaps)
610
+ are taken as empty.
611
+
612
+ Args:
613
+ dt: Window width in seconds.
614
+ edges: Equal-width bin edges (length ``N+1``).
615
+ counts: Total counts per bin with ``bkg_counts``, or net counts per
616
+ bin with ``counts_err``.
617
+ bkg_counts: Background counts per bin (Poisson resampling).
618
+ counts_err: 1-sigma errors of the net counts per bin (Gaussian
619
+ resampling).
620
+
621
+ Returns:
622
+ A tuple ``(peak_rate, bias, spread)``: the peak net rate of the
623
+ observed light curve; the median log10 peak rate of the resampled
624
+ curves minus log10 ``peak_rate``, in dex; and half the 16th-84th
625
+ percentile range of the resampled log10 peak rates, in dex.
626
+ ``peak_rate * 10 ** -bias`` is the bias-corrected peak rate.
627
+
628
+ Raises:
629
+ ValueError: If not exactly one of ``bkg_counts`` and ``counts_err``
630
+ is given, the ``edges``/``counts`` lengths are inconsistent, the
631
+ edges are not equal width, or the window is shorter than one bin
632
+ or longer than the light curve.
633
+ """
634
+
635
+ if (bkg_counts is None) == (counts_err is None):
636
+ raise ValueError('expected exactly one of bkg_counts and counts_err')
637
+
638
+ bin_edges = np.asarray(edges, dtype=float)
639
+ bin_counts = np.array(counts, dtype=float)
640
+ if bin_edges.size != bin_counts.size + 1:
641
+ raise ValueError(
642
+ f'edges (length {bin_edges.size}) must have one more element than '
643
+ f'counts (length {bin_counts.size})'
644
+ )
645
+
646
+ bin_widths = np.diff(bin_edges)
647
+ bin_width = float(bin_widths[0])
648
+ if not np.allclose(bin_widths, bin_width):
649
+ raise ValueError('expected equal-width edges')
650
+
651
+ bins_per_window = round(dt / bin_width)
652
+ if bins_per_window < 1 or bins_per_window > bin_counts.size:
653
+ raise ValueError(
654
+ f'a window of {bins_per_window} bins does not fit {bin_counts.size} bins of {bin_width}s'
655
+ )
656
+
657
+ # data gaps carry neither source nor background counts
658
+ gap = ~np.isfinite(bin_counts)
659
+ bin_counts[gap] = 0.0
660
+ if bkg_counts is not None:
661
+ bin_bkg = np.array(bkg_counts, dtype=float)
662
+ bin_bkg[gap] = 0.0
663
+ net_counts = bin_counts - bin_bkg
664
+ else:
665
+ bin_err = np.nan_to_num(np.asarray(counts_err, dtype=float))
666
+ net_counts = bin_counts
667
+
668
+ def calculate_peak_rate(net):
669
+ """Peak net rate of each row of net counts per bin."""
670
+
671
+ cumulative_net = np.cumsum(net, axis=-1)
672
+ cumulative_net = np.concatenate(
673
+ (np.zeros((*cumulative_net.shape[:-1], 1)), cumulative_net), axis=-1
674
+ )
675
+ counts_in_window = (
676
+ cumulative_net[..., bins_per_window:] - cumulative_net[..., :-bins_per_window]
677
+ )
678
+
679
+ return counts_in_window.max(axis=-1) / dt
680
+
681
+ peak_rate = float(calculate_peak_rate(net_counts))
682
+
683
+ # resample in 10 chunks of 100 curves to bound the memory of long, finely binned light curves
684
+ rng = np.random.default_rng(450001)
685
+ log_rates = []
686
+ for _ in range(10):
687
+ size = (100, bin_counts.size)
688
+ if bkg_counts is not None:
689
+ sample = rng.poisson(lam=bin_counts, size=size) - bin_bkg
690
+ else:
691
+ sample = rng.normal(loc=bin_counts, scale=bin_err, size=size)
692
+ log_rates.append(np.log10(calculate_peak_rate(sample)))
693
+
694
+ log_rates = np.concatenate(log_rates)
695
+ bias = float(np.median(log_rates) - np.log10(peak_rate))
696
+ spread = float(0.5 * np.diff(np.percentile(log_rates, [16, 84]))[0])
697
+
698
+ return peak_rate, bias, spread
699
+
700
+
599
701
  def split_bool_mask(mask, times, selection_value=False):
600
702
  """Convert a boolean mask into time intervals where the mask equals a value.
601
703
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: heapyx
3
- Version: 0.2.3
3
+ Version: 0.2.4
4
4
  Summary: High-energy (X-ray and gamma-ray) astronomical data analysis tools
5
5
  Home-page: https://github.com/jyangch/heapy
6
6
  Author: Jun Yang
@@ -49,6 +49,7 @@ Dynamic: summary
49
49
 
50
50
  <p align="center">
51
51
  <a href="https://pypi.org/project/heapyx/"><img alt="PyPI" src="https://img.shields.io/pypi/v/heapyx?color=4F46E5&labelColor=1f2937&logo=pypi&logoColor=white"></a>
52
+ <a href="https://doi.org/10.5281/zenodo.23283842"><img alt="DOI" src="https://zenodo.org/badge/DOI/10.5281/zenodo.23283842.svg"></a>
52
53
  <a href="https://github.com/jyangch/heapy/tree/main/examples"><img alt="Examples" src="https://img.shields.io/badge/docs-examples-06B6D4?labelColor=1f2937"></a>
53
54
  <a href="https://www.gnu.org/licenses/gpl-3.0"><img alt="License GPL-3.0" src="https://img.shields.io/badge/license-GPL--3.0-9CA3AF?labelColor=1f2937"></a>
54
55
  </p>
@@ -136,20 +137,25 @@ for typical workflows end to end.
136
137
 
137
138
  If you use `HEAPY` in your research, please include a software citation in
138
139
  your reference list and state the version used in your methods section.
139
- Citation metadata are available in [CITATION.cff](CITATION.cff).
140
+ Citation metadata are available in [CITATION.cff](CITATION.cff), with a
141
+ downloadable BibTeX entry in [CITATION.bib](CITATION.bib).
140
142
 
141
- Until a DOI-backed release is available, the repository can be cited as:
143
+ HEAPY version `0.2.3` is archived on Zenodo and can be cited as:
142
144
 
143
- > Yang, J. HEAPY: A Python toolkit for data reduction, temporal analysis, and
144
- > spectral extraction of X-ray and gamma-ray transients [Computer software].
145
- > https://github.com/jyangch/heapy
145
+ > Yang, J. (2026). HEAPY: A Python toolkit for data reduction, temporal analysis, and
146
+ > spectral extraction of X-ray and gamma-ray transients (v0.2.3) [Computer software].
147
+ > Zenodo. https://doi.org/10.5281/zenodo.23283842
146
148
 
147
149
  ```bibtex
148
150
  @software{heapy,
149
151
  author = {Yang, Jun},
150
152
  title = {{HEAPY}: A Python toolkit for data reduction, temporal analysis, and
151
153
  spectral extraction of X-ray and gamma-ray transients},
152
- url = {https://github.com/jyangch/heapy}
154
+ year = {2026},
155
+ version = {v0.2.3},
156
+ publisher = {Zenodo},
157
+ doi = {10.5281/zenodo.23283842},
158
+ url = {https://doi.org/10.5281/zenodo.23283842}
153
159
  }
154
160
  ```
155
161
 
@@ -1 +0,0 @@
1
- __version__ = '0.2.3'
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes