#!/usr/bin/env python # Last modified: Time-stamp: <2010-10-28 20:20:48 haines> """swan_model_plot""" import os, sys import datetime, time, dateutil.tz import pycdf import numpy sys.path.append('/opt/env/haines/dataproc/raw2proc') del(sys) os.environ["MPLCONFIGDIR"]="/home/haines/.matplotlib/" from pylab import figure, twinx, savefig, setp, getp, cm, colorbar import procutil import ncutil print 'swan_model_plot ...' # shows how to load mulitple files of same structure. ncFile1='/seacoos/data/nccoos/test_data/20101018_1800_NSNH_CG1.nc' ncFile2='/some/other/data/file.nc' # load data have_ncFile1 = os.path.exists(ncFile1) have_ncFile2 = os.path.exists(ncFile2) print ' ... loading data for graph from ...' print ' ... ... ' + ncFile1 + ' ... ' + str(have_ncFile1) print ' ... ... ' + ncFile2 + ' ... ' + str(have_ncFile2) if have_ncFile1 and have_ncFile2: nc = pycdf.CDFMF((ncFile1, ncFile2)) elif not have_ncFile1 and have_ncFile2: nc = pycdf.CDFMF((ncFile2,)) elif have_ncFile1 and not have_ncFile2: nc = pycdf.CDFMF((ncFile1,)) else: print ' ... both files do not exist -- NO DATA LOADED' exit() ncvars = nc.variables() print ncvars print ncvars['wndMag'] ####################################### fig = figure(figsize=(8, 10)) fig.subplots_adjust(left=0.1, bottom=0.1, right=0.9, top=0.9, wspace=0.1, hspace=0.1) ax = fig.add_subplot(2,1,1) # ---------- LAT and LON -------- x = nc.var('x')[:] y = nc.var('y')[:] # -------- WIND DATA ------------ wndDir = nc.var('wndDir')[:] wndMag = nc.var('wndMag')[:] # subset first record and first level, but all y and x # ('record', 'level', 'y', 'x'), (12, 1, 143, 103) # and then transpose so that wdir(x,y) wdir = wndDir[0,0,:,:] wdir = wdir.T wmag = wndMag[0,0,:,:] wmag = wmag.T u = wmag*numpy.sin(wdir*numpy.pi/180) v = wmag*numpy.cos(wdir*numpy.pi/180) # use masked array to hide 0's on plot mu = numpy.ma.masked_where(u==0, u) mv = numpy.ma.masked_where(v==0, v) ax.barbs(x, y, mu, mv) ax.set_ylabel('Latitude') ax.set_xlabel('Longitude') # ------- WAVE DATa ---------- Hs = nc.var('htsgw')[:] Dp = nc.var('dirpw')[:] Hs = Hs[0,0,:,:] Dp = Dp[0,0,:,:] X,Y = numpy.meshgrid(x,y) mHs = numpy.ma.masked_where(Hs==10, Hs) ax = fig.add_subplot(2,1,2) ax.pcolor(X, Y, mHs) savefig('/home/haines/rayleigh/test_swan_model_plot.png')