jacscanomaly 0.3.1__tar.gz → 0.3.3__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.
- jacscanomaly-0.3.3/MANIFEST.in +5 -0
- {jacscanomaly-0.3.1/src/jacscanomaly.egg-info → jacscanomaly-0.3.3}/PKG-INFO +188 -24
- {jacscanomaly-0.3.1 → jacscanomaly-0.3.3}/README.md +175 -23
- {jacscanomaly-0.3.1 → jacscanomaly-0.3.3}/pyproject.toml +33 -2
- jacscanomaly-0.3.3/setup.py +66 -0
- jacscanomaly-0.3.3/src/jacscanomaly/__init__.py +102 -0
- jacscanomaly-0.3.3/src/jacscanomaly/_cpp_grid.cpp +780 -0
- {jacscanomaly-0.3.1 → jacscanomaly-0.3.3}/src/jacscanomaly/config.py +126 -7
- jacscanomaly-0.3.3/src/jacscanomaly/criteria.py +36 -0
- {jacscanomaly-0.3.1 → jacscanomaly-0.3.3}/src/jacscanomaly/finder.py +447 -28
- jacscanomaly-0.3.3/src/jacscanomaly/magnification.py +28 -0
- jacscanomaly-0.3.3/src/jacscanomaly/models.py +242 -0
- jacscanomaly-0.3.3/src/jacscanomaly/parallax.py +612 -0
- jacscanomaly-0.3.3/src/jacscanomaly/planet_class/__init__.py +64 -0
- jacscanomaly-0.3.3/src/jacscanomaly/planet_class/atoms/__init__.py +41 -0
- jacscanomaly-0.3.3/src/jacscanomaly/planet_class/atoms/base.py +379 -0
- jacscanomaly-0.3.3/src/jacscanomaly/planet_class/atoms/bump.py +181 -0
- jacscanomaly-0.3.3/src/jacscanomaly/planet_class/atoms/central.py +140 -0
- jacscanomaly-0.3.3/src/jacscanomaly/planet_class/atoms/chang_refsdal.py +269 -0
- jacscanomaly-0.3.3/src/jacscanomaly/planet_class/atoms/cusp.py +165 -0
- jacscanomaly-0.3.3/src/jacscanomaly/planet_class/atoms/fold.py +713 -0
- jacscanomaly-0.3.3/src/jacscanomaly/planet_class/atoms/second_pspl.py +51 -0
- jacscanomaly-0.3.3/src/jacscanomaly/planet_class/atoms/smooth.py +194 -0
- jacscanomaly-0.3.3/src/jacscanomaly/planet_class/classifier.py +403 -0
- jacscanomaly-0.3.3/src/jacscanomaly/planet_class/features.py +72 -0
- jacscanomaly-0.3.3/src/jacscanomaly/planet_class/fold_kernel.py +246 -0
- jacscanomaly-0.3.3/src/jacscanomaly/planet_class/linear.py +45 -0
- jacscanomaly-0.3.3/src/jacscanomaly/planet_class/pspl.py +65 -0
- jacscanomaly-0.3.3/src/jacscanomaly/planet_class/seeds.py +331 -0
- jacscanomaly-0.3.3/src/jacscanomaly/planet_class/types.py +396 -0
- jacscanomaly-0.3.3/src/jacscanomaly/planet_signal.py +2244 -0
- {jacscanomaly-0.3.1 → jacscanomaly-0.3.3}/src/jacscanomaly/plot.py +88 -13
- {jacscanomaly-0.3.1 → jacscanomaly-0.3.3}/src/jacscanomaly/runner.py +187 -33
- jacscanomaly-0.3.3/src/jacscanomaly/singlelens_fit.py +1110 -0
- {jacscanomaly-0.3.1 → jacscanomaly-0.3.3}/src/jacscanomaly/singlelens_model.py +38 -1
- jacscanomaly-0.3.3/src/jacscanomaly/template_free.py +414 -0
- jacscanomaly-0.3.3/src/jacscanomaly/trajectory.py +91 -0
- {jacscanomaly-0.3.1 → jacscanomaly-0.3.3/src/jacscanomaly.egg-info}/PKG-INFO +188 -24
- jacscanomaly-0.3.3/src/jacscanomaly.egg-info/SOURCES.txt +61 -0
- jacscanomaly-0.3.3/src/jacscanomaly.egg-info/requires.txt +20 -0
- jacscanomaly-0.3.3/tests/test_config.py +27 -0
- jacscanomaly-0.3.3/tests/test_cpp_extension.py +8 -0
- jacscanomaly-0.3.3/tests/test_criteria.py +41 -0
- jacscanomaly-0.3.3/tests/test_extract.py +36 -0
- jacscanomaly-0.3.3/tests/test_models.py +87 -0
- jacscanomaly-0.3.3/tests/test_photometry.py +25 -0
- jacscanomaly-0.3.3/tests/test_planet_class.py +850 -0
- jacscanomaly-0.3.3/tests/test_planet_signal.py +378 -0
- jacscanomaly-0.3.3/tests/test_refit.py +41 -0
- jacscanomaly-0.3.3/tests/test_seasons.py +39 -0
- jacscanomaly-0.3.3/tests/test_space_parallax.py +434 -0
- jacscanomaly-0.3.3/tests/test_template_free.py +82 -0
- jacscanomaly-0.3.1/src/jacscanomaly/__init__.py +0 -29
- jacscanomaly-0.3.1/src/jacscanomaly/magnification.py +0 -16
- jacscanomaly-0.3.1/src/jacscanomaly/models.py +0 -106
- jacscanomaly-0.3.1/src/jacscanomaly/parallax.py +0 -258
- jacscanomaly-0.3.1/src/jacscanomaly/singlelens_fit.py +0 -349
- jacscanomaly-0.3.1/src/jacscanomaly/trajectory.py +0 -55
- jacscanomaly-0.3.1/src/jacscanomaly.egg-info/SOURCES.txt +0 -26
- jacscanomaly-0.3.1/src/jacscanomaly.egg-info/requires.txt +0 -4
- {jacscanomaly-0.3.1 → jacscanomaly-0.3.3}/LICENSE +0 -0
- {jacscanomaly-0.3.1 → jacscanomaly-0.3.3}/setup.cfg +0 -0
- {jacscanomaly-0.3.1 → jacscanomaly-0.3.3}/src/jacscanomaly/anomaly_models.py +0 -0
- {jacscanomaly-0.3.1 → jacscanomaly-0.3.3}/src/jacscanomaly/data/__init__.py +0 -0
- {jacscanomaly-0.3.1 → jacscanomaly-0.3.3}/src/jacscanomaly/data/earth_orbital_parallax_table.txt +0 -0
- {jacscanomaly-0.3.1 → jacscanomaly-0.3.3}/src/jacscanomaly/extract.py +0 -0
- {jacscanomaly-0.3.1 → jacscanomaly-0.3.3}/src/jacscanomaly/objective.py +0 -0
- {jacscanomaly-0.3.1 → jacscanomaly-0.3.3}/src/jacscanomaly/photometry.py +0 -0
- {jacscanomaly-0.3.1 → jacscanomaly-0.3.3}/src/jacscanomaly/seasons.py +0 -0
- {jacscanomaly-0.3.1 → jacscanomaly-0.3.3}/src/jacscanomaly.egg-info/dependency_links.txt +0 -0
- {jacscanomaly-0.3.1 → jacscanomaly-0.3.3}/src/jacscanomaly.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: jacscanomaly
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.3
|
|
4
4
|
Summary: JAX-based scan anomaly detection for time-series residuals
|
|
5
5
|
Author: Kansuke Nunota
|
|
6
6
|
License: MIT
|
|
@@ -14,27 +14,61 @@ Requires-Dist: numpy
|
|
|
14
14
|
Requires-Dist: jax
|
|
15
15
|
Requires-Dist: jaxopt
|
|
16
16
|
Requires-Dist: matplotlib
|
|
17
|
+
Provides-Extra: docs
|
|
18
|
+
Requires-Dist: sphinx>=7; extra == "docs"
|
|
19
|
+
Requires-Dist: sphinx-rtd-theme>=2; extra == "docs"
|
|
20
|
+
Requires-Dist: myst-parser>=2; extra == "docs"
|
|
21
|
+
Provides-Extra: test
|
|
22
|
+
Requires-Dist: pytest>=7; extra == "test"
|
|
23
|
+
Requires-Dist: coverage[toml]>=7; extra == "test"
|
|
24
|
+
Provides-Extra: vbm
|
|
25
|
+
Requires-Dist: scipy; extra == "vbm"
|
|
26
|
+
Requires-Dist: VBMicrolensing; extra == "vbm"
|
|
27
|
+
Provides-Extra: dev
|
|
28
|
+
Requires-Dist: jacscanomaly[docs,test,vbm]; extra == "dev"
|
|
17
29
|
Dynamic: license-file
|
|
18
30
|
|
|
19
31
|
# jacscanomaly
|
|
20
32
|
|
|
21
|
-
|
|
22
|
-
|
|
33
|
+
[](https://jacscanomaly.readthedocs.io/en/latest/?badge=latest)
|
|
34
|
+
|
|
35
|
+
**jacscanomaly** is a Python package for scan-based anomaly detection
|
|
36
|
+
in time-series light curves.
|
|
23
37
|
|
|
24
38
|
The package is designed to detect **microlensing planetary anomalies** by
|
|
25
39
|
scanning residuals after fitting a single lens model (e.g., PSPL),
|
|
26
|
-
|
|
40
|
+
with low-memory C++ backends for large survey light curves and JAX-based
|
|
41
|
+
fitters for flexible model development.
|
|
27
42
|
|
|
28
43
|
---
|
|
29
44
|
|
|
30
45
|
## Features
|
|
31
46
|
|
|
32
|
-
* **
|
|
33
|
-
* **
|
|
47
|
+
* **Scan-based anomaly detection** on residuals after single-lens fitting
|
|
48
|
+
* **C++ survey backends** for the PSPL fit and anomaly grid scan
|
|
49
|
+
* **JAX model components** for flexible single-lens and higher-order models
|
|
50
|
+
* **Candidate quality diagnostics**: effective contributing points,
|
|
51
|
+
peak-contribution fraction, and time-correlation metrics
|
|
34
52
|
* **Built-in visualization**: PSPL fit, residuals, and anomaly scan summary
|
|
35
53
|
|
|
36
54
|
---
|
|
37
55
|
|
|
56
|
+
## Documentation
|
|
57
|
+
|
|
58
|
+
The full documentation is available on ReadTheDocs:
|
|
59
|
+
|
|
60
|
+
https://jacscanomaly.readthedocs.io/en/latest/
|
|
61
|
+
|
|
62
|
+
Start with:
|
|
63
|
+
|
|
64
|
+
* [Installation](https://jacscanomaly.readthedocs.io/en/latest/installation.html)
|
|
65
|
+
* [Quickstart](https://jacscanomaly.readthedocs.io/en/latest/quickstart.html)
|
|
66
|
+
* [Examples](https://jacscanomaly.readthedocs.io/en/latest/examples.html)
|
|
67
|
+
* [Method overview](https://jacscanomaly.readthedocs.io/en/latest/method.html)
|
|
68
|
+
* [API reference](https://jacscanomaly.readthedocs.io/en/latest/api.html)
|
|
69
|
+
|
|
70
|
+
---
|
|
71
|
+
|
|
38
72
|
## Installation
|
|
39
73
|
|
|
40
74
|
```bash
|
|
@@ -48,14 +82,17 @@ pip install jacscanomaly
|
|
|
48
82
|
```python
|
|
49
83
|
import numpy as np
|
|
50
84
|
import matplotlib.pyplot as plt
|
|
51
|
-
from jacscanomaly import Finder, FinderConfig
|
|
85
|
+
from jacscanomaly import CandidateCriteria, Finder, FinderConfig
|
|
52
86
|
|
|
53
87
|
# load data (time, flux, flux_err)
|
|
54
88
|
data = np.load("example_data.npy")
|
|
55
89
|
time, flux, ferr = data[:, 0], data[:, 1], data[:, 2]
|
|
56
90
|
|
|
57
91
|
# run anomaly finder
|
|
58
|
-
config = FinderConfig(
|
|
92
|
+
config = FinderConfig(
|
|
93
|
+
fitter_kind="pspl",
|
|
94
|
+
candidate_criteria=CandidateCriteria(min_n_eff=2.0),
|
|
95
|
+
)
|
|
59
96
|
finder = Finder(config)
|
|
60
97
|
result = finder.run(time, flux, ferr)
|
|
61
98
|
|
|
@@ -63,19 +100,10 @@ result = finder.run(time, flux, ferr)
|
|
|
63
100
|
# p0 = np.array([10000, 10, 0.3])
|
|
64
101
|
# result = finder.run(time, flux, ferr, p0)
|
|
65
102
|
|
|
66
|
-
|
|
67
|
-
t0_pspl, tE_pspl, u0_pspl = result.fit.params
|
|
68
|
-
print(f" t0 = {float(t0_pspl):.3f}")
|
|
69
|
-
print(f" tE = {float(tE_pspl):.3f}")
|
|
70
|
-
print(f" u0 = {float(u0_pspl):.3f}")
|
|
71
|
-
print(f" chi2 / dof = {result.chi2_dof:.3f}\n")
|
|
103
|
+
result.print_summary()
|
|
72
104
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
print(f" t0 = {b.t0:.3f}")
|
|
76
|
-
print(f" teff = {b.teff:.3f}")
|
|
77
|
-
print(f" dchi2 = {b.dchi2:.3e}")
|
|
78
|
-
print(f" score = {b.score:.2f}")
|
|
105
|
+
# In notebooks, get a one-row table:
|
|
106
|
+
# display(result.summary_table())
|
|
79
107
|
```
|
|
80
108
|
|
|
81
109
|
---
|
|
@@ -102,6 +130,11 @@ These commands produce two complementary visualizations:
|
|
|
102
130
|
* A zoomed-in view around the best anomaly candidate
|
|
103
131
|
* Residuals are shown together with the anomaly template and the flat model
|
|
104
132
|
|
|
133
|
+
Example notebooks are available in `example/`:
|
|
134
|
+
|
|
135
|
+
* `template_scan_example.ipynb` for the standard bell-template scan
|
|
136
|
+
* `template_free_example.ipynb` for the template-free residual chi-square scan
|
|
137
|
+
|
|
105
138
|
---
|
|
106
139
|
|
|
107
140
|
## Method Overview
|
|
@@ -152,23 +185,105 @@ This measures how strongly the best candidate stands out from the rest of the gr
|
|
|
152
185
|
|
|
153
186
|
---
|
|
154
187
|
|
|
188
|
+
## Candidate Quality Diagnostics
|
|
189
|
+
|
|
190
|
+
Large Δχ² values can sometimes be dominated by one or two points. To make this
|
|
191
|
+
visible, `jacscanomaly` stores per-candidate support diagnostics in
|
|
192
|
+
`result.best.quality` and per-grid diagnostics in `result.grid_metrics_all`.
|
|
193
|
+
|
|
194
|
+
For the best candidate:
|
|
195
|
+
|
|
196
|
+
```python
|
|
197
|
+
q = result.best.quality
|
|
198
|
+
print(q.n_window) # points in the local chi2 window
|
|
199
|
+
print(q.n_contrib) # points above the per-point improvement threshold
|
|
200
|
+
print(q.n_eff) # effective number of contributing points
|
|
201
|
+
print(q.peak_frac) # strongest-point fraction of total positive improvement
|
|
202
|
+
print(q.rho1) # lag-1 autocorrelation of per-point improvements
|
|
203
|
+
print(q.longest_run) # longest consecutive run of contributing points
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
The effective point count is computed from positive per-point improvements
|
|
207
|
+
using a participation-ratio style statistic:
|
|
208
|
+
|
|
209
|
+
```
|
|
210
|
+
n_eff = (sum_i u_i)^2 / sum_i u_i^2
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
where `u_i = max(0, chi2_flat_i - chi2_anomaly_i)`. A one-point-dominated
|
|
214
|
+
candidate has `n_eff` close to 1 and a large `peak_frac`.
|
|
215
|
+
|
|
216
|
+
`result.grid_metrics_all` is a NumPy array with columns:
|
|
217
|
+
|
|
218
|
+
```
|
|
219
|
+
[t0, teff, dchi2, n_window, n_contrib, n_eff, peak_frac, rho1, longest_run]
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
---
|
|
223
|
+
|
|
224
|
+
## Result Summaries
|
|
225
|
+
|
|
226
|
+
`AnomalyResult` provides both CLI-friendly and notebook-friendly summaries:
|
|
227
|
+
|
|
228
|
+
```python
|
|
229
|
+
result.print_summary() # print formatted text
|
|
230
|
+
text = result.summary_text() # return formatted text
|
|
231
|
+
row = result.summary_dict() # return a plain dictionary
|
|
232
|
+
table = result.summary_table() # pandas.DataFrame when pandas is installed
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
`print(result)` also shows the formatted summary text.
|
|
236
|
+
|
|
237
|
+
---
|
|
238
|
+
|
|
155
239
|
## Configuration
|
|
156
240
|
|
|
157
241
|
Key parameters are controlled via `FinderConfig`:
|
|
158
242
|
|
|
159
243
|
```python
|
|
160
|
-
from jacscanomaly import FinderConfig
|
|
244
|
+
from jacscanomaly import CandidateCriteria, FinderConfig
|
|
161
245
|
|
|
162
246
|
config = FinderConfig(
|
|
247
|
+
grid_backend="cpp", # default for PSPL survey scans
|
|
248
|
+
single_fit_backend="cpp",
|
|
163
249
|
teff_init=0.03, # initial anomaly timescale
|
|
164
250
|
teff_grid_n=20, # number of teff grid points
|
|
165
|
-
sigma=3.0, # threshold for
|
|
251
|
+
sigma=3.0, # per-point improvement threshold for n_contrib
|
|
252
|
+
candidate_criteria=CandidateCriteria(min_n_eff=2.0),
|
|
166
253
|
best_score_trim_percentile=95.0, # trim upper tail for best-candidate score
|
|
167
254
|
)
|
|
168
255
|
```
|
|
169
256
|
|
|
170
257
|
See `FinderConfig` for the full list of options.
|
|
171
258
|
|
|
259
|
+
For finite-source single-lens baselines without JAX autodiff, use the
|
|
260
|
+
VBMicrolensing finite-difference fitters:
|
|
261
|
+
|
|
262
|
+
```python
|
|
263
|
+
config = FinderConfig(
|
|
264
|
+
fitter_kind="fspl_vbm_fd",
|
|
265
|
+
grid_backend="cpp",
|
|
266
|
+
)
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
For GULLS-convention spacecraft parallax:
|
|
270
|
+
|
|
271
|
+
```python
|
|
272
|
+
config = FinderConfig(
|
|
273
|
+
fitter_kind="fspl_space_parallax_gulls_vbm_fd",
|
|
274
|
+
grid_backend="cpp",
|
|
275
|
+
ra_deg=267.3,
|
|
276
|
+
dec_deg=-29.9,
|
|
277
|
+
tref=2461504.0,
|
|
278
|
+
satellite_ephemeris_path="gulls_orbit5_heliocentric.dat",
|
|
279
|
+
)
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
These fitters evaluate finite-source magnification with
|
|
283
|
+
`VBMicrolensing.ESPLMag` and optimize nonlinear parameters with SciPy
|
|
284
|
+
finite-difference least squares. They are useful for large CPU survey runs
|
|
285
|
+
where JAX FSPL autodiff overhead dominates runtime.
|
|
286
|
+
|
|
172
287
|
---
|
|
173
288
|
|
|
174
289
|
## Example Data
|
|
@@ -206,8 +321,23 @@ to the grid-scan and Δχ² evaluation in `jacscanomaly`.
|
|
|
206
321
|
|
|
207
322
|
### Finite-source magnification (FSPL)
|
|
208
323
|
|
|
209
|
-
|
|
210
|
-
|
|
324
|
+
`jacscanomaly` provides two FSPL implementation families:
|
|
325
|
+
|
|
326
|
+
* JAX/microjax fitters: `fspl`, `fspl_parallax`, and `fspl_space_parallax`.
|
|
327
|
+
* CPU finite-difference fitters using VBMicrolensing ESPL magnification:
|
|
328
|
+
`fspl_vbm_fd` and `fspl_space_parallax_gulls_vbm_fd`.
|
|
329
|
+
|
|
330
|
+
Install the VBM backend dependencies with:
|
|
331
|
+
|
|
332
|
+
```bash
|
|
333
|
+
pip install -e ".[vbm]"
|
|
334
|
+
```
|
|
335
|
+
|
|
336
|
+
The VBM fitters keep the anomaly grid scan in the compiled C++ backend when
|
|
337
|
+
`grid_backend="cpp"` is selected.
|
|
338
|
+
|
|
339
|
+
For the JAX/microjax FSPL fitters, finite-source magnifications are computed
|
|
340
|
+
using an external JAX-based implementation.
|
|
211
341
|
|
|
212
342
|
The original FFT-based extended-source algorithm is from:
|
|
213
343
|
https://github.com/git-sunao/fft-extended-source
|
|
@@ -252,3 +382,37 @@ which can be used directly by GitHub and reference managers.
|
|
|
252
382
|
* jax
|
|
253
383
|
* jaxopt
|
|
254
384
|
* matplotlib
|
|
385
|
+
|
|
386
|
+
Optional for VBM finite-difference FSPL fitters:
|
|
387
|
+
|
|
388
|
+
* scipy
|
|
389
|
+
* VBMicrolensing
|
|
390
|
+
|
|
391
|
+
---
|
|
392
|
+
|
|
393
|
+
## Development
|
|
394
|
+
|
|
395
|
+
Install the package with development dependencies:
|
|
396
|
+
|
|
397
|
+
```bash
|
|
398
|
+
pip install -e ".[dev]"
|
|
399
|
+
```
|
|
400
|
+
|
|
401
|
+
Run the unit tests:
|
|
402
|
+
|
|
403
|
+
```bash
|
|
404
|
+
pytest
|
|
405
|
+
```
|
|
406
|
+
|
|
407
|
+
Run the tests with coverage:
|
|
408
|
+
|
|
409
|
+
```bash
|
|
410
|
+
coverage run -m pytest
|
|
411
|
+
coverage report
|
|
412
|
+
```
|
|
413
|
+
|
|
414
|
+
Build the Sphinx documentation locally:
|
|
415
|
+
|
|
416
|
+
```bash
|
|
417
|
+
sphinx-build -W -b html docs docs/_build/html
|
|
418
|
+
```
|
|
@@ -1,22 +1,44 @@
|
|
|
1
1
|
# jacscanomaly
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
[](https://jacscanomaly.readthedocs.io/en/latest/?badge=latest)
|
|
4
|
+
|
|
5
|
+
**jacscanomaly** is a Python package for scan-based anomaly detection
|
|
6
|
+
in time-series light curves.
|
|
5
7
|
|
|
6
8
|
The package is designed to detect **microlensing planetary anomalies** by
|
|
7
9
|
scanning residuals after fitting a single lens model (e.g., PSPL),
|
|
8
|
-
|
|
10
|
+
with low-memory C++ backends for large survey light curves and JAX-based
|
|
11
|
+
fitters for flexible model development.
|
|
9
12
|
|
|
10
13
|
---
|
|
11
14
|
|
|
12
15
|
## Features
|
|
13
16
|
|
|
14
|
-
* **
|
|
15
|
-
* **
|
|
17
|
+
* **Scan-based anomaly detection** on residuals after single-lens fitting
|
|
18
|
+
* **C++ survey backends** for the PSPL fit and anomaly grid scan
|
|
19
|
+
* **JAX model components** for flexible single-lens and higher-order models
|
|
20
|
+
* **Candidate quality diagnostics**: effective contributing points,
|
|
21
|
+
peak-contribution fraction, and time-correlation metrics
|
|
16
22
|
* **Built-in visualization**: PSPL fit, residuals, and anomaly scan summary
|
|
17
23
|
|
|
18
24
|
---
|
|
19
25
|
|
|
26
|
+
## Documentation
|
|
27
|
+
|
|
28
|
+
The full documentation is available on ReadTheDocs:
|
|
29
|
+
|
|
30
|
+
https://jacscanomaly.readthedocs.io/en/latest/
|
|
31
|
+
|
|
32
|
+
Start with:
|
|
33
|
+
|
|
34
|
+
* [Installation](https://jacscanomaly.readthedocs.io/en/latest/installation.html)
|
|
35
|
+
* [Quickstart](https://jacscanomaly.readthedocs.io/en/latest/quickstart.html)
|
|
36
|
+
* [Examples](https://jacscanomaly.readthedocs.io/en/latest/examples.html)
|
|
37
|
+
* [Method overview](https://jacscanomaly.readthedocs.io/en/latest/method.html)
|
|
38
|
+
* [API reference](https://jacscanomaly.readthedocs.io/en/latest/api.html)
|
|
39
|
+
|
|
40
|
+
---
|
|
41
|
+
|
|
20
42
|
## Installation
|
|
21
43
|
|
|
22
44
|
```bash
|
|
@@ -30,14 +52,17 @@ pip install jacscanomaly
|
|
|
30
52
|
```python
|
|
31
53
|
import numpy as np
|
|
32
54
|
import matplotlib.pyplot as plt
|
|
33
|
-
from jacscanomaly import Finder, FinderConfig
|
|
55
|
+
from jacscanomaly import CandidateCriteria, Finder, FinderConfig
|
|
34
56
|
|
|
35
57
|
# load data (time, flux, flux_err)
|
|
36
58
|
data = np.load("example_data.npy")
|
|
37
59
|
time, flux, ferr = data[:, 0], data[:, 1], data[:, 2]
|
|
38
60
|
|
|
39
61
|
# run anomaly finder
|
|
40
|
-
config = FinderConfig(
|
|
62
|
+
config = FinderConfig(
|
|
63
|
+
fitter_kind="pspl",
|
|
64
|
+
candidate_criteria=CandidateCriteria(min_n_eff=2.0),
|
|
65
|
+
)
|
|
41
66
|
finder = Finder(config)
|
|
42
67
|
result = finder.run(time, flux, ferr)
|
|
43
68
|
|
|
@@ -45,19 +70,10 @@ result = finder.run(time, flux, ferr)
|
|
|
45
70
|
# p0 = np.array([10000, 10, 0.3])
|
|
46
71
|
# result = finder.run(time, flux, ferr, p0)
|
|
47
72
|
|
|
48
|
-
|
|
49
|
-
t0_pspl, tE_pspl, u0_pspl = result.fit.params
|
|
50
|
-
print(f" t0 = {float(t0_pspl):.3f}")
|
|
51
|
-
print(f" tE = {float(tE_pspl):.3f}")
|
|
52
|
-
print(f" u0 = {float(u0_pspl):.3f}")
|
|
53
|
-
print(f" chi2 / dof = {result.chi2_dof:.3f}\n")
|
|
73
|
+
result.print_summary()
|
|
54
74
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
print(f" t0 = {b.t0:.3f}")
|
|
58
|
-
print(f" teff = {b.teff:.3f}")
|
|
59
|
-
print(f" dchi2 = {b.dchi2:.3e}")
|
|
60
|
-
print(f" score = {b.score:.2f}")
|
|
75
|
+
# In notebooks, get a one-row table:
|
|
76
|
+
# display(result.summary_table())
|
|
61
77
|
```
|
|
62
78
|
|
|
63
79
|
---
|
|
@@ -84,6 +100,11 @@ These commands produce two complementary visualizations:
|
|
|
84
100
|
* A zoomed-in view around the best anomaly candidate
|
|
85
101
|
* Residuals are shown together with the anomaly template and the flat model
|
|
86
102
|
|
|
103
|
+
Example notebooks are available in `example/`:
|
|
104
|
+
|
|
105
|
+
* `template_scan_example.ipynb` for the standard bell-template scan
|
|
106
|
+
* `template_free_example.ipynb` for the template-free residual chi-square scan
|
|
107
|
+
|
|
87
108
|
---
|
|
88
109
|
|
|
89
110
|
## Method Overview
|
|
@@ -134,23 +155,105 @@ This measures how strongly the best candidate stands out from the rest of the gr
|
|
|
134
155
|
|
|
135
156
|
---
|
|
136
157
|
|
|
158
|
+
## Candidate Quality Diagnostics
|
|
159
|
+
|
|
160
|
+
Large Δχ² values can sometimes be dominated by one or two points. To make this
|
|
161
|
+
visible, `jacscanomaly` stores per-candidate support diagnostics in
|
|
162
|
+
`result.best.quality` and per-grid diagnostics in `result.grid_metrics_all`.
|
|
163
|
+
|
|
164
|
+
For the best candidate:
|
|
165
|
+
|
|
166
|
+
```python
|
|
167
|
+
q = result.best.quality
|
|
168
|
+
print(q.n_window) # points in the local chi2 window
|
|
169
|
+
print(q.n_contrib) # points above the per-point improvement threshold
|
|
170
|
+
print(q.n_eff) # effective number of contributing points
|
|
171
|
+
print(q.peak_frac) # strongest-point fraction of total positive improvement
|
|
172
|
+
print(q.rho1) # lag-1 autocorrelation of per-point improvements
|
|
173
|
+
print(q.longest_run) # longest consecutive run of contributing points
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
The effective point count is computed from positive per-point improvements
|
|
177
|
+
using a participation-ratio style statistic:
|
|
178
|
+
|
|
179
|
+
```
|
|
180
|
+
n_eff = (sum_i u_i)^2 / sum_i u_i^2
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
where `u_i = max(0, chi2_flat_i - chi2_anomaly_i)`. A one-point-dominated
|
|
184
|
+
candidate has `n_eff` close to 1 and a large `peak_frac`.
|
|
185
|
+
|
|
186
|
+
`result.grid_metrics_all` is a NumPy array with columns:
|
|
187
|
+
|
|
188
|
+
```
|
|
189
|
+
[t0, teff, dchi2, n_window, n_contrib, n_eff, peak_frac, rho1, longest_run]
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
---
|
|
193
|
+
|
|
194
|
+
## Result Summaries
|
|
195
|
+
|
|
196
|
+
`AnomalyResult` provides both CLI-friendly and notebook-friendly summaries:
|
|
197
|
+
|
|
198
|
+
```python
|
|
199
|
+
result.print_summary() # print formatted text
|
|
200
|
+
text = result.summary_text() # return formatted text
|
|
201
|
+
row = result.summary_dict() # return a plain dictionary
|
|
202
|
+
table = result.summary_table() # pandas.DataFrame when pandas is installed
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
`print(result)` also shows the formatted summary text.
|
|
206
|
+
|
|
207
|
+
---
|
|
208
|
+
|
|
137
209
|
## Configuration
|
|
138
210
|
|
|
139
211
|
Key parameters are controlled via `FinderConfig`:
|
|
140
212
|
|
|
141
213
|
```python
|
|
142
|
-
from jacscanomaly import FinderConfig
|
|
214
|
+
from jacscanomaly import CandidateCriteria, FinderConfig
|
|
143
215
|
|
|
144
216
|
config = FinderConfig(
|
|
217
|
+
grid_backend="cpp", # default for PSPL survey scans
|
|
218
|
+
single_fit_backend="cpp",
|
|
145
219
|
teff_init=0.03, # initial anomaly timescale
|
|
146
220
|
teff_grid_n=20, # number of teff grid points
|
|
147
|
-
sigma=3.0, # threshold for
|
|
221
|
+
sigma=3.0, # per-point improvement threshold for n_contrib
|
|
222
|
+
candidate_criteria=CandidateCriteria(min_n_eff=2.0),
|
|
148
223
|
best_score_trim_percentile=95.0, # trim upper tail for best-candidate score
|
|
149
224
|
)
|
|
150
225
|
```
|
|
151
226
|
|
|
152
227
|
See `FinderConfig` for the full list of options.
|
|
153
228
|
|
|
229
|
+
For finite-source single-lens baselines without JAX autodiff, use the
|
|
230
|
+
VBMicrolensing finite-difference fitters:
|
|
231
|
+
|
|
232
|
+
```python
|
|
233
|
+
config = FinderConfig(
|
|
234
|
+
fitter_kind="fspl_vbm_fd",
|
|
235
|
+
grid_backend="cpp",
|
|
236
|
+
)
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
For GULLS-convention spacecraft parallax:
|
|
240
|
+
|
|
241
|
+
```python
|
|
242
|
+
config = FinderConfig(
|
|
243
|
+
fitter_kind="fspl_space_parallax_gulls_vbm_fd",
|
|
244
|
+
grid_backend="cpp",
|
|
245
|
+
ra_deg=267.3,
|
|
246
|
+
dec_deg=-29.9,
|
|
247
|
+
tref=2461504.0,
|
|
248
|
+
satellite_ephemeris_path="gulls_orbit5_heliocentric.dat",
|
|
249
|
+
)
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
These fitters evaluate finite-source magnification with
|
|
253
|
+
`VBMicrolensing.ESPLMag` and optimize nonlinear parameters with SciPy
|
|
254
|
+
finite-difference least squares. They are useful for large CPU survey runs
|
|
255
|
+
where JAX FSPL autodiff overhead dominates runtime.
|
|
256
|
+
|
|
154
257
|
---
|
|
155
258
|
|
|
156
259
|
## Example Data
|
|
@@ -188,8 +291,23 @@ to the grid-scan and Δχ² evaluation in `jacscanomaly`.
|
|
|
188
291
|
|
|
189
292
|
### Finite-source magnification (FSPL)
|
|
190
293
|
|
|
191
|
-
|
|
192
|
-
|
|
294
|
+
`jacscanomaly` provides two FSPL implementation families:
|
|
295
|
+
|
|
296
|
+
* JAX/microjax fitters: `fspl`, `fspl_parallax`, and `fspl_space_parallax`.
|
|
297
|
+
* CPU finite-difference fitters using VBMicrolensing ESPL magnification:
|
|
298
|
+
`fspl_vbm_fd` and `fspl_space_parallax_gulls_vbm_fd`.
|
|
299
|
+
|
|
300
|
+
Install the VBM backend dependencies with:
|
|
301
|
+
|
|
302
|
+
```bash
|
|
303
|
+
pip install -e ".[vbm]"
|
|
304
|
+
```
|
|
305
|
+
|
|
306
|
+
The VBM fitters keep the anomaly grid scan in the compiled C++ backend when
|
|
307
|
+
`grid_backend="cpp"` is selected.
|
|
308
|
+
|
|
309
|
+
For the JAX/microjax FSPL fitters, finite-source magnifications are computed
|
|
310
|
+
using an external JAX-based implementation.
|
|
193
311
|
|
|
194
312
|
The original FFT-based extended-source algorithm is from:
|
|
195
313
|
https://github.com/git-sunao/fft-extended-source
|
|
@@ -234,3 +352,37 @@ which can be used directly by GitHub and reference managers.
|
|
|
234
352
|
* jax
|
|
235
353
|
* jaxopt
|
|
236
354
|
* matplotlib
|
|
355
|
+
|
|
356
|
+
Optional for VBM finite-difference FSPL fitters:
|
|
357
|
+
|
|
358
|
+
* scipy
|
|
359
|
+
* VBMicrolensing
|
|
360
|
+
|
|
361
|
+
---
|
|
362
|
+
|
|
363
|
+
## Development
|
|
364
|
+
|
|
365
|
+
Install the package with development dependencies:
|
|
366
|
+
|
|
367
|
+
```bash
|
|
368
|
+
pip install -e ".[dev]"
|
|
369
|
+
```
|
|
370
|
+
|
|
371
|
+
Run the unit tests:
|
|
372
|
+
|
|
373
|
+
```bash
|
|
374
|
+
pytest
|
|
375
|
+
```
|
|
376
|
+
|
|
377
|
+
Run the tests with coverage:
|
|
378
|
+
|
|
379
|
+
```bash
|
|
380
|
+
coverage run -m pytest
|
|
381
|
+
coverage report
|
|
382
|
+
```
|
|
383
|
+
|
|
384
|
+
Build the Sphinx documentation locally:
|
|
385
|
+
|
|
386
|
+
```bash
|
|
387
|
+
sphinx-build -W -b html docs docs/_build/html
|
|
388
|
+
```
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
[build-system]
|
|
2
|
-
requires = ["setuptools>=69", "wheel"]
|
|
2
|
+
requires = ["setuptools>=69", "wheel", "numpy"]
|
|
3
3
|
build-backend = "setuptools.build_meta"
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "jacscanomaly"
|
|
7
|
-
version = "0.3.
|
|
7
|
+
version = "0.3.3"
|
|
8
8
|
description = "JAX-based scan anomaly detection for time-series residuals"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.9"
|
|
@@ -17,6 +17,24 @@ dependencies = [
|
|
|
17
17
|
"matplotlib",
|
|
18
18
|
]
|
|
19
19
|
|
|
20
|
+
[project.optional-dependencies]
|
|
21
|
+
docs = [
|
|
22
|
+
"sphinx>=7",
|
|
23
|
+
"sphinx-rtd-theme>=2",
|
|
24
|
+
"myst-parser>=2",
|
|
25
|
+
]
|
|
26
|
+
test = [
|
|
27
|
+
"pytest>=7",
|
|
28
|
+
"coverage[toml]>=7",
|
|
29
|
+
]
|
|
30
|
+
vbm = [
|
|
31
|
+
"scipy",
|
|
32
|
+
"VBMicrolensing",
|
|
33
|
+
]
|
|
34
|
+
dev = [
|
|
35
|
+
"jacscanomaly[docs,test,vbm]",
|
|
36
|
+
]
|
|
37
|
+
|
|
20
38
|
[project.urls]
|
|
21
39
|
Homepage = "https://github.com/NunotaKansuke/jacscanomaly"
|
|
22
40
|
Repository = "https://github.com/NunotaKansuke/jacscanomaly"
|
|
@@ -31,3 +49,16 @@ exclude = ["jacscanomaly.test_tool*"]
|
|
|
31
49
|
|
|
32
50
|
[tool.setuptools.package-data]
|
|
33
51
|
jacscanomaly = ["data/*"]
|
|
52
|
+
|
|
53
|
+
[tool.pytest.ini_options]
|
|
54
|
+
testpaths = ["tests"]
|
|
55
|
+
python_files = ["test_*.py"]
|
|
56
|
+
addopts = "-ra"
|
|
57
|
+
|
|
58
|
+
[tool.coverage.run]
|
|
59
|
+
source = ["jacscanomaly"]
|
|
60
|
+
branch = true
|
|
61
|
+
|
|
62
|
+
[tool.coverage.report]
|
|
63
|
+
show_missing = true
|
|
64
|
+
skip_covered = true
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import sys
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
|
|
6
|
+
import numpy as np
|
|
7
|
+
from setuptools import Extension, setup
|
|
8
|
+
from setuptools.command.build_ext import build_ext as _build_ext
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
CPP_GRID_SOURCE = Path("src/jacscanomaly/_cpp_grid.cpp")
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def _compile_and_link_args() -> tuple[list[str], list[str]]:
|
|
15
|
+
"""Return platform-specific flags for the mandatory C++ backend."""
|
|
16
|
+
if sys.platform == "win32":
|
|
17
|
+
return ["/O2", "/std:c++17", "/openmp"], []
|
|
18
|
+
if sys.platform == "darwin":
|
|
19
|
+
return ["-O3", "-std=c++17", "-Xpreprocessor", "-fopenmp"], ["-lomp"]
|
|
20
|
+
return ["-O3", "-std=c++17", "-fopenmp"], ["-fopenmp"]
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class build_ext(_build_ext):
|
|
24
|
+
"""Build the C++ backend as a required extension.
|
|
25
|
+
|
|
26
|
+
The default PSPL workflow uses ``grid_backend='cpp'`` and
|
|
27
|
+
``single_fit_backend='cpp'``, so the package should fail during install if
|
|
28
|
+
the compiled backend cannot be built instead of installing a package that
|
|
29
|
+
later fails at runtime.
|
|
30
|
+
"""
|
|
31
|
+
|
|
32
|
+
def build_extensions(self) -> None:
|
|
33
|
+
if not CPP_GRID_SOURCE.exists():
|
|
34
|
+
raise RuntimeError(
|
|
35
|
+
f"Required C++ source file is missing from the source distribution: {CPP_GRID_SOURCE}."
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
compile_args, link_args = _compile_and_link_args()
|
|
39
|
+
for ext in self.extensions:
|
|
40
|
+
ext.extra_compile_args = list(ext.extra_compile_args or []) + compile_args
|
|
41
|
+
ext.extra_link_args = list(ext.extra_link_args or []) + link_args
|
|
42
|
+
|
|
43
|
+
try:
|
|
44
|
+
super().build_extensions()
|
|
45
|
+
except Exception as exc:
|
|
46
|
+
raise RuntimeError(
|
|
47
|
+
"Failed to build the required jacscanomaly._cpp_grid extension. "
|
|
48
|
+
"The default PSPL survey workflow needs this compiled backend. "
|
|
49
|
+
"Make sure a C++17 compiler and OpenMP runtime are available, then reinstall. "
|
|
50
|
+
"For a source build from PyPI, use: "
|
|
51
|
+
"python -m pip install --no-binary jacscanomaly jacscanomaly"
|
|
52
|
+
) from exc
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
setup(
|
|
56
|
+
ext_modules=[
|
|
57
|
+
Extension(
|
|
58
|
+
"jacscanomaly._cpp_grid",
|
|
59
|
+
[str(CPP_GRID_SOURCE)],
|
|
60
|
+
include_dirs=[np.get_include()],
|
|
61
|
+
language="c++",
|
|
62
|
+
depends=[str(CPP_GRID_SOURCE)],
|
|
63
|
+
)
|
|
64
|
+
],
|
|
65
|
+
cmdclass={"build_ext": build_ext},
|
|
66
|
+
)
|