I'm trying to plot wind barbs in basemap and I have two separate netCDF files.
Here is what I am trying to produce, or something like it:
How do I read a uwnd variable in a netCDF file in python?
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
This verifies that uwnd is indeed a variable, but why won't it read?
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'
I'm trying to plot some widnbarbs on the map. i have successfully gotten it to read the time, longitude, and latitude, bu what does the uwnd mean and how do I read it into the numpy format?
Here is the site I found on how to read netCDF files: http://www.hydro.washington.edu/~jhamman/hydro-logic/blog/2013/10/12/plot-netcdf-data/