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 getData(epic, campaign): ar = mastio.K2Archive() fits, hdr = ar.getLongTpf(epic, campaign, header=True) cube = tpf.getTargetPixelArrayFromFits(fits, hdr) # get the thruster firing indeces q = fits['QUALITY'].astype(np.uint32) idx1 = q & kplrfits.SapQuality['DefiniteRollTweak'] idx2 = q & kplrfits.SapQuality['MomDump'] idx3 = idx1 + idx2 return cube, idx3
def serveTask(clip): k2id = clip['value'] campaign = clip['config.campaign'] storeDir = clip['config.dataStorePath'] detrendType = clip.get('config.detrendType', 'PDC') ar = mastio.K2Archive(storeDir) clip['serve'] = loadTpfAndLc(k2id, campaign, ar, detrendType) #Enforce contract. (Make sure expected keys are in place) clip['serve.time'] clip['serve.cube'] clip['serve.socData'] clip['serve.tpfHeader'] return clip
def exampleDiffImgCentroiding(): k2id = 206103150 campaign = 3 ar = mastio.K2Archive() fits, hdr = ar.getLongTpf(k2id, campaign, header=True) hdr0 = ar.getLongTpf(k2id, campaign, ext=0) cube = tpf.getTargetPixelArrayFromFits(fits, hdr) idx = np.isfinite(cube) cube[~idx] = 0 #Remove Nans flags = fits['QUALITY'] ccdMod = hdr0['module'] ccdOut = hdr0['output'] #Compute roll phase llc = ar.getLongCadence(k2id, campaign) time = llc['TIME'] cent1 = llc['MOM_CENTR1'] cent2 = llc['MOM_CENTR2'] centColRow = np.vstack((cent1, cent2)).transpose() rot = arclen.computeArcLength(centColRow, flags > 0) rollPhase = rot[:, 0] rollPhase[flags > 0] = -9999 #A bad value prfObj = prf.KeplerPrf("/home/fergal/data/keplerprf") bbox = getBoundingBoxForImage(cube[0], hdr) period = 4.1591409 epoch = fits['time'][491] dur = 3.0 out, log = measureDiffOffset(period, epoch, dur, time, prfObj, \ ccdMod, ccdOut, cube, bbox, rollPhase, flags) idx = out[:, 1] > 0 mp.clf() mp.plot(out[:, 3] - out[:, 1], out[:, 4] - out[:, 2], 'ro') return out
def getData(epic, campaign): """Obtains the data for the star For a particular star, this obtains its pixel time series data cube as well as time points which may be bad due to thruster firings. Inputs: ---------- epic (int) The k2 epic number for the desired star campaign (int) The k2 campaign for the desired star Returns: ------------ cube (3d numpy array) The k2 pixel time series data for the star with dimensions (time, number of rows per cadence, number of columns per cadence) badIdx (1d boolean numpy array) Boolean array with true corresponding to a bad time point due to thruster firings """ ar = mastio.K2Archive() fits, hdr = ar.getLongTpf(epic, campaign, header=True) cube = tpf.getTargetPixelArrayFromFits(fits, hdr) # get the thruster firing indeces q = fits['QUALITY'].astype(np.uint32) rollTweakIdx = q & kplrfits.SapQuality['DefiniteRollTweak'] momDumpIdx = q & kplrfits.SapQuality['MomDump'] badIdx = rollTweakIdx | momDumpIdx badIdx = badIdx.astype(bool) return cube, badIdx
def example(): ar = mastio.K2Archive() kepid = 206103150 #A wasp planet fits = ar.getLongCadence(kepid, 3) flags = fits['SAP_QUALITY'] cent1 = fits['MOM_CENTR1'] cent2 = fits['MOM_CENTR2'] fits, hdr = ar.getLongTpf(kepid, 3, header=True) cube = tpf.getTargetPixelArrayFromFits(fits, hdr) # cube *= gain #Compute roll phase centColRow = np.vstack((cent1, cent2)).transpose() rot = arclen.computeArcLength(centColRow, flags > 0) rollPhase = rot[:, 0] rollPhase[flags > 0] = -9999 #A bad value cadenceInTransit = 490 diff, oot = constructK2DifferenceImage(cube, cadenceInTransit, rollPhase, flags) return diff, oot