Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
hippke committed Mar 20, 2020
1 parent bc363fa commit 70ce5de
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 14 deletions.
10 changes: 7 additions & 3 deletions wotan/flatten.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ def flatten(time,
robust=False,
max_splines=constants.PSPLINES_MAX_SPLINES,
return_nsplines=False,
mask=None
mask=None,
verbose=False
):
"""
``flatten`` removes low frequency trends in time-series data.
Expand Down Expand Up @@ -286,8 +287,11 @@ def flatten(time,
elif method == 'rspline':
trend_segment = iter_spline(time_view, flux_view, mask_view, window_length)
elif method == 'pspline':
print('Segment', i + 1, 'of', len(gaps_indexes) - 1)
trend_segment, nsplines_segment = pspline(time_view, flux_view, edge_cutoff, max_splines, return_nsplines)
if verbose:
print('Segment', i + 1, 'of', len(gaps_indexes) - 1)
trend_segment, nsplines_segment = pspline(
time_view, flux_view, edge_cutoff, max_splines, return_nsplines, verbose
)
nsplines = append(nsplines, nsplines_segment)
elif method in "ridge lasso elasticnet":
trend_segment = regression(time_view, flux_view, method, window_length, cval)
Expand Down
13 changes: 7 additions & 6 deletions wotan/pspline.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from wotan.helpers import cleaned_array


def pspline(time, flux, edge_cutoff, max_splines, return_nsplines):
def pspline(time, flux, edge_cutoff, max_splines, return_nsplines, verbose):
try:
from pygam import LinearGAM, s
except:
Expand All @@ -25,11 +25,12 @@ def pspline(time, flux, edge_cutoff, max_splines, return_nsplines):
stdev = np.std(detrended_flux)
mask_outliers = np.ma.where(
np.abs(1-detrended_flux) > constants.PSPLINES_STDEV_CUT*np.std(detrended_flux))
print('Iteration:', i + 1, 'Rejected outliers:', len(mask_outliers[0]))
# Check convergence
if len(mask_outliers[0]) == 0:
print('Converged.')
break
if verbose:
print('Iteration:', i + 1, 'Rejected outliers:', len(mask_outliers[0]))
# Check convergence
if len(mask_outliers[0]) == 0:
print('Converged.')
break

# Final iteration, applied to unclipped time series (interpolated over clipped values)
mask_outliers = np.ma.where(np.abs(1-detrended_flux) < constants.PSPLINES_STDEV_CUT*stdev)
Expand Down
9 changes: 5 additions & 4 deletions wotan/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,19 +431,20 @@ def main():
numpy.testing.assert_almost_equal(numpy.nansum(flatten_lc2), 1948.9000170463796, decimal=1)



print('Detrending 35 (pspline full features)')
flatten_lc, trend_lc, nsplines = flatten(
time,
flux,
method='pspline',
max_splines=100,
edge_cutoff=0.5,
return_trend=True,
return_nsplines=True
return_nsplines=True,
verbose=True
)

print('lightcurve was split into', len(nsplines), 'segments')
print('chosen number of splines', nsplines)
#print('lightcurve was split into', len(nsplines), 'segments')
#print('chosen number of splines', nsplines)
"""
import matplotlib.pyplot as plt
plt.scatter(time, flux, s=3, color='black')
Expand Down
2 changes: 1 addition & 1 deletion wotan/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
WOTAN_VERSIONING = "1.6"
WOTAN_VERSIONING = "1.7"

0 comments on commit 70ce5de

Please sign in to comment.