TOFFEE
TESS Overlapping Flare Finder and Energy Evaluator — a Python package for detrending TESS and Kepler light curves, detecting stellar flares, and measuring their energies.
TOFFEE's distinguishing feature is that it resolves overlapping and sympathetic flares: where most threshold-based finders return one event, TOFFEE models the decay of the brightest flare and searches the residuals for the fainter ones hidden inside it. That makes flare samples complete down to short waiting times, which is what the waiting-time statistics of magnetic reconnection actually depend on.
Statement of need
Threshold-based flare finders (following Chang, Byun & Hartman 2015) scan a detrended light curve for runs of points above some multiple of the photometric scatter. They work well on isolated events, but two problems limit the samples they produce:
- Overlapping flares are counted once. A flare that begins during the decay of a brighter one is absorbed into its parent. Any measurement of flare waiting times is biased precisely in the regime that distinguishes between models of sympathetic flaring.
- Detrending artefacts and instrumental noise masquerade as flares. Residual red noise left by the detrending step creeps over the detection threshold and inflates the sample at low amplitudes, where most flares live.
TOFFEE addresses the first with a top-down search: it starts at the brightest point, fits a rise and a decay model, and re-runs detection on the residuals to find secondaries. It addresses the second with two complementary purity methods (below). It also derives stellar parameters — spot modulation and rotation — with the flares masked out, so those estimates are not biased by the flares themselves.
Installation
pip install star_toffee
Requires Python 3.8 or newer. Dependencies (numpy, scipy, astropy, astroquery, lightkurve, wotan, pandas, matplotlib, scikit-learn) are installed automatically.
Quickstart
import numpy as np
import toffee
import lightkurve as lk
#grab a TESS 2-minute light curve
lc = lk.search_lightcurve('TIC 441420236', mission = 'TESS', cadence = 120)[0].download()
#detrend first. detect_flares expects a normalised, detrended light curve --
#it does not detrend for you. load_and_flatten also applies the quality filter.
time, flux, flux_err = toffee.load_and_flatten(lc.time.value, lc.flux.value,
lc.flux_err.value, lc.quality.value)
#then detect. the flags were handled above, so switch that step off here
flares = toffee.detect_flares(time, flux, flux_err, np.zeros(len(time)),
flag_values = None)
print(flares)
detect_flares returns a pandas DataFrame, one row per flare:
| Column | Meaning |
|---|---|
T_peak |
time of the flare peak, in days (same scale as the input time) |
T_start, T_end |
flare start and end, in days |
Amplitude |
peak flux above the normalised baseline |
ED |
equivalent duration, in seconds |
Primary_or_Secondary |
whether the flare was found directly, or inside another flare's residuals |
Num_Points |
cadences spanned by the flare |
Num_Abv_Threshold |
cadences above the detection threshold |
Amp_Sigma |
amplitude in units of the photometric scatter |
Most of detect_flares' arguments are tuned defaults. In practice only
primary_threshold, secondary_threshold, num_consec and num_consec_sec are
worth adjusting.
Sample purity
Two independent methods, designed to be used in that order:
Red noise smoothing. Mask the large flares found in a first detection pass, then re-detrend on a short window (~0.075–0.1 d) so the detrending fits around the flares rather than through them. This strips the low-amplitude residual noise that would otherwise clear the threshold.
result = toffee.flatten_detect_smooth(time, flux, flux_err, quality, window = 0.1)
result['first'] #flares before smoothing
result['second'] #flares after
result['dropped'] #first-pass flares the smoothing removed
result['new'] #flares the smoothing revealed
Square index cutting. The square index is flare duration over amplitude. Boxy,
high-SI shapes are usually artefacts rather than flares, so cutting log(SI) >~ 0.6
raises purity.
flares = toffee.add_square_index(flares, cadence = 120) #cadence in SECONDS
clean = toffee.select_by_square_index(flares, log_si_max = 0.6)
Other features
#detrending on its own. flatten's return arity depends on which stages you ask
#for: 3 values with no short_window, 4 with no periodogram, 5 with both
orbit_t, lc_quad, lc_wotan, lc_flat, periodic = toffee.flatten(
time, flux, flux_err, short_window = 0.25, periodogram = [0.1, 10])
#rotation period with the flares masked out, and its false-alarm probability
period, false_alarm = toffee.get_rot_period(time, flux, flux_err)
#plot a detection. takes the same detrended inputs as detect_flares
toffee.visualizer(time, flux, flux_err, np.zeros(len(time)), flag_values = None)
Documentation and tutorials
- Tutorials: TODO — link the rendered notebook series
- API reference: TODO — link the Sphinx site once it is published
Tests
pytest src/toffee/tests/test_toffee.py -q
The suite is hermetic: every light curve is synthetic and seeded, and the detrending tests monkeypatch the FFI-times download, so no network access or TESS data is needed.
Citation
If TOFFEE is useful in your work, please cite TODO — add the JOSS paper once it has a DOI, and the methods paper.
License
MIT. See LICENSE.
Metadata
Release files for star-toffee 1.6.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| star_toffee-1.6.1.tar.gz | 55.6 kB | Without provenance | Details for star_toffee-1.6.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| star_toffee-1.6.1-py3-none-any.whl | Python 3 | none | any | Details for star_toffee-1.6.1-py3-none-any.whl |
Total release size: 112.4 kB
Release files / star_toffee-1.6.1.tar.gz
| Download URL | star_toffee-1.6.1.tar.gz |
|---|---|
| Size | 55.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5ecd2bb225ce199f2185152f1a891a3818927132791d6c166d9de594462e9c0f
|
|
BLAKE2b-256 checksum How to use checksums |
2287219de0ff0122bd8a543a62bb24d5fdcdd238d4d58ead61671489f6283521
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.5
|
Release files / star_toffee-1.6.1-py3-none-any.whl
| Download URL | star_toffee-1.6.1-py3-none-any.whl |
|---|---|
| Size | 56.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
73ee469556cb1ec7c82b9c100421eb5a1e6b5e65c0184117e6f4d7353b82c842
|
|
BLAKE2b-256 checksum How to use checksums |
be16f2509c1466fb2a069cb39e33f211b88bbcbbb4736fc3b8c38bc7da2a5b97
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.5
|
Security for star-toffee 1.6.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.