How to use the lightkurve.KeplerTargetPixelFile function in lightkurve

To help you get started, we’ve selected a few lightkurve examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github afeinstein20 / eleanor / ELLIE_v1.2 / logo.py View on Github external
import matplotlib
matplotlib.use("Agg")
import matplotlib.gridspec as gridspec
from scipy.misc import imread

def animate(i):
    global scats, lines, lc
    ax1.imshow(tpf.flux[i], origin='lower', vmin=cbmin, vmax=cbmax)
    for line in lines:
        line.remove()
    lines = []
    lines.append(ax.scatter(lc.time[i], lcNorm[i], s=16, c='r'))


file = '219870537.fits'
tpf  = ktpf.from_fits(file)
lc   = tpf.to_lightcurve()
lcNorm   = lc.flux / np.nanmedian(lc.flux)

cbmin = np.max(tpf.flux[0])*0.05
cbmax = np.max(tpf.flux[0])*0.85

lines = []
img = imread('ellie_logo.png')
fig = plt.figure(figsize=(10,5))

plt.imshow(img)
plt.axis('off')
plt.tight_layout()

ax = fig.add_axes([0.685, 0.1335, 0.165, 0.176])
ax.plot(lc.time, lcNorm, 'k')
github afeinstein20 / eleanor / ELLIE / markGaia.py View on Github external
gaiaXY = WCS(post_header).all_world2pix(gaiaRA, gaiaDEC, 1)
    gaiaXY = pointingCorr(gaiaXY, camera, chip)
    gaiaXY, gaiaID, gaiaMAG = in_tpf(xy, gaiaXY, gaiaID, gaiaMAG)

    crossmatch = ctpf()
    crossTable = crossmatch.crossmatch_multi_to_tic(list=gaiaID.data)

    ticLabel, tmagLabel = np.zeros(len(gaiaID.data)), np.zeros(len(gaiaID.data))
    for i in range(len(gaiaID.data)):
        row = crossTable[i]
#        print(row['separation'])
        if row['separation'] <= 1.0 and row['Gmag'] <= 16.5:
            ticLabel[i]  = row['TIC_ID']
            tmagLabel[i] = row['Tmag']

    tpf = ktpf.from_fits(file)
    plot_with_hover(tpf, gaiaXY, gaiaID, gaiaMAG, ticLabel, tmagLabel)
github afeinstein20 / eleanor / eleanor / logo.py View on Github external
import matplotlib
matplotlib.use("Agg")
import matplotlib.gridspec as gridspec
from scipy.misc import imread

def animate(i):
    global scats, lines, lc
    ax1.imshow(tpf.flux[i], origin='lower', vmin=cbmin, vmax=cbmax)
    for line in lines:
        line.remove()
    lines = []
    lines.append(ax.scatter(lc.time[i], lcNorm[i], s=16, c='r'))


file = '219870537.fits'
tpf  = ktpf.from_fits(file)
lc   = tpf.to_lightcurve()
lcNorm   = lc.flux / np.nanmedian(lc.flux)

cbmin = np.max(tpf.flux[0])*0.05
cbmax = np.max(tpf.flux[0])*0.85

lines = []
img = imread('ellie_logo.png')
fig = plt.figure(figsize=(10,5))

plt.imshow(img)
plt.axis('off')
plt.tight_layout()

ax = fig.add_axes([0.685, 0.1335, 0.165, 0.176])
ax.plot(lc.time, lcNorm, 'k')
github afeinstein20 / eleanor / ELLIE_v1.2 / markGaia.py View on Github external
gaiaXY = WCS(header).all_world2pix(gaiaRA, gaiaDEC, 1)
    gaiaXY = pointingCorr(gaiaXY, camera, chip)
    gaiaXY, gaiaID, gaiaMAG = in_tpf(xy, gaiaXY, gaiaID, gaiaMAG)

    crossmatch = ctpf()
    crossTable = crossmatch.crossmatch_multi_to_tic(list=gaiaID.data)

    ticLabel, tmagLabel = np.zeros(len(gaiaID.data)), np.zeros(len(gaiaID.data))
    for i in range(len(gaiaID.data)):
        row = crossTable[i]
#        print(row['separation'])
        if row['separation'] <= 1.0 and row['Gmag'] <= 16.5:
            ticLabel[i]  = row['TIC_ID']
            tmagLabel[i] = row['Tmag']

    tpf = ktpf.from_fits(file)
    plot_with_hover(tpf, gaiaXY, gaiaID, gaiaMAG, ticLabel, tmagLabel)
github afeinstein20 / eleanor / ELLIE_v1.2 / oneTPF.py View on Github external
def main(camera, chip, id):
    """ Temporary Main Function """
    dir = './2019/2019_1_{}-{}/ffis/'.format(camera, chip)
    fns = np.array(os.listdir(dir))
    fns = fns[np.array([i for i,item in enumerate(fns) if "fits" in item])]
    fns = sortByDate(fns, dir)
    mast, mheader = openFITS(dir, fns[0])
    new_id, raDec, xy = getSourcePos(id, 'tic', mheader)
    print(xy)
    xy_corr = correctXY(xy[0], xy[1], camera, chip)
    print(xy_corr)
    fns = [dir+i for i in fns]
    tpf = ktpf.from_fits_images(images=fns, position=xy_corr, size=(9,9))
    tpf.to_fits(output_fn = '{}_rotation.fits'.format(id))
github afeinstein20 / eleanor / ELLIE_v1.2 / findSourceCamera.py View on Github external
initPos[0] = np.radians(initPos[0])
    x = xy[0]*np.cos(initPos[0]) - xy[1]*np.sin(initPos[0]) - initPos[1]
    y = xy[0]*np.sin(initPos[0]) + xy[1]*np.cos(initPos[0]) - initPos[2]# + 1.0
    xy_new = [x,y]

    fns = np.array(os.listdir(dir))
    fns = fns[np.array([i for i,item in enumerate(fns) if "fits" in item])]
    fns = sortByDate(fns, dir)
    fns = [dir+i for i in fns]

    gaia = crossmatch(pos, 1, 'Mast.GaiaDR2.Crossmatch')
    gaia_id = gaia['MatchID']
    print(xy, xy_new)

    tpf  =  ktpf.from_fits_images(images=fns, position=xy_new, size=(9,9))

    plt.imshow(tpf.flux[0], origin='lower')
    plt.show()

    output_fn = '{}_tpf.fits'.format(id)
    tpf.to_fits(output_fn=output_fn)
    
    names = ['TIC_ID', 'GAIA_ID', 'CEN_RA', 'CEN_DEC', 'CEN_X', 'CEN_Y']
    values = [return_id[0], gaia['MatchID'][0], pos[0], pos[1], float(xy[0]), float(xy[1])]

    for i in range(len(values)):
        print(names[i], values[i])
        fits.setval(output_fn, str(names[i]), value=values[i])
github afeinstein20 / eleanor / ELLIE_v1.2 / pixelCorrection.py View on Github external
x_cen, y_cen = len(mast)/2, len(mast[0])/2
    xy = np.zeros((len(x),2))


    for i in range(len(x)):
        xy[i][0] = x[i]-x_cen
        xy[i][1] = y[i]-y_cen
    with open(corrFile, 'w') as tf:
        tf.write('cadence medT medX medY\n')

    matrix = np.zeros((len(x), len(fns), 2))

    for i in range(len(x)):
        print(x[i], y[i])
        tpf = ktpf.from_fits_images(images=fns, position=(x[i], y[i]), size=(6,6))
        #tpf.to_fits(output_fn='test{}.fits'.format(i))
        for j in range(len(fns)):
            com = ndimage.measurements.center_of_mass(tpf.flux[j].T-np.median(tpf.flux[j])) # subtracts background
            matrix[i][j][0] = com[0]+xy[i][0]
            matrix[i][j][1] = com[1]+xy[i][1]


    for i in range(len(fns)):
        centroids = matrix[:,i]
        if i == 0:
            initGuess = [0.001, 0.1, -0.1]
        else:
            initGuess = solution.x

        bnds = ((-0.08, 0.08), (-5.0, 5.0), (-5.0, 5.0))
        solution = minimize(model, initGuess, method='L-BFGS-B', bounds=bnds, options={'ftol':5e-11,
github afeinstein20 / eleanor / eleanor / movie.py View on Github external
lcNorm = lc.flux / np.nanmedian(lc.flux)
#    lines.append(ax.scatter(lc.time[i], custLCC[i], s=20, c='r'))
#    lines.append(ax.scatter(lc.time[i], custLCR[i], s=20, c='k'))

#    circleShape = patches.Circle((x[i],y[i]), 1.5, fill=False, alpha=0.4)
#    rectanShape = patches.Rectangle((x[i]-1.5,y[i]-1.5), 3.0, 3.0, fill=False)
#    p = PatchCollection([rectanShape, circleShape], alpha=0.4)
#    colors = np.linspace(0,1,2)
#    p.set_array(np.array(colors))
#    p.set_edgecolor('face')
#    ps.append(ax1.add_collection(p))


id = str(sys.argv[1])
tpf = ktpf.from_fits('./figures/{}_tpf.fits'.format(id))
lc = tpf.to_lightcurve()

pointing = 'pointingModel_{}-{}.txt'.format(3,3)

theta, delX, delY = np.loadtxt(pointing, usecols=(1,2,3), skiprows=1, unpack=True)

new_id, pos, tmag = ticID(int(id))
x, y, scats, lines = [], [], [], []
ps = []

for i in range(len(tpf.flux)-1):
    if i == 0:
        x.append( 3.0*np.cos(theta[i+1]) - 4.0*np.sin(theta[i+1]) + delX[i+1] )
        y.append( 3.0*np.sin(theta[i+1]) + 4.0*np.cos(theta[i+1]) + delY[i+1] )
    else:
        x.append( x[i-1]*np.cos(theta[i+1]) - y[i-1]*np.sin(theta[i+1]) + delX[i+1] )
github afeinstein20 / eleanor / ELLIE_v1.2 / makePostcards.py View on Github external
x_cens, y_cens = [], []

cat = 'postcard_catalog.txt'
with open(cat, 'w') as tf:
    tf.write('filename ra_low ra_up dec_low dec_up\n')

for i in range(len(x)-1):
    for j in range(len(y)-1):
        fn = 'postcard_{}-{}.fits'.format(i, j)
        x_cen = (x[i]+x[i+1]) / 2.
        y_cen = (y[j]+y[j+1]) / 2.
        x_cens.append(x_cen)
        y_cens.append(y_cen)

        radec = WCS(mheader).all_pix2world(x_cen, y_cen, 1)
        tpf = ktpf.from_fits_images(images=fns, position=(x_cen,y_cen), size=(350,350))
        tpf.to_fits(output_fn=fn)
        
        fits.setval(fn, 'CEN_X' , value=np.round(x_cen,5))
        fits.setval(fn, 'CEN_Y' , value=np.round(y_cen,5))
        fits.setval(fn, 'CEN_RA', value=float(radec[0]))
        fits.setval(fn, 'CEN_DEC', value=float(radec[1]))

        lower = WCS(mheader).all_pix2world(x_cen-350, y_cen-350, 1)
        upper = WCS(mheader).all_pix2world(x_cen+350, y_cen+350, 1)
        row = [fn, lower[0], lower[1], upper[0], upper[1]]
        with open(cat, 'a') as tf:
            tf.write('{}\n'.format(' '.join(str(e) for e in row)))
github afeinstein20 / eleanor / eleanor / ellie.py View on Github external
typeList = np.full(len(colnames), 'S30', dtype='S30')
        t = Table(names=colnames, dtype=typeList)

        for i in range(len(x)-1):
            for j in range(len(y)-1):
                mast, mheader = fits.getdata(fns[0], header=True)
                fn = 'postcard_{}_{}-{}_{}-{}.fits'.format(sector, camera, chip, i, j)
                if os.path.isfile(self.post_dir+fn)==True:
                    return
                print("Creating postcard: {}".format(fn))
                x_cen = (x[i]+x[i+1]) / 2.
                y_cen = (y[j]+y[j+1]) / 2.

                radec = WCS(mheader).all_pix2world(x_cen, y_cen, 1)
                s = 300
                tpf   = ktpf.from_fits_images(images=fns, position=(x_cen,y_cen), size=(s,s))
                # Edits header of FITS files
                tempVals = list(mheader.values())
                moreData = [fn, s, s, x_cen, y_cen, float(radec[0]), float(radec[1])]
                for m in moreData:
                    tempVals.append(m)
                t.add_row(vals=tempVals)

                time_arrays = np.zeros((3, len(fns)))
                for f in range(len(fns)):
                    hdu = fits.open(fns[f])
                    hdr = hdu[1].header
                    time_arrays[0][f] = hdr['TSTART']
                    time_arrays[1][f] = hdr['TSTOP']
                    time_arrays[2][f] = hdr['BARYCORR']

                hdr = mheader