1
1
# -*- 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
+
2
62
VAR_DESCR = dict (
3
63
time = dict (
4
- attr_name = 'new_time_tmp ' ,
64
+ attr_name = 'time ' ,
5
65
nc_name = 'j1' ,
6
66
nc_type = 'int32' ,
7
67
nc_dims = ('Nobs' ,),
34
94
)
35
95
),
36
96
lon = dict (
37
- attr_name = 'new_lon_tmp' ,
97
+ attr_name = 'lon' ,
98
+ compute_type = 'float64' ,
38
99
nc_name = 'lon' ,
39
100
nc_type = 'float32' ,
40
101
nc_dims = ('Nobs' ,),
43
104
)
44
105
),
45
106
lat = dict (
46
- attr_name = 'new_lat_tmp' ,
107
+ attr_name = 'lat' ,
108
+ compute_type = 'float64' ,
47
109
nc_name = 'lat' ,
48
110
nc_type = 'float32' ,
49
111
nc_dims = ('Nobs' ,),
52
114
)
53
115
),
54
116
amplitude = dict (
55
- attr_name = 'new_amp_tmp ' ,
117
+ attr_name = 'amplitude ' ,
56
118
nc_name = 'A' ,
57
119
nc_type = 'float32' ,
58
120
nc_dims = ('Nobs' ,),
69
131
nc_name = 'L' ,
70
132
nc_type = 'float32' ,
71
133
nc_dims = ('Nobs' ,),
134
+ scale_factor = 1e-3 ,
72
135
nc_attr = dict (
73
136
long_name = 'speed radius scale' ,
74
137
units = 'km' ,
78
141
)
79
142
),
80
143
speed_radius = dict (
81
- attr_name = 'new_uavg_tmp' ,
144
+ attr_name = 'speed_radius' ,
145
+ scale_factor = 100 ,
82
146
nc_name = 'U' ,
83
147
nc_type = 'float32' ,
84
148
nc_dims = ('Nobs' ,),
90
154
)
91
155
),
92
156
eke = dict (
93
- attr_name = 'new_teke_tmp ' ,
157
+ attr_name = 'eke ' ,
94
158
nc_name = 'Teke' ,
95
159
nc_type = 'float32' ,
96
160
nc_dims = ('Nobs' ,),
102
166
)
103
167
),
104
168
radius_e = dict (
105
- attr_name = 'new_radii_e_tmp' ,
169
+ attr_name = 'radius_e' ,
170
+ scale_factor = 1e-3 ,
106
171
nc_name = 'radius_e' ,
107
172
nc_type = 'float32' ,
108
173
nc_dims = ('Nobs' ,),
112
177
description = 'effective eddy radius' ,
113
178
)
114
179
),
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
+ ),
115
192
track = dict (
116
193
attr_name = None ,
117
194
nc_name = 'track' ,
134
211
description = 'observation sequence number (XX day intervals)' ,
135
212
)
136
213
),
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