jacscanomaly 0.3.2__tar.gz → 0.3.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.
- jacscanomaly-0.3.4/MANIFEST.in +5 -0
- {jacscanomaly-0.3.2/src/jacscanomaly.egg-info → jacscanomaly-0.3.4}/PKG-INFO +4 -1
- {jacscanomaly-0.3.2 → jacscanomaly-0.3.4}/README.md +3 -0
- {jacscanomaly-0.3.2 → jacscanomaly-0.3.4}/pyproject.toml +1 -1
- jacscanomaly-0.3.4/setup.py +66 -0
- {jacscanomaly-0.3.2 → jacscanomaly-0.3.4}/src/jacscanomaly/__init__.py +44 -0
- {jacscanomaly-0.3.2 → jacscanomaly-0.3.4}/src/jacscanomaly/config.py +19 -5
- {jacscanomaly-0.3.2 → jacscanomaly-0.3.4}/src/jacscanomaly/finder.py +293 -12
- {jacscanomaly-0.3.2 → jacscanomaly-0.3.4}/src/jacscanomaly/magnification.py +0 -1
- jacscanomaly-0.3.4/src/jacscanomaly/planet_class/__init__.py +64 -0
- jacscanomaly-0.3.4/src/jacscanomaly/planet_class/atoms/__init__.py +41 -0
- jacscanomaly-0.3.4/src/jacscanomaly/planet_class/atoms/base.py +379 -0
- jacscanomaly-0.3.4/src/jacscanomaly/planet_class/atoms/bump.py +181 -0
- jacscanomaly-0.3.4/src/jacscanomaly/planet_class/atoms/central.py +140 -0
- jacscanomaly-0.3.4/src/jacscanomaly/planet_class/atoms/chang_refsdal.py +269 -0
- jacscanomaly-0.3.4/src/jacscanomaly/planet_class/atoms/cusp.py +165 -0
- jacscanomaly-0.3.4/src/jacscanomaly/planet_class/atoms/fold.py +713 -0
- jacscanomaly-0.3.4/src/jacscanomaly/planet_class/atoms/second_pspl.py +51 -0
- jacscanomaly-0.3.4/src/jacscanomaly/planet_class/atoms/smooth.py +194 -0
- jacscanomaly-0.3.4/src/jacscanomaly/planet_class/classifier.py +403 -0
- jacscanomaly-0.3.4/src/jacscanomaly/planet_class/features.py +72 -0
- jacscanomaly-0.3.4/src/jacscanomaly/planet_class/fold_kernel.py +246 -0
- jacscanomaly-0.3.4/src/jacscanomaly/planet_class/linear.py +45 -0
- jacscanomaly-0.3.4/src/jacscanomaly/planet_class/pspl.py +65 -0
- jacscanomaly-0.3.4/src/jacscanomaly/planet_class/seeds.py +331 -0
- jacscanomaly-0.3.4/src/jacscanomaly/planet_class/types.py +396 -0
- jacscanomaly-0.3.4/src/jacscanomaly/planet_signal.py +2244 -0
- {jacscanomaly-0.3.2 → jacscanomaly-0.3.4}/src/jacscanomaly/plot.py +48 -2
- {jacscanomaly-0.3.2 → jacscanomaly-0.3.4}/src/jacscanomaly/singlelens_fit.py +203 -3
- jacscanomaly-0.3.4/src/jacscanomaly/template_free.py +414 -0
- {jacscanomaly-0.3.2 → jacscanomaly-0.3.4/src/jacscanomaly.egg-info}/PKG-INFO +4 -1
- {jacscanomaly-0.3.2 → jacscanomaly-0.3.4}/src/jacscanomaly.egg-info/SOURCES.txt +23 -0
- jacscanomaly-0.3.4/tests/test_cpp_extension.py +8 -0
- jacscanomaly-0.3.4/tests/test_magnitude_input.py +75 -0
- jacscanomaly-0.3.4/tests/test_planet_class.py +850 -0
- jacscanomaly-0.3.4/tests/test_planet_signal.py +378 -0
- jacscanomaly-0.3.4/tests/test_refit.py +41 -0
- {jacscanomaly-0.3.2 → jacscanomaly-0.3.4}/tests/test_space_parallax.py +41 -0
- jacscanomaly-0.3.4/tests/test_template_free.py +82 -0
- jacscanomaly-0.3.2/MANIFEST.in +0 -1
- jacscanomaly-0.3.2/setup.py +0 -25
- jacscanomaly-0.3.2/src/jacscanomaly/template_free.py +0 -407
- jacscanomaly-0.3.2/tests/test_template_free.py +0 -30
- {jacscanomaly-0.3.2 → jacscanomaly-0.3.4}/LICENSE +0 -0
- {jacscanomaly-0.3.2 → jacscanomaly-0.3.4}/setup.cfg +0 -0
- {jacscanomaly-0.3.2 → jacscanomaly-0.3.4}/src/jacscanomaly/_cpp_grid.cpp +0 -0
- {jacscanomaly-0.3.2 → jacscanomaly-0.3.4}/src/jacscanomaly/anomaly_models.py +0 -0
- {jacscanomaly-0.3.2 → jacscanomaly-0.3.4}/src/jacscanomaly/criteria.py +0 -0
- {jacscanomaly-0.3.2 → jacscanomaly-0.3.4}/src/jacscanomaly/data/__init__.py +0 -0
- {jacscanomaly-0.3.2 → jacscanomaly-0.3.4}/src/jacscanomaly/data/earth_orbital_parallax_table.txt +0 -0
- {jacscanomaly-0.3.2 → jacscanomaly-0.3.4}/src/jacscanomaly/extract.py +0 -0
- {jacscanomaly-0.3.2 → jacscanomaly-0.3.4}/src/jacscanomaly/models.py +0 -0
- {jacscanomaly-0.3.2 → jacscanomaly-0.3.4}/src/jacscanomaly/objective.py +0 -0
- {jacscanomaly-0.3.2 → jacscanomaly-0.3.4}/src/jacscanomaly/parallax.py +0 -0
- {jacscanomaly-0.3.2 → jacscanomaly-0.3.4}/src/jacscanomaly/photometry.py +0 -0
- {jacscanomaly-0.3.2 → jacscanomaly-0.3.4}/src/jacscanomaly/runner.py +0 -0
- {jacscanomaly-0.3.2 → jacscanomaly-0.3.4}/src/jacscanomaly/seasons.py +0 -0
- {jacscanomaly-0.3.2 → jacscanomaly-0.3.4}/src/jacscanomaly/singlelens_model.py +0 -0
- {jacscanomaly-0.3.2 → jacscanomaly-0.3.4}/src/jacscanomaly/trajectory.py +0 -0
- {jacscanomaly-0.3.2 → jacscanomaly-0.3.4}/src/jacscanomaly.egg-info/dependency_links.txt +0 -0
- {jacscanomaly-0.3.2 → jacscanomaly-0.3.4}/src/jacscanomaly.egg-info/requires.txt +0 -0
- {jacscanomaly-0.3.2 → jacscanomaly-0.3.4}/src/jacscanomaly.egg-info/top_level.txt +0 -0
- {jacscanomaly-0.3.2 → jacscanomaly-0.3.4}/tests/test_config.py +0 -0
- {jacscanomaly-0.3.2 → jacscanomaly-0.3.4}/tests/test_criteria.py +0 -0
- {jacscanomaly-0.3.2 → jacscanomaly-0.3.4}/tests/test_extract.py +0 -0
- {jacscanomaly-0.3.2 → jacscanomaly-0.3.4}/tests/test_models.py +0 -0
- {jacscanomaly-0.3.2 → jacscanomaly-0.3.4}/tests/test_photometry.py +0 -0
- {jacscanomaly-0.3.2 → jacscanomaly-0.3.4}/tests/test_seasons.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: jacscanomaly
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.4
|
|
4
4
|
Summary: JAX-based scan anomaly detection for time-series residuals
|
|
5
5
|
Author: Kansuke Nunota
|
|
6
6
|
License: MIT
|
|
@@ -96,6 +96,9 @@ config = FinderConfig(
|
|
|
96
96
|
finder = Finder(config)
|
|
97
97
|
result = finder.run(time, flux, ferr)
|
|
98
98
|
|
|
99
|
+
# For magnitude data, pass mag and magerr in the same positions and select it:
|
|
100
|
+
# result = finder.run(time, mag, magerr, data_kind="mag")
|
|
101
|
+
|
|
99
102
|
# You can still pass an explicit initial guess if desired:
|
|
100
103
|
# p0 = np.array([10000, 10, 0.3])
|
|
101
104
|
# result = finder.run(time, flux, ferr, p0)
|
|
@@ -66,6 +66,9 @@ config = FinderConfig(
|
|
|
66
66
|
finder = Finder(config)
|
|
67
67
|
result = finder.run(time, flux, ferr)
|
|
68
68
|
|
|
69
|
+
# For magnitude data, pass mag and magerr in the same positions and select it:
|
|
70
|
+
# result = finder.run(time, mag, magerr, data_kind="mag")
|
|
71
|
+
|
|
69
72
|
# You can still pass an explicit initial guess if desired:
|
|
70
73
|
# p0 = np.array([10000, 10, 0.3])
|
|
71
74
|
# result = finder.run(time, flux, ferr, p0)
|
|
@@ -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
|
+
)
|
|
@@ -20,6 +20,7 @@ from .singlelens_fit import (
|
|
|
20
20
|
PSPLSpaceParallaxFitter,
|
|
21
21
|
FSPLSpaceParallaxFitter,
|
|
22
22
|
VBMFiniteDiffGullsFSPLSpaceParallaxFitter,
|
|
23
|
+
BICSingleLensFitter,
|
|
23
24
|
CVFitter,
|
|
24
25
|
)
|
|
25
26
|
from .template_free import (
|
|
@@ -28,6 +29,29 @@ from .template_free import (
|
|
|
28
29
|
TemplateFreeSearchConfig,
|
|
29
30
|
TemplateFreeSearchResult,
|
|
30
31
|
)
|
|
32
|
+
from .planet_signal import (
|
|
33
|
+
FlatBaselineDiagnostic,
|
|
34
|
+
PlanetSignalClassification,
|
|
35
|
+
PlanetSignalClassificationConfig,
|
|
36
|
+
PlanetSignalClassifier,
|
|
37
|
+
PlanetSignalComponentClassification,
|
|
38
|
+
PlanetSignalCandidate,
|
|
39
|
+
PlanetSignalConfig,
|
|
40
|
+
PlanetSignalExtractor,
|
|
41
|
+
PlanetSignalIteration,
|
|
42
|
+
PlanetSignalPeak,
|
|
43
|
+
PlanetSignalResult,
|
|
44
|
+
)
|
|
45
|
+
from .planet_class import (
|
|
46
|
+
AtomFitResult,
|
|
47
|
+
PlanetAnomalyClassifier,
|
|
48
|
+
PlanetAnomalyFitResult,
|
|
49
|
+
PlanetClassConfig,
|
|
50
|
+
PSPLParams,
|
|
51
|
+
SeedCandidate,
|
|
52
|
+
SegmentData,
|
|
53
|
+
SegmentModelResult,
|
|
54
|
+
)
|
|
31
55
|
|
|
32
56
|
__all__ = [
|
|
33
57
|
"FinderConfig",
|
|
@@ -47,12 +71,32 @@ __all__ = [
|
|
|
47
71
|
"PSPLSpaceParallaxFitter",
|
|
48
72
|
"FSPLSpaceParallaxFitter",
|
|
49
73
|
"VBMFiniteDiffGullsFSPLSpaceParallaxFitter",
|
|
74
|
+
"BICSingleLensFitter",
|
|
50
75
|
"CVFitter",
|
|
51
76
|
"SingleLensFitResult",
|
|
52
77
|
"TemplateFreeCandidate",
|
|
53
78
|
"TemplateFreeScanner",
|
|
54
79
|
"TemplateFreeSearchConfig",
|
|
55
80
|
"TemplateFreeSearchResult",
|
|
81
|
+
"FlatBaselineDiagnostic",
|
|
82
|
+
"PlanetSignalClassification",
|
|
83
|
+
"PlanetSignalClassificationConfig",
|
|
84
|
+
"PlanetSignalClassifier",
|
|
85
|
+
"PlanetSignalComponentClassification",
|
|
86
|
+
"PlanetSignalCandidate",
|
|
87
|
+
"PlanetSignalConfig",
|
|
88
|
+
"PlanetSignalExtractor",
|
|
89
|
+
"PlanetSignalIteration",
|
|
90
|
+
"PlanetSignalPeak",
|
|
91
|
+
"PlanetSignalResult",
|
|
92
|
+
"AtomFitResult",
|
|
93
|
+
"PlanetAnomalyClassifier",
|
|
94
|
+
"PlanetAnomalyFitResult",
|
|
95
|
+
"PlanetClassConfig",
|
|
96
|
+
"PSPLParams",
|
|
97
|
+
"SeedCandidate",
|
|
98
|
+
"SegmentData",
|
|
99
|
+
"SegmentModelResult",
|
|
56
100
|
]
|
|
57
101
|
|
|
58
102
|
__version__ = "0.3.2"
|
|
@@ -17,9 +17,6 @@ class _DisplayFloat(float):
|
|
|
17
17
|
def __repr__(self) -> str:
|
|
18
18
|
return self._repr_text
|
|
19
19
|
|
|
20
|
-
def __reduce__(self):
|
|
21
|
-
return (self.__class__, (float(self), self._repr_text))
|
|
22
|
-
|
|
23
20
|
|
|
24
21
|
_COMMON_RATIO_DEFAULT = _DisplayFloat(4.0 / 3.0, "4.0 / 3.0")
|
|
25
22
|
|
|
@@ -65,6 +62,7 @@ class FinderConfig:
|
|
|
65
62
|
"pspl_space_parallax",
|
|
66
63
|
"fspl_space_parallax",
|
|
67
64
|
"fspl_space_parallax_gulls_vbm_fd",
|
|
65
|
+
"bic_single_lens",
|
|
68
66
|
] = "pspl"
|
|
69
67
|
"""
|
|
70
68
|
Choice of single-lens model used for the initial fit.
|
|
@@ -89,6 +87,9 @@ class FinderConfig:
|
|
|
89
87
|
- ``"fspl_space_parallax_gulls_vbm_fd"`` :
|
|
90
88
|
GULLS-convention FSPL space-parallax fitter using VBMicrolensing ESPL
|
|
91
89
|
magnification and finite-difference SciPy least squares.
|
|
90
|
+
- ``"bic_single_lens"`` :
|
|
91
|
+
Select the lowest-BIC fit among PSPL and finite-difference FSPL, with
|
|
92
|
+
an optional GULLS FSPL space-parallax trial.
|
|
92
93
|
"""
|
|
93
94
|
|
|
94
95
|
ra_deg: Optional[float] = None
|
|
@@ -109,8 +110,9 @@ class FinderConfig:
|
|
|
109
110
|
Path to the spacecraft/observer ephemeris table used by space-parallax
|
|
110
111
|
models.
|
|
111
112
|
|
|
112
|
-
Required for ``"pspl_space_parallax"``, ``"fspl_space_parallax"``,
|
|
113
|
-
``"fspl_space_parallax_gulls_vbm_fd"
|
|
113
|
+
Required for ``"pspl_space_parallax"``, ``"fspl_space_parallax"``,
|
|
114
|
+
``"fspl_space_parallax_gulls_vbm_fd"``, and ``"bic_single_lens"`` when
|
|
115
|
+
``bic_include_space_parallax`` is enabled. Expected columns are
|
|
114
116
|
``JD RA_deg Dec_deg distance_AU``. The interpretation of the position is
|
|
115
117
|
controlled by ``space_parallax_convention``.
|
|
116
118
|
"""
|
|
@@ -135,6 +137,18 @@ class FinderConfig:
|
|
|
135
137
|
VBMicrolensing's ``t_in_HJD=0`` convention.
|
|
136
138
|
"""
|
|
137
139
|
|
|
140
|
+
max_piE: float = 1.0
|
|
141
|
+
"""Symmetric bound applied to fitted ``piEN`` and ``piEE`` when supported."""
|
|
142
|
+
|
|
143
|
+
piE_prior_weight: float = 0.0
|
|
144
|
+
"""Weight for the optional linear ``|piE|`` penalty in finite-difference fits."""
|
|
145
|
+
|
|
146
|
+
piE_prior_eps: float = 1.0e-3
|
|
147
|
+
"""Small numerical floor used by the finite-difference ``|piE|`` penalty."""
|
|
148
|
+
|
|
149
|
+
bic_include_space_parallax: bool = False
|
|
150
|
+
"""If True, ``bic_single_lens`` also tries the GULLS FSPL space-parallax model."""
|
|
151
|
+
|
|
138
152
|
# ==================================================
|
|
139
153
|
# 0b) Automatic single-lens initialization
|
|
140
154
|
# ==================================================
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
3
|
from dataclasses import dataclass, field, replace
|
|
4
|
-
from typing import Optional
|
|
4
|
+
from typing import Literal, Optional
|
|
5
5
|
import logging
|
|
6
6
|
|
|
7
7
|
import numpy as np
|
|
@@ -21,6 +21,16 @@ from .singlelens_fit import (
|
|
|
21
21
|
PSPLSpaceParallaxFitter,
|
|
22
22
|
FSPLSpaceParallaxFitter,
|
|
23
23
|
VBMFiniteDiffGullsFSPLSpaceParallaxFitter,
|
|
24
|
+
BICSingleLensFitter,
|
|
25
|
+
evaluate_single_lens_fixed,
|
|
26
|
+
)
|
|
27
|
+
from .singlelens_model import (
|
|
28
|
+
A_pspl_func,
|
|
29
|
+
A_fspl_logrho_func,
|
|
30
|
+
A_pspl_parallax_func,
|
|
31
|
+
A_fspl_parallax_logrho_func,
|
|
32
|
+
A_pspl_space_parallax_func,
|
|
33
|
+
A_fspl_space_parallax_logrho_func,
|
|
24
34
|
)
|
|
25
35
|
from .plot import AnomalyPlotter
|
|
26
36
|
from .seasons import SeasonSplitter
|
|
@@ -134,6 +144,7 @@ class Finder:
|
|
|
134
144
|
"pspl_space_parallax",
|
|
135
145
|
"fspl_space_parallax",
|
|
136
146
|
"fspl_space_parallax_gulls_vbm_fd",
|
|
147
|
+
"bic_single_lens",
|
|
137
148
|
}
|
|
138
149
|
if k not in valid:
|
|
139
150
|
raise ValueError(
|
|
@@ -150,7 +161,7 @@ class Finder:
|
|
|
150
161
|
"pspl_space_parallax",
|
|
151
162
|
"fspl_space_parallax",
|
|
152
163
|
"fspl_space_parallax_gulls_vbm_fd",
|
|
153
|
-
}
|
|
164
|
+
} or (k == "bic_single_lens" and self.config.bic_include_space_parallax)
|
|
154
165
|
if needs_sky:
|
|
155
166
|
if self.config.ra_deg is None or self.config.dec_deg is None:
|
|
156
167
|
raise ValueError(
|
|
@@ -161,7 +172,7 @@ class Finder:
|
|
|
161
172
|
"pspl_space_parallax",
|
|
162
173
|
"fspl_space_parallax",
|
|
163
174
|
"fspl_space_parallax_gulls_vbm_fd",
|
|
164
|
-
}
|
|
175
|
+
} or (k == "bic_single_lens" and self.config.bic_include_space_parallax)
|
|
165
176
|
if needs_satellite and self.config.satellite_ephemeris_path is None:
|
|
166
177
|
raise ValueError(
|
|
167
178
|
f"{k} requires satellite_ephemeris_path in FinderConfig."
|
|
@@ -231,6 +242,22 @@ class Finder:
|
|
|
231
242
|
Dec=self.config.dec_deg,
|
|
232
243
|
tref=tref,
|
|
233
244
|
satellite_ephemeris_path=self.config.satellite_ephemeris_path,
|
|
245
|
+
max_piE=float(self.config.max_piE),
|
|
246
|
+
piE_prior_weight=float(self.config.piE_prior_weight),
|
|
247
|
+
piE_prior_eps=float(self.config.piE_prior_eps),
|
|
248
|
+
)
|
|
249
|
+
return
|
|
250
|
+
|
|
251
|
+
if k == "bic_single_lens":
|
|
252
|
+
self.fitter = BICSingleLensFitter(
|
|
253
|
+
RA=self.config.ra_deg,
|
|
254
|
+
Dec=self.config.dec_deg,
|
|
255
|
+
tref=tref,
|
|
256
|
+
satellite_ephemeris_path=self.config.satellite_ephemeris_path,
|
|
257
|
+
max_piE=float(self.config.max_piE),
|
|
258
|
+
piE_prior_weight=float(self.config.piE_prior_weight),
|
|
259
|
+
piE_prior_eps=float(self.config.piE_prior_eps),
|
|
260
|
+
include_space_parallax=bool(self.config.bic_include_space_parallax),
|
|
234
261
|
)
|
|
235
262
|
return
|
|
236
263
|
|
|
@@ -252,6 +279,8 @@ class Finder:
|
|
|
252
279
|
flux,
|
|
253
280
|
ferr,
|
|
254
281
|
x0=None,
|
|
282
|
+
*,
|
|
283
|
+
data_kind: Literal["flux", "mag"] = "flux",
|
|
255
284
|
) -> SingleLensFitResult:
|
|
256
285
|
"""
|
|
257
286
|
Run only the single-lens fit selected by the current configuration.
|
|
@@ -259,17 +288,24 @@ class Finder:
|
|
|
259
288
|
Parameters
|
|
260
289
|
----------
|
|
261
290
|
time, flux, ferr : array-like
|
|
262
|
-
One-dimensional light-curve arrays.
|
|
291
|
+
One-dimensional light-curve arrays. With ``data_kind="mag"``,
|
|
292
|
+
``flux`` and ``ferr`` are interpreted as magnitude and magnitude
|
|
293
|
+
error, respectively, and are converted to relative flux internally.
|
|
263
294
|
x0 : array-like, optional
|
|
264
295
|
Initial guess for the nonlinear model parameters.
|
|
265
296
|
If omitted, initial values are estimated from a scan of the light curve.
|
|
297
|
+
data_kind : {"flux", "mag"}, optional
|
|
298
|
+
Input photometry representation. The default ``"flux"`` preserves
|
|
299
|
+
the existing API. Magnitude inputs are converted to relative flux.
|
|
266
300
|
|
|
267
301
|
Returns
|
|
268
302
|
-------
|
|
269
303
|
SingleLensFitResult
|
|
270
304
|
Result of the single-lens fit.
|
|
271
305
|
"""
|
|
272
|
-
time_j, flux_j, ferr_j, x0_j, time_np, _, _ = self._to_arrays(
|
|
306
|
+
time_j, flux_j, ferr_j, x0_j, time_np, _, _ = self._to_arrays(
|
|
307
|
+
time, flux, ferr, x0, data_kind=data_kind
|
|
308
|
+
)
|
|
273
309
|
self._ensure_fitter(float(np.median(time_np)))
|
|
274
310
|
if x0_j is None:
|
|
275
311
|
return self._fit_from_auto_initial_guesses(time_j, flux_j, ferr_j, time_np)
|
|
@@ -282,6 +318,8 @@ class Finder:
|
|
|
282
318
|
ferr,
|
|
283
319
|
x0=None,
|
|
284
320
|
*,
|
|
321
|
+
data_kind: Literal["flux", "mag"] = "flux",
|
|
322
|
+
refit: bool = True,
|
|
285
323
|
verbose: bool = True,
|
|
286
324
|
log: Optional[logging.Logger] = None,
|
|
287
325
|
) -> AnomalyResult:
|
|
@@ -291,28 +329,53 @@ class Finder:
|
|
|
291
329
|
Parameters
|
|
292
330
|
----------
|
|
293
331
|
time, flux, ferr : array-like
|
|
294
|
-
One-dimensional light-curve arrays.
|
|
332
|
+
One-dimensional light-curve arrays. With ``data_kind="mag"``,
|
|
333
|
+
pass ``mag`` and ``magerr`` in these positions; they are converted
|
|
334
|
+
to relative flux and flux error before fitting and scanning.
|
|
295
335
|
x0 : array-like, optional
|
|
296
336
|
Initial guess for the single-lens model parameters. If omitted, the
|
|
297
337
|
finder estimates multiple initial values and uses the best fit.
|
|
338
|
+
data_kind : {"flux", "mag"}, optional
|
|
339
|
+
Input photometry representation. ``"mag"`` converts magnitudes to
|
|
340
|
+
a numerically stable relative-flux scale internally.
|
|
341
|
+
refit : bool, optional
|
|
342
|
+
If True, optimize the single-lens nonlinear parameters starting from
|
|
343
|
+
``x0``. If False, require ``x0`` and use it as fixed nonlinear
|
|
344
|
+
parameters; only the linear flux parameters are solved.
|
|
298
345
|
verbose : bool, optional
|
|
299
346
|
If True, print progress messages.
|
|
300
347
|
log : logging.Logger, optional
|
|
301
|
-
Logger used for
|
|
348
|
+
Logger used for progress reporting. When omitted, module-level
|
|
349
|
+
logging is used. ``verbose=False`` suppresses progress messages.
|
|
302
350
|
|
|
303
351
|
Returns
|
|
304
352
|
-------
|
|
305
353
|
AnomalyResult
|
|
306
354
|
Object containing the single-lens fit, residuals,
|
|
307
355
|
per-season cluster summaries, and the best anomaly candidate.
|
|
356
|
+
|
|
357
|
+
Raises
|
|
358
|
+
------
|
|
359
|
+
ValueError
|
|
360
|
+
If the input arrays are not finite one-dimensional arrays of equal
|
|
361
|
+
length, ``ferr`` is non-positive, or ``refit=False`` is used
|
|
362
|
+
without ``x0``.
|
|
363
|
+
|
|
364
|
+
Notes
|
|
365
|
+
-----
|
|
366
|
+
``refit=False`` fixes only nonlinear model parameters. The linear
|
|
367
|
+
source and blend fluxes are still solved for the supplied data before
|
|
368
|
+
residuals are scanned. See :doc:`workflows` for when to use this mode.
|
|
308
369
|
"""
|
|
309
370
|
time_j, flux_j, ferr_j, x0_j, time_np, flux_np, ferr_np = self._to_arrays(
|
|
310
|
-
time, flux, ferr, x0
|
|
371
|
+
time, flux, ferr, x0, data_kind=data_kind
|
|
311
372
|
)
|
|
312
373
|
|
|
313
374
|
self._ensure_fitter(float(np.median(time_np)))
|
|
314
375
|
|
|
315
|
-
if
|
|
376
|
+
if not refit:
|
|
377
|
+
fit = self._fixed_single_lens_from_x0(time_j, flux_j, ferr_j, x0_j)
|
|
378
|
+
elif x0_j is None:
|
|
316
379
|
if verbose:
|
|
317
380
|
(logger if log is None else log).info("Estimating single-lens initial values.")
|
|
318
381
|
fit = self._fit_from_auto_initial_guesses(time_j, flux_j, ferr_j, time_np)
|
|
@@ -363,6 +426,7 @@ class Finder:
|
|
|
363
426
|
ferr,
|
|
364
427
|
x0=None,
|
|
365
428
|
*,
|
|
429
|
+
data_kind: Literal["flux", "mag"] = "flux",
|
|
366
430
|
fit: Optional[SingleLensFitResult] = None,
|
|
367
431
|
config: Optional[TemplateFreeSearchConfig] = None,
|
|
368
432
|
) -> TemplateFreeSearchResult:
|
|
@@ -370,9 +434,37 @@ class Finder:
|
|
|
370
434
|
Run a template-free anomaly search on single-lens residuals.
|
|
371
435
|
|
|
372
436
|
This leaves the existing bell-template anomaly pipeline untouched.
|
|
437
|
+
|
|
438
|
+
Parameters
|
|
439
|
+
----------
|
|
440
|
+
time, flux, ferr : array-like
|
|
441
|
+
One-dimensional light-curve arrays. With ``data_kind="mag"``,
|
|
442
|
+
``flux`` and ``ferr`` are interpreted as magnitude and magnitude
|
|
443
|
+
error. Flux errors are used to normalize residuals even when
|
|
444
|
+
``fit`` is supplied.
|
|
445
|
+
x0 : array-like, optional
|
|
446
|
+
Nonlinear initial values used only when ``fit`` is omitted.
|
|
447
|
+
data_kind : {"flux", "mag"}, optional
|
|
448
|
+
Input photometry representation.
|
|
449
|
+
fit : SingleLensFitResult, optional
|
|
450
|
+
Existing baseline fit whose residuals should be searched. Passing
|
|
451
|
+
this skips all single-lens fitting.
|
|
452
|
+
config : TemplateFreeSearchConfig, optional
|
|
453
|
+
Template-free search settings. If omitted, the finder season gap is
|
|
454
|
+
reused and all other settings use their defaults.
|
|
455
|
+
|
|
456
|
+
Returns
|
|
457
|
+
-------
|
|
458
|
+
TemplateFreeSearchResult
|
|
459
|
+
Residual z-scores and ranked zero-crossing candidates.
|
|
460
|
+
|
|
461
|
+
Notes
|
|
462
|
+
-----
|
|
463
|
+
To scan residuals without constructing a ``Finder`` or a
|
|
464
|
+
``SingleLensFitResult``, call :class:`TemplateFreeScanner` directly.
|
|
373
465
|
"""
|
|
374
466
|
time_j, flux_j, ferr_j, x0_j, time_np, _, ferr_np = self._to_arrays(
|
|
375
|
-
time, flux, ferr, x0
|
|
467
|
+
time, flux, ferr, x0, data_kind=data_kind
|
|
376
468
|
)
|
|
377
469
|
|
|
378
470
|
if fit is None:
|
|
@@ -391,14 +483,21 @@ class Finder:
|
|
|
391
483
|
# ------------------------------------------------------------------
|
|
392
484
|
# Internal helpers
|
|
393
485
|
# ------------------------------------------------------------------
|
|
394
|
-
def _to_arrays(self, time, flux, ferr, x0):
|
|
486
|
+
def _to_arrays(self, time, flux, ferr, x0, *, data_kind: Literal["flux", "mag"] = "flux"):
|
|
395
487
|
"""
|
|
396
|
-
Validate inputs and convert them to
|
|
488
|
+
Validate inputs and convert them to flux-space NumPy and JAX arrays.
|
|
489
|
+
|
|
490
|
+
``data_kind="mag"`` treats ``flux`` and ``ferr`` as magnitude and
|
|
491
|
+
magnitude error. The conversion uses a median magnitude zero point so
|
|
492
|
+
that the relative flux is of order unity, avoiding numerical underflow
|
|
493
|
+
for the large magnitude zero points commonly used in catalogs.
|
|
397
494
|
"""
|
|
398
495
|
time_np = np.asarray(time, dtype=float)
|
|
399
496
|
flux_np = np.asarray(flux, dtype=float)
|
|
400
497
|
ferr_np = np.asarray(ferr, dtype=float)
|
|
401
498
|
|
|
499
|
+
if data_kind not in {"flux", "mag"}:
|
|
500
|
+
raise ValueError("data_kind must be either 'flux' or 'mag'.")
|
|
402
501
|
if time_np.ndim != 1 or flux_np.ndim != 1 or ferr_np.ndim != 1:
|
|
403
502
|
raise ValueError("time/flux/ferr must be 1D arrays.")
|
|
404
503
|
if not (len(time_np) == len(flux_np) == len(ferr_np)):
|
|
@@ -408,6 +507,17 @@ class Finder:
|
|
|
408
507
|
if np.any(ferr_np <= 0):
|
|
409
508
|
raise ValueError("ferr must be positive.")
|
|
410
509
|
|
|
510
|
+
if data_kind == "mag":
|
|
511
|
+
mag0 = float(np.median(flux_np))
|
|
512
|
+
exponent = -0.4 * np.log(10.0) * (flux_np - mag0)
|
|
513
|
+
float_info = np.finfo(np.float32)
|
|
514
|
+
exponent = np.clip(exponent, np.log(float_info.tiny), np.log(float_info.max))
|
|
515
|
+
flux_np = np.exp(exponent)
|
|
516
|
+
ferr_np = np.maximum(
|
|
517
|
+
(np.log(10.0) / 2.5) * flux_np * ferr_np,
|
|
518
|
+
float_info.tiny,
|
|
519
|
+
)
|
|
520
|
+
|
|
411
521
|
time_j = jnp.asarray(time_np)
|
|
412
522
|
flux_j = jnp.asarray(flux_np)
|
|
413
523
|
ferr_j = jnp.asarray(ferr_np)
|
|
@@ -453,6 +563,177 @@ class Finder:
|
|
|
453
563
|
|
|
454
564
|
return best_fit
|
|
455
565
|
|
|
566
|
+
def _fixed_single_lens_from_x0(
|
|
567
|
+
self,
|
|
568
|
+
time_j: jnp.ndarray,
|
|
569
|
+
flux_j: jnp.ndarray,
|
|
570
|
+
ferr_j: jnp.ndarray,
|
|
571
|
+
x0_j: Optional[jnp.ndarray],
|
|
572
|
+
) -> SingleLensFitResult:
|
|
573
|
+
if x0_j is None:
|
|
574
|
+
raise ValueError("Finder.run(refit=False) requires x0.")
|
|
575
|
+
|
|
576
|
+
k = self.config.fitter_kind
|
|
577
|
+
P = getattr(self.fitter, "_P", None)
|
|
578
|
+
|
|
579
|
+
if k == "pspl":
|
|
580
|
+
return evaluate_single_lens_fixed(
|
|
581
|
+
time=time_j,
|
|
582
|
+
flux=flux_j,
|
|
583
|
+
ferr=ferr_j,
|
|
584
|
+
x0=x0_j,
|
|
585
|
+
build_A=A_pspl_func,
|
|
586
|
+
dof=3,
|
|
587
|
+
param_names=("t0", "tE", "u0"),
|
|
588
|
+
min_points=4,
|
|
589
|
+
)
|
|
590
|
+
|
|
591
|
+
if k == "fspl":
|
|
592
|
+
def q_to_params(q):
|
|
593
|
+
t0, tE, u0, logrho = q
|
|
594
|
+
return jnp.array([t0, tE, u0, jnp.exp(logrho)])
|
|
595
|
+
|
|
596
|
+
return evaluate_single_lens_fixed(
|
|
597
|
+
time=time_j,
|
|
598
|
+
flux=flux_j,
|
|
599
|
+
ferr=ferr_j,
|
|
600
|
+
x0=x0_j,
|
|
601
|
+
build_A=A_fspl_logrho_func,
|
|
602
|
+
dof=4,
|
|
603
|
+
param_names=("t0", "tE", "u0", "rho"),
|
|
604
|
+
x_to_params=q_to_params,
|
|
605
|
+
min_points=4,
|
|
606
|
+
store_raw_params=True,
|
|
607
|
+
)
|
|
608
|
+
|
|
609
|
+
if k == "fspl_vbm_fd":
|
|
610
|
+
return self._fixed_single_lens_from_numpy_model(
|
|
611
|
+
time_j=time_j,
|
|
612
|
+
flux_j=flux_j,
|
|
613
|
+
ferr_j=ferr_j,
|
|
614
|
+
x0_j=x0_j,
|
|
615
|
+
dof=4,
|
|
616
|
+
param_names=("t0", "tE", "u0", "rho"),
|
|
617
|
+
parallax_projector=None,
|
|
618
|
+
)
|
|
619
|
+
|
|
620
|
+
if k == "pspl_parallax":
|
|
621
|
+
return evaluate_single_lens_fixed(
|
|
622
|
+
time=time_j,
|
|
623
|
+
flux=flux_j,
|
|
624
|
+
ferr=ferr_j,
|
|
625
|
+
x0=x0_j,
|
|
626
|
+
build_A=lambda p, t: A_pspl_parallax_func(p, t, P),
|
|
627
|
+
dof=5,
|
|
628
|
+
param_names=("t0", "tE", "u0", "piEN", "piEE"),
|
|
629
|
+
min_points=6,
|
|
630
|
+
parallax_projector=P,
|
|
631
|
+
)
|
|
632
|
+
|
|
633
|
+
if k == "fspl_parallax":
|
|
634
|
+
def q_to_params(q):
|
|
635
|
+
t0, tE, u0, logrho, piEN, piEE = q
|
|
636
|
+
return jnp.array([t0, tE, u0, jnp.exp(logrho), piEN, piEE])
|
|
637
|
+
|
|
638
|
+
return evaluate_single_lens_fixed(
|
|
639
|
+
time=time_j,
|
|
640
|
+
flux=flux_j,
|
|
641
|
+
ferr=ferr_j,
|
|
642
|
+
x0=x0_j,
|
|
643
|
+
build_A=lambda q, t: A_fspl_parallax_logrho_func(q, t, P),
|
|
644
|
+
dof=6,
|
|
645
|
+
param_names=("t0", "tE", "u0", "rho", "piEN", "piEE"),
|
|
646
|
+
x_to_params=q_to_params,
|
|
647
|
+
min_points=7,
|
|
648
|
+
store_raw_params=True,
|
|
649
|
+
parallax_projector=P,
|
|
650
|
+
)
|
|
651
|
+
|
|
652
|
+
if k == "pspl_space_parallax":
|
|
653
|
+
return evaluate_single_lens_fixed(
|
|
654
|
+
time=time_j,
|
|
655
|
+
flux=flux_j,
|
|
656
|
+
ferr=ferr_j,
|
|
657
|
+
x0=x0_j,
|
|
658
|
+
build_A=lambda p, t: A_pspl_space_parallax_func(p, t, P),
|
|
659
|
+
dof=5,
|
|
660
|
+
param_names=("t0", "tE", "u0", "piEN", "piEE"),
|
|
661
|
+
min_points=6,
|
|
662
|
+
parallax_projector=P,
|
|
663
|
+
)
|
|
664
|
+
|
|
665
|
+
if k == "fspl_space_parallax":
|
|
666
|
+
def q_to_params(q):
|
|
667
|
+
t0, tE, u0, logrho, piEN, piEE = q
|
|
668
|
+
return jnp.array([t0, tE, u0, jnp.exp(logrho), piEN, piEE])
|
|
669
|
+
|
|
670
|
+
return evaluate_single_lens_fixed(
|
|
671
|
+
time=time_j,
|
|
672
|
+
flux=flux_j,
|
|
673
|
+
ferr=ferr_j,
|
|
674
|
+
x0=x0_j,
|
|
675
|
+
build_A=lambda q, t: A_fspl_space_parallax_logrho_func(q, t, P),
|
|
676
|
+
dof=6,
|
|
677
|
+
param_names=("t0", "tE", "u0", "rho", "piEN", "piEE"),
|
|
678
|
+
x_to_params=q_to_params,
|
|
679
|
+
min_points=7,
|
|
680
|
+
store_raw_params=True,
|
|
681
|
+
parallax_projector=P,
|
|
682
|
+
)
|
|
683
|
+
|
|
684
|
+
if k == "fspl_space_parallax_gulls_vbm_fd":
|
|
685
|
+
return self._fixed_single_lens_from_numpy_model(
|
|
686
|
+
time_j=time_j,
|
|
687
|
+
flux_j=flux_j,
|
|
688
|
+
ferr_j=ferr_j,
|
|
689
|
+
x0_j=x0_j,
|
|
690
|
+
dof=6,
|
|
691
|
+
param_names=("t0", "tE", "u0", "rho", "piEN", "piEE"),
|
|
692
|
+
parallax_projector=P,
|
|
693
|
+
)
|
|
694
|
+
|
|
695
|
+
raise ValueError(f"Unknown fitter_kind '{k}'.")
|
|
696
|
+
|
|
697
|
+
def _fixed_single_lens_from_numpy_model(
|
|
698
|
+
self,
|
|
699
|
+
*,
|
|
700
|
+
time_j: jnp.ndarray,
|
|
701
|
+
flux_j: jnp.ndarray,
|
|
702
|
+
ferr_j: jnp.ndarray,
|
|
703
|
+
x0_j: jnp.ndarray,
|
|
704
|
+
dof: int,
|
|
705
|
+
param_names: tuple[str, ...],
|
|
706
|
+
parallax_projector,
|
|
707
|
+
) -> SingleLensFitResult:
|
|
708
|
+
if not hasattr(self.fitter, "_model_and_residual"):
|
|
709
|
+
raise TypeError(
|
|
710
|
+
f"{type(self.fitter).__name__} does not support fixed-parameter evaluation."
|
|
711
|
+
)
|
|
712
|
+
|
|
713
|
+
time_np = np.asarray(jax.device_get(time_j), dtype=float)
|
|
714
|
+
flux_np = np.asarray(jax.device_get(flux_j), dtype=float)
|
|
715
|
+
ferr_np = np.maximum(np.asarray(jax.device_get(ferr_j), dtype=float), 1e-12)
|
|
716
|
+
q = np.asarray(jax.device_get(x0_j), dtype=float)
|
|
717
|
+
model, residual, chi2, fs, fb = self.fitter._model_and_residual(q, time_np, flux_np, ferr_np)
|
|
718
|
+
rho = float(np.exp(np.clip(q[3], -50.0, 10.0)))
|
|
719
|
+
params = np.asarray([q[0], q[1], q[2], rho, *q[4:]], dtype=float)
|
|
720
|
+
|
|
721
|
+
return SingleLensFitResult(
|
|
722
|
+
time=time_np,
|
|
723
|
+
flux=flux_np,
|
|
724
|
+
ferr=ferr_np,
|
|
725
|
+
params=jnp.asarray(params),
|
|
726
|
+
param_names=param_names,
|
|
727
|
+
chi2=jnp.asarray(chi2),
|
|
728
|
+
chi2_dof=jnp.asarray(chi2 / max(int(time_np.size) - dof, 1)),
|
|
729
|
+
fs=jnp.asarray(fs),
|
|
730
|
+
fb=jnp.asarray(fb),
|
|
731
|
+
model_flux=jnp.asarray(model),
|
|
732
|
+
residual=jnp.asarray(residual),
|
|
733
|
+
raw_params=jnp.asarray(q),
|
|
734
|
+
parallax_projector=parallax_projector,
|
|
735
|
+
)
|
|
736
|
+
|
|
456
737
|
def _estimate_single_lens_initial_guesses(
|
|
457
738
|
self,
|
|
458
739
|
*,
|