11# -*- coding: utf-8 -*- 
2+ from  argparse  import  ArgumentParser 
3+ import  logging 
4+ 
5+ 
6+ class  ColoredFormatter (logging .Formatter ):
7+     COLOR_LEVEL  =  dict (
8+         CRITICAL = "\037 [37;41m" ,
9+         ERROR = "\033 [31;47m" ,
10+         WARNING = "\033 [30;47m" ,
11+         INFO = "\033 [36m" ,
12+         DEBUG = "\033 [34m" ,
13+         )
14+ 
15+     def  __init__ (self , message ):
16+         super (ColoredFormatter , self ).__init__ (message )
17+ 
18+     def  format (self , record ):
19+         color  =  self .COLOR_LEVEL .get (record .levelname , '' )
20+         color_reset  =  '\033 [0m' 
21+         model  =  color  +  '%s'  +  color_reset 
22+         record .msg  =  model  %  record .msg 
23+         record .funcName  =  model  %  record .funcName 
24+         record .module  =  model  %  record .module 
25+         record .levelname  =  model  %  record .levelname 
26+         return  super (ColoredFormatter , self ).format (record )
27+ 
28+ 
29+ class  EddyParser (ArgumentParser ):
30+     """General parser for applications 
31+     """ 
32+ 
33+     FORMAT_LOG  =  "%(levelname)-8s %(asctime)s %(module)s."  \
34+                      "%(funcName)s :\n \t \t \t \t \t %(message)s" 
35+ 
36+     def  __init__ (self , * args , ** kwargs ):
37+         super (EddyParser , self ).__init__ (* args , ** kwargs )
38+         self .add_base_argument ()
39+ 
40+     def  add_base_argument (self ):
41+         """Base arguments 
42+         """ 
43+         self .add_argument ('-v' , '--verbose' ,
44+                           dest = 'logging_level' ,
45+                           default = 'ERROR' ,
46+                           help = 'Levels : DEBUG, INFO, WARNING,' 
47+                           ' ERROR, CRITICAL' )
48+         
49+     def  parse_args (self , * args , ** kwargs ):
50+         # set up logging to CONSOLE 
51+         console  =  logging .StreamHandler ()
52+         console .setFormatter (ColoredFormatter (self .FORMAT_LOG ))
53+         # add the handler to the root logger 
54+         logging .getLogger ('' ).addHandler (console )
55+         # Parsing 
56+         opts  =  super (EddyParser , self ).parse_args (* args , ** kwargs )
57+         # set current level 
58+         logging .getLogger ().setLevel (getattr (logging , opts .logging_level .upper ()))
59+         return  opts 
60+ 
61+ 
262VAR_DESCR  =  dict (
363    time = dict (
4-         attr_name = 'new_time_tmp ' ,
64+         attr_name = 'time ' ,
565        nc_name = 'j1' ,
666        nc_type = 'int32' ,
767        nc_dims = ('Nobs' ,),
3494            )
3595        ),
3696    lon = dict (
37-         attr_name = 'new_lon_tmp' ,
97+         attr_name = 'lon' ,
98+         compute_type = 'float64' ,
3899        nc_name = 'lon' ,
39100        nc_type = 'float32' ,
40101        nc_dims = ('Nobs' ,),
43104            )
44105        ),
45106    lat = dict (
46-         attr_name = 'new_lat_tmp' ,
107+         attr_name = 'lat' ,
108+         compute_type = 'float64' ,
47109        nc_name = 'lat' ,
48110        nc_type = 'float32' ,
49111        nc_dims = ('Nobs' ,),
52114            )
53115        ),
54116    amplitude = dict (
55-         attr_name = 'new_amp_tmp ' ,
117+         attr_name = 'amplitude ' ,
56118        nc_name = 'A' ,
57119        nc_type = 'float32' ,
58120        nc_dims = ('Nobs' ,),
69131        nc_name = 'L' ,
70132        nc_type = 'float32' ,
71133        nc_dims = ('Nobs' ,),
134+         scale_factor = 1e-3 ,
72135        nc_attr = dict (
73136            long_name = 'speed radius scale' ,
74137            units = 'km' ,
78141            )
79142        ),
80143    speed_radius = dict (
81-         attr_name = 'new_uavg_tmp' ,
144+         attr_name = 'speed_radius' ,
145+         scale_factor = 100 ,
82146        nc_name = 'U' ,
83147        nc_type = 'float32' ,
84148        nc_dims = ('Nobs' ,),
90154            )
91155        ),
92156    eke = dict (
93-         attr_name = 'new_teke_tmp ' ,
157+         attr_name = 'eke ' ,
94158        nc_name = 'Teke' ,
95159        nc_type = 'float32' ,
96160        nc_dims = ('Nobs' ,),
102166            )
103167        ),
104168    radius_e = dict (
105-         attr_name = 'new_radii_e_tmp' ,
169+         attr_name = 'radius_e' ,
170+         scale_factor = 1e-3 ,
106171        nc_name = 'radius_e' ,
107172        nc_type = 'float32' ,
108173        nc_dims = ('Nobs' ,),
112177            description = 'effective eddy radius' ,
113178            )
114179        ),
180+     radius_s = dict (
181+         attr_name = 'radius_s' ,
182+         scale_factor = 1e-3 ,
183+         nc_name = 'L' ,
184+         nc_type = 'float32' ,
185+         nc_dims = ('Nobs' ,),
186+         nc_attr = dict (
187+             long_name = 'speed radius scale' ,
188+             units = 'km' ,
189+             description = 'speed eddy radius' ,
190+             )
191+         ),
115192    track = dict (
116193        attr_name = None ,
117194        nc_name = 'track' ,
134211            description = 'observation sequence number (XX day intervals)' ,
135212            )
136213        ),
137-     )
214+     contour_e = dict (
215+         attr_name = None ,
216+         nc_name = 'contour_e' ,
217+         nc_type = 'f4' ,
218+         nc_dims = ('contour_points' , 'Nobs' ,),
219+         nc_attr = dict (
220+             long_name = 'positions of effective contour points' ,
221+             description = 'lons/lats of effective contour points; lons (lats) ' 
222+                         'in first (last) half of vector' ,
223+             )
224+         ),
225+     contour_s = dict (
226+         attr_name = None ,
227+         nc_name = 'contour_s' ,
228+         nc_type = 'f4' ,
229+         nc_dims = ('contour_points' , 'Nobs' ,),
230+         nc_attr = dict (
231+             long_name = 'positions of speed-based contour points' ,
232+             description = 'lons/lats of speed-based contour points; lons (lats) ' 
233+                         'in first (last) half of vector' ,
234+             )
235+         ),
236+     uavg_profile = dict (
237+         attr_name = None ,
238+         nc_name = 'uavg_profile' ,
239+         nc_type = 'f4' ,
240+         nc_dims = ('uavg_contour_count' , 'Nobs' ,),
241+         nc_attr = dict (
242+             long_name = 'radial profile of uavg' ,
243+             description = 'all uavg values from effective contour inwards to ' 
244+                         'smallest inner contour (pixel == 1)' ,
245+             )
246+         ),
247+     shape_error = dict (
248+         attr_name = None ,
249+         nc_name = 'shape_error' ,
250+         nc_type = 'f2' ,
251+         nc_dims = ('Nobs' ,),
252+         nc_attr = dict (
253+             units = '%' ,
254+             )
255+         ),
256+     )
0 commit comments