HEN2xspec cannot handle Lomb-Scargle spectra

Abierto
#197 1 comentario 0 reacciones 0 asignados Ver en GitHub

@aviralgarg05 ya está trabajando en esto.

Desde el 8/11/2026.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
55/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Activo
Stack tecnológico
python
Área
cli, data

Línea de trabajo

Comienza en hendrics/save_as_xspec.py con el manejo de df, power_err y time_lag, y luego compara la rama de lag en hendrics/timelags.py. Comprueba hendrics/io.py:845 para entender el tipo de espectro cruzado Lomb-Scargle recargado. Se considera terminado cuando HEN2xspec procesa estos archivos con un comportamiento definido para la columna de errores y el lag, o los rechaza con un mensaje claro, manteniendo el manejo de entrada existente.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.

Lenguaje dominante
Jupyter Notebook
Estrellas
26
Forks
19
Merge medio
1 h 26 min
PR fusionados (30 d)
2

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de StingraySoftware/HENDRICS

Todos los issues de StingraySoftware/HENDRICS

Issues similares

Más issues de CLI

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.