HEN2xspec cannot handle Lomb-Scargle spectra

Aperta
#197 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

@aviralgarg05 ci sta già lavorando.

Dal 8/11/2026.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
55/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
python
Ambito
cli, data

Direzione di ricerca

Inizia in hendrics/save_as_xspec.py dalla gestione di df, power_err e time_lag, quindi confronta il ramo lag in hendrics/timelags.py. Controlla hendrics/io.py:845 per capire il tipo di spettro incrociato Lomb-Scargle ricaricato. Il lavoro è completato quando HEN2xspec elabora questi file con un comportamento definito per la colonna degli errori e il lag, oppure li rifiuta con un messaggio chiaro, mantenendo la gestione degli input esistente.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

bug

HENfspec --lombscargle produces LombScarglePowerspectrum / LombScargleCrossspectrum
objects. HEN2xspec accepts those files (get_file_type maps them to pds/cpds) but
cannot process them, because the Lomb-Scargle classes do not carry the attributes
save_as_xspec reads.

Reproduction

from stingray import Lightcurve
from stingray.lombscargle import LombScargleCrossspectrum
from hendrics.io import save_pds
from hendrics.save_as_xspec import save_as_xspec

# ... build lc1, lc2 ...
save_pds(LombScargleCrossspectrum(lc1, lc2), "ls_cpds.nc")
save_as_xspec("ls_cpds.nc")
TypeError: unsupported operand type(s) for /: 'NoneType' and 'int'

Three separate causes

  1. df is None. hendrics/save_as_xspec.py:37-38 does
    contents.freq - contents.df / 2. The Lomb-Scargle classes never set df, in memory
    or after a HENDRICS save/load round trip. This is the error above.

  2. power_err is None. Line 41 (contents.power_err.real) fails next, for the same
    reason.

  3. time_lag() returns a bare array, not a pair. Line 50 does
    lags, lags_err = contents.time_lag(). That is correct for
    AveragedCrossspectrum, which returns (lag, lag_err), but
    Crossspectrum.time_lag() and LombScargleCrossspectrum.time_lag() return the lags
    alone — there is no ensemble of segments to take an uncertainty from. With df and
    power_err patched in, this raises ValueError: too many values to unpack (expected 2).

    Note that hendrics/io.py:845 reconstructs a saved LombScargleCrossspectrum as a
    plain Crossspectrum (it matches on the substring "Crossspectrum"), so the reloaded
    object is in the no-error-bars branch either way.

HENlags already handles cause 3 correctly and works on these files.

Possible fix

  • Derive df from np.median(np.diff(freq)) when it is None.
  • Decide what to write in the error column when power_err is absent — refuse with a
    clear message, or write zeros, or compute something meaningful.
  • Guard the lag unpacking with isinstance(lag, tuple), as hendrics/timelags.py does.

Alternatively, refuse Lomb-Scargle input in HEN2xspec with an explicit error message,
which is at least honest.

Lingua principale
Jupyter Notebook
Stelle
26
Fork
18
Merge medio
1h 26m
PR unite (30g)
2

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di StingraySoftware/HENDRICS

Tutte le issue di StingraySoftware/HENDRICS

Issue simili

Altre issue su CLI

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.