#!/usr/bin/env python ### A. Spiga -- LMD -- 30/05/2011 def domain (namefile,proj="ortho",back="molabw",target=None,var='HGT'): from netCDF4 import Dataset from myplot import getcoord2d,define_proj,makeplotpng,simplinterv from matplotlib.pyplot import contourf nc = Dataset(namefile) [lon2d,lat2d] = getcoord2d(nc) [wlon,wlat] = simplinterv(lon2d,lat2d) m = define_proj(proj,wlon,wlat,back=back) x, y = m(lon2d, lat2d) contourf(x, y, nc.variables[var][0,:,:], 40) if not target: zeplot = namefile+".domain" else: zeplot = target+"/domain" makeplotpng(zeplot,pad_inches_value=0.35) if __name__ == "__main__": import sys ### to be replaced by argparse from optparse import OptionParser parser = OptionParser() parser.add_option('-f', action='store', dest='namefile', type="string", default=None, help='name of WRF file [NEEDED]') parser.add_option('-p', action='store', dest='proj', type="string", default="ortho", help='projection') parser.add_option('-b', action='store', dest='back', type="string", default="molabw", help='background') parser.add_option('-t', action='store', dest='target', type="string", default=None, help='destination folder') parser.add_option('-v', action='store', dest='var', type="string", default='HGT', help='variable contoured') (opt,args) = parser.parse_args() if opt.namefile is None: print "I want to eat one file at least ! Use domain.py -f name_of_my_file. Or type domain.py -h" exit() print "Options:", opt domain (opt.namefile,proj=opt.proj,back=opt.back,target=opt.target,var=opt.var)