Package: untrendy
In an age where studying exoplanets is just the hippest thing ever, sometimes
it’s good to step out of line and be a little untrendy! This library is a set
of hacks that can robustly remove the out-of-transit trends in light curve
data.InstallationUntrendydepends onnumpyandscipyso make sure that you install
those first. Then, you can install usingpip:pip install untrendyUsageUntrendyis really complicated. It has approximatelyonefunction and
about200 lines of code (including documentation). It mostly runs on love
and magic (more complete details are given below if you want).Let’s say that you have a light curve with time samplest, flux
measurementsfand uncertaintiessigma. You can simply run:importuntrendyf_detrend,sigma_detrend=untrendy.untrend(t,f,sigma)to find a robust estimate of the global trends of the time series and remove
it. The default settings are tuned to work well for finding the
“out-of-transit” trends in Kepler data but a detailed description of the
options is listed below. You can also just fit for the trends and get a
callable representation of the trend:trend=untrendy.fit_trend(t,f,ferr)In this case, you can find the background level at some timet0by calling
the function:bkg=trend(t0)NotesThe spline sometimes goes to hell in regions where you don’t have any
samples so be careful with that.This whole procedure introduces correlated errors. You’ve been warned.Command Line UntrendingThere is also the option of usingUntrendyfrom the command line if you
don’t want to bother with all the Python stuff. If you have a whitespace
separated ASCII file containing your light curve, you can de-trend it by
running:untrend /path/to/data.txtThe code will assume that your file has 2 or 3 columns with time, flux and
(optionally) uncertainties for each observation. Then, the de-trended light
curve will be written to standard out in the same format. Alternatively, the
same program can read the data right from standard in:cat /path/to/data.txt | untrendThis gives you the option of doing something crazy and then piping it all
UNIX-like. Personally, I would just use Python.APIFit the trenduntrendy.fit_trend(x,y,yerr=None,Q=12,dt=3.0,tol=0.00125,maxiter=15,fill_times=None,maxditer=4,nfill=4)Use iteratively re-weighted least squares to fit a spline to the
out-of-transit trends in a time series. The input data should be “clean”.
In other words, bad data should be masked and it often helps to normalize
the fluxes (by the median or something).Parametersx:The sampled times.y:The fluxes corresponding to the times inx.yerr:(optional) The 1-sigma error bars ony.Q:(optional) The parameter controlling the severity of the
re-weighting.dt:(optional) The initial spacing between time control
points.tol:(optional) The convergence criterion.maxiter:(optional) The maximum number of re-weighting iterations
to run.fill_times:(optional) If provided, this number sets the minimum time
spacing between adjacent samples that is acceptable. If
the spacing is larger, knots will be added to fill in
the gap.maxditer:(optional) The maximum number of discontinuity search
iterations to run.nfill:(optional) The number of knots to use to fill in the
gaps.Returnstrend:A callable representation of the trend.Remove the trenduntrendy.untrend(x,y,yerr=None,**kwargs)Use iteratively re-weighted least squares to remove the out-of-transit
trends in a light curve. Unlikefit_trend, this function masks bad
data (NaN) and normalizes the data before fitting.Parametersx:The sampled times.y:The fluxes corresponding to the times inx.yerr:(optional) The 1-sigma error bars ony.**kwargs:(optional) Other arguments passed to thefit_trendfunction.Returnsflux:The de-trended relative fluxes.ferr:The de-trended uncertainties onflux.