3

How can I fix *ProjError: x, y, z, and time must be same size+ error?

I was loading an .nc-file and view dataset.

lat, lon are of data exchanging Basemap type.

But the error message call three valuation. x, y, z.

XU_OCEAN_uv = uv.variables['XU_OCEAN'][:]
YU_OCEAN_uv = uv.variables['YU_OCEAN'][:]

lon_0 = XU_OCEAN_uv.mean()
lat_0 = YU_OCEAN_uv.mean()

fig = plt.figure(figsize=[12,15])

plt.rc("font", size=20)
plt.rcParams['font.family'] = 'New Century Schoolbook'

from datetime import datetime
fig = plt.figure(figsize=[12,15])

m = Basemap(width=5000000,height=3500000,
               resolution='l',projection='stere',\
               lat_ts=40,lat_0=lat_0,lon_0=lon_0)



m.drawcoastlines()
m.drawcountries()
m.drawmapboundary(fill_color='white')
m.drawparallels(np.arange(-90,91,30),labels=[1,0,0,0],dashes=[2,2])
m.drawmeridians(np.arange(0,361,60),labels=[0,0,0,1],dashes=[2,2]) 



VO_uv_firstTimestep = VO_uv[0,:,:]
cs = m.pcolor(LON,LAT,VO_uv_firstTimestep)

cbar = m.colorbar(cs, location='bottom', pad="10%")
cbar.set_label(VO_uv_units)

# Add Title
plt.title('sea level height')

plt.show()

The dataset looks like this:

enter image description here

The Error code is:

---------------------------------------------------------------------------
ProjError                                 Traceback (most recent call last)
<ipython-input-59-abf5ef221078> in <module>
     26 
     27 #m.scatter(X, Y, c=VAL, s=1.0, marker="s", zorder=1, vmin=0, vmax=1200,                     cmap=plt.cm.get_cmap('jet'), alpha=1.0)
---> 28 LON,LAT = m(XU_OCEAN_uv,YU_OCEAN_uv)
     29 
     30 VO_uv_firstTimestep = VO_uv[0,:,:]

/opt/anaconda3/envs/py37/lib/python3.7/site-packages/mpl_toolkits/basemap/__init__.py in         __call__(self, x, y, inverse)
   1186             except TypeError:
   1187                 y = [_dg2rad*yy for yy in y]
-> 1188         xout,yout = self.projtran(x,y,inverse=inverse)
   1189         if self.celestial and inverse:
   1190             try:

/opt/anaconda3/envs/py37/lib/python3.7/site-packages/mpl_toolkits/basemap/proj.py in     __call__(self, *args, **kw)
    291             outxy = self._proj4(xy, inverse=inverse)
    292         else:
--> 293             outx,outy = self._proj4(x, y, inverse=inverse)
    294         if inverse:
    295             if self.projection in ['merc','mill','gall']:

/opt/anaconda3/envs/py37/lib/python3.7/site-packages/pyproj/proj.py in __call__(self, longitude,     latitude, inverse, errcheck, radians)
    185             direction=direction,
    186             errcheck=errcheck,
--> 187             radians=radians,
    188         )
    189 

/opt/anaconda3/envs/py37/lib/python3.7/site-packages/pyproj/transformer.py in     transform(self, xx, yy, zz, tt, radians, errcheck, direction)
    493             direction=direction,
    494             radians=radians,
--> 495             errcheck=errcheck,
    496         )
    497         # if inputs were lists, tuples or floats, convert back.

pyproj/_transformer.pyx in pyproj._transformer._Transformer._transform()

ProjError: x, y, z, and time must be same size
max
  • 3,915
  • 2
  • 9
  • 25
bigdata
  • 31
  • 1
  • 2
  • 1
    Welcome to stackoverflow. I found it hard to follow your description. Nevertheless, your example-code misses the line, which produces the error `LON,LAT = m(XU_OCEAN_uv,YU_OCEAN_uv)`... – max Jan 11 '21 at 15:11
  • You should use `XU_OCEAN_uv` and `YU_OCEAN_uv` to create meshgrid first. The result of meshgrid can be used as `LON,LAT = m(XU_mesh, YU_mesh)` in place of `LON,LAT = m(XU_OCEAN_uv,YU_OCEAN_uv)` which causes error. – swatchai Jan 14 '21 at 10:02

0 Answers0