[178] | 1 | #!/usr/bin/env python |
---|
| 2 | |
---|
[202] | 3 | ### A. Spiga -- LMD -- 30/06/2011 -- slight modif early 07/2011 |
---|
[178] | 4 | |
---|
[225] | 5 | def domain (namefile,proj=None,back="vishires",target=None): |
---|
[178] | 6 | from netCDF4 import Dataset |
---|
[241] | 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 |
---|
[202] | 10 | from numpy.core.defchararray import find |
---|
[241] | 11 | from numpy import arange |
---|
[202] | 12 | ### |
---|
[178] | 13 | nc = Dataset(namefile) |
---|
[202] | 14 | ### |
---|
[225] | 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 | ### |
---|
[241] | 27 | lon2d = dumpbdy(lon2d,5) |
---|
| 28 | lat2d = dumpbdy(lat2d,5) |
---|
[225] | 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) |
---|
[202] | 32 | ### |
---|
[180] | 33 | m = define_proj(proj,wlon,wlat,back=back) |
---|
[178] | 34 | x, y = m(lon2d, lat2d) |
---|
[202] | 35 | ### |
---|
[241] | 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 ! |
---|
[202] | 42 | ### |
---|
| 43 | if not target: zeplot = namefile[0:find(namefile,'wrfout')] + zeplot |
---|
| 44 | else: zeplot = target + "/" + zeplot |
---|
| 45 | ### |
---|
[241] | 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) |
---|
[202] | 50 | #rcParams['savefig.facecolor'] = 'black' |
---|
| 51 | #makeplotpng(zeplot+"b",pad_inches_value=0.35) |
---|
[178] | 52 | |
---|
| 53 | if __name__ == "__main__": |
---|
| 54 | import sys |
---|
[184] | 55 | ### to be replaced by argparse |
---|
| 56 | from optparse import OptionParser |
---|
| 57 | parser = OptionParser() |
---|
[202] | 58 | parser.add_option('-f', action='store', dest='namefile', type="string", default=None, help='name of WRF file [NEEDED]') |
---|
[225] | 59 | parser.add_option('-p', action='store', dest='proj', type="string", default=None, help='projection') |
---|
[202] | 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') |
---|
[184] | 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 |
---|
[225] | 67 | domain (opt.namefile,proj=opt.proj,back=opt.back,target=opt.target) |
---|