2015-10-21 64 views
0

我想繪製輪廓/箭袋情節下的底圖。我的下面的代碼沒有提供任何錯誤,但圖像無法正確顯示;只顯示顫抖。任何幫助?輪廓/箭袋情節上的底圖疊加Python

import netCDF4 
import numpy as np 
import matplotlib 
import matplotlib.pyplot as plt 
import pylab 
from mpl_toolkits.basemap import Basemap 

ncfile = netCDF4.Dataset('30JUNE2012_0400UTC.cdf', 'r') 
dbZ = ncfile.variables['MAXDBZF'] 
u = ncfile.variables['UNEW'] 
v = ncfile.variables['VNEW'] 
print u 
print v 
print dbZ 

data = dbZ[0,0] 

data.shape 

print data.shape 


z_index = 0 # z-level you want to plot (0-19) 
U = u[0,z_index, :,:] #[time,z,x,y] 
V = v[0,z_index, :,:] 

map = Basemap(projection = 'merc',llcrnrlat=36,urcrnrlat=40,\ 
llcrnrlon=-80,urcrnrlon=-74,lat_ts=20,resolution='i') 
x = np.arange(0,150) 
y = np.arange(0,150) 

X,Y = np.meshgrid(x,y) 
lon, lat = map(X,Y, inverse = True) 

levels = np.arange(5,60,3) 
c = plt.contourf(lon,lat,data, levels, cmap='jet') 
plt.colorbar() 
plt.hold(True) 
q=plt.quiver(U,V,width=0.002, scale_units='xy',scale=10) 
qk= plt.quiverkey (q,0.95, 1.02, 20, '20m/s', labelpos='N') 
plt.xlim([0,120]) 

plt.ylim([0,120]) 


plt.xlabel('X') 
plt.ylabel('Y') 
plt.title('Reflectivity and Dual-Doppler Winds at 1 KM', fontsize=12) 
plt.show() 

Here is my data structure: 
<type 'netCDF4.Variable'> 
float32 UNEW(time, z, y, x) 
    missing_value: -32768.0 
unlimited dimensions: time 
current shape = (1, 20, 150, 150) 
filling off 

<type 'netCDF4.Variable'> 
float32 VNEW(time, z, y, x) 
    missing_value: -32768.0 
unlimited dimensions: time 
current shape = (1, 20, 150, 150) 
filling off 

<type 'netCDF4.Variable'> 
float32 MAXDBZF(time, z, y, x) 
    missing_value: -32768.0 
unlimited dimensions: time 
current shape = (1, 20, 150, 150) 
filling off 

圖像看上去像: enter image description here

+0

在這裏你有一些混淆,經/緯度,您使用範圍0-150代表Y,其中在緯度範圍從-90到90的範圍內是沒有意義的。你的netCDF文件是否包含x和y維度的緯度/經度的顯式聲明? – daryl

+0

是的,它只在文件中有1個點。 Lat = 38.97和Lon = -77.47daryl –

回答

0

您需要添加經度,緯度你也顫抖,否則將在其他軸的比例來繪製。 您使用的經緯度是沒有意義的(正如@daryl在評論中所說的)。 根據您的地圖投影,我建議是這樣的:

lonmin = -80 
lonmax = -74 
latmin = 36 
latmax = 40 

m = Basemap(projection = 'merc',llcrnrlat=latmin,urcrnrlat=latmax, llcrnrlon=lonmin,urcrnrlon=lonmax,lat_ts=20,resolution='i') 

#you should avoid using "map" since its a build-in function. 

x = np.arange(lonmin,lonmax,(lonmax-lonmin)/float(U.shape[2])) 
y = np.arange(latmin,latmax,(latmax-latmin)/float(U.shape[1])) 

X,Y = np.meshgrid(x,y) 
lon, lat = m(X,Y) 

則:

c = plt.contourf(lon,lat,data, levels, cmap='jet') 
plt.colorbar(c) 

q=plt.quiver(lon,lat,U,V,width=0.002, scale_units='xy',scale=10) 
qk= plt.quiverkey (q,0.95, 1.02, 20, '20m/s', labelpos='N') 

plt.xlim([lon[0,0],lon[-1,-1]]) 
plt.ylim([lat[0,0],lat[-1,-1]]) 

plt.xlabel('X') 
plt.ylabel('Y') 
plt.title('Reflectivity and Dual-Doppler Winds at 1 KM', fontsize=12) 
plt.show()