NCCOOS Trac Projects: Top | Web | Platforms | Processing | Viz | Sprints | Sandbox | (Wind)

root/sodar/branches/raw2proc-dev/proc_remtech_rawdata_pa0.py

Revision 188 (checked in by cbc, 16 years ago)

Saving work.

Line 
1 #!/usr/bin/env python
2 """
3 Parse sodar data and assert what data and info goes into
4 creating and updating monthly netcdf files.
5
6 >> (parse, create, update) = load_processors('proc_rdi_rawdata_sodar')
7 >> data = parse(lines)
8 >> create(platform_info, sensor_info, data)
9 >> update(platform_info, sensor_info, data)
10 """
11
12 from sodar import rawData
13 import numpy as n
14 from datetime import timedelta
15 from procutil import scanf_datetime, dt2es
16
17 def parser(platform_info, sensor_info, lines):
18     """
19     Parse and assign wind profile data from raw Sodar file.
20     """
21    
22     rawDataObject = rawdata.RawData('\n'.join(lines))
23    
24     numIntervals = len(rawDataObject)
25     numAltitudes = sensor_info[num_altitudes]
26    
27     data = {
28         'block'   : n.array(n.ones((numIntervals,), dtype=int) * n.nan),
29         'dt'      : n.array(n.ones((numIntervals,), dtype=object) * n.nan),
30         'es'      : n.array(n.ones((numIntervals,), dtype=long) * n.nan),
31         'val1'    : n.array(n.ones((numIntervals,), dtype=int) * n.nan),
32         'val2'    : n.array(n.ones((numIntervals,), dtype=int) * n.nan),
33         'val3'    : n.array(n.ones((numIntervals,), dtype=int) * n.nan),
34         'val4'    : n.array(n.ones((numIntervals,), dtype=int) * n.nan),
35         'spu1'    : n.array(n.ones((numIntervals,), dtype=int) * n.nan),
36         'spu2'    : n.array(n.ones((numIntervals,), dtype=int) * n.nan),
37         'spu3'    : n.array(n.ones((numIntervals,), dtype=int) * n.nan),
38         'spu4'    : n.array(n.ones((numIntervals,), dtype=int) * n.nan),
39         'nois1'   : n.array(n.ones((numIntervals,), dtype=int) * n.nan),
40         'nois2'   : n.array(n.ones((numIntervals,), dtype=int) * n.nan),
41         'nois3'   : n.array(n.ones((numIntervals,), dtype=int) * n.nan),
42         'nois4'   : n.array(n.ones((numIntervals,), dtype=int) * n.nan),
43         'femax'   : n.array(n.ones((numIntervals,), dtype=int) * n.nan),
44         'softw'   : n.array(n.ones((numIntervals,), dtype=int) * n.nan),
45         'fe11'    : n.array(n.ones((numIntervals,), dtype=int) * n.nan),
46         'fe12'    : n.array(n.ones((numIntervals,), dtype=int) * n.nan),
47         'fe21'    : n.array(n.ones((numIntervals,), dtype=int) * n.nan),
48         'fe22'    : n.array(n.ones((numIntervals,), dtype=int) * n.nan),
49         'snr1'    : n.array(n.ones((numIntervals,), dtype=int) * n.nan),
50         'snr2'    : n.array(n.ones((numIntervals,), dtype=int) * n.nan),
51         'snr3'    : n.array(n.ones((numIntervals,), dtype=int) * n.nan),
52         'snr4'    : n.array(n.ones((numIntervals,), dtype=int) * n.nan),
53         'check'   : n.array(n.ones((numIntervals,), dtype=int) * n.nan),
54         'jam'     : n.array(n.ones((numIntervals,), dtype=int) * n.nan),
55         'z'       : n.array(n.ones((numAltitudes,), dtype=float) * n.nan),
56         'u'       : n.array(n.ones((numIntervals,
57                                     numAltitudes), dtype=float) * n.nan),
58         'v'       : n.array(n.ones((numIntervals,
59                                     numAltitudes), dtype=float) * n.nan),
60         'w'       : n.array(n.ones((numIntervals,
61                                     numAltitudes), dtype=float) * n.nan),
62         'echo'    : n.array(n.ones((numIntervals,
63                                     numAltitudes), dtype = int) * n.nan),
64         }
65    
66     for sample in rawDataObject:
67         i = rawDataObject.index(sample)
68        
69         data['block'][i] = int(sample['BL#'])
70                                
71         dt = {'month' : int(sample['MONTH']),
72               'day'   : int(sample['DAY']),
73               'year'  : int(sample['YEAR']),
74               'hour'  : int(sample['HOUR']),
75               'min'   : int(sample['MIN']),
76             }
77         dt = '%(month)02d-%(day)02d-%(year)04d %(hour)02d:%02d(min)' % dt
78         dt = scanf_datetime(dt, fmt='%m-%d-%Y %H:%M')
79         if sensor_info['utc_offset']:
80             dt = dt + timedelta(hours=sensor_info['utc_offset'])
81         data['dt'][i] = dt
82        
83         data['es'][i] = dt2es(dt)
84        
85         data['val1'][i] = int(sample['VAL1'])
86         data['val2'][i] = int(sample['VAL2'])
87         data['val3'][i] = int(sample['VAL3'])
88         data['val4'][i] = int(sample['VAL4'])
89        
90         data['spu1'][i] = int(sample['SPU1'])
91         data['spu2'][i] = int(sample['SPU2'])
92         data['spu3'][i] = int(sample['SPU3'])
93         data['spu4'][i] = int(sample['SPU4'])
94        
95         data['nois1'][i] = int(sample['NOIS1'])
96         data['nois2'][i] = int(sample['NOIS2'])
97         data['nois3'][i] = int(sample['NOIS3'])
98         data['nois4'][i] = int(sample['NOIS4'])
99
100         data['femax'][i] = int(sample['FEMAX'])
101         data['softw'][i] = int(sample['SOFTW'])
102        
103         data['fe11'][i] = int(sample['FE11'])
104         data['fe12'][i] = int(sample['FE12'])
105         data['fe21'][i] = int(sample['FE21'])
106         data['fe22'][i] = int(sample['FE22'])
107        
108         data['snr1'][i] = int(sample['SNR1'])
109         data['snr2'][i] = int(sample['SNR2'])
110         data['snr3'][i] = int(sample['SNR3'])
111         data['snr4'][i] = int(sample['SNR4'])
112
113         data['check'][i] = int(sample['CHECK'])
114         data['jam'][i]   = int(sample['JAM'])
115     return data
116
117 def creator(platform_info, sensor_info, data):
118     #
119     #
120     title_str = sensor_info['description']+' at '+ platform_info['location']
121     global_atts = {
122         'title' : title_str,
123         'institution' : 'Unversity of North Carolina at Chapel Hill (UNC-CH)',
124         'institution_url' : 'http://nccoos.unc.edu',
125         'institution_dods_url' : 'http://nccoos.unc.edu',
126         'metadata_url' : 'http://nccoos.unc.edu',
127         'references' : 'http://nccoos.unc.edu',
128         'contact' : 'Sara Haines (haines@email.unc.edu)',
129         #
130         'source' : 'fixed-profiler (acoustic doppler) observation',
131         'history' : 'Data processed by NCCOOS',
132         'comment' : 'File created using pycdf'+pycdfVersion()+' and numpy '+pycdfArrayPkg(),
133         # conventions
134         'Conventions' : 'CF-1.0; SEACOOS-CDL-v2.0',
135         # SEACOOS CDL codes
136         'format_category_code' : 'fixed-profiler',
137         'institution_code' : platform_info['instituion'],
138         'platform_code' : platform_info['id'],
139         'package_code' : sensor_info['id'],
140         # institution specific
141         'project' : 'North Carolina Coastal Ocean Observing System (NCCOOS)',
142         'project_url' : 'http://nccoos.unc.edu',
143         # timeframe of data contained in file yyyy-mm-dd HH:MM:SS
144         'start_date' : data['sample_dt'].strftime("%Y-%m-%d %H:%M:%S"),
145         'end_date' : data['sample_dt'].strftime("%Y-%m-%d %H:%M:%S"),
146         'release_date' : now.strftime("%Y-%m-%d %H:%M:%S"),
147         #
148         'creation_date' : now.strftime("%Y-%m-%d %H:%M:%S"),
149         'modification_date' : now.strftime("%Y-%m-%d %H:%M:%S"),
150         'process_level' : 'level1',
151         #
152         # must type match to data (e.g. fillvalue is real if data is real)
153         '_FillValue' : -99999.,
154         }
155
156     var_atts = {
157         # coordinate variables
158         'time' : {'short_name': 'time',
159                   'long_name': 'Time',
160                   'standard_name': 'time',
161                   'units': 'seconds since 1970-1-1 00:00:00 -0', # UTC
162                   'axis': 'T',
163                   },
164         'lat' : {'short_name': 'lat',
165              'long_name': 'Latitude',
166              'standard_name': 'latitude',
167              'reference':'geographic coordinates',
168              'units': 'degrees_north',
169              'valid_range':(-90.,90.),
170              'axis': 'Y',
171              },
172         'lon' : {'short_name': 'lon',
173                  'long_name': 'Longtitude',
174                  'standard_name': 'longtitude',
175                  'reference':'geographic coordinates',
176                  'units': 'degrees_east',
177                  'valid_range':(-180.,180.),
178                  'axis': 'Y',
179                  },
180         'z' : {'short_name': 'z',
181                'long_name': 'Height',
182                'standard_name': 'height',
183                'reference':'zero at sea-surface',
184                'units': 'm',
185                'axis': 'Z',
186                },
187         # data variables
188         'u': {'long_name': 'East/West Component of Current',
189               'standard_name': 'eastward_current',
190               'units': 'm s-1',
191               'reference': 'clockwise from True East',
192               },
193         'v': {'long_name': 'North/South Component of Current',
194               'standard_name': 'northward_current',                         
195               'units': 'm s-1',
196               'reference': 'clockwise from True North',
197               },
198         'w': {'long_name': 'Upward/Downward Component of Current',
199               'standard_name': 'upward_current',                         
200               'units': 'm s-1',
201               'positive': 'up',
202               },
203         'back_scatter':{'long_name': 'Backscatter',
204                         'standard_name': 'back_scatter',                   
205                         'units': 'decibels',
206                         },
207         'wtemp': {'long_name': 'Water Temperature',
208                   'standard_name': 'water_temperature',
209                   'units': 'degrees Celsius',
210                   },
211         }
212
213
214     # integer values
215     ntime=NC.UNLIMITED
216     nlat=1
217     nlon=1
218     nz=sensor_info['nbins']
219    
220     # dimension names use tuple so order of initialization is maintained
221     dimensions = ('ntime', 'nlat', 'nlon', 'nz')
222    
223     # using tuple of tuples so order of initialization is maintained
224     # using dict for attributes order of init not important
225     # use dimension names not values
226     # (varName, varType, (dimName1, [dimName2], ...))
227     var_inits = (
228         # coordinate variables
229         ('time', NC.INT, ('ntime',)),
230         ('lat', NC.FLOAT, ('nlat',)),
231         ('lon', NC.FLOAT, ('nlon',)),
232         ('z',  NC.FLOAT, ('nz',)),
233         # data variables
234         ('u', NC.FLOAT, ('ntime', 'nz')),
235         ('v', NC.FLOAT, ('ntime', 'nz')),
236         ('w', NC.FLOAT, ('ntime', 'nz')),
237         ('back_scatter', NC.FLOAT, ('ntime', 'nz')),
238         ('wtemp', NC.FLOAT, ('ntime',)),
239         )
240    
241     # var data
242     var_data = (
243         ('lat',  platform_info['lat']),
244         ('lon', platform_info['lon']),
245         ('z', []),
246         ('u', []),
247         ('v', []),
248         ('w', []),
249         ('back_scatter', []),
250         ('wtemp', []),
251         )
252
253     return (global_atts, dimensions, var_inits, var_data)
254
255 def updater(platform_info, sensor_info, data):
256     #
257     global_atts = {
258         # timeframe of data contained in file yyyy-mm-dd HH:MM:SS
259         'end_date' : data['sample_dt'].strftime("%Y-%m-%d %H:%M:%S"),
260         'release_date' : now.strftime("%Y-%m-%d %H:%M:%S"),
261         #
262         'creation_date' : now.strftime("%Y-%m-%d %H:%M:%S"),
263         'modification_date' : now.strftime("%Y-%m-%d %H:%M:%S"),
264         }
265     # var data
266     var_data = (
267         ('u', data['u']),
268         ('v', data['v']),
269         ('w',  data['w']),
270         ('back_scatter', data['back_scatter']),
271         ('wtemp', data['wtemp']),
272         )
273     return (global_atts, var_data)
274 #
275
Note: See TracBrowser for help on using the browser.