source: trunk/MESOSCALE/PLOT/PYTHON/scripts/domain.py @ 203

Last change on this file since 203 was 203, checked in by aslmd, 13 years ago

MESOSCALE: python. sorry, forgot one bug fix: dumpbdy in domain.py

  • Property svn:executable set to *
File size: 2.1 KB
Line 
1#!/usr/bin/env python
2
3### A. Spiga -- LMD -- 30/06/2011 -- slight modif early 07/2011
4
5def domain (namefile,proj="ortho",back="vishires",target=None,var='HGT'): 
6    from netCDF4 import Dataset
7    from myplot import getcoord2d,define_proj,makeplotpng,simplinterv,getprefix,dumpbdy
8    from matplotlib.pyplot import contourf,rcParams
9    from numpy.core.defchararray import find
10    ###
11    nc  = Dataset(namefile)
12    ###
13    [lon2d,lat2d] = getcoord2d(nc)
14    lon2d = dumpbdy(lon2d)
15    lat2d = dumpbdy(lat2d)
16    [wlon,wlat] = simplinterv(lon2d,lat2d)
17    ###
18    m = define_proj(proj,wlon,wlat,back=back)
19    x, y = m(lon2d, lat2d)
20    ###
21    what_I_plot = dumpbdy( nc.variables[var][0,:,:] )
22    contourf(x, y, what_I_plot, 40)
23    ###
24    zeplot = getprefix(nc) + "domain"
25    if not target:   zeplot = namefile[0:find(namefile,'wrfout')] + zeplot
26    else:            zeplot = target + "/" + zeplot         
27    ###
28    makeplotpng(zeplot,pad_inches_value=0.35)
29    #rcParams['savefig.facecolor'] = 'black'
30    #makeplotpng(zeplot+"b",pad_inches_value=0.35)
31
32if __name__ == "__main__":
33    import sys
34    ### to be replaced by argparse
35    from optparse import OptionParser
36    parser = OptionParser()
37    parser.add_option('-f', action='store', dest='namefile',    type="string",  default=None,       help='name of WRF file [NEEDED]')
38    parser.add_option('-p', action='store', dest='proj',        type="string",  default="ortho",    help='projection')
39    parser.add_option('-b', action='store', dest='back',        type="string",  default="vishires", help='background')
40    parser.add_option('-t', action='store', dest='target',      type="string",  default=None,       help='destination folder')
41    parser.add_option('-v', action='store', dest='var',         type="string",  default='HGT',      help='variable contoured')
42    (opt,args) = parser.parse_args()
43    if opt.namefile is None:
44        print "I want to eat one file at least ! Use domain.py -f name_of_my_file. Or type domain.py -h"
45        exit()
46    print "Options:", opt
47    domain (opt.namefile,proj=opt.proj,back=opt.back,target=opt.target,var=opt.var)
Note: See TracBrowser for help on using the repository browser.