0
如何在python中的netCDF文件中读取uwnd变量?在NetCDF文件中的uwnd变量
from mpl_toolkits.basemap import Basemap
from netCDF4 import Dataset, date2index
import numpy as np
import matplotlib.pyplot as plt
from datetime import datetime
from IPython.display import Image
from IPython.core.display import HTML
import netCDF4 as nc
plt.clf()
nc_file = '042711_V.nc'
nc_file2 = '042711_U.nc'
V = Dataset(nc_file, mode='r')
U = Dataset(nc_file2, mode='r')
print U.variables
这验证了uwnd确实是一个变量,但它为什么不读它?
OrderedDict([(u'lat', <type 'netCDF4._netCDF4.Variable'>
float32 lat(lat)
units: degrees_north
actual_range: [ 90. -90.]
long_name: Latitude
unlimited dimensions:
current shape = (73,)
filling off
), (u'lon', <type 'netCDF4._netCDF4.Variable'>
float32 lon(lon)
units: degrees_east
long_name: Longitude
actual_range: [ 0. 357.5]
unlimited dimensions:
current shape = (144,)
filling off
), (u'time', <type 'netCDF4._netCDF4.Variable'>
float64 time(time)
units: hours since 1800-1-1 00:00:0.0
long_name: Time
actual_range: [ 71870952. 71870952.]
delta_t: 0000-01-00 00:00:00
unlimited dimensions: time
current shape = (1,)
filling off
), (u'uwnd', <type 'netCDF4._netCDF4.Variable'>
float32 uwnd(time, lat, lon)
long_name: u wind
valid_range: [-99999. 99999.]
actual_range: [ -26.84999084 377.20001221]
units: m/s
add_offset: 0.0
scale_factor: 1.0
missing_value: -9.96921e+36
precision: 99
least_significant_digit: 99
var_desc: u wind
dataset: CDC Derived NCEP Reanalysis Products
level_desc: 500mb Pressure Level
statistic: Composite
parent_stat: Other
unlimited dimensions: time
current shape = (1, 73, 144)
filling off
)])
KeyError: 'uwnd'
我想在地图上绘制一些widnbarbs。我已经成功地读取了它的时间,经度和纬度,这个uwnd是什么意思,我怎么把它读成numpy格式?
这里是我如何读的netCDF文件中找到的网站: http://www.hydro.washington.edu/~jhamman/hydro-logic/blog/2013/10/12/plot-netcdf-data/
我想它调整到你所拥有的,我仍然获得“uwnd”未找到的关键错误。我同意格式匹配,但我仍然得到错误。 –
可以肯定的是,你可以在某处发布'ncdump -h 042711_U.nc'的输出吗? – Bart
我在IPython的笔记本工作,所以我得到: 文件 “”,第1行 ncdump -h 042711_U.nc ^ 语法错误:无效的语法 –