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,makeplotres,simplinterv,getprefix,dumpbdy,getproj,latinterv,wrfinterv,simplinterv |
---|
8 | from mymath import max,min |
---|
9 | from matplotlib.pyplot import contourf,rcParams,pcolor |
---|
10 | from numpy.core.defchararray import find |
---|
11 | from numpy import arange |
---|
12 | ### |
---|
13 | nc = Dataset(namefile) |
---|
14 | ### |
---|
15 | if proj == None: proj = "ortho" #proj = getproj(nc) |
---|
16 | ### |
---|
17 | prefix = namefile[0] + namefile[1] + namefile[2] |
---|
18 | if prefix == "geo": |
---|
19 | [lon2d,lat2d] = getcoord2d(nc,nlat='XLAT_M',nlon='XLONG_M') |
---|
20 | var = 'HGT_M' |
---|
21 | zeplot = "domain" |
---|
22 | else: |
---|
23 | [lon2d,lat2d] = getcoord2d(nc) |
---|
24 | var = "HGT" |
---|
25 | zeplot = getprefix(nc) + "domain" |
---|
26 | ### |
---|
27 | lon2d = dumpbdy(lon2d,5) |
---|
28 | lat2d = dumpbdy(lat2d,5) |
---|
29 | if proj == "npstere": [wlon,wlat] = latinterv("North_Pole") |
---|
30 | elif proj in ["lcc","laea"]: [wlon,wlat] = wrfinterv(lon2d,lat2d) |
---|
31 | else: [wlon,wlat] = simplinterv(lon2d,lat2d) |
---|
32 | ### |
---|
33 | m = define_proj(proj,wlon,wlat,back=back) |
---|
34 | x, y = m(lon2d, lat2d) |
---|
35 | ### |
---|
36 | what_I_plot = dumpbdy(nc.variables[var][0,:,:], 5) |
---|
37 | #levinterv = 250. |
---|
38 | #zelevels = arange(min(what_I_plot)-levinterv,max(what_I_plot)+levinterv,levinterv) |
---|
39 | zelevels = 30 |
---|
40 | contourf(x, y, what_I_plot, zelevels) |
---|
41 | #pcolor(x,y,what_I_plot) ## on voit trop les lignes ! |
---|
42 | ### |
---|
43 | if not target: zeplot = namefile[0:find(namefile,'wrfout')] + zeplot |
---|
44 | else: zeplot = target + "/" + zeplot |
---|
45 | ### |
---|
46 | pad_inches_value = 0.35 |
---|
47 | makeplotres(zeplot,res=100.,pad_inches_value=pad_inches_value) #,erase=True) ## a miniature |
---|
48 | makeplotres(zeplot,res=200.,pad_inches_value=pad_inches_value,disp=False) |
---|
49 | #makeplotpng(zeplot,pad_inches_value=0.35) |
---|
50 | #rcParams['savefig.facecolor'] = 'black' |
---|
51 | #makeplotpng(zeplot+"b",pad_inches_value=0.35) |
---|
52 | |
---|
53 | if __name__ == "__main__": |
---|
54 | import sys |
---|
55 | ### to be replaced by argparse |
---|
56 | from optparse import OptionParser |
---|
57 | parser = OptionParser() |
---|
58 | parser.add_option('-f', action='store', dest='namefile', type="string", default=None, help='name of WRF file [NEEDED]') |
---|
59 | parser.add_option('-p', action='store', dest='proj', type="string", default=None, help='projection') |
---|
60 | parser.add_option('-b', action='store', dest='back', type="string", default="vishires", help='background') |
---|
61 | parser.add_option('-t', action='store', dest='target', type="string", default=None, help='destination folder') |
---|
62 | (opt,args) = parser.parse_args() |
---|
63 | if opt.namefile is None: |
---|
64 | print "I want to eat one file at least ! Use domain.py -f name_of_my_file. Or type domain.py -h" |
---|
65 | exit() |
---|
66 | print "Options:", opt |
---|
67 | domain (opt.namefile,proj=opt.proj,back=opt.back,target=opt.target) |
---|