def blsTask(clip): # import dave.blsCode.bls_ktwo as bls import bls time_days = clip['serve.time'] flux_norm = clip['detrend.flux_frac'] flags = clip['detrend.flags'] minPeriod = 1. maxPeriod = 20. period, epoch, duration, depth, bls_search_periods, convolved_bls = \ bls.doSearch(time_days[~flags], flux_norm[~flags], minPeriod, maxPeriod) out = clipboard.Clipboard() out['period'] = period out['epoch'] = epoch ut['duration_hrs'] = duration * 24 out['depth'] = depth clip['bls'] = out ##Enforce contract clip['bls.period'] clip['bls.epoch'] clip['bls.duration_hrs'] return clip
def createConfig(detrendType, sector, tic, planetNum, period, tepoch, tdepth, tdur, debugMode=True): cfg = dict() cfg['debug'] = debugMode cfg['sector'] = sector cfg['campaign'] = sector cfg['tic'] = tic cfg['planetNum'] = planetNum cfg['value'] = tic cfg['detrendType'] = detrendType#"eleanor"#"tess"# cfg['period'] = period cfg['tepoch'] = tepoch cfg['tdepth'] = tdepth cfg['tdur'] = tdur #TODO This shouldn't be hardcoded, but passed as a parameter cfg['dvtLocalPath'] = "/Users/.eleanor/" #TODO Need modshift paths cfg['lppMapFile'] = "/Users/LPP_map/combMapDR25AugustMapDV_6574.mat" cfg['modshiftBasename'] = "/Users/justVet/" cfg['onepageBasename'] = "/Users/justVet/" if detrendType == 'tess': cfg['taskList'] = ['serveTask', 'trapezoidFitTask','modshiftTask', 'sweetTask', 'lppMetricTask','centroidsTask', 'dispositionTask'] elif detrendType == 'eleanor': cfg['taskList'] = ['serveTask', 'detrendTask', 'trapezoidFitTask','modshiftTask', 'sweetTask', 'lppMetricTask', 'centroidsTask', 'dispositionTask'] clip = clipboard.Clipboard(cfg) return clip
def dispositionTask(clip): """Decide whether an event is a planet candidate or not TODO: Much of this should be parcelled off into a function """ #Thresholds snrThreshold = clip['config.minSnrForDetection'] lppThreshold = clip['config.maxLppForTransit'] minProbForFail = clip['config.minProbDiffImgCentroidForFail'] snr = clip['trapFit.snr'] modshiftDict = clip['modshift'] centroidArray = clip['diffImg.centroid_timeseries'] out = clipboard.Clipboard(isSignificantEvent=True, isCandidate=True, \ reasonForFail="None") #Compute centroid offset and significance centVet = {'Warning': "None"} try: prob, chisq = cent.measureOffsetProbabilityInTimeseries(centroidArray) except ValueError, e: centVet['Warning'] = "Probability not computed: %s" % (e) prob = 0 chisq = 0
def getMilesLightcurveTask(clip): # get input data from clip cube = clip['serve.cube'] time = clip['serve.time'] flags = clip['serve.flags'] > 0 flags |= ~np.isfinite(time) nt, nr, nc = cube.shape pixSeries, pixSeriesNorm = milesPCA.pixSeriesPrep(cube, flags) totLightcurve = milesPCA.getRawLightcurve(pixSeries) # package results out = clipboard.Clipboard() out['rawLightcurve'] = totLightcurve out['time'] = time out['pixSeries'] = pixSeries out['pixSeriesNorm'] = pixSeriesNorm out['flags'] = flags clip['extract'] = out #Enforce contract clip['extract.rawLightcurve'] clip['extract.time'] clip['extract.pixSeries'] clip['extract.pixSeriesNorm'] clip['extract.flags'] return clip
def loadMultipleDetrendings(epic, campaign, dataStorePath, detrendTypes): #Definition of the different kinds of detrendings and how to #parse the output of their archive class dTypeDict = dict() dTypeDict['PDC'] = (mastio.K2Archive(), pdcParser, "PDC") dTypeDict['AGP'] = (mastio.K2SCArchive(), agpParser, "K2SC") dTypeDict['EVEREST'] = (mastio.EverestArchive(), everestParser, "Everest") dTypeDict['SFF'] = (mastio.VanderburgArchive(), sffParser, "Vanderburg SFF") out = dpc.Clipboard() #Load the TPF data cube ar = mastio.K2Archive(dataStorePath) fits, hdr = ar.getLongTpf(epic, campaign, header=True, mmap=False) hdr0 = ar.getLongTpf(epic, campaign, ext=0, mmap=False) cube = tpf.getTargetPixelArrayFromFits(fits, hdr) out['time'] = fits['TIME'] out['cube'] = cube out['tpfHeader'] = hdr out['tpfHeader0'] = hdr0 #Load PA data fits = ar.getLongCadence(epic, campaign) out['rawFlux'] = fits['SAP_FLUX'] #Load lightcurves from a specific detrending, and replace #the pdc time series with the new detrending nDetrend = 0 for i, dType in enumerate(detrendTypes): key = dType.upper() if key not in dTypeDict: raise IOError("Unrecognised detrended %s" % (key)) ar, parser, label = dTypeDict[key] data = ar.getLongCadence(epic, campaign) flux = parser(out['time'], data) typeName = "type%i" % (i + 1) out[typeName] = key fluxName = "flux%i" % (i + 1) out[fluxName] = flux labelName = "label%i" % (i + 1) out[labelName] = label nDetrend += 1 out['numDetrendings'] = nDetrend #Enforce contract out['flux1'] out['label1'] out['cube'] return out
def runOneEphem(k2id, period, epoch, config, duration=2, depth=.0001): """ Run just the vetting and return an output. Inputs: ------------- k2id (int) Epic id of the target to run on. period (float) period of the target epoch (float) Time in days config (dict) Dictionary of configuration parameters """ tasks = """dpp.checkDirExistTask dpp.serveTask dpp.extractLightcurveFromTpfTask dpp.computeCentroidsTask dpp.rollPhaseTask dpp.cotrendSffDataTask dpp.detrendDataTask dpp.trapezoidFitTask dpp.lppMetricTask dpp.modshiftTask dpp.measureDiffImgCentroidsTask dpp.dispositionTask dpp.saveOnError""".split() taskList = tasks clip = clipboard.Clipboard() clip['config'] = config clip['value'] = k2id out = clipboard.Clipboard() out['period'] = period out['epoch'] = epoch out['duration_hrs'] = duration out['depth'] = depth clip['bls'] = out #Check that all the tasks are properly defined for t in taskList: f = eval(t) #Now run them. for t in taskList: f = eval(t) clip = f(clip) return clip
def dispositionTask(clip): """Decide whether an event is a planet candidate or not TODO: Much of this should be parcelled off into a function """ #Thresholds snrThreshold = clip['config.minSnrForDetection'] # lppThreshold = clip['config.maxLppForTransit'] offsetThreshold_sigma = clip['config.minCentroidSignifForFp'] #Data on which to make a decision snr = clip['trapFit.snr'] modshiftDict = clip['modshift'] centroidArray = clip['diffImg.centroid_timeseries'] out = clipboard.Clipboard(isSignificantEvent=True, isCandidate=True, \ reasonForFail="None") if snr < snrThreshold: out['isSignificantEvent'] = False out['isCandidate'] = False out['reasonForFail'] = "SNR (%.1f) below threshold %.1f" \ %(snr, snrThreshold) return out #Parse modshift results fluxVetDict = RoboVet.roboVet(modshiftDict) out['fluxVet'] = fluxVetDict assert (fluxVetDict['disp'] in ["candidate", "false positive"]) if fluxVetDict['disp'] == "false positive": out['isCandidate'] = False out['reasonForFail'] = fluxVetDict['comments'] return out #Compute centroid offset and significance result = cent.measureOffsetInTimeseries(centroidArray) out['centroidVet'] = result signif = result['signif'] offset = result['offset'] if signif > offsetThreshold_sigma: out['isCandidate'] = False out['reasonForFail'] = "Centroid offset of %.2f (%.1f sigma) detected" \ %( offset, signif) return out clip['disposition'] = out #Enforce contract clip['disposition.isSignificantEvent'] clip['disposition.isCandidate'] clip['disposition.reasonForFail'] return clip
def runOneDv(detrendType , sector, tic, planetNum, period, epoch, tdepth, tdur, debugMode=True): cfg = createConfig(detrendType, sector, tic, planetNum, period, epoch, tdepth, tdur, debugMode=True) clip = tessPipeline.runOne(cfg,returnClip=True) out = clipboard.Clipboard(isSignificantEvent=True, isCandidate=True, reasonForFail="None") # This is an attempt at quickly vetting the signals. # This should be its own task. return clip
def runOneEphem(k2id,period,epoch,config,duration=3.5,depth=.0001): """ Run just the vetting and return an output. Inputs: ------------- k2id (int) Epic id of the target to run on. period (float) period of the target epoch (float) Time in days config (dict) Dictionary of configuration parameters """ taskList = config['taskList']; clip = clipboard.Clipboard() clip['config'] = config clip['value'] = k2id out = clipboard.Clipboard() out['period'] = period out['epoch'] = epoch out['duration_hrs'] = duration out['depth'] = depth clip['bls'] = out #Check that all the tasks are properly defined for t in taskList: f = eval(t) #Now run them. for t in taskList: f = eval(t) clip = f(clip) return clip
def placeholderBls(clip): """Debugging code. Returns the ephemeris of the largest event in K2Id 206103150 """ out = clipboard.Clipboard() out['period'] = 4.15892 out['epoch'] = 2145.76 out['duration_hrs'] = 1.94443 out['depth'] = .01112825 clip['bls'] = out return clip
def searchForEvent(clip): subClip = clip.shallowCopy() originalKeyList = subClip.keys() taskList = clip['config.searchTaskList'] #Set the flags attribute of the new subclip #Problem with this code is it closely tied to the behaviour #of multiEventSearchTask try: tmp = clip.eventList[-1] flags = tmp['flags'] except (IndexError, KeyError): flags = clip['detrend.flags'] subClip['flags'] = flags #Check that all the tasks are properly defined for t in taskList: f = eval(t) #Now run them. for t in taskList: f = eval(t) subClip = f(subClip) # #@TODO List of tasks to run should be config param # subClip = placeholderBls(subClip) # subClip = trapezoidFitTask(subClip) # subClip = modshiftTask(subClip) # subClip = measureDiffImgCentroidsTask(subClip) # subClip = dispositionTask(subClip) newKeys = list(set(subClip.keys()) - set(originalKeyList)) out = clipboard.Clipboard(__meta__=subClip['__meta__']) for k in newKeys: out[k] = subClip[k] #Mark all locations for this event as data not to be used. time = subClip['serve.time'] period_days = subClip['trapFit.period_days'] epoch_bkjd = subClip['trapFit.epoch_bkjd'] duration_days = subClip['trapFit.duration_hrs'] / 24. # assert(np.all(np.isfinite(time[~flags]))) # assert(np.any(flags)) idx = kplrfits.markTransitCadences(time, period_days, epoch_bkjd, \ duration_days, numberOfDurations=2, flags=flags) out['flags'] = flags | idx return out
def runOne(k2id, config, returnClip=False): """Run the pipeline on a single target. Inputs: ------------ k2id (int) Epic id of target to run on. config (dict) Dictionary of configuration parameters as created by, e.g loadMyConfiguration() Returns: --------- A clipboard containing the results. Notes: --------- Don't edit this function. The pipeline can recover gracefully from errors in any individual task, but an error in this function will crash the pipeline """ taskList = config['taskList'] clip = clipboard.Clipboard() clip['config'] = config clip['value'] = k2id #Check that all the tasks are properly defined print "Checking tasks exist" for t in taskList: f = eval(t) #Now run them. for t in taskList: print "Running %s" % (t) f = eval(t) clip = f(clip) gc.collect() if returnClip: return clip
def runOne(k2id, config): taskList = config['taskList'] clip = clipboard.Clipboard() clip['config'] = config clip['value'] = k2id #clip['dataStorePath'] = config['dataStorePath'] #Check that all the tasks are properly defined for t in taskList: f = eval(t) #Now run them. for t in taskList: f = eval(t) clip = f(clip) return clip
def createConfig(sector, tic, planetNum, debugMode=True): cfg = dict() cfg['debug'] = debugMode cfg['sector'] = sector cfg['tic'] = tic cfg['planetNum'] = planetNum #TODO This shouldn't be hardcoded, but passed as a parameter cfg['dvtLocalPath'] = "/home/fergal/data/tess/dvt/sector1" #TODO Need modshift paths cfg['lppMapFile'] = "/home/fergal/data/tess/lppmaps/combMapDR25AugustMapDV_6574.mat" cfg['modshiftBasename'] = "/home/fergal/data/tess/daveOutput/" # cfg['taskList'] = ['serveTask', 'lppMetricTask', 'modshiftTask'] cfg['taskList'] = ['serveTask', 'sweetTask'] clip = clipboard.Clipboard(cfg) return clip
def dispositionTask(clip): """Decide whether an event is a planet candidate or not """ out = clipboard.Clipboard(isSignificantEvent=True, isCandidate=True, reasonForFail="None") # CENTROID VET minProbForFail = 0.99 centVet = {'Warning':"None"} try: centroids = clip['diffImgCentroids.results'] ootCol_prf, ootRow_prf = np.mean([centroids[:,0],centroids[:,4]], axis = 0), np.mean([centroids[:,1],centroids[:,5]], axis = 0) diffCol_prf, diffRow_prf = centroids[:,2], centroids[:,3] diffC, diffR = (ootCol_prf - diffCol_prf), (ootRow_prf - diffRow_prf) prob, chisq = covar.computeProbabilityOfObservedOffset(diffC, diffR) except ValueError, e: centVet['Warning'] = "Probability not computed: %s" %(e) prob = 0 chisq = 0
def createConfig(sector, tic, planetNum, debugMode=True): cfg = dict() cfg['debug'] = debugMode cfg['sector'] = sector cfg['tic'] = tic cfg['planetNum'] = planetNum cfg['value'] = tic #TODO This shouldn't be hardcoded, but passed as a parameter cfg['dvtLocalPath'] = "/Users/smullally/TESS/TCEs/Sector1/dvt/" #TODO Need modshift paths cfg['lppMapFile'] = "/Users/smullally/Code/lpptransitlikemetric/data/maps/combMapDR25AugustMapDV_6574.mat" cfg['modshiftBasename'] = "/Users/smullally/TESS/TCEs/Sector1/dave" cfg['taskList'] = ['serveTask', 'lppMetricTask','sweetTask'] clip = clipboard.Clipboard(cfg) return clip
def runOne(k2id, config): print "WARN: This function is deprecated. See main.py instead." taskList = config['taskList'] clip = clipboard.Clipboard() clip['config'] = config clip['value'] = k2id #clip['dataStorePath'] = config['dataStorePath'] #Check that all the tasks are properly defined for t in taskList: f = eval(t) #Now run them. for t in taskList: f = eval(t) clip = f(clip) if 'vet' in clip.keys( ): # Jeff edits here - See if vetting has been done yet if 'reasonForFail' in clip.vet.keys( ): # Make sure a value for reason to fail exists else program may crash if 'ODD_EVEN_DIFF' in clip[ 'vet.reasonForFail']: # If it failed due to odd-even, then clip['bls.period'] = 2 * clip[ 'bls.period'] # Double the period taskList = """trapezoidFitTask vetTask plotTask""".split( ) # And re-fit, re-vet, and re-plot clip['vet.fluxVet.comments'] = clip[ 'vet.fluxVet.comments'] + "Re-fit at twice period due to odd/even" # Make a note we re-fit at 2*period for t in taskList: f = eval(t) clip = f(clip) print "WARN: This function is deprecated. See main.py instead." return clip
def vetTask(clip): print "WARN: vetTask is deprecated. Use dispostionTask instead" snr = clip['trapFit.snr'] snrThreshold = clip['config.minSnrForDetection'] lppThreshold = clip['config.maxLppForTransit'] offsetThreshold_sigma = clip['config.minCentroidSignifForFp'] out = clipboard.Clipboard(isCandidate=True, reasonForFail="None") if snr < snrThreshold: out['isCandidate'] = False out['reasonForFail'] = "SNR (%.1f) below threshold %.1f" \ %(snr, snrThreshold) # clip['vet'] = out # return clip clip = lppMetricTask(clip) if 'exception' in clip.keys(): return clip # Tlpp = clip['lpp.TLpp'] # if Tlpp > lppThreshold: # out['isCandidate'] = False # out['reasonForFail'] = "TLpp (%.1f) above threshold %.1f" \ # %(Tlpp, lppThreshold) ## clip['vet'] = out ## return clip clip = modshiftTask(clip) if 'exception' in clip.keys(): return clip modshift = clip['modshift'] fluxVetDict = RoboVet.roboVet(modshift) out['fluxVet'] = fluxVetDict assert (fluxVetDict['disp'] in ["candidate", "false positive"]) if fluxVetDict['disp'] == "false positive": out['isCandidate'] = False out['reasonForFail'] = fluxVetDict['comments'] # clip['vet'] = out # return clip clip = measureDiffImgCentroidsTask(clip) if 'exception' in clip.keys(): return clip centroids = clip['diffImg.centroid_timeseries'] result = cent.measureOffsetInTimeseries(centroids) out['centroidVet'] = result signif = result['signif'] offset = result['offset'] if signif > offsetThreshold_sigma: out['isCandidate'] = False out['reasonForFail'] = "Centroid offset of %.2f (%.1f sigma) detected" \ %( offset, signif) # clip['vet'] = out # return clip clip['vet'] = out #Enforce contract clip['vet.isCandidate'] clip['vet.reasonForFail'] return clip