def spline_int(x, y, a, b): from scipy.interpolate import splrep as bspline from scipy.interpolate import splint as integ list_assert(x, 'x') list_assert(y, 'y') numeric_assert(a, 'a') numeric_assert(b, 'b') bspline_obj = bspline(x, y) int_spline_val = integ(a, b, bspline_obj) return (int_spline_val)
def spline_vals(xnew, x, y, der): from scipy.interpolate import interp1d as spln from scipy.interpolate import splrep as bspline from scipy.interpolate import splev as deriv list_assert(xnew, 'xnew') list_assert(x, 'x') list_assert(y, 'y') int_assert(der, 'der') assert der >= 0, "Error: 'der' must be an integer greater than or equal to zero" spline = spln(x, y, kind='cubic') spline_vals = spline(xnew) if (der == 0): return (spline_vals) if (der > 0): bspline_obj = bspline(x, y) der_spline_vals = deriv(xnew, bspline_obj, der) return (der_spline_vals)
def get_limb_coeff(Tstar,loggstar,filter='Kp',plot=False,network=None,limb='quad',interp='linear'): from scipy.interpolate import griddata import pylab as pl from mpl_toolkits.mplot3d import axes3d, Axes3D from scipy.interpolate import RectBivariateSpline as bspline global ldc1func,ldc2func,ldc3func,ldc4func # Account for gap in look up tables between 4800 and 5000K if (Tstar > 4800 and Tstar <= 4900): Tstar = 4800 if (Tstar > 4900 and Tstar < 5000): Tstar = 5000 # Choose proper file to read if limb == 'nlin': skiprows = 49 filtcol = 8 metcol = 9 mercol = 10 col1 = 4 col2 = 5 col3 = 6 col4 = 7 if (Tstar <= 4800): file = 'Claret_cool_nlin.dat' if (Tstar >= 5000): file = 'Claret_hot_nlin.dat' else: skiprows = 58 filtcol = 4 metcol = 5 mercol = 6 col1 = 9 col2 = 10 col3 = 11 col4 = 12 if (Tstar <= 4800): file = 'Claret_cool.dat' if (Tstar >= 5000): file = 'Claret_hot.dat' if network == 'doug': path = '/home/douglas/Astronomy/Resources/' if network == 'astro': path = '/home/jswift/Mdwarfs/' if network == None: path = '/Users/jonswift/Astronomy/Exoplanets/TransitFits/' limbdata = np.loadtxt(path+file,dtype='string', delimiter='|',skiprows=skiprows) logg = limbdata[:,0].astype(np.float).flatten() Teff = limbdata[:,1].astype(np.float).flatten() Z = limbdata[:,2].astype(np.float).flatten() xi = limbdata[:,3].astype(np.float).flatten() filt = np.char.strip(limbdata[:,filtcol].flatten()) method = limbdata[:,metcol].flatten() avec = limbdata[:,col1].astype(np.float).flatten() bvec = limbdata[:,col2].astype(np.float).flatten() cvec = limbdata[:,col3].astype(np.float).flatten() dvec = limbdata[:,col4].astype(np.float).flatten() # Select out the limb darkening coefficients # inds = np.where((filt == 'Kp') & (Teff == 3000) & (logg == 5.0) & (method == 'L')) idata, = np.where((filt == filter) & (method == 'L')) npts = idata.size uTeff = np.unique(Teff[idata]) ulogg = np.unique(logg[idata]) # agrid0 = np.zeros((len(uTeff),len(ulogg))) # for i in np.arange(len(uTeff)): # for ii in np.arange(len(ulogg)): # ind, = np.where((Teff[idata] == uTeff[i]) & (logg[idata] == ulogg[ii])) # val = avec[idata[ind]] # if len(val) > 0: # agrid0[i,ii] = val[0] # else: # pass #pdb.set_trace() locs = np.zeros(2*npts).reshape(npts,2) locs[:,0] = Teff[idata].flatten() locs[:,1] = logg[idata].flatten() vals = np.zeros(npts) vals[:] = avec[idata] agrid = np.zeros((len(uTeff),len(ulogg))) for i in np.arange(len(uTeff)): for ii in np.arange(len(ulogg)): eval = np.array([uTeff[i],ulogg[ii]]).reshape(1,2) val = griddata(locs,vals,eval,method='cubic') if len(val) > 0: agrid[i,ii] = val[0] else: pass #pdb.set_trace() ldc1func = bspline(uTeff, ulogg, agrid, kx=1, ky=1, s=0) aval = ldc1func(Tstar,loggstar)[0][0] if plot: plt.figure(1) plt.clf() plt.imshow(agrid,interpolation='none', extent=[np.min(ulogg),np.max(ulogg),np.min(uTeff),np.max(uTeff)], aspect=1./1000,vmin=np.min(agrid),vmax=np.max(agrid)) plt.colorbar() #------------------------------ # Second coefficient #------------------------------ vals = np.zeros(npts) vals[:] = bvec[idata] bgrid = np.zeros((len(uTeff),len(ulogg))) for i in np.arange(len(uTeff)): for ii in np.arange(len(ulogg)): eval = np.array([uTeff[i],ulogg[ii]]).reshape(1,2) val = griddata(locs,vals,eval,method='cubic') if len(val) > 0: bgrid[i,ii] = val[0] else: pass ldc2func = bspline(uTeff, ulogg, bgrid, kx=1, ky=1, s=0) bval = ldc2func(Tstar,loggstar)[0][0] if plot: plt.figure(2) plt.clf() plt.imshow(bgrid,interpolation='none', extent=[np.min(ulogg),np.max(ulogg),np.min(uTeff),np.max(uTeff)], aspect=1./1000,vmin=np.min(bgrid),vmax=np.max(bgrid)) plt.colorbar() #------------------------------ # Third coefficient #------------------------------ vals = np.zeros(npts) vals[:] = cvec[idata] cgrid = np.zeros((len(uTeff),len(ulogg))) for i in np.arange(len(uTeff)): for ii in np.arange(len(ulogg)): eval = np.array([uTeff[i],ulogg[ii]]).reshape(1,2) val = griddata(locs,vals,eval,method='cubic') if len(val) > 0: cgrid[i,ii] = val[0] else: pass ldc3func = bspline(uTeff, ulogg, cgrid, kx=1, ky=1, s=0) cval = ldc3func(Tstar,loggstar)[0][0] if plot: plt.figure(3) plt.clf() plt.imshow(cgrid,interpolation='none', extent=[np.min(ulogg),np.max(ulogg),np.min(uTeff),np.max(uTeff)], aspect=1./1000,vmin=np.min(cgrid),vmax=np.max(cgrid)) plt.colorbar() #------------------------------ # Fourth coefficient #------------------------------ vals = np.zeros(npts) vals[:] = dvec[idata] dgrid = np.zeros((len(uTeff),len(ulogg))) for i in np.arange(len(uTeff)): for ii in np.arange(len(ulogg)): eval = np.array([uTeff[i],ulogg[ii]]).reshape(1,2) val = griddata(locs,vals,eval,method='cubic') if len(val) > 0: dgrid[i,ii] = val[0] else: pass ldc4func = bspline(uTeff, ulogg, dgrid, kx=1, ky=1, s=0) dval = ldc4func(Tstar,loggstar)[0][0] if plot: plt.figure(4) plt.clf() plt.imshow(dgrid,interpolation='none', extent=[np.min(ulogg),np.max(ulogg),np.min(uTeff),np.max(uTeff)], aspect=1./1000,vmin=np.min(dgrid),vmax=np.max(dgrid)) plt.colorbar() if limb == 'quad': return aval, bval if limb == 'sqrt': return cval, dval if limb == 'nlin': return aval, bval, cval, dval