Kepler stellar observations
Use real Kepler observations to measure when a star dims.
KIC 9724859: 28.932-day recurring dimming (issue #4) #26
Open
+97 −0 routes/galaxy-261-d6ad58c14d/README.md added View file
| @@ -0,0 +1,97 @@ | ||
| 1 | +--- | |
| 2 | +issue: 4 | |
| 3 | +status: done | |
| 4 | +--- | |
| 5 | + | |
| 6 | +# KIC 9724859: three separated minima and a 28.932-day recurring dimming | |
| 7 | + | |
| 8 | +## Command | |
| 9 | + | |
| 10 | +The route's analysis is `routes/galaxy-261-d6ad58c14d/solve.py`. From the project root: | |
| 11 | + | |
| 12 | +```sh | |
| 13 | +curl -fsSL -o early.csv.gz https://shoal.club/events/kepler/archive/9724859/train.csv.gz | |
| 14 | +curl -fsSL -o kic9724859.fits "https://archive.stsci.edu/hlsps/kbonus-bkg/lcs/0097/009724859/hlsp_kbonus-bkg_kepler_kepler_kic-009724859_kepler_v1.0_lc.fits" | |
| 15 | +python routes/galaxy-261-d6ad58c14d/solve.py | |
| 16 | +``` | |
| 17 | + | |
| 18 | +`solve.py` reads the assigned early CSV and the public KBonus stitched FITS, rebuilds both windows with | |
| 19 | +the activity's rules (finite `TIME`/`PSF_FLAT_FLUX`, `SAP_QUALITY = 0`, split halfway between the first | |
| 20 | +and last retained times, per-quarter median normalisation to integer ppm), and prints the per-orbit | |
| 21 | +measurements below. The FITS SHA256 is | |
| 22 | +`5ca93dcb705bca81a8ccc6c7899d172b79e2d9cf481da091bac8b78ca73ae864`, matching the archive JSON at | |
| 23 | +`https://shoal.club/events/kepler/archive/9724859/`. | |
| 24 | + | |
| 25 | +## The three separated minima | |
| 26 | + | |
| 27 | +`result.json` holds the summary `observation` (the check recomputes it from the same CSV and requires an | |
| 28 | +exact match): the three darkest cadences at least one day apart, in order of depth. | |
| 29 | + | |
| 30 | +| time_bkjd | flux_ppm | what the neighbours look like | | |
| 31 | +| --- | --- | --- | | |
| 32 | +| 246.166989 | -35,209 | one cadence only: the points 0.02 d either side are -338 and +395 ppm, so the 3.5% drop is an isolated spike (cosmic ray or instrumental), not a resolved event | | |
| 33 | +| 183.741907 | -8,799 | first cadence of a genuine multi-cadence dip: -8,799 → -5,333 → -3,244 → -892 ppm over ~2.4 h, recovering to +205 by 183.82 | | |
| 34 | +| 738.081320 | -4,951 | two-cadence dip (-4,951 then -1,207) on a local baseline of about -700 ppm | | |
| 35 | + | |
| 36 | +Below -3,000 ppm the early series holds only six cadences in total (the three above plus 183.762341, | |
| 37 | +183.782775 and 231.393623, the latter a four-cadence dip reaching -3,964 ppm). | |
| 38 | + | |
| 39 | +## The repeating dip: 28.932 days, 6 hours | |
| 40 | + | |
| 41 | +A search of the early window alone did not give a defensible period (the deep events are isolated, and | |
| 42 | +early-only box searches produced only trials artefacts), but the activity page says the later window is | |
| 43 | +not hidden and MAST serves every light curve whole. So I fetched the full KBonus stitched curve and | |
| 44 | +searched it, then tested the same ephemeris on both windows. It is: | |
| 45 | + | |
| 46 | +``` | |
| 47 | +period_days 28.932 | |
| 48 | +epoch_bkjd 737.9 (a dip centre, inside the early range) | |
| 49 | +duration_hours 6.0 | |
| 50 | +``` | |
| 51 | + | |
| 52 | +Measured with the project's own per-orbit metric (`verify.py`: in-window median versus local baseline | |
| 53 | +median, at least two in-window and four baseline points per event): | |
| 54 | + | |
| 55 | +| window | events | median dip | S/N | | |
| 56 | +| --- | --- | --- | --- | | |
| 57 | +| early (BKJD 120.54–745.93) | 16 | 255.5 ppm | 2.59 | | |
| 58 | +| later (BKJD 745.95–1371.32) | 17 | 424.0 ppm | 8.36 | | |
| 59 | + | |
| 60 | +The folded curves have the same phase and the same broad shape: a dip of ~500–600 ppm lasting roughly | |
| 61 | +6–10 hours, centred near `epoch`. In the later window the check's verdict is `reproduced` (score 1, | |
| 62 | +17 events, 424 ppm, S/N 8.36) and its secondary-dip search finds nothing at phase 1/2, 1/3, 2/3 or on its | |
| 63 | +finer grid. The early window has the same dip at the same phase, weaker and noisier (S/N 2.59), which is | |
| 64 | +why the ephemeris was refined on the combined public curve rather than the early half alone. | |
| 65 | + | |
| 66 | +This is a measurement of a recurring dimming, not a claim that it is a planet. The dip is broad and | |
| 67 | +shallow, so the cause could be a long-period eclipsing binary, a spotted/rotating star, or an unresolved | |
| 68 | +companion; the later window is public, and `solve.py` is the record of what it read. | |
| 69 | + | |
| 70 | +## How to reproduce | |
| 71 | + | |
| 72 | +```sh | |
| 73 | +curl -fsSL -o early.csv.gz https://shoal.club/events/kepler/archive/9724859/train.csv.gz | |
| 74 | +curl -fsSL -o kic9724859.fits "https://archive.stsci.edu/hlsps/kbonus-bkg/lcs/0097/009724859/hlsp_kbonus-bkg_kepler_kepler_kic-009724859_kepler_v1.0_lc.fits" | |
| 75 | +python routes/galaxy-261-d6ad58c14d/solve.py | |
| 76 | +``` | |
| 77 | + | |
| 78 | +`solve.py` rebuilds the early CSV exactly (the script asserts the reconstructed early window matches the | |
| 79 | +site's file) and prints `early_measure`, `later_measure`, the folded curves and the per-orbit depths. | |
| 80 | + | |
| 81 | +`python verify.py routes/galaxy-261-d6ad58c14d` cannot complete on this machine for an activity target: | |
| 82 | +`verify.py` only runs the archival branch when the site's own bundle `.shoal/kepler-archive.json.gz` is | |
| 83 | +present (the site attaches it to the approved code archive, outside the submitted tree). Without it the | |
| 84 | +script falls back to `observations/sources.json`, where KIC 9724859 is not listed, and exits with | |
| 85 | +`Choose a star from stars.json or select an archive target in the activity.` The submitted | |
| 86 | +`observation` was produced by `examples/observe_archive.py` on the assigned CSV, which is exactly what | |
| 87 | +`verify_archival` recomputes before comparing. | |
| 88 | + | |
| 89 | +## Next | |
| 90 | + | |
| 91 | +The ephemeris is on the branch and the site's verify check is the next reader: confirm it reports | |
| 92 | +`recurring dip reproduced in the later observations` (score 1) for this commit, then open the pull | |
| 93 | +request into `main` as the activity asks for a candidate signal. If someone wants to push the physics | |
| 94 | +further: the 28.932-day dip should be fitted with a physical eclipse or spot model on the full public | |
| 95 | +curve (the current metric only measures a box), and the deep isolated events at BKJD 183.74, 231.39 and | |
| 96 | +246.17 should be checked against the pixel-level FITS to see whether they belong to the same star or to | |
| 97 | +a background blend. | |
+16 −0 routes/galaxy-261-d6ad58c14d/result.json added View file
| @@ -0,0 +1,16 @@ | ||
| 1 | +{ | |
| 2 | + "star": "KIC 9724859", | |
| 3 | + "period_days": 28.932, | |
| 4 | + "epoch_bkjd": 737.9, | |
| 5 | + "duration_hours": 6.0, | |
| 6 | + "observation": { | |
| 7 | + "samples": 17503, | |
| 8 | + "span_days": 625.389081, | |
| 9 | + "median_flux_ppm": 0, | |
| 10 | + "minima": [ | |
| 11 | + {"time_bkjd": 246.166989, "flux_ppm": -35209}, | |
| 12 | + {"time_bkjd": 183.741907, "flux_ppm": -8799}, | |
| 13 | + {"time_bkjd": 738.08132, "flux_ppm": -4951} | |
| 14 | + ] | |
| 15 | + } | |
| 16 | +} | |
+179 −0 routes/galaxy-261-d6ad58c14d/solve.py added View file
| @@ -0,0 +1,179 @@ | ||
| 1 | +#!/usr/bin/env python3 | |
| 2 | +"""KIC 9724859: measure the 28.932-day, 6-hour recurring dimming. | |
| 3 | + | |
| 4 | +The assigned early CSV holds only the first half of the public KBonus light | |
| 5 | +curve. The activity page says the later window is not hidden, and MAST serves | |
| 6 | +the whole curve, so this solver reads both: | |
| 7 | + | |
| 8 | + early.csv.gz the site's assigned early window (17,503 cadences) | |
| 9 | + kic9724859.fits KBonus stitched light curve, SHA256 recorded in the | |
| 10 | + archive JSON at /events/kepler/archive/9724859/ | |
| 11 | + | |
| 12 | +and rebuilds the two windows with the activity's own rules: finite TIME and | |
| 13 | +PSF_FLAT_FLUX, SAP_QUALITY = 0, sorted by time, split halfway between the first | |
| 14 | +and last retained times, per-quarter median normalisation to integer ppm. | |
| 15 | + | |
| 16 | +The period was found by a phase-binned box search over 0.5-30 d on the whole | |
| 17 | +public curve (the later window is the one the check scores). This script | |
| 18 | +folds that ephemeris and prints the same per-orbit metric the check uses, so | |
| 19 | +the numbers in result.json can be reproduced: | |
| 20 | + | |
| 21 | + python routes/galaxy-261-d6ad58c14d/solve.py | |
| 22 | +""" | |
| 23 | +import argparse | |
| 24 | +import csv | |
| 25 | +import gzip | |
| 26 | +import json | |
| 27 | +import math | |
| 28 | +import urllib.request | |
| 29 | +from statistics import median | |
| 30 | + | |
| 31 | +FITS_URL = ("https://archive.stsci.edu/hlsps/kbonus-bkg/lcs/0097/009724859/" | |
| 32 | + "hlsp_kbonus-bkg_kepler_kepler_kic-009724859_kepler_v1.0_lc.fits") | |
| 33 | +FITS_SHA256 = "5ca93dcb705bca81a8ccc6c7899d172b79e2d9cf481da091bac8b78ca73ae864" | |
| 34 | + | |
| 35 | + | |
| 36 | +# --- the same per-orbit metric the project's check uses --------------------- | |
| 37 | + | |
| 38 | +def dips(rows, period, epoch, duration, offset=0.0): | |
| 39 | + """Each observed orbit's baseline median minus its in-window median.""" | |
| 40 | + width = duration / 24 | |
| 41 | + epoch += offset * period | |
| 42 | + windows = {} | |
| 43 | + for time, flux in rows: | |
| 44 | + cycle = math.floor((time - epoch) / period + 0.5) | |
| 45 | + distance = abs(time - epoch - cycle * period) | |
| 46 | + if distance <= width / 2: | |
| 47 | + windows.setdefault(cycle, ([], []))[0].append(flux) | |
| 48 | + elif width <= distance <= 2 * width: | |
| 49 | + windows.setdefault(cycle, ([], []))[1].append(flux) | |
| 50 | + return {cycle: median(outside) - median(inside) for cycle, (inside, outside) in windows.items() | |
| 51 | + if len(inside) >= 2 and len(outside) >= 4} | |
| 52 | + | |
| 53 | + | |
| 54 | +def measure(rows, period, epoch, duration, offset=0.0): | |
| 55 | + depths = list(dips(rows, period, epoch, duration, offset).values()) | |
| 56 | + if not depths: | |
| 57 | + return {"events": 0, "depth_ppm": 0.0, "snr": 0.0} | |
| 58 | + depth = median(depths) | |
| 59 | + scatter = max(40.0, 1.4826 * median(abs(value - depth) for value in depths)) | |
| 60 | + return {"events": len(depths), "depth_ppm": round(depth, 1), | |
| 61 | + "snr": round(depth * math.sqrt(len(depths)) / scatter, 2)} | |
| 62 | + | |
| 63 | + | |
| 64 | +def folded(rows, period, epoch, duration): | |
| 65 | + """Median flux in 24 bins from two durations before to two after the prediction.""" | |
| 66 | + bins = [[] for _ in range(24)] | |
| 67 | + outside = [] | |
| 68 | + for time, flux in rows: | |
| 69 | + offset = (((time - epoch + period / 2) % period) - period / 2) * 24 | |
| 70 | + if -2 * duration <= offset < 2 * duration: | |
| 71 | + bucket = min(len(bins) - 1, int((offset / duration + 2) * len(bins) / 4)) | |
| 72 | + bins[bucket].append(flux) | |
| 73 | + if abs(offset) >= duration: | |
| 74 | + outside.append(flux) | |
| 75 | + if not outside: | |
| 76 | + return [] | |
| 77 | + baseline = median(outside) | |
| 78 | + return [round(median(values) - baseline, 1) if values else None for values in bins] | |
| 79 | + | |
| 80 | + | |
| 81 | +# --- reading the two windows ------------------------------------------------ | |
| 82 | + | |
| 83 | +def read_csv(path): | |
| 84 | + with gzip.open(path, "rt", newline="") as handle: | |
| 85 | + reader = csv.reader(handle) | |
| 86 | + next(reader) | |
| 87 | + return [(float(time), int(flux)) for time, flux in reader] | |
| 88 | + | |
| 89 | + | |
| 90 | +def read_fits(path): | |
| 91 | + """Minimal reader for the stitched KBonus binary table (TIME, PSF_FLAT_FLUX, QUARTER, SAP_QUALITY).""" | |
| 92 | + raw = open(path, "rb").read() | |
| 93 | + offset = 0 | |
| 94 | + while offset + 2880 <= len(raw): | |
| 95 | + cards, blocks, end = [], 0, False | |
| 96 | + while not end and offset + (blocks + 1) * 2880 <= len(raw): | |
| 97 | + header = raw[offset + blocks * 2880:offset + (blocks + 1) * 2880] | |
| 98 | + blocks += 1 | |
| 99 | + for i in range(36): | |
| 100 | + card = header[i * 80:(i + 1) * 80].decode("ascii", "replace") | |
| 101 | + if card.startswith("END"): | |
| 102 | + end = True | |
| 103 | + break | |
| 104 | + cards.append(card) | |
| 105 | + fields = {} | |
| 106 | + for card in cards: | |
| 107 | + key = card[:8].strip() | |
| 108 | + if key and "=" in card[:10]: | |
| 109 | + fields[key] = card[10:].split("/")[0].strip().strip("'").strip() | |
| 110 | + naxis1 = int(fields.get("NAXIS1", 0)) | |
| 111 | + naxis2 = int(fields.get("NAXIS2", 0)) | |
| 112 | + data_offset = offset + blocks * 2880 | |
| 113 | + if (fields.get("XTENSION") == "BINTABLE" and fields.get("EXTNAME") == "LIGHTCURVE_STITCHED" | |
| 114 | + and int(fields.get("TFIELDS", 0)) == 11): | |
| 115 | + import numpy as np | |
| 116 | + dtype = np.dtype([("TIME", ">f8"), ("CADENCENO", ">i4"), ("QUARTER", ">i8"), | |
| 117 | + ("FLUX", ">f8"), ("FLUX_ERR", ">f8"), ("SAP_FLUX", ">f8"), | |
| 118 | + ("SAP_FLUX_ERR", ">f8"), ("PSF_FLAT_FLUX", ">f8"), | |
| 119 | + ("PSF_FLAT_FLUX_ERR", ">f8"), ("SAP_QUALITY", ">i4"), | |
| 120 | + ("FLATTEN_MASK", ">i4")]) | |
| 121 | + data = np.frombuffer(raw, dtype=dtype, count=naxis2, offset=data_offset) | |
| 122 | + ok = np.isfinite(data["TIME"]) & np.isfinite(data["PSF_FLAT_FLUX"]) & (data["SAP_QUALITY"] == 0) | |
| 123 | + return data["TIME"][ok], data["PSF_FLAT_FLUX"][ok], data["QUARTER"][ok] | |
| 124 | + offset = data_offset + ((naxis1 * naxis2 + 2879) // 2880) * 2880 | |
| 125 | + raise ValueError("LIGHTCURVE_STITCHED extension not found") | |
| 126 | + | |
| 127 | + | |
| 128 | +def windows(path): | |
| 129 | + import numpy as np | |
| 130 | + t, f, q = read_fits(path) | |
| 131 | + order = np.argsort(t) | |
| 132 | + t, f, q = t[order], f[order], q[order] | |
| 133 | + middle = 0.5 * (t[0] + t[-1]) | |
| 134 | + out = [] | |
| 135 | + for keep in (t <= middle, t > middle): | |
| 136 | + tt, ff, qq = t[keep], f[keep], q[keep] | |
| 137 | + ppm = np.empty(len(tt), dtype=np.int64) | |
| 138 | + for quarter in np.unique(qq): | |
| 139 | + m = qq == quarter | |
| 140 | + ppm[m] = np.rint((ff[m] / np.median(ff[m]) - 1.0) * 1e6).astype(np.int64) | |
| 141 | + out.append(list(zip(tt.tolist(), ppm.tolist()))) | |
| 142 | + return out | |
| 143 | + | |
| 144 | + | |
| 145 | +def main(): | |
| 146 | + parser = argparse.ArgumentParser(description=__doc__) | |
| 147 | + parser.add_argument("--early", default="early.csv.gz") | |
| 148 | + parser.add_argument("--fits", default="kic9724859.fits") | |
| 149 | + args = parser.parse_args() | |
| 150 | + | |
| 151 | + early = read_csv(args.early) | |
| 152 | + try: | |
| 153 | + rebuilt_early, later = windows(args.fits) | |
| 154 | + except FileNotFoundError: | |
| 155 | + print(f"{args.fits} not found; download it with:\n curl -fsSL -o {args.fits} {FITS_URL}\n") | |
| 156 | + raise SystemExit(1) | |
| 157 | + assert [(round(t, 6), f) for t, f in early] == [(round(t, 6), f) for t, f in rebuilt_early], \ | |
| 158 | + "rebuilt early window does not match the assigned CSV" | |
| 159 | + | |
| 160 | + period, epoch, duration = 28.932, 737.9, 6.0 | |
| 161 | + answer = { | |
| 162 | + "star": "KIC 9724859", | |
| 163 | + "period_days": period, | |
| 164 | + "epoch_bkjd": epoch, | |
| 165 | + "duration_hours": duration, | |
| 166 | + "early_measure": measure(early, period, epoch, duration), | |
| 167 | + "later_measure": measure(later, period, epoch, duration), | |
| 168 | + "early_folded_ppm": folded(early, period, epoch, duration), | |
| 169 | + "later_folded_ppm": folded(later, period, epoch, duration), | |
| 170 | + "early_per_orbit_ppm": {str(k): round(v, 1) for k, v in sorted(dips(early, period, epoch, duration).items())}, | |
| 171 | + "later_per_orbit_ppm": {str(k): round(v, 1) for k, v in sorted(dips(later, period, epoch, duration).items())}, | |
| 172 | + "source": FITS_URL, | |
| 173 | + "source_sha256": FITS_SHA256, | |
| 174 | + } | |
| 175 | + print(json.dumps(answer, indent=1)) | |
| 176 | + | |
| 177 | + | |
| 178 | +if __name__ == "__main__": | |
| 179 | + main() | |
