jacscanomaly 0.3.2__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.2/src/jacscanomaly.egg-info → jacscanomaly-0.3.3}/PKG-INFO +1 -1
- {jacscanomaly-0.3.2 → jacscanomaly-0.3.3}/pyproject.toml +1 -1
- jacscanomaly-0.3.3/setup.py +66 -0
- {jacscanomaly-0.3.2 → jacscanomaly-0.3.3}/src/jacscanomaly/__init__.py +44 -0
- {jacscanomaly-0.3.2 → jacscanomaly-0.3.3}/src/jacscanomaly/config.py +19 -5
- {jacscanomaly-0.3.2 → jacscanomaly-0.3.3}/src/jacscanomaly/finder.py +247 -4
- {jacscanomaly-0.3.2 → jacscanomaly-0.3.3}/src/jacscanomaly/magnification.py +0 -1
- 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.2 → jacscanomaly-0.3.3}/src/jacscanomaly/plot.py +48 -2
- {jacscanomaly-0.3.2 → jacscanomaly-0.3.3}/src/jacscanomaly/singlelens_fit.py +203 -3
- jacscanomaly-0.3.3/src/jacscanomaly/template_free.py +414 -0
- {jacscanomaly-0.3.2 → jacscanomaly-0.3.3/src/jacscanomaly.egg-info}/PKG-INFO +1 -1
- {jacscanomaly-0.3.2 → jacscanomaly-0.3.3}/src/jacscanomaly.egg-info/SOURCES.txt +22 -0
- jacscanomaly-0.3.3/tests/test_cpp_extension.py +8 -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.2 → jacscanomaly-0.3.3}/tests/test_space_parallax.py +41 -0
- jacscanomaly-0.3.3/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.3}/LICENSE +0 -0
- {jacscanomaly-0.3.2 → jacscanomaly-0.3.3}/README.md +0 -0
- {jacscanomaly-0.3.2 → jacscanomaly-0.3.3}/setup.cfg +0 -0
- {jacscanomaly-0.3.2 → jacscanomaly-0.3.3}/src/jacscanomaly/_cpp_grid.cpp +0 -0
- {jacscanomaly-0.3.2 → jacscanomaly-0.3.3}/src/jacscanomaly/anomaly_models.py +0 -0
- {jacscanomaly-0.3.2 → jacscanomaly-0.3.3}/src/jacscanomaly/criteria.py +0 -0
- {jacscanomaly-0.3.2 → jacscanomaly-0.3.3}/src/jacscanomaly/data/__init__.py +0 -0
- {jacscanomaly-0.3.2 → jacscanomaly-0.3.3}/src/jacscanomaly/data/earth_orbital_parallax_table.txt +0 -0
- {jacscanomaly-0.3.2 → jacscanomaly-0.3.3}/src/jacscanomaly/extract.py +0 -0
- {jacscanomaly-0.3.2 → jacscanomaly-0.3.3}/src/jacscanomaly/models.py +0 -0
- {jacscanomaly-0.3.2 → jacscanomaly-0.3.3}/src/jacscanomaly/objective.py +0 -0
- {jacscanomaly-0.3.2 → jacscanomaly-0.3.3}/src/jacscanomaly/parallax.py +0 -0
- {jacscanomaly-0.3.2 → jacscanomaly-0.3.3}/src/jacscanomaly/photometry.py +0 -0
- {jacscanomaly-0.3.2 → jacscanomaly-0.3.3}/src/jacscanomaly/runner.py +0 -0
- {jacscanomaly-0.3.2 → jacscanomaly-0.3.3}/src/jacscanomaly/seasons.py +0 -0
- {jacscanomaly-0.3.2 → jacscanomaly-0.3.3}/src/jacscanomaly/singlelens_model.py +0 -0
- {jacscanomaly-0.3.2 → jacscanomaly-0.3.3}/src/jacscanomaly/trajectory.py +0 -0
- {jacscanomaly-0.3.2 → jacscanomaly-0.3.3}/src/jacscanomaly.egg-info/dependency_links.txt +0 -0
- {jacscanomaly-0.3.2 → jacscanomaly-0.3.3}/src/jacscanomaly.egg-info/requires.txt +0 -0
- {jacscanomaly-0.3.2 → jacscanomaly-0.3.3}/src/jacscanomaly.egg-info/top_level.txt +0 -0
- {jacscanomaly-0.3.2 → jacscanomaly-0.3.3}/tests/test_config.py +0 -0
- {jacscanomaly-0.3.2 → jacscanomaly-0.3.3}/tests/test_criteria.py +0 -0
- {jacscanomaly-0.3.2 → jacscanomaly-0.3.3}/tests/test_extract.py +0 -0
- {jacscanomaly-0.3.2 → jacscanomaly-0.3.3}/tests/test_models.py +0 -0
- {jacscanomaly-0.3.2 → jacscanomaly-0.3.3}/tests/test_photometry.py +0 -0
- {jacscanomaly-0.3.2 → jacscanomaly-0.3.3}/tests/test_seasons.py +0 -0
|
@@ -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
|
# ==================================================
|
|
@@ -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
|
|
|
@@ -282,6 +309,7 @@ class Finder:
|
|
|
282
309
|
ferr,
|
|
283
310
|
x0=None,
|
|
284
311
|
*,
|
|
312
|
+
refit: bool = True,
|
|
285
313
|
verbose: bool = True,
|
|
286
314
|
log: Optional[logging.Logger] = None,
|
|
287
315
|
) -> AnomalyResult:
|
|
@@ -295,16 +323,34 @@ class Finder:
|
|
|
295
323
|
x0 : array-like, optional
|
|
296
324
|
Initial guess for the single-lens model parameters. If omitted, the
|
|
297
325
|
finder estimates multiple initial values and uses the best fit.
|
|
326
|
+
refit : bool, optional
|
|
327
|
+
If True, optimize the single-lens nonlinear parameters starting from
|
|
328
|
+
``x0``. If False, require ``x0`` and use it as fixed nonlinear
|
|
329
|
+
parameters; only the linear flux parameters are solved.
|
|
298
330
|
verbose : bool, optional
|
|
299
331
|
If True, print progress messages.
|
|
300
332
|
log : logging.Logger, optional
|
|
301
|
-
Logger used for
|
|
333
|
+
Logger used for progress reporting. When omitted, module-level
|
|
334
|
+
logging is used. ``verbose=False`` suppresses progress messages.
|
|
302
335
|
|
|
303
336
|
Returns
|
|
304
337
|
-------
|
|
305
338
|
AnomalyResult
|
|
306
339
|
Object containing the single-lens fit, residuals,
|
|
307
340
|
per-season cluster summaries, and the best anomaly candidate.
|
|
341
|
+
|
|
342
|
+
Raises
|
|
343
|
+
------
|
|
344
|
+
ValueError
|
|
345
|
+
If the input arrays are not finite one-dimensional arrays of equal
|
|
346
|
+
length, ``ferr`` is non-positive, or ``refit=False`` is used
|
|
347
|
+
without ``x0``.
|
|
348
|
+
|
|
349
|
+
Notes
|
|
350
|
+
-----
|
|
351
|
+
``refit=False`` fixes only nonlinear model parameters. The linear
|
|
352
|
+
source and blend fluxes are still solved for the supplied data before
|
|
353
|
+
residuals are scanned. See :doc:`workflows` for when to use this mode.
|
|
308
354
|
"""
|
|
309
355
|
time_j, flux_j, ferr_j, x0_j, time_np, flux_np, ferr_np = self._to_arrays(
|
|
310
356
|
time, flux, ferr, x0
|
|
@@ -312,7 +358,9 @@ class Finder:
|
|
|
312
358
|
|
|
313
359
|
self._ensure_fitter(float(np.median(time_np)))
|
|
314
360
|
|
|
315
|
-
if
|
|
361
|
+
if not refit:
|
|
362
|
+
fit = self._fixed_single_lens_from_x0(time_j, flux_j, ferr_j, x0_j)
|
|
363
|
+
elif x0_j is None:
|
|
316
364
|
if verbose:
|
|
317
365
|
(logger if log is None else log).info("Estimating single-lens initial values.")
|
|
318
366
|
fit = self._fit_from_auto_initial_guesses(time_j, flux_j, ferr_j, time_np)
|
|
@@ -370,6 +418,30 @@ class Finder:
|
|
|
370
418
|
Run a template-free anomaly search on single-lens residuals.
|
|
371
419
|
|
|
372
420
|
This leaves the existing bell-template anomaly pipeline untouched.
|
|
421
|
+
|
|
422
|
+
Parameters
|
|
423
|
+
----------
|
|
424
|
+
time, flux, ferr : array-like
|
|
425
|
+
One-dimensional light-curve arrays. ``ferr`` is used to normalize
|
|
426
|
+
the residuals even when ``fit`` is supplied.
|
|
427
|
+
x0 : array-like, optional
|
|
428
|
+
Nonlinear initial values used only when ``fit`` is omitted.
|
|
429
|
+
fit : SingleLensFitResult, optional
|
|
430
|
+
Existing baseline fit whose residuals should be searched. Passing
|
|
431
|
+
this skips all single-lens fitting.
|
|
432
|
+
config : TemplateFreeSearchConfig, optional
|
|
433
|
+
Template-free search settings. If omitted, the finder season gap is
|
|
434
|
+
reused and all other settings use their defaults.
|
|
435
|
+
|
|
436
|
+
Returns
|
|
437
|
+
-------
|
|
438
|
+
TemplateFreeSearchResult
|
|
439
|
+
Residual z-scores and ranked zero-crossing candidates.
|
|
440
|
+
|
|
441
|
+
Notes
|
|
442
|
+
-----
|
|
443
|
+
To scan residuals without constructing a ``Finder`` or a
|
|
444
|
+
``SingleLensFitResult``, call :class:`TemplateFreeScanner` directly.
|
|
373
445
|
"""
|
|
374
446
|
time_j, flux_j, ferr_j, x0_j, time_np, _, ferr_np = self._to_arrays(
|
|
375
447
|
time, flux, ferr, x0
|
|
@@ -453,6 +525,177 @@ class Finder:
|
|
|
453
525
|
|
|
454
526
|
return best_fit
|
|
455
527
|
|
|
528
|
+
def _fixed_single_lens_from_x0(
|
|
529
|
+
self,
|
|
530
|
+
time_j: jnp.ndarray,
|
|
531
|
+
flux_j: jnp.ndarray,
|
|
532
|
+
ferr_j: jnp.ndarray,
|
|
533
|
+
x0_j: Optional[jnp.ndarray],
|
|
534
|
+
) -> SingleLensFitResult:
|
|
535
|
+
if x0_j is None:
|
|
536
|
+
raise ValueError("Finder.run(refit=False) requires x0.")
|
|
537
|
+
|
|
538
|
+
k = self.config.fitter_kind
|
|
539
|
+
P = getattr(self.fitter, "_P", None)
|
|
540
|
+
|
|
541
|
+
if k == "pspl":
|
|
542
|
+
return evaluate_single_lens_fixed(
|
|
543
|
+
time=time_j,
|
|
544
|
+
flux=flux_j,
|
|
545
|
+
ferr=ferr_j,
|
|
546
|
+
x0=x0_j,
|
|
547
|
+
build_A=A_pspl_func,
|
|
548
|
+
dof=3,
|
|
549
|
+
param_names=("t0", "tE", "u0"),
|
|
550
|
+
min_points=4,
|
|
551
|
+
)
|
|
552
|
+
|
|
553
|
+
if k == "fspl":
|
|
554
|
+
def q_to_params(q):
|
|
555
|
+
t0, tE, u0, logrho = q
|
|
556
|
+
return jnp.array([t0, tE, u0, jnp.exp(logrho)])
|
|
557
|
+
|
|
558
|
+
return evaluate_single_lens_fixed(
|
|
559
|
+
time=time_j,
|
|
560
|
+
flux=flux_j,
|
|
561
|
+
ferr=ferr_j,
|
|
562
|
+
x0=x0_j,
|
|
563
|
+
build_A=A_fspl_logrho_func,
|
|
564
|
+
dof=4,
|
|
565
|
+
param_names=("t0", "tE", "u0", "rho"),
|
|
566
|
+
x_to_params=q_to_params,
|
|
567
|
+
min_points=4,
|
|
568
|
+
store_raw_params=True,
|
|
569
|
+
)
|
|
570
|
+
|
|
571
|
+
if k == "fspl_vbm_fd":
|
|
572
|
+
return self._fixed_single_lens_from_numpy_model(
|
|
573
|
+
time_j=time_j,
|
|
574
|
+
flux_j=flux_j,
|
|
575
|
+
ferr_j=ferr_j,
|
|
576
|
+
x0_j=x0_j,
|
|
577
|
+
dof=4,
|
|
578
|
+
param_names=("t0", "tE", "u0", "rho"),
|
|
579
|
+
parallax_projector=None,
|
|
580
|
+
)
|
|
581
|
+
|
|
582
|
+
if k == "pspl_parallax":
|
|
583
|
+
return evaluate_single_lens_fixed(
|
|
584
|
+
time=time_j,
|
|
585
|
+
flux=flux_j,
|
|
586
|
+
ferr=ferr_j,
|
|
587
|
+
x0=x0_j,
|
|
588
|
+
build_A=lambda p, t: A_pspl_parallax_func(p, t, P),
|
|
589
|
+
dof=5,
|
|
590
|
+
param_names=("t0", "tE", "u0", "piEN", "piEE"),
|
|
591
|
+
min_points=6,
|
|
592
|
+
parallax_projector=P,
|
|
593
|
+
)
|
|
594
|
+
|
|
595
|
+
if k == "fspl_parallax":
|
|
596
|
+
def q_to_params(q):
|
|
597
|
+
t0, tE, u0, logrho, piEN, piEE = q
|
|
598
|
+
return jnp.array([t0, tE, u0, jnp.exp(logrho), piEN, piEE])
|
|
599
|
+
|
|
600
|
+
return evaluate_single_lens_fixed(
|
|
601
|
+
time=time_j,
|
|
602
|
+
flux=flux_j,
|
|
603
|
+
ferr=ferr_j,
|
|
604
|
+
x0=x0_j,
|
|
605
|
+
build_A=lambda q, t: A_fspl_parallax_logrho_func(q, t, P),
|
|
606
|
+
dof=6,
|
|
607
|
+
param_names=("t0", "tE", "u0", "rho", "piEN", "piEE"),
|
|
608
|
+
x_to_params=q_to_params,
|
|
609
|
+
min_points=7,
|
|
610
|
+
store_raw_params=True,
|
|
611
|
+
parallax_projector=P,
|
|
612
|
+
)
|
|
613
|
+
|
|
614
|
+
if k == "pspl_space_parallax":
|
|
615
|
+
return evaluate_single_lens_fixed(
|
|
616
|
+
time=time_j,
|
|
617
|
+
flux=flux_j,
|
|
618
|
+
ferr=ferr_j,
|
|
619
|
+
x0=x0_j,
|
|
620
|
+
build_A=lambda p, t: A_pspl_space_parallax_func(p, t, P),
|
|
621
|
+
dof=5,
|
|
622
|
+
param_names=("t0", "tE", "u0", "piEN", "piEE"),
|
|
623
|
+
min_points=6,
|
|
624
|
+
parallax_projector=P,
|
|
625
|
+
)
|
|
626
|
+
|
|
627
|
+
if k == "fspl_space_parallax":
|
|
628
|
+
def q_to_params(q):
|
|
629
|
+
t0, tE, u0, logrho, piEN, piEE = q
|
|
630
|
+
return jnp.array([t0, tE, u0, jnp.exp(logrho), piEN, piEE])
|
|
631
|
+
|
|
632
|
+
return evaluate_single_lens_fixed(
|
|
633
|
+
time=time_j,
|
|
634
|
+
flux=flux_j,
|
|
635
|
+
ferr=ferr_j,
|
|
636
|
+
x0=x0_j,
|
|
637
|
+
build_A=lambda q, t: A_fspl_space_parallax_logrho_func(q, t, P),
|
|
638
|
+
dof=6,
|
|
639
|
+
param_names=("t0", "tE", "u0", "rho", "piEN", "piEE"),
|
|
640
|
+
x_to_params=q_to_params,
|
|
641
|
+
min_points=7,
|
|
642
|
+
store_raw_params=True,
|
|
643
|
+
parallax_projector=P,
|
|
644
|
+
)
|
|
645
|
+
|
|
646
|
+
if k == "fspl_space_parallax_gulls_vbm_fd":
|
|
647
|
+
return self._fixed_single_lens_from_numpy_model(
|
|
648
|
+
time_j=time_j,
|
|
649
|
+
flux_j=flux_j,
|
|
650
|
+
ferr_j=ferr_j,
|
|
651
|
+
x0_j=x0_j,
|
|
652
|
+
dof=6,
|
|
653
|
+
param_names=("t0", "tE", "u0", "rho", "piEN", "piEE"),
|
|
654
|
+
parallax_projector=P,
|
|
655
|
+
)
|
|
656
|
+
|
|
657
|
+
raise ValueError(f"Unknown fitter_kind '{k}'.")
|
|
658
|
+
|
|
659
|
+
def _fixed_single_lens_from_numpy_model(
|
|
660
|
+
self,
|
|
661
|
+
*,
|
|
662
|
+
time_j: jnp.ndarray,
|
|
663
|
+
flux_j: jnp.ndarray,
|
|
664
|
+
ferr_j: jnp.ndarray,
|
|
665
|
+
x0_j: jnp.ndarray,
|
|
666
|
+
dof: int,
|
|
667
|
+
param_names: tuple[str, ...],
|
|
668
|
+
parallax_projector,
|
|
669
|
+
) -> SingleLensFitResult:
|
|
670
|
+
if not hasattr(self.fitter, "_model_and_residual"):
|
|
671
|
+
raise TypeError(
|
|
672
|
+
f"{type(self.fitter).__name__} does not support fixed-parameter evaluation."
|
|
673
|
+
)
|
|
674
|
+
|
|
675
|
+
time_np = np.asarray(jax.device_get(time_j), dtype=float)
|
|
676
|
+
flux_np = np.asarray(jax.device_get(flux_j), dtype=float)
|
|
677
|
+
ferr_np = np.maximum(np.asarray(jax.device_get(ferr_j), dtype=float), 1e-12)
|
|
678
|
+
q = np.asarray(jax.device_get(x0_j), dtype=float)
|
|
679
|
+
model, residual, chi2, fs, fb = self.fitter._model_and_residual(q, time_np, flux_np, ferr_np)
|
|
680
|
+
rho = float(np.exp(np.clip(q[3], -50.0, 10.0)))
|
|
681
|
+
params = np.asarray([q[0], q[1], q[2], rho, *q[4:]], dtype=float)
|
|
682
|
+
|
|
683
|
+
return SingleLensFitResult(
|
|
684
|
+
time=time_np,
|
|
685
|
+
flux=flux_np,
|
|
686
|
+
ferr=ferr_np,
|
|
687
|
+
params=jnp.asarray(params),
|
|
688
|
+
param_names=param_names,
|
|
689
|
+
chi2=jnp.asarray(chi2),
|
|
690
|
+
chi2_dof=jnp.asarray(chi2 / max(int(time_np.size) - dof, 1)),
|
|
691
|
+
fs=jnp.asarray(fs),
|
|
692
|
+
fb=jnp.asarray(fb),
|
|
693
|
+
model_flux=jnp.asarray(model),
|
|
694
|
+
residual=jnp.asarray(residual),
|
|
695
|
+
raw_params=jnp.asarray(q),
|
|
696
|
+
parallax_projector=parallax_projector,
|
|
697
|
+
)
|
|
698
|
+
|
|
456
699
|
def _estimate_single_lens_initial_guesses(
|
|
457
700
|
self,
|
|
458
701
|
*,
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
from .classifier import PlanetAnomalyClassifier
|
|
2
|
+
from .pspl import (
|
|
3
|
+
angle_of,
|
|
4
|
+
pspl_flux,
|
|
5
|
+
pspl_magnification_from_u,
|
|
6
|
+
pspl_params_from_result,
|
|
7
|
+
q_grid_from_width,
|
|
8
|
+
r_major,
|
|
9
|
+
r_minor,
|
|
10
|
+
u_abs,
|
|
11
|
+
u_vec,
|
|
12
|
+
)
|
|
13
|
+
from .fold_kernel import (
|
|
14
|
+
FoldKernelLookup,
|
|
15
|
+
LimbDarkenedFoldKernelLookup,
|
|
16
|
+
default_fold_kernel_lookup,
|
|
17
|
+
default_limb_darkened_fold_kernel_lookup,
|
|
18
|
+
fold_g0,
|
|
19
|
+
fold_g0_integral,
|
|
20
|
+
fold_gn_integral,
|
|
21
|
+
fold_limb_darkened,
|
|
22
|
+
)
|
|
23
|
+
from .atoms.chang_refsdal import cr_relative_magnification, warm_chang_refsdal_lookup_cache
|
|
24
|
+
from .types import (
|
|
25
|
+
AtomFitResult,
|
|
26
|
+
PlanetAnomalyFitResult,
|
|
27
|
+
PlanetClassConfig,
|
|
28
|
+
PSPLParams,
|
|
29
|
+
SeedCandidate,
|
|
30
|
+
SegmentData,
|
|
31
|
+
SegmentModelResult,
|
|
32
|
+
)
|
|
33
|
+
from .seeds import central_caustic_seeds
|
|
34
|
+
|
|
35
|
+
__all__ = [
|
|
36
|
+
"PlanetAnomalyClassifier",
|
|
37
|
+
"PlanetClassConfig",
|
|
38
|
+
"PlanetAnomalyFitResult",
|
|
39
|
+
"SegmentModelResult",
|
|
40
|
+
"SegmentData",
|
|
41
|
+
"AtomFitResult",
|
|
42
|
+
"SeedCandidate",
|
|
43
|
+
"PSPLParams",
|
|
44
|
+
"pspl_params_from_result",
|
|
45
|
+
"pspl_flux",
|
|
46
|
+
"pspl_magnification_from_u",
|
|
47
|
+
"u_vec",
|
|
48
|
+
"u_abs",
|
|
49
|
+
"r_major",
|
|
50
|
+
"r_minor",
|
|
51
|
+
"angle_of",
|
|
52
|
+
"q_grid_from_width",
|
|
53
|
+
"central_caustic_seeds",
|
|
54
|
+
"FoldKernelLookup",
|
|
55
|
+
"LimbDarkenedFoldKernelLookup",
|
|
56
|
+
"default_fold_kernel_lookup",
|
|
57
|
+
"default_limb_darkened_fold_kernel_lookup",
|
|
58
|
+
"fold_g0",
|
|
59
|
+
"fold_g0_integral",
|
|
60
|
+
"fold_gn_integral",
|
|
61
|
+
"fold_limb_darkened",
|
|
62
|
+
"cr_relative_magnification",
|
|
63
|
+
"warm_chang_refsdal_lookup_cache",
|
|
64
|
+
]
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
from .central import CentralDoubleCuspAtom, CentralPerturbationAtom
|
|
2
|
+
from .chang_refsdal import ChangRefsdalPerturbationAtom
|
|
3
|
+
from .cusp import CanonicalCuspAtom, CuspTailAtom, FiniteSourceCuspAtom
|
|
4
|
+
from .fold import (
|
|
5
|
+
CurvedFoldCausticAtom,
|
|
6
|
+
FoldCausticAtom,
|
|
7
|
+
FullCausticCrossingAtom,
|
|
8
|
+
GrazingFoldCausticAtom,
|
|
9
|
+
LimbDarkenedFoldCausticAtom,
|
|
10
|
+
RimTroughCausticAtom,
|
|
11
|
+
SignedTwoFoldCausticAtom,
|
|
12
|
+
TwoFoldCausticAtom,
|
|
13
|
+
)
|
|
14
|
+
from .bump import MinorImageBoxTroughAtom, NegativeDipAtom, PositiveBumpAtom, PSPLPositiveBumpAtom
|
|
15
|
+
from .second_pspl import SecondPSPLAtom
|
|
16
|
+
from .smooth import PSPLMisfitAtom, ShearQuadrupoleAtom, SystematicsArtifactAtom
|
|
17
|
+
|
|
18
|
+
__all__ = [
|
|
19
|
+
"CentralPerturbationAtom",
|
|
20
|
+
"CentralDoubleCuspAtom",
|
|
21
|
+
"CanonicalCuspAtom",
|
|
22
|
+
"ChangRefsdalPerturbationAtom",
|
|
23
|
+
"CuspTailAtom",
|
|
24
|
+
"CurvedFoldCausticAtom",
|
|
25
|
+
"FiniteSourceCuspAtom",
|
|
26
|
+
"FoldCausticAtom",
|
|
27
|
+
"FullCausticCrossingAtom",
|
|
28
|
+
"GrazingFoldCausticAtom",
|
|
29
|
+
"LimbDarkenedFoldCausticAtom",
|
|
30
|
+
"MinorImageBoxTroughAtom",
|
|
31
|
+
"NegativeDipAtom",
|
|
32
|
+
"PositiveBumpAtom",
|
|
33
|
+
"PSPLPositiveBumpAtom",
|
|
34
|
+
"SecondPSPLAtom",
|
|
35
|
+
"PSPLMisfitAtom",
|
|
36
|
+
"ShearQuadrupoleAtom",
|
|
37
|
+
"SystematicsArtifactAtom",
|
|
38
|
+
"RimTroughCausticAtom",
|
|
39
|
+
"SignedTwoFoldCausticAtom",
|
|
40
|
+
"TwoFoldCausticAtom",
|
|
41
|
+
]
|