matplotlib.mlab.griddata very slow and returns array of nan when valid data is input

后端 未结 4 727
予麋鹿
予麋鹿 2021-02-10 00:23

I am trying to map an irregularly gridded dataset (raw satellite data) with associated latitudes and longitudes to a regularly gridded set of latitudes and longitudes given by <

相关标签:
4条回答
  • 2021-02-10 01:00

    More than likely, griddata is way too hard. It's designed to work with randomly sampled data. Your data is almost certainly regularly sampled -- just not on the same grid as your target output grid.

    Look at a much simpler approach like an affine transformation or a series of affine transformations on small chips if the earth's topology or curvature affect yoru results.

    There are some out of the box solutions that might help. GDAL is a good example.

    Also, this type of issue is often discussed in GIS. See:

    https://gis.stackexchange.com/questions/10430/changing-image-projection-using-python

    0 讨论(0)
  • 2021-02-10 01:02

    If your data is on a grid such that data point at point (datalon[i], datalat[j]) is in data[i,j], then you can use scipy.interpolate.RectBivariateSpline instead of griddata. Some geography-specific libraries may offer more functionality, though.

    0 讨论(0)
  • 2021-02-10 01:06

    If you use pclormesh, you don't have to do any sort of interpolation. pcolormesh would gladly accept the data structure the way you have given here:

    from mpl_toolkits.basemap import Basemap
    m = Basemap(-----)
    x,y = m(datalon, datalat)
    m.pcolormesh(x,y,var)
    plt.show()
    

    kindly use this and tell me if this works or not.

    However, there is some problem in pcolormesh when there is overlap of the orbit data. Please refer to this question of mine, you may find something useful.

    Using pcolormesh for plotting an orbit data

    0 讨论(0)
  • 2021-02-10 01:10

    It looks like the mlab.griddata routine may introduce additional constraints on your output data that may not be necessary. While the input locations may be anything, the output locations must be a regular grid - since your example is in lat/lon space, your choice of map projection may violate this (i.e. regular grid in x/y is not a regular grid in lat/lon).

    You might try the interpolate.griddata routine from SciPy as an alternative - you'll need to combine your location variables into a single array, though, since the call signature is different: something like

    import scipy.interpolate
    data_locations = np.vstack(datalon.ravel(), datalat.ravel()).T
    grid_locations = np.vstack(gridlon.ravel(), gridlat.ravel()).T
    grid_data      = scipy.interpolate.griddata(data_locations, val.ravel(),
                                                grid_locations, method='nearest')
    

    for nearest-neighbor interpolation. This gets the locations into an array with 2 columns corresponding to your 2 dimensions. You may also want to perform the interpolation in the transformed space of your map projection.

    0 讨论(0)
提交回复
热议问题