local variable 'tsOut' referenced before assignment when using own arrays for lightcurve data
warrickball opened this issue · 2 comments
The following snippet
import numpy as np
import pbjam
t = np.arange(1000.)
y = np.sin(t/10.)
s = pbjam.session(ID='tsOut_error', timeseries=[t, y],
numax=(240.0, 10.0), dnu=(20.0, 0.2),
teff=(5000, 100), bp_rp=(1.0, 0.02))
s(make_plots=True)
produces the error
Checkpoint exception raise
/home/wball/.local/lib/python3.7/site-packages/statsmodels/tools/_testing.py:19: FutureWarning: pandas.util.testing is deprecated. Use the functions in the public API at pandas.testing instead.
import pandas.util.testing as tm
Traceback (most recent call last):
File "tsOut_error.py", line 8, in <module>
teff=(5000, 100), bp_rp=(1.0, 0.02))
File "/home/wball/pypi/PBjam/pbjam/session.py", line 579, in __init__
lkwargs)
File "/home/wball/pypi/PBjam/pbjam/session.py", line 356, in _lc_to_lk
if tsOut:
UnboundLocalError: local variable 'tsOut' referenced before assignment
It looks like the problem is that this option hasn't been implemented in session._lc_to_lk
. The main block looks like this (starting at line 332):
if isinstance(tsIn, str):
try:
t, d = np.genfromtxt(tsIn, usecols=(0, 1), delimiter = ',').T
except:
try:
t, d = np.genfromtxt(tsIn, usecols=(0, 1), delimiter = ' ').T
except:
raise IOError('Failed to read the provided ascii files. Please check that they have the required 2-column format, and they are use either comma or white-space delimiters.')
d += tinyoffset
tsOut = lk.LightCurve(time=t, flux=d, targetid=ID)
elif not tsIn:
if specIn:
pass
else:
tsOut = _query_lightkurve(ID, download_dir, use_cached, lkwargs)
elif tsIn.__module__ == lk.lightcurve.__name__:
pass
else:
raise TypeError("Can't handle this type of time series object")
if tsOut:
_sort_lc(tsOut)
return tsOut
I checked the type of tsIn
in my snippet and it should be caught by tsIn.__module__ == lk.lightcurve.__name__
but that just leads to pass
, so tsOut
is never set. Because it isn't implemented, I thought it would've been left for the else
clause to raise a TypeError
but maybe someone intended to work on it.
I've honestly gone cross-eyed with all the wrapping in DataFrame and LightCurve objects so I'm not sure what's meant to happen. Maybe just return tsIn
?
Yup, that elif line just asks if what was given is a lightkurve time series. In which case it should have just been returned. It should be passed to _sort_lc(tsOut) first though, as it does some sigma clipping and flattening if I remember correctly, so replacing pass with tsIn=tsOut should fix this issue.
tsOut = tsIn
has worked for me.