def newDetrendDataTask(clip): flux = clip['cotrend.flux_frac'] flags = clip['cotrend.flags'] nPoints = clip['config.nPointsForMedianSmooth'] #When you detrend, you must do something about the gaps and bad values. #This is the simplest possible thing. Replace all bad/missing data with #zeros. This is a placehold. Bad data inside a transit is replaced with #a zero, which is not what you want. flux[flags] = 0 #Do a simple detrend. detrend = kplrfits.medianSubtract1d(flux, nPoints) clip['detrend'] = dict() clip['detrend.flux_frac'] = detrend clip['detrend.flags'] = flags clip['detrend.source'] = "Simple Median detrend" rollTweakAmp = noise.computeRollTweakAmplitude(detrend[~flags]) clip['detrend.rollTweakAmp'] = rollTweakAmp cdpp6 = noise.computeSgCdpp_ppm(detrend[~flags]) clip['detrend.cdpp6_ppm'] = cdpp6 perPointScatter = noise.estimateScatterWithMarshallMethod(detrend[~flags]) clip['detrend.perPointScatter_ppm'] = 1e6 * perPointScatter assert (detrend is not None) return clip
def newDetrendDataTask(clip): flux = clip['cotrend.flux_frac'] flags = clip['cotrend.flags'] nPoints = clip['config.nPointsForMedianSmooth'] #When you detrend, you must do something about the gaps and bad values. #This is the simplest possible thing. Replace all bad/missing data with #zeros. This is a placehold. Bad data inside a transit is replaced with #a zero, which is not what you want. flux[flags] = 0 #Do a simple detrend. detrend = kplrfits.medianSubtract1d(flux, nPoints) clip['detrend'] = dict() clip['detrend.flux_frac'] = detrend clip['detrend.flags'] = flags clip['detrend.source'] = "Simple Median detrend" rollTweakAmp = noise.computeRollTweakAmplitude(detrend[~flags]) clip['detrend.rollTweakAmp'] = rollTweakAmp cdpp6 = noise.computeSgCdpp_ppm(detrend[~flags]) clip['detrend.cdpp6_ppm'] = cdpp6 perPointScatter = noise.estimateScatterWithMarshallMethod(detrend[~flags]) clip['detrend.perPointScatter_ppm'] = 1e6*perPointScatter assert(detrend is not None) return clip
def getNoiseParams(lcv): # sigma clip it sigmaClip_tf = noise.sigmaClip(lcv, 5.0) lcv = lcv[~sigmaClip_tf] # get params rta = noise.computeRollTweakAmplitude(lcv) sgcdpp = noise.computeSgCdpp_ppm(lcv) scatter = noise.estimateScatterWithMarshallMethod(lcv) return rta, sgcdpp, scatter
def getNoiseParams(lcv): # sigma clip it sigmaClip_tf = noise.sigmaClip(lcv, 5.) lcv = lcv[~sigmaClip_tf] # get params rta = noise.computeRollTweakAmplitude(lcv) sgcdpp = noise.computeSgCdpp_ppm(lcv) scatter = noise.estimateScatterWithMarshallMethod(lcv) return rta, sgcdpp, scatter
def paramSubplot(cadenceSum, numPrinCompList, results_list): y = cadenceSum / np.mean(cadenceSum) - 1 raw_rta = noise.computeRollTweakAmplitude(y) raw_sgcdpp = noise.computeSgCdpp_ppm(noise.sigmaClip(y, 5.0)) raw_scatter = noise.estimateScatterWithMarshallMethod(y) f, axarr = plt.subplots(3, sharex=True) axarr[0].axhline(raw_rta, label="RTA for raw light curve") axarr[1].axhline(raw_sgcdpp, label="sgcdpp for raw light curve") axarr[2].axhline(raw_scatter, label="scatter for raw light curve") axarr[0].plot(numPrinCompList, results_list.T[1], ".", color="green") axarr[1].plot(numPrinCompList, results_list.T[2], ".", color="green") axarr[2].plot(numPrinCompList, results_list.T[3], ".", color="green") plt.xlabel("Number of Principal Components") axarr[0].set_ylabel("Roll Tweak Amplitude") axarr[1].set_ylabel("sgcdpp") axarr[2].set_ylabel("scatter") plt.show()
def paramSubplot(cadenceSum, numPrinCompList, results_list): y = cadenceSum / np.mean(cadenceSum) - 1 raw_rta = noise.computeRollTweakAmplitude(y) raw_sgcdpp = noise.computeSgCdpp_ppm(noise.sigmaClip(y, 5.)) raw_scatter = noise.estimateScatterWithMarshallMethod(y) f, axarr = plt.subplots(3, sharex=True) axarr[0].axhline(raw_rta, label="RTA for raw light curve") axarr[1].axhline(raw_sgcdpp, label="sgcdpp for raw light curve") axarr[2].axhline(raw_scatter, label="scatter for raw light curve") axarr[0].plot(numPrinCompList, results_list.T[1], ".", color="green") axarr[1].plot(numPrinCompList, results_list.T[2], ".", color="green") axarr[2].plot(numPrinCompList, results_list.T[3], ".", color="green") plt.xlabel("Number of Principal Components") axarr[0].set_ylabel("Roll Tweak Amplitude") axarr[1].set_ylabel("sgcdpp") axarr[2].set_ylabel("scatter") plt.show()
def varyPrinComp(epic, campaign, plotMask): # get the data getData_return = getData(epic, campaign) data = getData_return[0] inds_to_eliminate = getData_return[1].astype(bool) # plot the image # plotCadence(data[0], axis='relative') # create a mask for the light curve mask = createMask(data[0], thresh=0, title="Light Curve Mask", plotMask=plotMask) lcvMatrix = reduceAperture(mask, data) # create a mask for PCA pca_mask = createMask(data[0], thresh=0, title="PCA Mask", plotMask=plotMask) pcaMatrix = reduceAperture(pca_mask, data) # take out data points with thruster firings lcvMatrix = lcvMatrix[:, ~inds_to_eliminate] pcaMatrix = pcaMatrix[:, ~inds_to_eliminate] # get rid of nans in matrices lcvMatrix = noMoreNaN(lcvMatrix) assert checkNaN(lcvMatrix) pcaMatrix = noMoreNaN(pcaMatrix) assert checkNaN(pcaMatrix) # make the raw light curve cadenceSum = np.sum(lcvMatrix, axis=0) t = np.arange(len(cadenceSum)) # plot the raw light curve make_plot(t, cadenceSum, title="Raw Light Curve, e: %s, c: %s" % (epic, campaign)) # make a list of number of principal comps to try numPrinCompList = np.arange(2, np.sum(mask), 2) rta_list = [] sgcdpp_list = [] scatter_list = [] results_list = [] n = 0 offset = 0.1 # plt.figure() for numPrinComps in numPrinCompList: curveFit_return = curveFit(pcaMatrix, cadenceSum, numPrinComps) fittedCurve = curveFit_return[0] # make the mean zero corrected = correctedCurve(cadenceSum, fittedCurve) corrected /= np.mean(corrected) corrected -= 1 sigmaClip_tf = noise.sigmaClip(corrected, 5.0) corrected = corrected[~sigmaClip_tf] rta = noise.computeRollTweakAmplitude(corrected) sgcdpp = noise.computeSgCdpp_ppm(corrected) scatter = noise.estimateScatterWithMarshallMethod(corrected) rta_list.append(rta) sgcdpp_list.append(sgcdpp) scatter_list.append(scatter) results_list.append([numPrinComps, rta, sgcdpp, scatter]) # plt.plot(range(len(corrected)), corrected+ n*offset, ".", markersize=4, label = "%f,%i"%(sgcdpp, int(numPrinComps))) n += 1 # plt.legend() # plt.show() # plot the three params wrt the raw values if plotMask == True: y = cadenceSum / np.mean(cadenceSum) - 1 raw_rta = noise.computeRollTweakAmplitude(y) raw_sgcdpp = noise.computeSgCdpp_ppm(noise.sigmaClip(y, 5.0)) raw_scatter = noise.estimateScatterWithMarshallMethod(y) f, axarr = plt.subplots(3, sharex=True) axarr[0].axhline(raw_rta, label="RTA for raw light curve") axarr[1].axhline(raw_sgcdpp, label="sgcdpp for raw light curve") axarr[2].axhline(raw_scatter, label="scatter for raw light curve") axarr[0].plot(numPrinCompList, rta_list, ".", color="green") axarr[1].plot(numPrinCompList, sgcdpp_list, ".", color="green") axarr[2].plot(numPrinCompList, scatter_list, ".", color="green") plt.xlabel("Number of Principal Components") axarr[0].set_ylabel("Roll Tweak Amplitude") axarr[1].set_ylabel("sgcdpp") axarr[2].set_ylabel("scatter") plt.show() # plot the corrected light curve with the lowest sgcdpp # ============================================================================== # optimalPC = numPrinCompList[np.argmin(sgcdpp_list)] # fittedCurve = curveFit(pcaMatrix, cadenceSum, optimalPC)[0] # optimal_lcv = correctedCurve(cadenceSum, fittedCurve) # make_plot(t, optimal_lcv, title="e: %s, c: %s,sgcdpp=%s PC=%s"%(epic, campaign, # str(np.min(sgcdpp_list)), # numPrinCompList[np.argmin(sgcdpp_list)])) # ============================================================================== # plot the corrected light curve with the smallest slope between sgcdpp values smallest_slope = np.argmin(np.abs(np.diff(sgcdpp_list))) optimalPC = numPrinCompList[smallest_slope] fittedCurve = curveFit(pcaMatrix, cadenceSum, optimalPC)[0] optimal_lcv = correctedCurve(cadenceSum, fittedCurve) sigmaClip_tf = noise.sigmaClip(optimal_lcv, 5.0) make_plot(t, optimal_lcv, show=False) make_plot( t[sigmaClip_tf], optimal_lcv[sigmaClip_tf], new=False, title="e:%s, c:%s, smallest slope, PC=%s" % (epic, campaign, numPrinCompList[smallest_slope]), marker="ro", ) folded = np.fmod(t, 4.16) make_plot(t, folded) # ============================================================================== # # plot the corrected light curve with the lowest rta # plt.figure() # plt.title("epic %s campaign %s lowest rta=%s PC=%s"%(epic, campaign, # str(np.min(rta_list)), # numPrinCompList[np.argmin(rta_list)])) # optimalPC = numPrinCompList[np.argmin(rta_list)] # fittedCurve = curveFit(pcaMatrix, cadenceSum, optimalPC)[0] # optimal_lcv = correctedCurve(cadenceSum, fittedCurve) # plt.plot(range(len(optimal_lcv)), optimal_lcv, ".") # ============================================================================== # plt.show() return np.array(results_list).T
def varyPrinComp(epic, campaign, plotMask): # get the data getData_return = getData(epic, campaign) data = getData_return[0] inds_to_eliminate = getData_return[1].astype(bool) # plot the image #plotCadence(data[0], axis='relative') # create a mask for the light curve mask = createMask(data[0], thresh=0, title="Light Curve Mask", plotMask=plotMask) lcvMatrix = reduceAperture(mask, data) # create a mask for PCA pca_mask = createMask(data[0], thresh=0, title="PCA Mask", plotMask=plotMask) pcaMatrix = reduceAperture(pca_mask, data) # take out data points with thruster firings lcvMatrix = lcvMatrix[:, ~inds_to_eliminate] pcaMatrix = pcaMatrix[:, ~inds_to_eliminate] #get rid of nans in matrices lcvMatrix = noMoreNaN(lcvMatrix) assert checkNaN(lcvMatrix) pcaMatrix = noMoreNaN(pcaMatrix) assert checkNaN(pcaMatrix) # make the raw light curve cadenceSum = np.sum(lcvMatrix, axis=0) t = np.arange(len(cadenceSum)) # plot the raw light curve make_plot(t, cadenceSum, title="Raw Light Curve, e: %s, c: %s" % (epic, campaign)) # make a list of number of principal comps to try numPrinCompList = np.arange(2, np.sum(mask), 2) rta_list = [] sgcdpp_list = [] scatter_list = [] results_list = [] n = 0 offset = 0.1 #plt.figure() for numPrinComps in numPrinCompList: curveFit_return = curveFit(pcaMatrix, cadenceSum, numPrinComps) fittedCurve = curveFit_return[0] # make the mean zero corrected = correctedCurve(cadenceSum, fittedCurve) corrected /= np.mean(corrected) corrected -= 1 sigmaClip_tf = noise.sigmaClip(corrected, 5.) corrected = corrected[~sigmaClip_tf] rta = noise.computeRollTweakAmplitude(corrected) sgcdpp = noise.computeSgCdpp_ppm(corrected) scatter = noise.estimateScatterWithMarshallMethod(corrected) rta_list.append(rta) sgcdpp_list.append(sgcdpp) scatter_list.append(scatter) results_list.append([numPrinComps, rta, sgcdpp, scatter]) #plt.plot(range(len(corrected)), corrected+ n*offset, ".", markersize=4, label = "%f,%i"%(sgcdpp, int(numPrinComps))) n += 1 #plt.legend() #plt.show() # plot the three params wrt the raw values if plotMask == True: y = cadenceSum / np.mean(cadenceSum) - 1 raw_rta = noise.computeRollTweakAmplitude(y) raw_sgcdpp = noise.computeSgCdpp_ppm(noise.sigmaClip(y, 5.)) raw_scatter = noise.estimateScatterWithMarshallMethod(y) f, axarr = plt.subplots(3, sharex=True) axarr[0].axhline(raw_rta, label="RTA for raw light curve") axarr[1].axhline(raw_sgcdpp, label="sgcdpp for raw light curve") axarr[2].axhline(raw_scatter, label="scatter for raw light curve") axarr[0].plot(numPrinCompList, rta_list, ".", color="green") axarr[1].plot(numPrinCompList, sgcdpp_list, ".", color="green") axarr[2].plot(numPrinCompList, scatter_list, ".", color="green") plt.xlabel("Number of Principal Components") axarr[0].set_ylabel("Roll Tweak Amplitude") axarr[1].set_ylabel("sgcdpp") axarr[2].set_ylabel("scatter") plt.show() # plot the corrected light curve with the lowest sgcdpp #============================================================================== # optimalPC = numPrinCompList[np.argmin(sgcdpp_list)] # fittedCurve = curveFit(pcaMatrix, cadenceSum, optimalPC)[0] # optimal_lcv = correctedCurve(cadenceSum, fittedCurve) # make_plot(t, optimal_lcv, title="e: %s, c: %s,sgcdpp=%s PC=%s"%(epic, campaign, # str(np.min(sgcdpp_list)), # numPrinCompList[np.argmin(sgcdpp_list)])) #============================================================================== # plot the corrected light curve with the smallest slope between sgcdpp values smallest_slope = np.argmin(np.abs(np.diff(sgcdpp_list))) optimalPC = numPrinCompList[smallest_slope] fittedCurve = curveFit(pcaMatrix, cadenceSum, optimalPC)[0] optimal_lcv = correctedCurve(cadenceSum, fittedCurve) sigmaClip_tf = noise.sigmaClip(optimal_lcv, 5.) make_plot(t, optimal_lcv, show=False) make_plot(t[sigmaClip_tf], optimal_lcv[sigmaClip_tf], new=False, title="e:%s, c:%s, smallest slope, PC=%s" % (epic, campaign, numPrinCompList[smallest_slope]), marker='ro') folded = np.fmod(t, 4.16) make_plot(t, folded) #============================================================================== # # plot the corrected light curve with the lowest rta # plt.figure() # plt.title("epic %s campaign %s lowest rta=%s PC=%s"%(epic, campaign, # str(np.min(rta_list)), # numPrinCompList[np.argmin(rta_list)])) # optimalPC = numPrinCompList[np.argmin(rta_list)] # fittedCurve = curveFit(pcaMatrix, cadenceSum, optimalPC)[0] # optimal_lcv = correctedCurve(cadenceSum, fittedCurve) # plt.plot(range(len(optimal_lcv)), optimal_lcv, ".") #============================================================================== #plt.show() return np.array(results_list).T