def acf(times, yvals): """ computes the autocorrelation function for an evenly-sampled time-series """ cadence = np.median(np.diff(times)) N = len(yvals) max_lag = N / 2 median_yval = np.median(yvals) norm_term = np.sum((yvals - median_yval)**2) lags = np.arange(max_lag) #print median_yval,norm_term,max_lag ACF0 = [ np.sum((yvals[:N - j] - median_yval) * (yvals[j:] - median_yval)) for j in lags ] ACF1 = ACF0 / norm_term # smooth the ACF gauss_kernel = Gaussian1DKernel(18, x_size=55) ACF = ap_convolve(ACF1, gauss_kernel, boundary="extend") #ACF = ACF1 periods = cadence * lags return periods, ACF
def acf(times,yvals): """ computes the autocorrelation function for an evenly-sampled time-series """ cadence = np.median(np.diff(times)) N = len(yvals) max_lag = N/2 median_yval = np.median(yvals) norm_term = np.sum((yvals - median_yval)**2) lags = np.arange(max_lag) #print median_yval,norm_term,max_lag ACF0 = [np.sum((yvals[:N-j] - median_yval)*(yvals[j:] - median_yval)) for j in lags] ACF1 = ACF0/norm_term # smooth the ACF gauss_kernel = Gaussian1DKernel(18,x_size=55) ACF = ap_convolve(ACF1, gauss_kernel,boundary="extend") #ACF = ACF1 periods = cadence*lags return periods,ACF
def calc_sigma(time,flux,flux_err): """ Following McQuillan et al. (2013), determines the standard deviation of the flux by iteratively smoothing the flux and removing outliers, then calculating the standard deviation of the residuals between the smoothed flux and the original flux. """ x,y,yerr = np.float64(time),np.float64(flux),np.float64(flux_err) #print len(x),len(y),len(yerr) bad = (np.isnan(y) | np.isnan(yerr) | np.isnan(x)) good = np.where(bad==False)[0] x,y,yerr = x[good],y[good],yerr[good] #print len(x),len(y),len(yerr) x1,y1,yerr1 = np.copy(x),np.copy(y),np.copy(yerr) # Loop three times, applying a median filter then a boxcar filter before clipping 3-sigma outliers for i in range(1): y_med = medfilt(y1,11) y_boxed = ap_convolve(y_med, Box1DKernel(11),boundary="extend") residuals = y_med - y1 sigma_residuals = np.std(residuals) to_clip = (abs(residuals)>(3*sigma_residuals)) to_keep = np.where(to_clip==False)[0] x1,y1,yerr1 = x1[to_keep],y1[to_keep],yerr1[to_keep] #print len(x1),len(y1),len(yerr1) # After outliers have been removed, apply the smoothing one last time # then determine the residuals from this smoothed curve. y_smoothed1 = medfilt(y1,11) y_smoothed = ap_convolve(y_smoothed1, Box1DKernel(11)) # smoothing screws up the endpoints, which screws up the std(residuals) residuals = (y_smoothed - y1)[10:-10] sigma_res = np.std(residuals) return x,y,yerr,sigma_res
def acf(times,yvals): """ Compute the autocorrelation function for an evenly-sampled time-series Inputs: ------- times: array of epochs/time points yvals: array of fluxes corresponding to times Returns: -------- periods: array of lag times ACF: autocorrelation function corresponding to the lags """ # And the number of observations # (the maximum lag that will be tested is half the number of observations) N = len(yvals) max_lag = N//2 lags = np.arange(max_lag) # Calculate values for normalizing the ACF median_yval = np.median(yvals) norm_term = np.sum((yvals - median_yval)**2) #print median_yval,norm_term,max_lag # Compute the ACF following McQuillan+2013 ACF0 = [np.sum((yvals[:N-j] - median_yval)*(yvals[j:] - median_yval)) for j in lags] ACF1 = ACF0/norm_term # smooth the ACF gauss_kernel = Gaussian1DKernel(18,x_size=55) ACF = ap_convolve(ACF1, gauss_kernel,boundary="extend") #ACF = ACF1 # Compute the lags in index-space to time-space cadence = np.median(np.diff(times)) periods = cadence*lags return periods,ACF
from astropy.convolution import convolve as ap_convolve from astropy.convolution import Box2DKernel box_2D_kernel = Box2DKernel(9) nan = float('nan') data = np.where(data == 0, nan, data) data[:, 0] = nan data[:, -1] = nan data[0, :] = nan data[-1, :] = nan data2 = ap_convolve(data, box_2D_kernel, normalize_kernel=True) plt.clf() dd = data - data2 dd = np.ma.masked_invalid(dd) ddmean = np.mean(dd) ddstd = np.std(dd) dd = dd - ddmean ddcvlo = -ddstd * 2. ddcvhi = +ddstd * 2. ddcvin = (ddcvhi - ddcvlo) / 100. plt.pcolor(dd[:, 0:2500].T, np.arange(ddcvlo, ddcvhi, ddcvin), cmap=plt.cm.get_cmap('Blues'))