#mesh_filename = 'x1.2621442.grid.nc' # 15 km mesh mesh_nc = Dataset(mesh_filename) lats = mesh_nc.variables['latCell'][:] print 'min/max lats:',lats.min(), lats.max() lons = mesh_nc.variables['lonCell'][:] print 'min/max lons:',lons.min(), lons.max() # fake test data. def test_func(lon, lat): nexp = 8 return np.cos(nexp*lon)*np.sin(0.5*lon)**nexp*np.cos(lat)**nexp+np.sin(lat)**nexp icos_data = test_func(lons,lats) t1 = time.clock() print 'triangulation of', len(lons),' points' tri = trintrp(lons, lats, reorder='lat') print 'triangulation took',time.clock()-t1,' secs' nlons = 360; nlats = nlons/2 # 1 degree output mesh delta = 360./nlons olons = delta*np.arange(nlons) olats = -90.0 + 0.5*delta + delta*np.arange(nlats) olons = np.radians(olons); olats = np.radians(olats) olons, olats = np.meshgrid(olons, olats) t1 = time.clock() order = 1 # can be 0 (nearest neighbor), 1 (linear) or 3 (cubic) latlon_data = tri.interp(olons,olats,icos_data,order=order) print 'interpolation took',time.clock()-t1,' secs' latlon_datax = test_func(olons,olats)
if phi < 0.: phi = 2.*pi+phi lons.append( phi ) return np.array(lats), np.array(lons) # fake test data. def test_func(lon, lat): nexp = 8 return np.cos(nexp*lon)*np.sin(0.5*lon)**nexp*np.cos(lat)**nexp+np.sin(lat)**nexp npts = 360*180/4 lats, lons = fibonacci_pts(npts) icos_data = test_func(lons,lats) t1 = time.clock() print 'triangulation of', len(lons),' points' tri = trintrp(lons, lats) print 'triangulation took',time.clock()-t1,' secs' nlons = 360; nlats = nlons/2 + 1 # 1 degree output mesh delta = 360./nlons olons = delta*np.arange(nlons) olats = -90.0 + delta*np.arange(nlats) olons = np.radians(olons); olats = np.radians(olats) olons, olats = np.meshgrid(olons, olats) t1 = time.clock() order = 1 # can be 0 (nearest neighbor), 1 (linear) or 3 (cubic) latlon_data = tri.interp(olons,olats,icos_data,order=order) print 'interpolation took',time.clock()-t1,' secs' latlon_datax = test_func(olons,olats)
return np.array(lats), np.array(lons) # fake test data. def test_func(lon, lat): nexp = 8 return np.cos(nexp * lon) * np.sin(0.5 * lon) ** nexp * np.cos(lat) ** nexp + np.sin(lat) ** nexp npts = 360 * 180 / 4 lats, lons = fibonacci_pts(npts) icos_data = test_func(lons, lats) t1 = time.clock() print "triangulation of", len(lons), " points" tri = trintrp(lons, lats) print "triangulation took", time.clock() - t1, " secs" nlons = 360 nlats = nlons / 2 + 1 # 1 degree output mesh delta = 360.0 / nlons olons = delta * np.arange(nlons) olats = -90.0 + delta * np.arange(nlats) olons = np.radians(olons) olats = np.radians(olats) olons, olats = np.meshgrid(olons, olats) t1 = time.clock() order = 1 # can be 0 (nearest neighbor), 1 (linear) or 3 (cubic) latlon_data = tri.interp(olons, olats, icos_data, order=order) print "interpolation took", time.clock() - t1, " secs"
lons = mesh_nc.variables['lonCell'][:] print 'min/max lons:', lons.min(), lons.max() # fake test data. def test_func(lon, lat): nexp = 8 return np.cos(nexp * lon) * np.sin( 0.5 * lon)**nexp * np.cos(lat)**nexp + np.sin(lat)**nexp icos_data = test_func(lons, lats) t1 = time.clock() print 'triangulation of', len(lons), ' points' tri = trintrp(lons, lats, reorder='lat') print 'triangulation took', time.clock() - t1, ' secs' nlons = 360 nlats = nlons / 2 # 1 degree output mesh delta = 360. / nlons olons = delta * np.arange(nlons) olats = -90.0 + 0.5 * delta + delta * np.arange(nlats) olons = np.radians(olons) olats = np.radians(olats) olons, olats = np.meshgrid(olons, olats) t1 = time.clock() order = 1 # can be 0 (nearest neighbor), 1 (linear) or 3 (cubic) latlon_data = tri.interp(olons, olats, icos_data, order=order) print 'interpolation took', time.clock() - t1, ' secs'