reflection-method 0.3.0__py3-none-any.whl
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.
- reflection_method/__init__.py +47 -0
- reflection_method/cli.py +210 -0
- reflection_method/core.py +820 -0
- reflection_method/io.py +221 -0
- reflection_method/plot.py +459 -0
- reflection_method/result.py +140 -0
- reflection_method-0.3.0.dist-info/METADATA +370 -0
- reflection_method-0.3.0.dist-info/RECORD +12 -0
- reflection_method-0.3.0.dist-info/WHEEL +5 -0
- reflection_method-0.3.0.dist-info/entry_points.txt +2 -0
- reflection_method-0.3.0.dist-info/licenses/LICENSE +674 -0
- reflection_method-0.3.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
"""Result container for the reflection method."""
|
|
2
|
+
|
|
3
|
+
from dataclasses import dataclass
|
|
4
|
+
from typing import Optional
|
|
5
|
+
|
|
6
|
+
import numpy as np
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def jd_to_datetime(jd: float) -> np.datetime64:
|
|
10
|
+
"""Convert a Julian Date to a UTC ``datetime64``.
|
|
11
|
+
|
|
12
|
+
Reference epoch: JD 2451545.0 corresponds to 2000-01-01T12:00:00 UTC.
|
|
13
|
+
|
|
14
|
+
Parameters
|
|
15
|
+
----------
|
|
16
|
+
jd : float
|
|
17
|
+
Julian Date (geocentric, observation time).
|
|
18
|
+
|
|
19
|
+
Returns
|
|
20
|
+
-------
|
|
21
|
+
np.datetime64
|
|
22
|
+
The corresponding UTC timestamp (second precision).
|
|
23
|
+
"""
|
|
24
|
+
return np.datetime64("2000-01-01T12:00:00") + np.timedelta64(
|
|
25
|
+
int(round((jd - 2451545.0) * 86400)), "s"
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def _utc_iso(ts: np.datetime64) -> str:
|
|
30
|
+
"""Format a ``datetime64`` as ISO-8601 UTC (trailing ``Z``)."""
|
|
31
|
+
utc_str = np.datetime_as_string(ts, unit="s", timezone="UTC")
|
|
32
|
+
if utc_str.endswith("Z"):
|
|
33
|
+
return utc_str
|
|
34
|
+
if "T" in utc_str:
|
|
35
|
+
return utc_str + "Z"
|
|
36
|
+
return utc_str.replace(" ", "T") + "Z"
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
@dataclass(frozen=True, slots=True)
|
|
40
|
+
class MinimumResult:
|
|
41
|
+
"""Result of the reflection-method minimum finding.
|
|
42
|
+
|
|
43
|
+
All x-values are in the **same linear time units as the input `x` array**
|
|
44
|
+
(e.g., JD, HJD, MJD, phase, minutes from start). The library performs
|
|
45
|
+
**no time conversion** — this is the responsibility of the caller
|
|
46
|
+
(or the CLI layer).
|
|
47
|
+
|
|
48
|
+
Attributes
|
|
49
|
+
----------
|
|
50
|
+
x0 : float
|
|
51
|
+
Optimal reflection point (abscissa of the symmetry axis / minimum).
|
|
52
|
+
Units: same as input ``x``.
|
|
53
|
+
x0_std : float
|
|
54
|
+
Bootstrap standard error (sample standard deviation of bootstrap
|
|
55
|
+
distribution, ddof=1). Units: same as input ``x``.
|
|
56
|
+
x0_lo : float
|
|
57
|
+
16th percentile of the bootstrap distribution (lower bound of the
|
|
58
|
+
68% confidence interval). Units: same as input ``x``.
|
|
59
|
+
x0_hi : float
|
|
60
|
+
84th percentile of the bootstrap distribution (upper bound of the
|
|
61
|
+
68% confidence interval). Units: same as input ``x``.
|
|
62
|
+
sigma_min : float
|
|
63
|
+
Minimum value of the residual standard deviation ``σ₂`` achieved
|
|
64
|
+
at ``x0``. Dimensionless (same units as input ``y``).
|
|
65
|
+
n_points : int
|
|
66
|
+
Number of data points used in the fit.
|
|
67
|
+
n_bootstrap : int
|
|
68
|
+
Number of bootstrap iterations performed.
|
|
69
|
+
|
|
70
|
+
Notes
|
|
71
|
+
-----
|
|
72
|
+
- The 68% confidence interval ``[x0_lo, x0_hi]`` corresponds to the
|
|
73
|
+
central 68% of the bootstrap distribution, approximately equivalent
|
|
74
|
+
to ±1σ for a Gaussian distribution.
|
|
75
|
+
- For asymmetric bootstrap distributions, the interval is not centered
|
|
76
|
+
on ``x0``; report both bounds.
|
|
77
|
+
- ``x0_std`` is the sample standard deviation (ddof=1) of the bootstrap
|
|
78
|
+
estimates. It may differ from ``(x0_hi - x0_lo) / 2`` for non-Gaussian
|
|
79
|
+
bootstrap distributions.
|
|
80
|
+
|
|
81
|
+
Examples
|
|
82
|
+
--------
|
|
83
|
+
>>> from reflection_method import MinimumResult
|
|
84
|
+
>>> result = MinimumResult(
|
|
85
|
+
... x0=2459000.5, x0_std=0.001, x0_lo=2459000.498, x0_hi=2459000.502,
|
|
86
|
+
... sigma_min=0.005, n_points=150, n_bootstrap=100
|
|
87
|
+
... )
|
|
88
|
+
>>> print(f"Minimum at JD {result.x0:.3f} ± {result.x0_std:.3f}")
|
|
89
|
+
Minimum at JD 2459000.500 ± 0.001
|
|
90
|
+
>>> print(f"68% CI: [{result.x0_lo:.3f}, {result.x0_hi:.3f}]")
|
|
91
|
+
68% CI: [2459000.498, 2459000.502]
|
|
92
|
+
"""
|
|
93
|
+
x0: float
|
|
94
|
+
x0_std: float
|
|
95
|
+
x0_lo: float
|
|
96
|
+
x0_hi: float
|
|
97
|
+
sigma_min: float
|
|
98
|
+
n_points: int
|
|
99
|
+
n_bootstrap: int
|
|
100
|
+
|
|
101
|
+
def to_dict(
|
|
102
|
+
self,
|
|
103
|
+
t0_utc: Optional[np.datetime64] = None,
|
|
104
|
+
time_format: str = "iso",
|
|
105
|
+
) -> dict:
|
|
106
|
+
"""Return a JSON-serializable report, including a UTC time when known.
|
|
107
|
+
|
|
108
|
+
Parameters
|
|
109
|
+
----------
|
|
110
|
+
t0_utc : np.datetime64 or None, optional
|
|
111
|
+
Earliest observation timestamp, needed when ``x0`` is in minutes
|
|
112
|
+
from that origin (``time_format="iso"``).
|
|
113
|
+
time_format : str, optional
|
|
114
|
+
``"iso"`` (x0 in minutes from ``t0_utc``) or ``"jd"`` (x0 is a
|
|
115
|
+
Julian Date). Default ``"iso"``.
|
|
116
|
+
|
|
117
|
+
Returns
|
|
118
|
+
-------
|
|
119
|
+
dict
|
|
120
|
+
Fields ``x0``, ``x0_std``, ``x0_lo``, ``x0_hi``, ``sigma_min``,
|
|
121
|
+
``n_points``, ``n_bootstrap`` and, when the minimum can be
|
|
122
|
+
expressed as a UTC time, ``utc_time`` and ``utc_uncertainty_s``.
|
|
123
|
+
"""
|
|
124
|
+
out = {
|
|
125
|
+
"x0": float(self.x0),
|
|
126
|
+
"x0_std": float(self.x0_std),
|
|
127
|
+
"x0_lo": float(self.x0_lo),
|
|
128
|
+
"x0_hi": float(self.x0_hi),
|
|
129
|
+
"sigma_min": float(self.sigma_min),
|
|
130
|
+
"n_points": int(self.n_points),
|
|
131
|
+
"n_bootstrap": int(self.n_bootstrap),
|
|
132
|
+
}
|
|
133
|
+
if time_format == "jd":
|
|
134
|
+
out["utc_time"] = _utc_iso(jd_to_datetime(float(self.x0)))
|
|
135
|
+
out["utc_uncertainty_s"] = float(self.x0_std * 86400)
|
|
136
|
+
elif t0_utc is not None:
|
|
137
|
+
ts = t0_utc + np.timedelta64(int(self.x0 * 60), "s")
|
|
138
|
+
out["utc_time"] = _utc_iso(ts)
|
|
139
|
+
out["utc_uncertainty_s"] = float(self.x0_std * 60)
|
|
140
|
+
return out
|
|
@@ -0,0 +1,370 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: reflection-method
|
|
3
|
+
Version: 0.3.0
|
|
4
|
+
Summary: Eclipsing binary minimum finder using the reflection method
|
|
5
|
+
Author: Jochym
|
|
6
|
+
License: GPL-3.0-or-later
|
|
7
|
+
Classifier: Development Status :: 3 - Alpha
|
|
8
|
+
Classifier: Intended Audience :: Science/Research
|
|
9
|
+
Classifier: License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: Topic :: Scientific/Engineering :: Astronomy
|
|
12
|
+
Requires-Python: >=3.10
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
License-File: LICENSE
|
|
15
|
+
Requires-Dist: numpy>=1.24
|
|
16
|
+
Requires-Dist: scipy>=1.10
|
|
17
|
+
Provides-Extra: plot
|
|
18
|
+
Requires-Dist: matplotlib>=3.7; extra == "plot"
|
|
19
|
+
Provides-Extra: cli
|
|
20
|
+
Requires-Dist: click>=8.1; extra == "cli"
|
|
21
|
+
Requires-Dist: pyyaml>=6.0; extra == "cli"
|
|
22
|
+
Dynamic: license-file
|
|
23
|
+
|
|
24
|
+
# reflection-method
|
|
25
|
+
|
|
26
|
+
Eclipsing binary minimum finder using the **reflection method** (symmetry about the eclipse minimum).
|
|
27
|
+
|
|
28
|
+
## What is this for?
|
|
29
|
+
|
|
30
|
+
About half of all stars are members of binary or multiple systems. When the
|
|
31
|
+
orbital plane of such a system is seen close to edge-on, the two stars
|
|
32
|
+
periodically **eclipse** each other: one star passes in front of the other
|
|
33
|
+
and briefly blocks part of its light. Seen from Earth, the star's brightness
|
|
34
|
+
dips and recovers — this dip is called an *eclipse* (or *minimum*), and a
|
|
35
|
+
plot of brightness against time is a *light curve*.
|
|
36
|
+
|
|
37
|
+
Measuring the exact moment of an eclipse minimum is one of the most important
|
|
38
|
+
and frequently performed tasks in stellar astronomy:
|
|
39
|
+
|
|
40
|
+
- it pins down the **period** of the system when combined with other
|
|
41
|
+
eclipses (eclipse timings),
|
|
42
|
+
- small, periodic shifts in the timing betray the presence of a third body
|
|
43
|
+
(*light-time effect*), apsidal motion, or mass exchange,
|
|
44
|
+
- it is the standard measurement made by thousands of **amateur observers**
|
|
45
|
+
of variable stars who submit their data to databases like the AAVSO.
|
|
46
|
+
|
|
47
|
+
This is harder than it sounds. Real light curves are unevenly sampled, noisy,
|
|
48
|
+
and the minimum is often sampled by only a handful of points. Simply picking
|
|
49
|
+
the dimmest observation is meaningless — the noise can easily shift it by
|
|
50
|
+
minutes. Instead, one needs a robust way to use *all* points in the dip to
|
|
51
|
+
estimate the minimum and its uncertainty.
|
|
52
|
+
|
|
53
|
+
## How does it work?
|
|
54
|
+
|
|
55
|
+
The reflection method exploits the **symmetry of an eclipse**: the light
|
|
56
|
+
curve just before the minimum is a mirror image of the curve just after it.
|
|
57
|
+
The algorithm therefore:
|
|
58
|
+
|
|
59
|
+
1. Fits a smooth B-spline to the observed light curve.
|
|
60
|
+
2. Picks a trial moment `x₀` and **reflects every point about it**
|
|
61
|
+
(`x → 2x₀ − x`), merging the reflected points with the original ones.
|
|
62
|
+
3. Fits a spline to the combined dataset and measures the residual
|
|
63
|
+
standard deviation σ₂ — weighted in σ units when per-point errors are
|
|
64
|
+
supplied as `w = 1/sigma`.
|
|
65
|
+
4. Repeats steps 2–3 for a grid of trial values: the true minimum is the
|
|
66
|
+
`x₀` that makes the combined data **most symmetric**, i.e. minimises σ₂.
|
|
67
|
+
The grid minimum is refined with a **local polynomial fit** to the σ₂
|
|
68
|
+
curve — a quartic fitted inside a narrow window around the grid minimum
|
|
69
|
+
(a parabola when fewer points are available). This is more stable than
|
|
70
|
+
interpolating the σ₂ curve with a spline, which can produce spurious
|
|
71
|
+
minima when the curve is flat near the minimum.
|
|
72
|
+
5. Quantifies the uncertainty with a **bootstrap**: residuals are resampled
|
|
73
|
+
(per-point with a random sign when weights are supplied, otherwise pooled),
|
|
74
|
+
the whole search is repeated, and the spread of the resulting `x₀`
|
|
75
|
+
estimates gives the standard error and a 68% confidence interval.
|
|
76
|
+
|
|
77
|
+
The method is a modern, statistically well-founded descendant of the classic
|
|
78
|
+
Kwee–van Woerden algorithm (1956) and works with arbitrary, non-uniformly
|
|
79
|
+
sampled data, without folding the light curve.
|
|
80
|
+
|
|
81
|
+
## Who is it for?
|
|
82
|
+
|
|
83
|
+
- **Amateur variable-star observers** who want the minimum time of their
|
|
84
|
+
latest observation run and an honest error bar on it — the
|
|
85
|
+
[command-line interface](#cli) takes an AAVSO-format CSV and prints a
|
|
86
|
+
ready-to-report time.
|
|
87
|
+
- **Astronomers and students** who need the algorithm in their own pipeline —
|
|
88
|
+
the core is a pure, dependency-light Python API with no I/O.
|
|
89
|
+
- **Anyone** curious how an eclipse-minimum timing can be extracted from a
|
|
90
|
+
noisy light curve.
|
|
91
|
+
|
|
92
|
+
## Installation
|
|
93
|
+
|
|
94
|
+
The package is not yet published to PyPI. Install directly from GitHub:
|
|
95
|
+
|
|
96
|
+
```bash
|
|
97
|
+
# Core library only (numpy, scipy)
|
|
98
|
+
pip install git+https://github.com/jochym/reflection-method.git
|
|
99
|
+
|
|
100
|
+
# With plotting (matplotlib)
|
|
101
|
+
pip install "git+https://github.com/jochym/reflection-method.git[plot]"
|
|
102
|
+
|
|
103
|
+
# With CLI (click)
|
|
104
|
+
pip install "git+https://github.com/jochym/reflection-method.git[cli]"
|
|
105
|
+
|
|
106
|
+
# Full
|
|
107
|
+
pip install "git+https://github.com/jochym/reflection-method.git[plot,cli]"
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
### From source (development)
|
|
111
|
+
|
|
112
|
+
```bash
|
|
113
|
+
git clone https://github.com/jochym/reflection-method.git
|
|
114
|
+
cd reflection-method
|
|
115
|
+
pip install -e ".[plot,cli]"
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
A PyPI release will be available after the first tagged release (see [Release Process](#release-process)).
|
|
119
|
+
|
|
120
|
+
## Quickstart
|
|
121
|
+
|
|
122
|
+
```python
|
|
123
|
+
import numpy as np
|
|
124
|
+
from reflection_method import find_minimum
|
|
125
|
+
|
|
126
|
+
# x, y in any linear time units (JD, HJD, MJD, phase, minutes...)
|
|
127
|
+
x = np.array([...]) # time
|
|
128
|
+
y = np.array([...]) # magnitude (logarithmic scale)
|
|
129
|
+
|
|
130
|
+
# An eclipse is a *maximum* of the magnitude light curve -> find_peak=True
|
|
131
|
+
result = find_minimum(x, y, pts_per_knot=10, degree=3, n_bootstrap=60, find_peak=True)
|
|
132
|
+
|
|
133
|
+
print(f"Minimum at x0 = {result.x0:.4f} ± {result.x0_std:.4f}")
|
|
134
|
+
print(f"68% CI: [{result.x0_lo:.4f}, {result.x0_hi:.4f}]")
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
Result is a frozen `MinimumResult` dataclass with all values in the **same units as input `x`**. The library performs no time conversion. If your data is already in **flux units** (eclipse = dip = minimum of `y`), simply omit `find_peak=True`.
|
|
138
|
+
|
|
139
|
+
## Algorithm
|
|
140
|
+
|
|
141
|
+
1. Fit a low-order spline to the original data
|
|
142
|
+
2. Scan reflection point `x0` — for each candidate, reflect all points about `x0`, combine with original, refit spline, compute residual standard deviation `σ₂` (weighted when `w` is supplied)
|
|
143
|
+
3. Refine the grid minimum with a local polynomial fit to `σ₂` (quartic by default; see `parabola_window`)
|
|
144
|
+
4. Bootstrap uncertainty: resample residuals, repeat scan, compute percentiles
|
|
145
|
+
|
|
146
|
+
## Examples
|
|
147
|
+
|
|
148
|
+
### Python API
|
|
149
|
+
|
|
150
|
+
See [`examples/quickstart.py`](examples/quickstart.py) for a minimal script.
|
|
151
|
+
|
|
152
|
+
See [`examples/plot_aavso.py`](examples/plot_aavso.py) for a full worked
|
|
153
|
+
example on **real AAVSO photometry**: it loads two stars, finds each primary
|
|
154
|
+
minimum **directly on the magnitude scale** (`find_peak=True`), and saves the
|
|
155
|
+
diagnostic figures to `examples/plots/`:
|
|
156
|
+
|
|
157
|
+
```bash
|
|
158
|
+
pip install "reflection-method[plot]"
|
|
159
|
+
python examples/plot_aavso.py
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
See [`examples/notebook/example.ipynb`](examples/notebook/example.ipynb) for a full Jupyter notebook with step-by-step walkthrough and plotting.
|
|
163
|
+
|
|
164
|
+
### Full pipeline with diagnostics (test-backed)
|
|
165
|
+
|
|
166
|
+
The figure below comes from
|
|
167
|
+
[`tests/test_docs_examples.py`](tests/test_docs_examples.py), which runs a
|
|
168
|
+
**realistic ground-based light curve** end to end and asserts the recovered
|
|
169
|
+
minimum. It is the canonical, executed version of the documented example;
|
|
170
|
+
the notebook follows the same `find_minimum(..., return_scan=True)` and
|
|
171
|
+
`prepare_plot_data` path.
|
|
172
|
+
|
|
173
|
+
The synthetic data mimics real AAVSO observations:
|
|
174
|
+
- Single-night window with gaps
|
|
175
|
+
- Heteroscedastic errors (larger at edges)
|
|
176
|
+
- Asymmetric eclipse from limb darkening
|
|
177
|
+
- Magnitude scale (eclipse = maximum)
|
|
178
|
+
|
|
179
|
+

|
|
180
|
+
|
|
181
|
+
Regenerate the committed image with:
|
|
182
|
+
|
|
183
|
+
```bash
|
|
184
|
+
REFLECTION_WRITE_DOCS=1 python -m pytest tests/test_docs_examples.py
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
### Results on real AAVSO data
|
|
188
|
+
|
|
189
|
+
Eclipse minimum of **V500 Peg** (2026-08-08, 120 points) — `x0 = 94.86 ± 0.17 min`
|
|
190
|
+
from start, i.e. `2026-08-08T22:14:03Z`:
|
|
191
|
+
|
|
192
|
+

|
|
193
|
+
|
|
194
|
+
Eclipse minimum of **V456 Cyg** (2026-07-29, 142 points) — `x0 = 54.69 ± 0.14 min`
|
|
195
|
+
from start, i.e. `2026-07-29T21:57:23Z`:
|
|
196
|
+
|
|
197
|
+

|
|
198
|
+
|
|
199
|
+
Both stars' eclipses aligned to their detected minima:
|
|
200
|
+
|
|
201
|
+

|
|
202
|
+
|
|
203
|
+
### CLI
|
|
204
|
+
|
|
205
|
+
```bash
|
|
206
|
+
# Install with CLI and plotting (from GitHub until PyPI release)
|
|
207
|
+
pip install "git+https://github.com/jochym/reflection-method.git[plot,cli]"
|
|
208
|
+
|
|
209
|
+
# Run on the included V500 Peg test fixture (reproduces the plot in this README)
|
|
210
|
+
reflection-method tests/fixtures/V500_Peg_2461261_2026-08-08_G.aavso.txt \
|
|
211
|
+
-x DATE-OBS -y MAG -w MAG_ERR \
|
|
212
|
+
-t iso -k 10 -d 3 -n 200 -b 60 -s 42 \
|
|
213
|
+
-p v500_result.png
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
YAML output (default, human-readable):
|
|
217
|
+
|
|
218
|
+
```bash
|
|
219
|
+
reflection-method tests/fixtures/V500_Peg_2461261_2026-08-08_G.aavso.txt \
|
|
220
|
+
-x DATE-OBS -y MAG -w MAG_ERR \
|
|
221
|
+
-t iso -k 10 -d 3 -n 200 -b 60 -s 42
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
JSON output for scripting:
|
|
225
|
+
|
|
226
|
+
```bash
|
|
227
|
+
reflection-method tests/fixtures/V500_Peg_2461261_2026-08-08_G.aavso.txt \
|
|
228
|
+
-x DATE-OBS -y MAG -w MAG_ERR \
|
|
229
|
+
-t iso -k 10 -d 3 -n 200 -b 60 -s 42 --format json
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
**CLI Options:**
|
|
233
|
+
|
|
234
|
+
| Option | Short | Default | Description |
|
|
235
|
+
|--------|-------|---------|-------------|
|
|
236
|
+
| `--x-col` | `-x` | `DATE-OBS` | Time column name |
|
|
237
|
+
| `--y-col` | `-y` | `MAG` | Magnitude column name |
|
|
238
|
+
| `--w-col` | `-w` | (none) | Weight/error column name |
|
|
239
|
+
| `--time-format` | `-t` | `iso` | `iso` (DATE-OBS→UTC) or `jd` (Julian Date) |
|
|
240
|
+
| `--pts-per-knot` | `-k` | `10` | Points per spline knot |
|
|
241
|
+
| `--degree` | `-d` | `3` | Spline degree (1-5) |
|
|
242
|
+
| `--n-scan` | `-n` | `200` | Scan resolution for x₀ search |
|
|
243
|
+
| `--x0-window` | `-W` | `0.1` | Scan window as fraction of x-range |
|
|
244
|
+
| `--parabola-window` | `-P` | `0.05` | Fit window for polynomial refinement, as fraction of scan range |
|
|
245
|
+
| `--n-bootstrap` | `-b` | `60` | Bootstrap iterations |
|
|
246
|
+
| `--n-scan-boot` | `-B` | `80` | Scan resolution per bootstrap iteration |
|
|
247
|
+
| `--seed` | `-s` | (none) | Random seed for reproducibility |
|
|
248
|
+
| `--output`, `-o` | — | stdout | Output JSON file |
|
|
249
|
+
| `--plot` | `-p` | (none) | Save 4-panel plot to file |
|
|
250
|
+
| `--plot-format` | `-F` | `png` | `png`, `pdf`, `svg` |
|
|
251
|
+
|
|
252
|
+
**Output YAML (default) includes:**
|
|
253
|
+
|
|
254
|
+
```yaml
|
|
255
|
+
x0: 94.86194335135798
|
|
256
|
+
x0_std: 0.17109769482858908
|
|
257
|
+
x0_lo: 94.70813527584849
|
|
258
|
+
x0_hi: 95.06582529422745
|
|
259
|
+
sigma_min: 0.013983038037592096
|
|
260
|
+
n_points: 120
|
|
261
|
+
n_bootstrap: 60
|
|
262
|
+
utc_time: '2026-08-08T22:14:03Z'
|
|
263
|
+
utc_uncertainty_s: 10.265861689715345
|
|
264
|
+
input_file: tests/fixtures/V500_Peg_2461261_2026-08-08_G.aavso.txt
|
|
265
|
+
time_format: iso
|
|
266
|
+
parameters:
|
|
267
|
+
pts_per_knot: 10
|
|
268
|
+
degree: 3
|
|
269
|
+
n_scan: 200
|
|
270
|
+
x0_window: 0.1
|
|
271
|
+
parabola_window: 0.05
|
|
272
|
+
n_bootstrap: 60
|
|
273
|
+
n_scan_boot: 80
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
Use `--format json` for JSON output (e.g., for scripting).
|
|
277
|
+
|
|
278
|
+
The CLI handles:
|
|
279
|
+
- AAVSO extended format (comments, header in `#NAME,DATE-OBS,...` line)
|
|
280
|
+
- Time formats: `iso` (DATE-OBS→minutes + UTC), `jd`
|
|
281
|
+
- Magnitudes used directly on the logarithmic scale (the eclipse is a *maximum*
|
|
282
|
+
of the magnitude light curve; the algorithm runs with `find_peak=True`)
|
|
283
|
+
- Weights from `MAG_ERR`
|
|
284
|
+
- `--seed` for reproducible bootstrap
|
|
285
|
+
|
|
286
|
+
## API Reference
|
|
287
|
+
|
|
288
|
+
### Core functions
|
|
289
|
+
|
|
290
|
+
```python
|
|
291
|
+
from reflection_method import (
|
|
292
|
+
fit_spline, # Fit LSQ spline to data
|
|
293
|
+
find_x0, # Scan x0 to minimize σ₂
|
|
294
|
+
refine_x0_minimum, # Local polynomial refinement of the σ₂ minimum
|
|
295
|
+
prepare_plot_data, # Intermediate arrays for plot_all
|
|
296
|
+
bootstrap_x0, # Residual bootstrap uncertainty
|
|
297
|
+
find_minimum, # Full pipeline
|
|
298
|
+
MinimumResult, # Result container
|
|
299
|
+
)
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
### Result type
|
|
303
|
+
|
|
304
|
+
```python
|
|
305
|
+
MinimumResult(
|
|
306
|
+
x0: float, # reflection point (input units)
|
|
307
|
+
x0_std: float, # bootstrap std (input units)
|
|
308
|
+
x0_lo: float, # 16th percentile (input units)
|
|
309
|
+
x0_hi: float, # 84th percentile (input units)
|
|
310
|
+
sigma_min: float, # minimum σ₂
|
|
311
|
+
n_points: int, # data points used
|
|
312
|
+
n_bootstrap: int, # bootstrap iterations
|
|
313
|
+
)
|
|
314
|
+
```
|
|
315
|
+
|
|
316
|
+
### Plotting (optional `[plot]` extra)
|
|
317
|
+
|
|
318
|
+
```python
|
|
319
|
+
from reflection_method.plot import plot_all, plot_original_spline, plot_scan
|
|
320
|
+
|
|
321
|
+
fig = plot_all(
|
|
322
|
+
x, y, spl1, xr, spl2,
|
|
323
|
+
x0_opt, x0_std,
|
|
324
|
+
x0_grid, sigma2, spl_sigma, x0_boot,
|
|
325
|
+
xlabel="Time", ylabel="magnitude", x_unit="min", invert_y=True
|
|
326
|
+
)
|
|
327
|
+
fig.savefig("output.png", dpi=150, bbox_inches="tight")
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
`invert_y=True` shows the magnitude axis with brighter stars on top, the
|
|
331
|
+
standard convention. Pass `find_peak=True` to `find_minimum` when working
|
|
332
|
+
with magnitudes (eclipse = maximum of the light curve).
|
|
333
|
+
|
|
334
|
+
### Reproducibility
|
|
335
|
+
|
|
336
|
+
Pass `rng=np.random.default_rng(seed)` to `find_minimum` or `bootstrap_x0`.
|
|
337
|
+
|
|
338
|
+
## Requirements
|
|
339
|
+
|
|
340
|
+
- Python ≥ 3.10
|
|
341
|
+
- numpy ≥ 1.24
|
|
342
|
+
- scipy ≥ 1.10
|
|
343
|
+
|
|
344
|
+
Optional:
|
|
345
|
+
- matplotlib ≥ 3.7 (`[plot]` extra)
|
|
346
|
+
- click ≥ 8.1 (`[cli]` extra)
|
|
347
|
+
|
|
348
|
+
|
|
349
|
+
|
|
350
|
+
## Release Process
|
|
351
|
+
|
|
352
|
+
Releases are automated via GitHub Actions:
|
|
353
|
+
|
|
354
|
+
1. Tag a release: `git tag v0.2.1 && git push origin v0.2.1`
|
|
355
|
+
2. GitHub Actions:
|
|
356
|
+
- Builds the package
|
|
357
|
+
- Publishes to PyPI via [trusted publishing](https://docs.pypi.org/trusted-publishers/) (no API tokens needed)
|
|
358
|
+
- Creates a GitHub Release with auto-generated changelog
|
|
359
|
+
3. The release appears on [PyPI](https://pypi.org/project/reflection-method/) and [GitHub Releases](https://github.com/jochym/reflection-method/releases)
|
|
360
|
+
|
|
361
|
+
The workflow uses [trusted publishing](https://docs.pypi.org/trusted-publishers/) - no API tokens needed.
|
|
362
|
+
|
|
363
|
+
## License
|
|
364
|
+
|
|
365
|
+
GNU General Public License v3.0 or later (GPL-3.0-or-later). See [LICENSE](LICENSE).
|
|
366
|
+
|
|
367
|
+
## Changelog
|
|
368
|
+
|
|
369
|
+
See [CHANGELOG.md](CHANGELOG.md) for API and behaviour changes in 0.2.1,
|
|
370
|
+
including a migration checklist for dependent projects.
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
reflection_method/__init__.py,sha256=NQzE7KnxxhnLS5IHK0W9kznKQKC5ixoh6GtcsdBt6OU,1075
|
|
2
|
+
reflection_method/cli.py,sha256=pfG3fNtPmguXNtZkTo1Ma9tnrNK33LRXp-Gbgswa80k,8042
|
|
3
|
+
reflection_method/core.py,sha256=JnVModf1wA6dQHRXwwb6LCEKDK5v2Ah-2R4T3z_X-Yk,32037
|
|
4
|
+
reflection_method/io.py,sha256=kMtWBbN-8AmVJfM3VZqg6dadQam8UPEBUgqg6KsW5WM,7325
|
|
5
|
+
reflection_method/plot.py,sha256=-ouEV-p6Rr8vVB-WlrN3KWp9uHb5jkON8GmawDOQQe0,18449
|
|
6
|
+
reflection_method/result.py,sha256=NcmRU11JX0XjjH3wS2Y_Da1E_WtoNBUBH2bA1JUA-Go,4942
|
|
7
|
+
reflection_method-0.3.0.dist-info/licenses/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
|
|
8
|
+
reflection_method-0.3.0.dist-info/METADATA,sha256=Y65NJ81dMMBJrUq1kLZuHnkfssDBNk-7U_nPp_14w9s,13632
|
|
9
|
+
reflection_method-0.3.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
|
|
10
|
+
reflection_method-0.3.0.dist-info/entry_points.txt,sha256=eGMlpYAPEkJVtmJ8y5fS7tSq9M3AwpaC_vd0I1BdAas,65
|
|
11
|
+
reflection_method-0.3.0.dist-info/top_level.txt,sha256=_TsrnJ4jIX92BTKMxODRBn0YdTRtWbv4O0sEk5Oj8E4,18
|
|
12
|
+
reflection_method-0.3.0.dist-info/RECORD,,
|