gputls 2.2.3__tar.gz → 2.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 (35) hide show
  1. {gputls-2.2.3/src/gputls.egg-info → gputls-2.2.4}/PKG-INFO +8 -1
  2. {gputls-2.2.3 → gputls-2.2.4}/README.md +7 -0
  3. {gputls-2.2.3 → gputls-2.2.4}/src/gputls/core.py +9 -12
  4. {gputls-2.2.3 → gputls-2.2.4}/src/gputls/stats.py +68 -0
  5. {gputls-2.2.3 → gputls-2.2.4}/src/gputls/version.py +1 -1
  6. {gputls-2.2.3 → gputls-2.2.4/src/gputls.egg-info}/PKG-INFO +8 -1
  7. {gputls-2.2.3 → gputls-2.2.4}/src/gputls.egg-info/SOURCES.txt +1 -0
  8. gputls-2.2.4/tests/test_final_candidate.py +69 -0
  9. {gputls-2.2.3 → gputls-2.2.4}/LICENSE +0 -0
  10. {gputls-2.2.3 → gputls-2.2.4}/pyproject.toml +0 -0
  11. {gputls-2.2.3 → gputls-2.2.4}/setup.cfg +0 -0
  12. {gputls-2.2.3 → gputls-2.2.4}/src/gputls/__init__.py +0 -0
  13. {gputls-2.2.3 → gputls-2.2.4}/src/gputls/constants.py +0 -0
  14. {gputls-2.2.3 → gputls-2.2.4}/src/gputls/grid.py +0 -0
  15. {gputls-2.2.3 → gputls-2.2.4}/src/gputls/helpers.py +0 -0
  16. {gputls-2.2.3 → gputls-2.2.4}/src/gputls/interpolation.py +0 -0
  17. {gputls-2.2.3 → gputls-2.2.4}/src/gputls/kernels.cu +0 -0
  18. {gputls-2.2.3 → gputls-2.2.4}/src/gputls/main.py +0 -0
  19. {gputls-2.2.3 → gputls-2.2.4}/src/gputls/results.py +0 -0
  20. {gputls-2.2.3 → gputls-2.2.4}/src/gputls/screening.py +0 -0
  21. {gputls-2.2.3 → gputls-2.2.4}/src/gputls/transit.py +0 -0
  22. {gputls-2.2.3 → gputls-2.2.4}/src/gputls/validate.py +0 -0
  23. {gputls-2.2.3 → gputls-2.2.4}/src/gputls/workspace.py +0 -0
  24. {gputls-2.2.3 → gputls-2.2.4}/src/gputls.egg-info/dependency_links.txt +0 -0
  25. {gputls-2.2.3 → gputls-2.2.4}/src/gputls.egg-info/requires.txt +0 -0
  26. {gputls-2.2.3 → gputls-2.2.4}/src/gputls.egg-info/top_level.txt +0 -0
  27. {gputls-2.2.3 → gputls-2.2.4}/tests/test_bucket_sort.py +0 -0
  28. {gputls-2.2.3 → gputls-2.2.4}/tests/test_candidate_screening.py +0 -0
  29. {gputls-2.2.3 → gputls-2.2.4}/tests/test_gtls.py +0 -0
  30. {gputls-2.2.3 → gputls-2.2.4}/tests/test_patch_scan.py +0 -0
  31. {gputls-2.2.3 → gputls-2.2.4}/tests/test_snr_units.py +0 -0
  32. {gputls-2.2.3 → gputls-2.2.4}/tests/test_stats.py +0 -0
  33. {gputls-2.2.3 → gputls-2.2.4}/tests/test_tls_compare.py +0 -0
  34. {gputls-2.2.3 → gputls-2.2.4}/tests/test_window_reuse.py +0 -0
  35. {gputls-2.2.3 → gputls-2.2.4}/tests/test_workspace.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: gputls
3
- Version: 2.2.3
3
+ Version: 2.2.4
4
4
  Summary: GPU-accelerated Transit Least Squares (TLS) for periodic transit detection
5
5
  Author-email: Quanquan Hu <huqq1917@outlook.com>
6
6
  Maintainer-email: Quanquan Hu <huqq1917@outlook.com>
@@ -59,6 +59,13 @@ in parallel on an NVIDIA GPU, which makes it several times faster than CPU TLS.
59
59
 
60
60
  ## Features
61
61
 
62
+ Version 2.2.4 aligns the final candidate's epoch fit and duration conversion
63
+ with TLS2 2.0.4. The reported transit times and noise statistics now use those
64
+ windows. This adds one CPU epoch fit after the GPU search; periodograms and
65
+ the default 0.01 epoch-search margins are unchanged. Native template/depth
66
+ selection remains on the GPU, so this does not promise bitwise equality of
67
+ every output with TLS2.
68
+
62
69
  Version 2.2.3 corrects the out-of-transit noise masks used by `snr` and
63
70
  `snrPink`: their duration is now expressed in days, matching the time array.
64
71
  Earlier versions passed a fractional duration, which could bias the reported
@@ -12,6 +12,13 @@ in parallel on an NVIDIA GPU, which makes it several times faster than CPU TLS.
12
12
 
13
13
  ## Features
14
14
 
15
+ Version 2.2.4 aligns the final candidate's epoch fit and duration conversion
16
+ with TLS2 2.0.4. The reported transit times and noise statistics now use those
17
+ windows. This adds one CPU epoch fit after the GPU search; periodograms and
18
+ the default 0.01 epoch-search margins are unchanged. Native template/depth
19
+ selection remains on the GPU, so this does not promise bitwise equality of
20
+ every output with TLS2.
21
+
15
22
  Version 2.2.3 corrects the out-of-transit noise masks used by `snr` and
16
23
  `snrPink`: their duration is now expressed in days, matching the time array.
17
24
  Earlier versions passed a fractional duration, which could bias the reported
@@ -13,7 +13,8 @@ from .helpers import transit_mask
13
13
  from .screening import (certificates, MIN_WIDTH, SCREEN_TOLERANCES,
14
14
  UNIFORM_PREFIX_STRIDE, GENERAL_PREFIX_STRIDE,
15
15
  uniform_sparse_certificate, sparse_certificate, prefix_quantization)
16
- from .stats import all_transit_times, calcDurationDays, intransit_stats, snr_stats, spectra
16
+ from .stats import (all_transit_times, calculate_transit_duration_in_days, final_T0_fit,
17
+ intransit_stats, snr_stats, spectra)
17
18
  from .workspace import (BatchWorkspace, LAYOUT_ALLOWANCE, bucket_count,
18
19
  bytes_per_period as workspace_bytes_per_period)
19
20
 
@@ -726,7 +727,7 @@ def search_single_period(search, period, t, y, dy):
726
727
  durationPointsNum = durations[durationIndex]
727
728
  rawDuration = single_lc_cache_overview["duration"][durationIndex]
728
729
 
729
- bestTime, bestFlux, _ = foldCPU(t, y, dy, period)
730
+ _, bestFlux, _ = foldCPU(t, y, dy, period)
730
731
  bestFlux = np.concatenate((bestFlux, bestFlux[:maxDuration]))
731
732
 
732
733
  bestRowT0 = bestLocation % (tSize)
@@ -745,20 +746,16 @@ def search_single_period(search, period, t, y, dy):
745
746
  DataSlideAvg = (DataCumsum[durationPointsNum:] - DataCumsum[:-durationPointsNum]) / durationPointsNum
746
747
  redNoise = np.std(DataSlideAvg)
747
748
 
748
- Tx = bestTime[bestRowT0]
749
- minTime = min(t)
750
- T0 = Tx - int((Tx - minTime) / period) * period - period
751
- transit_times = all_transit_times(T0, t, period)
749
+ # Keep the GPU-selected template/depth, but fit its epoch and convert its
750
+ # duration with TLS2's final-candidate conventions. The periodogram is fixed.
751
+ signal = search.lc_arr[durationsBool][durationIndex]
752
+ T0 = final_T0_fit(signal, 1 - transitDepth, t, y, dy, period, search.T0_fit_margin)
753
+ transit_times = np.asarray(all_transit_times(T0, t, period))
752
754
 
753
755
  snrFitPink = transitDepth / (
754
756
  (whiteNoise ** 2 / (durationPointsNum)) + (redNoise ** 2 / (len(transit_times)))) ** 0.5
755
757
 
756
- transit_duration_in_days = calcDurationDays(t, period, T0, rawDuration)
757
-
758
- T0 = T0 + transit_duration_in_days / 2
759
- transit_times = transit_times + transit_duration_in_days / 2
760
- if T0 < minTime:
761
- T0 = T0 + period
758
+ transit_duration_in_days = calculate_transit_duration_in_days(t, period, transit_times, rawDuration)
762
759
 
763
760
  # SNR
764
761
  all_flux_intransit_odd, all_flux_intransit_even, per_transit_count = intransit_stats(
@@ -1,4 +1,5 @@
1
1
  import numpy as np
2
+ from numba import njit
2
3
 
3
4
  from . import constants
4
5
  from .helpers import running_median, transit_mask
@@ -78,6 +79,73 @@ def calcDurationDays(times, period, StartT0, rawDuration):
78
79
  return DurationDays
79
80
 
80
81
 
82
+ @njit(fastmath=True, cache=True)
83
+ def _fold_phase(time, period, T0):
84
+ # Match the phase arithmetic of TLS2's final epoch fit.
85
+ return (time - T0) / period - np.floor((time - T0) / period)
86
+
87
+
88
+ @njit(cache=True)
89
+ def _t0_scan(flux, weights, signal, starts, total):
90
+ best = np.inf
91
+ best_index = 0
92
+ for index in range(len(starts)):
93
+ start = starts[index]
94
+ delta = 0.0
95
+ for k in range(len(signal)):
96
+ value = flux[start + k]
97
+ delta += ((value - signal[k]) ** 2 - (value - 1.0) ** 2) * weights[start + k]
98
+ residual = total + delta
99
+ if residual < best:
100
+ best = residual
101
+ best_index = index
102
+ return best_index
103
+
104
+
105
+ def final_T0_fit(signal, depth, t, y, dy, period, T0_fit_margin):
106
+ """TLS2-compatible epoch fit for one fixed period, template and depth.
107
+
108
+ Here ``depth`` is the in-transit flux (1 minus the fractional drop),
109
+ matching TLS2. Sort once, then scan cyclic template windows on its
110
+ uniform epoch grid. Cost: O(N log N + trials * template_width).
111
+ Adapted from MIT-licensed TLS2 2.0.4's final_T0_fit.
112
+ """
113
+ signal = np.asarray(signal, dtype=np.float64)
114
+ width = len(signal)
115
+ n = len(y)
116
+ points = n if T0_fit_margin == 0 else min(n, int(n / (T0_fit_margin * width)))
117
+ # Flat/no-fit GTLS results keep their existing undefined SDE/SNR contract.
118
+ # A zero-depth template cannot identify an epoch; use the first trial.
119
+ if depth == 1.0:
120
+ return float(np.min(t))
121
+ scale = constants.SIGNAL_DEPTH / (1 - depth)
122
+ signal = 1 - ((1 - signal) / scale)
123
+ epochs = np.linspace(np.min(t), np.min(t) + period, num=points)
124
+ phases = _fold_phase(t, period, np.min(t))
125
+ order = np.argsort(phases, kind="mergesort")
126
+ phase_sorted = phases[order]
127
+ flux = y[order]
128
+ weights = 1 / dy[order] ** 2
129
+ offsets = (epochs - np.min(t)) / period
130
+ starts = np.searchsorted(phase_sorted, offsets, side="left")
131
+ starts = (starts - (int(width / 2) + 1)) % n
132
+ flux_p = np.concatenate([flux, flux[:width]])
133
+ weights_p = np.concatenate([weights, weights[:width]])
134
+ total = np.sum((flux - 1) ** 2 * weights)
135
+ best = _t0_scan(flux_p, weights_p, signal, starts.astype(np.int64), total)
136
+ return epochs[best]
137
+
138
+
139
+ def calculate_transit_duration_in_days(t, period, transit_times, duration):
140
+ """Convert a template's fractional width with TLS2's epoch stretch.
141
+
142
+ Gaps do not multiply the duration by an observing fill factor.
143
+ Keep TLS2's operation order, including the period in the stretch.
144
+ """
145
+ stretch = ((np.max(t) - np.min(t)) / period) / len(transit_times)
146
+ return duration * stretch * period
147
+
148
+
81
149
  def _transit_flux(t, y, transit_times, transit_duration_in_days):
82
150
  """Yield the original strict time windows without changing sample order."""
83
151
  ordered = np.all(t[1:] >= t[:-1])
@@ -1,2 +1,2 @@
1
- __version__ = "2.2.3"
1
+ __version__ = "2.2.4"
2
2
  __date__ = "Nov-2026"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: gputls
3
- Version: 2.2.3
3
+ Version: 2.2.4
4
4
  Summary: GPU-accelerated Transit Least Squares (TLS) for periodic transit detection
5
5
  Author-email: Quanquan Hu <huqq1917@outlook.com>
6
6
  Maintainer-email: Quanquan Hu <huqq1917@outlook.com>
@@ -59,6 +59,13 @@ in parallel on an NVIDIA GPU, which makes it several times faster than CPU TLS.
59
59
 
60
60
  ## Features
61
61
 
62
+ Version 2.2.4 aligns the final candidate's epoch fit and duration conversion
63
+ with TLS2 2.0.4. The reported transit times and noise statistics now use those
64
+ windows. This adds one CPU epoch fit after the GPU search; periodograms and
65
+ the default 0.01 epoch-search margins are unchanged. Native template/depth
66
+ selection remains on the GPU, so this does not promise bitwise equality of
67
+ every output with TLS2.
68
+
62
69
  Version 2.2.3 corrects the out-of-transit noise masks used by `snr` and
63
70
  `snrPink`: their duration is now expressed in days, matching the time array.
64
71
  Earlier versions passed a fractional duration, which could bias the reported
@@ -23,6 +23,7 @@ src/gputls.egg-info/requires.txt
23
23
  src/gputls.egg-info/top_level.txt
24
24
  tests/test_bucket_sort.py
25
25
  tests/test_candidate_screening.py
26
+ tests/test_final_candidate.py
26
27
  tests/test_gtls.py
27
28
  tests/test_patch_scan.py
28
29
  tests/test_snr_units.py
@@ -0,0 +1,69 @@
1
+ """Final epochs and durations against direct CPU residuals and time geometry."""
2
+ import numpy as np
3
+ import pytest
4
+
5
+ from gputls import gtls, stats
6
+
7
+
8
+ def direct_epoch(signal, depth, t, y, dy, period, margin):
9
+ """Slow independent reference: re-fold and sum all residuals at each epoch."""
10
+ width, n = len(signal), len(t)
11
+ count = n if margin == 0 else min(n, int(n / (margin * width)))
12
+ epochs = np.linspace(t.min(), t.min() + period, count)
13
+ model = np.ones(n)
14
+ model[:width] = 1 - (1 - np.asarray(signal, float)) / (.5 / (1 - depth))
15
+ residuals = []
16
+ for epoch in epochs:
17
+ phase = (t - epoch) / period
18
+ phase -= np.floor(phase)
19
+ order = np.roll(np.argsort(phase, kind='stable'), int(width / 2) + 1)
20
+ residuals.append(np.sum(((y[order] - model) / dy[order]) ** 2))
21
+ return epochs[np.argmin(residuals)]
22
+
23
+
24
+ @pytest.mark.parametrize('width', [7, 8, 31])
25
+ @pytest.mark.parametrize('margin', [0., .01, .2])
26
+ @pytest.mark.parametrize('ordered', [False, True])
27
+ def test_final_epoch_matches_direct_weighted_residuals(width, margin, ordered):
28
+ rng = np.random.default_rng(224 + width)
29
+ t = np.sort(rng.uniform(1.2, 35., 127))
30
+ y = 1 + rng.normal(0, .002, len(t))
31
+ dy = rng.uniform(.001, .004, len(t))
32
+ if not ordered:
33
+ indices = rng.permutation(len(t)); t, y, dy = t[indices], y[indices], dy[indices]
34
+ signal = 1 - .5 * np.sin(np.linspace(.1, np.pi-.1, width))
35
+ args = (signal, .997, t, y, dy, 3.731, margin)
36
+ assert stats.final_T0_fit(*args) == direct_epoch(*args)
37
+
38
+
39
+ def test_duration_uses_full_baseline_across_gaps():
40
+ t = np.r_[np.arange(1., 5., .1), np.arange(40., 44., .1)]
41
+ period, epoch, fraction = 7.3, 2.7, .03
42
+ times = stats.all_transit_times(epoch, t, period)
43
+ expected = fraction * (t.max() - t.min()) / len(times)
44
+ assert stats.calculate_transit_duration_in_days(t, period, times, fraction) == pytest.approx(expected)
45
+
46
+
47
+ def test_zero_depth_has_no_preferred_epoch():
48
+ t = np.array([4., 1., 2., 3.])
49
+ assert stats.final_T0_fit(np.array([.5]), 1., t, np.ones(4), np.ones(4), 2., .01) == 1.
50
+
51
+
52
+ @pytest.mark.parametrize('period', [.73, 7.31])
53
+ def test_final_candidate_uses_epoch_fit_and_stretched_duration(period):
54
+ rng = np.random.default_rng(224)
55
+ t = np.arange(1.001, 31., .04)
56
+ t = t[~((t > 12) & (t < 15))]
57
+ distance = (t - 1.213 + period/2) % period - period/2
58
+ dy = rng.uniform(.0002, .0006, len(t))
59
+ y = 1 - .005 * (abs(distance) < .05) + rng.normal(size=len(t))*dy
60
+ model = gtls(t, y, dy, verbose=False)
61
+ result = model.power(periods=np.linspace(period*.999, period*1.001, 51),
62
+ T0_fit_margin=.01, T0_refine_margin=.01)
63
+ row = np.flatnonzero(model.lc_cache_overview['duration'] == result.rawDuration)[0]
64
+ expected = direct_epoch(model.lc_arr[row], 1-result.depth, model.t, model.y, model.dy,
65
+ result.period, .01)
66
+ assert result.T0 == expected
67
+ centers = stats.all_transit_times(expected, model.t, result.period)
68
+ np.testing.assert_array_equal(result.transitTimes, centers)
69
+ assert result.duration == pytest.approx(result.rawDuration*(t.max()-t.min())/len(centers))
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