1 | #!/usr/bin/env python |
---|
2 | |
---|
3 | ### A. Spiga -- LMD -- 30/06/2011 -- slight modif early 07/2011 |
---|
4 | |
---|
5 | def domain (namefile,proj=None,back="vishires",target=None): |
---|
6 | from netCDF4 import Dataset |
---|
7 | from myplot import getcoord2d,define_proj,makeplotpng,simplinterv,getprefix,dumpbdy,getproj,latinterv,wrfinterv,simplinterv |
---|
8 | from matplotlib.pyplot import contourf,rcParams |
---|
9 | from numpy.core.defchararray import find |
---|
10 | ### |
---|
11 | nc = Dataset(namefile) |
---|
12 | ### |
---|
13 | if proj == None: proj = "ortho" #proj = getproj(nc) |
---|
14 | ### |
---|
15 | prefix = namefile[0] + namefile[1] + namefile[2] |
---|
16 | if prefix == "geo": |
---|
17 | [lon2d,lat2d] = getcoord2d(nc,nlat='XLAT_M',nlon='XLONG_M') |
---|
18 | var = 'HGT_M' |
---|
19 | zeplot = "domain" |
---|
20 | else: |
---|
21 | [lon2d,lat2d] = getcoord2d(nc) |
---|
22 | var = "HGT" |
---|
23 | zeplot = getprefix(nc) + "domain" |
---|
24 | ### |
---|
25 | lon2d = dumpbdy(lon2d) |
---|
26 | lat2d = dumpbdy(lat2d) |
---|
27 | if proj == "npstere": [wlon,wlat] = latinterv("North_Pole") |
---|
28 | elif proj in ["lcc","laea"]: [wlon,wlat] = wrfinterv(lon2d,lat2d) |
---|
29 | else: [wlon,wlat] = simplinterv(lon2d,lat2d) |
---|
30 | ### |
---|
31 | m = define_proj(proj,wlon,wlat,back=back) |
---|
32 | x, y = m(lon2d, lat2d) |
---|
33 | ### |
---|
34 | what_I_plot = dumpbdy( nc.variables[var][0,:,:] ) |
---|
35 | contourf(x, y, what_I_plot, 40) |
---|
36 | ### |
---|
37 | if not target: zeplot = namefile[0:find(namefile,'wrfout')] + zeplot |
---|
38 | else: zeplot = target + "/" + zeplot |
---|
39 | ### |
---|
40 | makeplotpng(zeplot,pad_inches_value=0.35) |
---|
41 | #rcParams['savefig.facecolor'] = 'black' |
---|
42 | #makeplotpng(zeplot+"b",pad_inches_value=0.35) |
---|
43 | |
---|
44 | if __name__ == "__main__": |
---|
45 | import sys |
---|
46 | ### to be replaced by argparse |
---|
47 | from optparse import OptionParser |
---|
48 | parser = OptionParser() |
---|
49 | parser.add_option('-f', action='store', dest='namefile', type="string", default=None, help='name of WRF file [NEEDED]') |
---|
50 | parser.add_option('-p', action='store', dest='proj', type="string", default=None, help='projection') |
---|
51 | parser.add_option('-b', action='store', dest='back', type="string", default="vishires", help='background') |
---|
52 | parser.add_option('-t', action='store', dest='target', type="string", default=None, help='destination folder') |
---|
53 | (opt,args) = parser.parse_args() |
---|
54 | if opt.namefile is None: |
---|
55 | print "I want to eat one file at least ! Use domain.py -f name_of_my_file. Or type domain.py -h" |
---|
56 | exit() |
---|
57 | print "Options:", opt |
---|
58 | domain (opt.namefile,proj=opt.proj,back=opt.back,target=opt.target) |
---|