gputls 2.2.2__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.2/src/gputls.egg-info → gputls-2.2.4}/PKG-INFO +14 -1
  2. {gputls-2.2.2 → gputls-2.2.4}/README.md +13 -0
  3. {gputls-2.2.2 → gputls-2.2.4}/src/gputls/core.py +12 -14
  4. {gputls-2.2.2 → gputls-2.2.4}/src/gputls/stats.py +69 -1
  5. {gputls-2.2.2 → gputls-2.2.4}/src/gputls/version.py +1 -1
  6. {gputls-2.2.2 → gputls-2.2.4/src/gputls.egg-info}/PKG-INFO +14 -1
  7. {gputls-2.2.2 → gputls-2.2.4}/src/gputls.egg-info/SOURCES.txt +2 -0
  8. gputls-2.2.4/tests/test_final_candidate.py +69 -0
  9. gputls-2.2.4/tests/test_snr_units.py +34 -0
  10. {gputls-2.2.2 → gputls-2.2.4}/LICENSE +0 -0
  11. {gputls-2.2.2 → gputls-2.2.4}/pyproject.toml +0 -0
  12. {gputls-2.2.2 → gputls-2.2.4}/setup.cfg +0 -0
  13. {gputls-2.2.2 → gputls-2.2.4}/src/gputls/__init__.py +0 -0
  14. {gputls-2.2.2 → gputls-2.2.4}/src/gputls/constants.py +0 -0
  15. {gputls-2.2.2 → gputls-2.2.4}/src/gputls/grid.py +0 -0
  16. {gputls-2.2.2 → gputls-2.2.4}/src/gputls/helpers.py +0 -0
  17. {gputls-2.2.2 → gputls-2.2.4}/src/gputls/interpolation.py +0 -0
  18. {gputls-2.2.2 → gputls-2.2.4}/src/gputls/kernels.cu +0 -0
  19. {gputls-2.2.2 → gputls-2.2.4}/src/gputls/main.py +0 -0
  20. {gputls-2.2.2 → gputls-2.2.4}/src/gputls/results.py +0 -0
  21. {gputls-2.2.2 → gputls-2.2.4}/src/gputls/screening.py +0 -0
  22. {gputls-2.2.2 → gputls-2.2.4}/src/gputls/transit.py +0 -0
  23. {gputls-2.2.2 → gputls-2.2.4}/src/gputls/validate.py +0 -0
  24. {gputls-2.2.2 → gputls-2.2.4}/src/gputls/workspace.py +0 -0
  25. {gputls-2.2.2 → gputls-2.2.4}/src/gputls.egg-info/dependency_links.txt +0 -0
  26. {gputls-2.2.2 → gputls-2.2.4}/src/gputls.egg-info/requires.txt +0 -0
  27. {gputls-2.2.2 → gputls-2.2.4}/src/gputls.egg-info/top_level.txt +0 -0
  28. {gputls-2.2.2 → gputls-2.2.4}/tests/test_bucket_sort.py +0 -0
  29. {gputls-2.2.2 → gputls-2.2.4}/tests/test_candidate_screening.py +0 -0
  30. {gputls-2.2.2 → gputls-2.2.4}/tests/test_gtls.py +0 -0
  31. {gputls-2.2.2 → gputls-2.2.4}/tests/test_patch_scan.py +0 -0
  32. {gputls-2.2.2 → gputls-2.2.4}/tests/test_stats.py +0 -0
  33. {gputls-2.2.2 → gputls-2.2.4}/tests/test_tls_compare.py +0 -0
  34. {gputls-2.2.2 → gputls-2.2.4}/tests/test_window_reuse.py +0 -0
  35. {gputls-2.2.2 → 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.2
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,19 @@ 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
+
69
+ Version 2.2.3 corrects the out-of-transit noise masks used by `snr` and
70
+ `snrPink`: their duration is now expressed in days, matching the time array.
71
+ Earlier versions passed a fractional duration, which could bias the reported
72
+ signal-to-noise ratios. Period searches, periodograms, and the default 0.01
73
+ epoch-search margins are unchanged by this correction.
74
+
62
75
  - Drop-in replacement for the `transitleastsquares` search API
63
76
  - Limb-darkened transit templates (default, grazing and box-shaped)
64
77
  - Batches trial periods automatically to fit the free GPU memory
@@ -12,6 +12,19 @@ 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
+
22
+ Version 2.2.3 corrects the out-of-transit noise masks used by `snr` and
23
+ `snrPink`: their duration is now expressed in days, matching the time array.
24
+ Earlier versions passed a fractional duration, which could bias the reported
25
+ signal-to-noise ratios. Period searches, periodograms, and the default 0.01
26
+ epoch-search margins are unchanged by this correction.
27
+
15
28
  - Drop-in replacement for the `transitleastsquares` search API
16
29
  - Limb-darkened transit templates (default, grazing and box-shaped)
17
30
  - Batches trial periods automatically to fit the free GPU memory
@@ -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(
@@ -767,7 +764,7 @@ def search_single_period(search, period, t, y, dy):
767
764
  t=t,
768
765
  y=y,
769
766
  period=period,
770
- duration=rawDuration,
767
+ duration=transit_duration_in_days,
771
768
  T0=T0,
772
769
  transit_times=transit_times,
773
770
  transit_duration_in_days=transit_duration_in_days,
@@ -776,7 +773,8 @@ def search_single_period(search, period, t, y, dy):
776
773
  )
777
774
 
778
775
  all_flux_intransit = np.concatenate([all_flux_intransit_odd, all_flux_intransit_even])
779
- intransit = transit_mask(t, period, 2 * rawDuration, T0)
776
+ # The mask uses the same time units as t; rawDuration is a fraction of P.
777
+ intransit = transit_mask(t, period, 2 * transit_duration_in_days, T0)
780
778
  flux_ootr = y[~intransit]
781
779
  depth_mean = np.mean(all_flux_intransit)
782
780
  snr = ((1 - depth_mean) / np.std(flux_ootr)) * len(all_flux_intransit) ** (0.5)
@@ -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])
@@ -136,7 +204,7 @@ def pink_noise(data, width, window_std=None):
136
204
 
137
205
  def snr_stats(t, y, period, duration, T0, transit_times, transit_duration_in_days, per_transit_count,
138
206
  window_std=None):
139
- """Return the pink-noise SNR of each transit"""
207
+ """Return per-transit pink-noise SNR; both duration arguments are in days."""
140
208
 
141
209
  snr_pink_per_transit = np.zeros([len(transit_times)])
142
210
  intransit = transit_mask(t, period, 2 * duration, T0)
@@ -1,2 +1,2 @@
1
- __version__ = "2.2.2"
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.2
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,19 @@ 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
+
69
+ Version 2.2.3 corrects the out-of-transit noise masks used by `snr` and
70
+ `snrPink`: their duration is now expressed in days, matching the time array.
71
+ Earlier versions passed a fractional duration, which could bias the reported
72
+ signal-to-noise ratios. Period searches, periodograms, and the default 0.01
73
+ epoch-search margins are unchanged by this correction.
74
+
62
75
  - Drop-in replacement for the `transitleastsquares` search API
63
76
  - Limb-darkened transit templates (default, grazing and box-shaped)
64
77
  - Batches trial periods automatically to fit the free GPU memory
@@ -23,8 +23,10 @@ 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
29
+ tests/test_snr_units.py
28
30
  tests/test_stats.py
29
31
  tests/test_tls_compare.py
30
32
  tests/test_window_reuse.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))
@@ -0,0 +1,34 @@
1
+ """End-to-end regression for day vs fractional-period noise-mask durations."""
2
+ import numpy as np
3
+ import pytest
4
+
5
+ from gputls import gtls, stats
6
+
7
+
8
+ @pytest.mark.parametrize("period", [0.73, 7.31])
9
+ def test_native_noise_statistics_use_duration_in_days(period):
10
+ rng = np.random.default_rng(223)
11
+ t = np.arange(1.001, 81., .02)
12
+ epoch, duration = 1.213, .08
13
+ distance = (t - epoch + period / 2) % period - period / 2
14
+ y = 1 - .005 * (np.abs(distance) < duration / 2)
15
+ y += rng.normal(0, .0003, len(t))
16
+ result = gtls(t, y, np.full(len(t), .0003), verbose=False).power(
17
+ periods=np.linspace(period * .999, period * 1.001, 101),
18
+ T0_fit_margin=.01, T0_refine_margin=.01)
19
+
20
+ # Independent masks in time units, and direct per-event sample selection.
21
+ distance = (t - result.T0 + result.period / 2) % result.period - result.period / 2
22
+ oot = y[np.abs(distance) >= result.duration]
23
+ events = [y[(t > mid - result.duration / 2) &
24
+ (t < mid + result.duration / 2)] for mid in result.transitTimes]
25
+ inside = np.concatenate(events[1::2] + events[::2])
26
+ expected = (1 - inside.mean()) / oot.std() * np.sqrt(len(inside))
27
+ assert result.snr == pytest.approx(expected, rel=1e-12)
28
+
29
+ # CPU pink_noise is independently fed the correctly excluded OOT sample.
30
+ width = int(np.mean([len(event) for event in events]))
31
+ pink = stats.pink_noise(oot, width)
32
+ per_event = [(1 - event.mean()) / pink if len(event) else 0 for event in events]
33
+ expected_pink = np.mean(per_event) * np.sqrt(len(events))
34
+ assert result.snrPink == pytest.approx(expected_pink, rel=1e-10)
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