Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.4k views
in Technique[技术] by (71.8m points)

python: scipy.interpolate.griddata causes script to end

I am trying to use scipy interpolate griddata to interpolate a regular grid of lat/lon data points. When I try to run the script however I get the 'Zipped' line printed, then a pause, then the script ends without printing anything else or plotting the contour plot. There are no errror messages displayed. What am I doing wrong. See relavent section of code below.

general_file = r'datal3bx
etcdf
0024ir2_20160815_114117_232_l3bx_v10.nc'
    file_data = Dataset(general_file)                                                   #Reading in the data
    m = Basemap(projection='moll', resolution=None, lat_0=0, lon_0=0)

    axis1 = file_data.variables['axis1'][:].data                                             #Extracting values neeed
    axis2 = file_data.variables['axis2'][:].data
    rad = file_data.variables['radiance'][0].data

    lon = file_data.variables['lon'][:][0].data   
    lat = file_data.variables['lat'][:][0].data

    xi = np.arange(-180,190,10)
    yi = np.arange(-90,100,10)
    grid_x, grid_y = np.meshgrid(xi,yi)

    rad = rad.flatten()
    lon = lon.flatten()
    lat = lat.flatten()
    points = np.array(list(zip(lon,lat)))
    print('Zipped')
    grid_z = interpolate(points, rad, grid_x, grid_y)
    plt.contourf(grid_x, grid_y, grid_z,25,cmap='Greys_r')
    plt.colorbar()
    plt.show()
    print('End')

def interpolate(points, rad, grid_x, grid_y):
    grid_z = griddata((lon, lat), rad, (grid_x, grid_y), method='nearest')
    print('Interpolated')
    return grid_z

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...