5 import matplotlib
as mpl
8 from mpl_toolkits.basemap
import Basemap
10 import matplotlib.pyplot
as plt
14 import get_grib_field
as ggf
17 '''Defines the standard set of figures produced by the graphics package. 18 Top key is user's choice of a short descriptor for the figure generated. 19 Subdictionary for each individual figure with following params: 20 lev: 'lev' for desired variable in grib file 21 sname: 'shortName' value of desired variable from grib file 22 pname: 'parameterName' value of desired variable from grib file. Used when shortName is unavailable 23 step: 'stepType' value of desired variable from grib file. e.g., avg or instant 24 barbs: flag for plotting winds over variable 25 hgt: flag for plotting height over variable 26 vc: 'typeOfLevel' value in grib to set vertical coordinate 28 Both lev and vc are required to determine the appropriate level of the given variable. 29 sname and pname are alternative methods to define the variable name. sname is preferred. 30 If pname is used, the title and file names will reflect the top-level dictionary entry. A corresponding 31 variable entry to match the figure describer must be made in the maps.py dictionary of variables. 34 if preset_flag ==
'testbed':
36 '250_wind': {
'lev':
'250',
'sname':
'wind',
'barbs':
True,
'hgt':
True,
'vc':
'isobaricInhPa'},
37 '250_temp': {
'lev':
'250',
'sname':
't',
'barbs':
True,
'hgt':
True,
'vc':
'isobaricInhPa'},
38 '500_hgt': {
'lev':
'500',
'sname':
'gh',
'barbs':
True,
'hgt':
True,
'vc':
'isobaricInhPa'},
39 '500_temp': {
'lev':
'500',
'sname':
't',
'barbs':
True,
'hgt':
True,
'vc':
'isobaricInhPa'},
40 '500_vort': {
'lev':
'500',
'sname':
'absv',
'barbs':
False,
'hgt':
True,
'vc':
'isobaricInhPa'},
41 '700_temp': {
'lev':
'700',
'sname':
't',
'barbs':
True,
'hgt':
True,
'vc':
'isobaricInhPa'},
42 '700_vvel': {
'lev':
'700',
'sname':
'w',
'barbs':
False,
'hgt':
True,
'vc':
'isobaricInhPa'},
43 '850_hgt': {
'lev':
'850',
'sname':
'gh',
'barbs':
True,
'hgt':
False,
'vc':
'isobaricInhPa'},
44 '850_temp': {
'lev':
'850',
'sname':
't',
'barbs':
True,
'hgt':
True,
'vc':
'isobaricInhPa'},
45 '850_rh': {
'lev':
'850',
'sname':
'r', 'barbs': True, 'hgt': True, 'vc': 'isobaricInhPa'},
46 '2m_tmp': {
'lev':
'2',
'sname':
'2t',
'barbs':
False,
'hgt':
False,
'vc':
'heightAboveGround'},
47 '2m_dpt': {
'lev':
'2',
'sname':
'2d',
'barbs':
False,
'hgt':
False,
'vc':
'heightAboveGround'},
48 '6h_acpcp': {
'lev':
'0',
'sname':
'acpcp',
'barbs':
False,
'hgt':
False,
'vc':
'surface'},
49 '6h_apcp': {
'lev':
'0',
'sname':
'tp',
'barbs':
False,
'hgt':
False,
'vc':
'surface'}
51 elif preset_flag ==
'reg_test_flx':
54 '2m_tmp': {
'lev':
'2',
'sname':
'2t',
'barbs':
False,
'hgt':
False,
'vc':
'heightAboveGround'},
55 '2m_spfh': {
'lev':
'2',
'sname':
'q',
'barbs':
False,
'hgt':
False,
'vc':
'heightAboveGround'},
56 'pwat': {
'lev':
'0',
'sname':
'pwat',
'barbs':
False,
'hgt':
False,
'vc':
'entireAtmosphere'},
57 'prate': {
'lev':
'0',
'sname':
'prate',
'barbs':
False,
'hgt':
False,
'vc':
'surface'},
58 '10m_u': {
'lev':
'10',
'sname':
'10u',
'barbs':
False,
'hgt':
False,
'vc':
'heightAboveGround'},
59 '10m_v': {
'lev':
'10',
'sname':
'10v',
'barbs':
False,
'hgt':
False,
'vc':
'heightAboveGround'},
61 elif preset_flag ==
'reg_test_unknown':
63 'ULWRF': {
'lev':
'0',
'pname':
'212',
'barbs':
False,
'hgt':
False,
'vc':
'surface',
'step':
'avg'},
64 '2m_tmp': {
'lev':
'2',
'sname':
'2t',
'barbs':
False,
'hgt':
False,
'vc':
'heightAboveGround'},
65 '2m_spfh': {
'lev':
'2',
'sname':
'q',
'barbs':
False,
'hgt':
False,
'vc':
'heightAboveGround'},
66 'pwat': {
'lev':
'0',
'sname':
'pwat',
'barbs':
False,
'hgt':
False,
'vc':
'entireAtmosphere'},
67 'prate': {
'lev':
'0',
'sname':
'prate',
'barbs':
False,
'hgt':
False,
'vc':
'surface'},
68 'CPRAT': {
'lev':
'0',
'pname':
'214',
'barbs':
False,
'hgt':
False,
'vc':
'surface',
'step':
'avg'},
69 '10m_u': {
'lev':
'10',
'sname':
'10u',
'barbs':
False,
'hgt':
False,
'vc':
'heightAboveGround'},
70 '10m_v': {
'lev':
'10',
'sname':
'10v',
'barbs':
False,
'hgt':
False,
'vc':
'heightAboveGround'},
77 indir=os.getenv(
'IDIR')
78 outdir=os.getenv(
'ODIR')
81 for fhr
in range(24,48,120):
83 fnbase=os.getenv(
'FBASE')
84 filename=
''.join([fnbase,
'{:02d}'.format(fhr)])
90 preset_flag=
'reg_test_unknown' 91 grib=
'/'.join([indir, filename])
98 print grib, outdir, fhr
101 sname=[
'wind',
'q',
't']
103 plevels=range(1,64,10)
107 for level
in plevels:
109 if plot_wind
or var ==
'wind':
110 u = ggf.get_ua_field(grib,level,coord,shortName=
'u') 111 v = ggf.get_ua_field(grib,level,coord,shortName='v')
119 field=ggf.get_ua_field(grib,level,coord,shortname=var)
125 winds=winds, fhr=fhr)
128 mymap.save_figure(outdir)
135 level = def_maps[fig].get(
'lev')
137 sname = def_maps[fig].get(
'sname',
None)
138 pname = def_maps[fig].get(
'pname',
None)
139 step = def_maps[fig].get(
'step',
None)
140 hgt = def_maps[fig].get(
'hgt')
141 plot_wind = def_maps[fig].get(
'barbs',
False)
142 coord = def_maps[fig].get(
'vc')
147 if sname
is not None:
151 print level,var, hgt,plot_wind, hgt
155 if plot_wind
or var ==
'wind':
156 u = ggf.get_ua_field(grib,level,coord,shortName=
'u') 157 v = ggf.get_ua_field(grib,level,coord,shortName='v')
165 field=ggf.get_ua_field(grib,level,coord,shortName=sname,parameterName=pname,stepType=step)
171 height = ggf.get_ua_field(grib,
'gh',level,coord)
175 winds=winds, plot_height=height,def_maps=def_maps,
179 mymap.save_figure(outdir)
181 print 'Skipping figure' def set_def_maps(preset_flag)