Skip to content

Commit

Permalink
pspline now clips in both directions and on the first iteration
Browse files Browse the repository at this point in the history
  • Loading branch information
Gijs Mulders (Laptop) committed Feb 23, 2020
1 parent d1cdebd commit 203e961
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions wotan/pspline.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@ def pspline(time, flux):

newflux = flux.copy()
newtime = time.copy()
detrended_flux = flux.copy()
detrended_flux = flux.copy()/numpy.nanmedian(newflux)

for i in range(constants.PSPLINES_MAXITER):
mask_outliers = numpy.ma.where(
1-detrended_flux < constants.PSPLINES_STDEV_CUT*numpy.std(detrended_flux))
numpy.abs(1-detrended_flux) < constants.PSPLINES_STDEV_CUT*numpy.std(detrended_flux))
newtime, newflux = cleaned_array(newtime[mask_outliers], newflux[mask_outliers])
gam = LinearGAM(s(0, n_splines=constants.PSPLINES_MAX_SPLINES))
search_gam = gam.gridsearch(newtime[:, numpy.newaxis], newflux, progress=False)
trend = search_gam.predict(newtime)
detrended_flux = newflux / trend
stdev = numpy.std(detrended_flux)
mask_outliers = numpy.ma.where(
1-detrended_flux > constants.PSPLINES_STDEV_CUT*numpy.std(detrended_flux))
numpy.abs(1-detrended_flux) > constants.PSPLINES_STDEV_CUT*numpy.std(detrended_flux))
print('Iteration:', i + 1, 'Rejected outliers:', len(mask_outliers[0]))

# Check convergence
Expand All @@ -33,7 +33,7 @@ def pspline(time, flux):
break

# Final iteration, applied to unclipped time series (interpolated over clipped values)
mask_outliers = numpy.ma.where(1-detrended_flux < constants.PSPLINES_STDEV_CUT*stdev)
mask_outliers = numpy.ma.where(numpy.abs(1-detrended_flux) < constants.PSPLINES_STDEV_CUT*stdev)
newtime, newflux = cleaned_array(newtime[mask_outliers], newflux[mask_outliers])
gam = LinearGAM(s(0, n_splines=constants.PSPLINES_MAX_SPLINES))
search_gam = gam.gridsearch(newtime[:, numpy.newaxis], newflux, progress=False)
Expand Down

0 comments on commit 203e961

Please sign in to comment.