JAX-based scan anomaly detection for time-series residuals
Project description
jacscanomaly
jacscanomaly is a JAX-based framework for anomaly detection in time-series data.
The package is designed to detect microlensing planetary anomalies by scanning residuals after fitting a single lens model (e.g., PSPL), while remaining fast thanks to JAX.
Features
- JAX-powered: fast, vectorized grid scans with JIT compilation
- Scan-based anomaly detection on residuals
- Built-in visualization: PSPL fit, residuals, and anomaly scan summary
Installation
pip install jacscanomaly
Quick Example
import numpy as np
import matplotlib.pyplot as plt
from jacscanomaly import Finder, FinderConfig
# load data (time, flux, flux_err)
data = np.load("example_data.npy")
time, flux, ferr = data[:, 0], data[:, 1], data[:, 2]
# initial guess for PSPL parameters
p0 = np.array([10000, 10, 0.3])
# run anomaly finder
config = FinderConfig(fitter_kind="pspl")
finder = Finder(config)
result = finder.run(time, flux, ferr, p0)
print("=== PSPL fit ===")
t0_pspl, tE_pspl, u0_pspl = result.fit.params
print(f" t0 = {float(t0_pspl):.3f}")
print(f" tE = {float(tE_pspl):.3f}")
print(f" u0 = {float(u0_pspl):.3f}")
print(f" chi2 / dof = {result.chi2_dof:.3f}\n")
b = result.best
print("=== Anomaly candidate ===")
print(f" t0 = {b.t0:.3f}")
print(f" teff = {b.teff:.3f}")
print(f" dchi2 = {b.dchi2:.3e}")
print(f" score = {b.score:.2f}")
Visualization
finder.plot_result()
finder.plot_anomaly_window()
plt.show()
These commands produce two complementary visualizations:
-
Three-panel summary plot (
finder.plot_result)- Top: Observed light curve with the best-fit baseline model (PSPL)
- Middle: Residuals after baseline fitting
- Bottom: Anomaly scan result (Δχ² vs. time), showing where localized deviations from the baseline model are detected
-
Focused anomaly window plot (
finder.plot_anomaly_window)- A zoomed-in view around the best anomaly candidate
- Residuals are shown together with the anomaly template and the flat model
Method Overview
The workflow of jacscanomaly is:
-
First fitting Fit a single lens model (e.g. PSPL) to the full light curve.
-
Residual analysis Compute residuals:
residual = data − single_lens_model -
Local anomaly scan For each grid point
(t0, teff), compare:- a flat model
- an anomaly template model within a local time window.
-
Detection statistic The improvement is measured by:
Δχ² = χ²_flat − χ²_anomaly
Anomaly Score
To quantify how significant the best anomaly candidate is relative to others, we define a score:
score = (Δχ²_best − median(Δχ²_others)) / std(Δχ²_others)
In practice, jacscanomaly estimates median(Δχ²_others) and
std(Δχ²_others) from the bulk of the other cluster peaks, trimming values
above best_score_trim_percentile first when possible. This makes the score
less sensitive to a few strong secondary peaks.
This measures how strongly the best candidate stands out from the rest of the grid.
Configuration
Key parameters are controlled via FinderConfig:
from jacscanomaly import FinderConfig
config = FinderConfig(
teff_init=0.03, # initial anomaly timescale
teff_grid_n=20, # number of teff grid points
sigma=3.0, # threshold for outlier counting
best_score_trim_percentile=95.0, # trim upper tail for best-candidate score
)
See FinderConfig for the full list of options.
Example Data
The light curves used as examples in this repository are drawn from an original set of 2,371 simulated Roman light curves generated by the Roman Galactic Exoplanet Survey Project Infrastructure Team (RGES PIT), WG07 Survey Simulations and Pipeline Validation (Farzaneh Zohrabi, Matthew Penny, Macy Huston, Ali Crisp, et al).
This representative sample of 2,371 light curves was selected assuming the Cassan exoplanet mass function and consists of simulated Roman light curves of planetary microlensing events, including higher-order effects such as parallax and orbital motion.
Algorithmic Background
The anomaly scan implemented in jacscanomaly is inspired by the
systematic anomaly search methodology developed for microlensing surveys
(e.g., the KMTNet AnomalyFinder series). In particular, the approach
of scanning residual light curves over a grid of anomaly times and
durations is based on key ideas presented in:
Zang, W., Jung, Y., Yee, J., et al. (2021). Systematic KMTNet Planetary Anomaly Search, Paper I: OGLE-2019-BLG-1053Lb, A Buried Terrestrial Planet. The Astronomical Journal, 162, 163.
DOI: 10.3847/1538-3881/ac12d4 :contentReference[oaicite:3]{index=3}
This work described a semi-automated search algorithm that iteratively
scans events for localized deviations relative to a baseline model and
quantifies the significance of detected signals — an idea that is central
to the grid-scan and Δχ² evaluation in jacscanomaly.
Finite-source magnification (FSPL)
Finite-source magnifications are computed using an external JAX-based implementation.
The original FFT-based extended-source algorithm is from
https://github.com/git-sunao/fft-extended-source
This algorithm is provided in JAX form by
https://github.com/ShotaMiyazaki94/microjax
Specifically, scanomaly uses the FFT disk-integration implementation
available via microjax.fastlens.mag_fft_jax.
Citation
If you use jacscanomaly in academic work, including journal articles, conference proceedings, or theses, please cite the software.
Citation metadata is provided in the citation.cff file in this repository,
which can be used directly by GitHub and reference managers.
Requirements
- Python ≥ 3.9
- numpy
- jax
- jaxopt
- matplotlib
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file jacscanomaly-0.3.0.tar.gz.
File metadata
- Download URL: jacscanomaly-0.3.0.tar.gz
- Upload date:
- Size: 1.8 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.19
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
653f96dc9529aa34539081df26e95caf69b13adc2285ed0842cb254f1a1fc452
|
|
| MD5 |
a72a68b73b357fe0fb56465ed3a3acbc
|
|
| BLAKE2b-256 |
314fc0758510384ad29354b5946238638402870e706d522b7956aacd02da5275
|
File details
Details for the file jacscanomaly-0.3.0-py3-none-any.whl.
File metadata
- Download URL: jacscanomaly-0.3.0-py3-none-any.whl
- Upload date:
- Size: 1.8 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.19
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0245bce2e7b0367540656d4fb65bdee083fd8ca61e36adcff554eb522f07b914
|
|
| MD5 |
ae81142f9e569c354c55a109e2cd8a27
|
|
| BLAKE2b-256 |
ef010e994d13684e07532d940c89f983c977e10988826a7d6a358d55747a626c
|