[178] | 1 | #!/usr/bin/env python |
---|
| 2 | |
---|
[202] | 3 | ### A. Spiga -- LMD -- 30/06/2011 -- slight modif early 07/2011 |
---|
[178] | 4 | |
---|
[202] | 5 | def domain (namefile,proj="ortho",back="vishires",target=None,var='HGT'): |
---|
[178] | 6 | from netCDF4 import Dataset |
---|
[203] | 7 | from myplot import getcoord2d,define_proj,makeplotpng,simplinterv,getprefix,dumpbdy |
---|
[202] | 8 | from matplotlib.pyplot import contourf,rcParams |
---|
| 9 | from numpy.core.defchararray import find |
---|
| 10 | ### |
---|
[178] | 11 | nc = Dataset(namefile) |
---|
[202] | 12 | ### |
---|
[178] | 13 | [lon2d,lat2d] = getcoord2d(nc) |
---|
[203] | 14 | lon2d = dumpbdy(lon2d) |
---|
| 15 | lat2d = dumpbdy(lat2d) |
---|
[178] | 16 | [wlon,wlat] = simplinterv(lon2d,lat2d) |
---|
[202] | 17 | ### |
---|
[180] | 18 | m = define_proj(proj,wlon,wlat,back=back) |
---|
[178] | 19 | x, y = m(lon2d, lat2d) |
---|
[202] | 20 | ### |
---|
[203] | 21 | what_I_plot = dumpbdy( nc.variables[var][0,:,:] ) |
---|
| 22 | contourf(x, y, what_I_plot, 40) |
---|
[202] | 23 | ### |
---|
| 24 | zeplot = getprefix(nc) + "domain" |
---|
| 25 | if not target: zeplot = namefile[0:find(namefile,'wrfout')] + zeplot |
---|
| 26 | else: zeplot = target + "/" + zeplot |
---|
| 27 | ### |
---|
[181] | 28 | makeplotpng(zeplot,pad_inches_value=0.35) |
---|
[202] | 29 | #rcParams['savefig.facecolor'] = 'black' |
---|
| 30 | #makeplotpng(zeplot+"b",pad_inches_value=0.35) |
---|
[178] | 31 | |
---|
| 32 | if __name__ == "__main__": |
---|
| 33 | import sys |
---|
[184] | 34 | ### to be replaced by argparse |
---|
| 35 | from optparse import OptionParser |
---|
| 36 | parser = OptionParser() |
---|
[202] | 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') |
---|
[184] | 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) |
---|