[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 |
---|
[225] | 7 | from myplot import getcoord2d,define_proj,makeplotpng,simplinterv,getprefix,dumpbdy,getproj,latinterv,wrfinterv,simplinterv |
---|
[202] | 8 | from matplotlib.pyplot import contourf,rcParams |
---|
| 9 | from numpy.core.defchararray import find |
---|
| 10 | ### |
---|
[178] | 11 | nc = Dataset(namefile) |
---|
[202] | 12 | ### |
---|
[225] | 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 | ### |
---|
[203] | 25 | lon2d = dumpbdy(lon2d) |
---|
| 26 | lat2d = dumpbdy(lat2d) |
---|
[225] | 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) |
---|
[202] | 30 | ### |
---|
[180] | 31 | m = define_proj(proj,wlon,wlat,back=back) |
---|
[178] | 32 | x, y = m(lon2d, lat2d) |
---|
[202] | 33 | ### |
---|
[203] | 34 | what_I_plot = dumpbdy( nc.variables[var][0,:,:] ) |
---|
| 35 | contourf(x, y, what_I_plot, 40) |
---|
[202] | 36 | ### |
---|
| 37 | if not target: zeplot = namefile[0:find(namefile,'wrfout')] + zeplot |
---|
| 38 | else: zeplot = target + "/" + zeplot |
---|
| 39 | ### |
---|
[181] | 40 | makeplotpng(zeplot,pad_inches_value=0.35) |
---|
[202] | 41 | #rcParams['savefig.facecolor'] = 'black' |
---|
| 42 | #makeplotpng(zeplot+"b",pad_inches_value=0.35) |
---|
[178] | 43 | |
---|
| 44 | if __name__ == "__main__": |
---|
| 45 | import sys |
---|
[184] | 46 | ### to be replaced by argparse |
---|
| 47 | from optparse import OptionParser |
---|
| 48 | parser = OptionParser() |
---|
[202] | 49 | parser.add_option('-f', action='store', dest='namefile', type="string", default=None, help='name of WRF file [NEEDED]') |
---|
[225] | 50 | parser.add_option('-p', action='store', dest='proj', type="string", default=None, help='projection') |
---|
[202] | 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') |
---|
[184] | 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 |
---|
[225] | 58 | domain (opt.namefile,proj=opt.proj,back=opt.back,target=opt.target) |
---|