I have a netcdf file with high resolution grided data (.1 x .1 deg) and plotting on the basemap using matplotlib. The plot I am trying to do is contour lines. For a specific reason I would like to plot the data at the interval of 1 x 1 deg resolution. For which I have used the following code sample example from here Regridding regular netcdf data.
See the update 1 for link to actual data.
For the sake of clearity following is the code I am trying to execute for regridding to lower resolution:-
from mpl_toolkits import basemap
from netCDF4 import Dataset
filename = 'path/to/netcdf/file.nc'
with Dataset(filename, mode='r') as fh:
lons = fh.variables['LON'][:]
lats = fh.variables['LAT'][:]
data = fh.variables['Data'][:].squeeze()
lons_sub, lats_sub = np.meshgrid(lons[::4], lats[::4], sparse=True)
data_coarse = basemap.interp(data, lons, lats, lons_sub, lats_sub, order=1)
The code seems to be correct. But when I execute the code I get the following error in the line data_coarse = basemap.interp(data, lons, lats, lons_sub, lats_sub, order=3)
:-
/__init__.py", line 4897, in interp
if xin[-1]-xin[0] < 0 or yin[-1]-yin[0] < 0:
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
I have not understood where the problem lies and how to solve this?
Any help is appreciated.
Update 1
link to the actual data https://www.dropbox.com/s/ddlpbw5vvj5kz5w/mslp.txt?dl=0
link to lats https://www.dropbox.com/s/lpwjavxtwtt3r13/xlat.txt?dl=0
and the link to lons https://www.dropbox.com/s/1a0q49drfcd2o9h/xlon.txt?dl=0
netcdf
expert, but I don't see how the code you provided can be run with the plain text file you uploaded. – lanerydata = np.loadtxt('mslp.txt',delimiter=',')
. – sundar_imadata
is (189, 309) and it is not obvious to me whatlons
andlats
should be. – lanery