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

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

Revision 186 (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         'dt'      : n.array(n.ones((numIntervals,), dtype=object) * n.nan),
29         'es'      : n.array(n.ones((numIntervals,), dtype=long) * n.nan),
30         'val1'    : n.array(n.ones((numIntervals,), dtype=int) * n.nan),
31         'val2'    : n.array(n.ones((numIntervals,), dtype=int) * n.nan),
32         'val3'    : n.array(n.ones((numIntervals,), dtype=int) * n.nan),
33         'val4'    : n.array(n.ones((numIntervals,), dtype=int) * n.nan),
34         'spu1'    : n.array(n.ones((numIntervals,), dtype=int) * n.nan),
35         'spu2'    : n.array(n.ones((numIntervals,), dtype=int) * n.nan),
36         'spu3'    : n.array(n.ones((numIntervals,), dtype=int) * n.nan),
37         'spu4'    : n.array(n.ones((numIntervals,), dtype=int) * n.nan),
38         'nois1'   : n.array(n.ones((numIntervals,), dtype=int) * n.nan),
39         'nois2'   : n.array(n.ones((numIntervals,), dtype=int) * n.nan),
40         'nois3'   : n.array(n.ones((numIntervals,), dtype=int) * n.nan),
41         'nois4'   : n.array(n.ones((numIntervals,), dtype=int) * n.nan),
42         'femax'   : n.array(n.ones((numIntervals,), dtype=int) * n.nan),
43         'softw'   : n.array(n.ones((numIntervals,), dtype=int) * n.nan),
44         'fe11'    : n.array(n.ones((numIntervals,), dtype=int) * n.nan),
45         'fe12'    : n.array(n.ones((numIntervals,), dtype=int) * n.nan),
46         'fe21'    : n.array(n.ones((numIntervals,), dtype=int) * n.nan),
47         'fe22'    : n.array(n.ones((numIntervals,), dtype=int) * n.nan),
48         'snr1'    : n.array(n.ones((numIntervals,), dtype=int) * n.nan),
49         'snr2'    : n.array(n.ones((numIntervals,), dtype=int) * n.nan),
50         'snr3'    : n.array(n.ones((numIntervals,), dtype=int) * n.nan),
51         'snr4'    : n.array(n.ones((numIntervals,), dtype=int) * n.nan),
52         'jam'     : n.array(n.ones((numIntervals,), dtype=int) * n.nan),
53         'z'       : n.array(n.ones((numAltitudes,), dtype=float) * n.nan),
54         'u'       : n.array(n.ones((numIntervals,
55                                     numAltitudes), dtype=float) * n.nan),
56         'v'       : n.array(n.ones((numIntervals,
57                                     numAltitudes), dtype=float) * n.nan),
58         'w'       : n.array(n.ones((numIntervals,
59                                     numAltitudes), dtype=float) * n.nan),
60         'echo'    : n.array(n.ones((numIntervals,
61                                     numAltitudes), dtype = int) * n.nan),
62         }
63    
64     for sample in rawDataObject:
65         i = rawDataObject.index(sample)
66        
67         dt = {'month' : int(sample['MONTH']),
68               'day'   : int(sample['DAY']),
69               'year'  : int(sample['YEAR']),
70               'hour'  : int(sample['HOUR']),
71               'min'   : int(sample['MIN']),
72             }
73         dt = '%(month)02d-%(day)02d-%(year)04d %(hour)02d:%02d(min)' % dt
74         dt = scanf_datetime(dt, fmt='%m-%d-%Y %H:%M')
75         if sensor_info['utc_offset']:
76             dt = dt + timedelta(hours=sensor_info['utc_offset'])
77         data['dt'][i] = dt
78         data['es'][i] = dt2es(dt)
79    
80     return data
81
82 def creator(platform_info, sensor_info, data):
83     #
84     #
85     title_str = sensor_info['description']+' at '+ platform_info['location']
86     global_atts = {
87         'title' : title_str,
88         'institution' : 'Unversity of North Carolina at Chapel Hill (UNC-CH)',
89         'institution_url' : 'http://nccoos.unc.edu',
90         'institution_dods_url' : 'http://nccoos.unc.edu',
91         'metadata_url' : 'http://nccoos.unc.edu',
92         'references' : 'http://nccoos.unc.edu',
93         'contact' : 'Sara Haines (haines@email.unc.edu)',
94         #
95         'source' : 'fixed-profiler (acoustic doppler) observation',
96         'history' : 'Data processed by NCCOOS',
97         'comment' : 'File created using pycdf'+pycdfVersion()+' and numpy '+pycdfArrayPkg(),
98         # conventions
99         'Conventions' : 'CF-1.0; SEACOOS-CDL-v2.0',
100         # SEACOOS CDL codes
101         'format_category_code' : 'fixed-profiler',
102         'institution_code' : platform_info['instituion'],
103         'platform_code' : platform_info['id'],
104         'package_code' : sensor_info['id'],
105         # institution specific
106         'project' : 'North Carolina Coastal Ocean Observing System (NCCOOS)',
107         'project_url' : 'http://nccoos.unc.edu',
108         # timeframe of data contained in file yyyy-mm-dd HH:MM:SS
109         'start_date' : data['sample_dt'].strftime("%Y-%m-%d %H:%M:%S"),
110         'end_date' : data['sample_dt'].strftime("%Y-%m-%d %H:%M:%S"),
111         'release_date' : now.strftime("%Y-%m-%d %H:%M:%S"),
112         #
113         'creation_date' : now.strftime("%Y-%m-%d %H:%M:%S"),
114         'modification_date' : now.strftime("%Y-%m-%d %H:%M:%S"),
115         'process_level' : 'level1',
116         #
117         # must type match to data (e.g. fillvalue is real if data is real)
118         '_FillValue' : -99999.,
119         }
120
121     var_atts = {
122         # coordinate variables
123         'time' : {'short_name': 'time',
124                   'long_name': 'Time',
125                   'standard_name': 'time',
126                   'units': 'seconds since 1970-1-1 00:00:00 -0', # UTC
127                   'axis': 'T',
128                   },
129         'lat' : {'short_name': 'lat',
130              'long_name': 'Latitude',
131              'standard_name': 'latitude',
132              'reference':'geographic coordinates',
133              'units': 'degrees_north',
134              'valid_range':(-90.,90.),
135              'axis': 'Y',
136              },
137         'lon' : {'short_name': 'lon',
138                  'long_name': 'Longtitude',
139                  'standard_name': 'longtitude',
140                  'reference':'geographic coordinates',
141                  'units': 'degrees_east',
142                  'valid_range':(-180.,180.),
143                  'axis': 'Y',
144                  },
145         'z' : {'short_name': 'z',
146                'long_name': 'Height',
147                'standard_name': 'height',
148                'reference':'zero at sea-surface',
149                'units': 'm',
150                'axis': 'Z',
151                },
152         # data variables
153         'u': {'long_name': 'East/West Component of Current',
154               'standard_name': 'eastward_current',
155               'units': 'm s-1',
156               'reference': 'clockwise from True East',
157               },
158         'v': {'long_name': 'North/South Component of Current',
159               'standard_name': 'northward_current',                         
160               'units': 'm s-1',
161               'reference': 'clockwise from True North',
162               },
163         'w': {'long_name': 'Upward/Downward Component of Current',
164               'standard_name': 'upward_current',                         
165               'units': 'm s-1',
166               'positive': 'up',
167               },
168         'back_scatter':{'long_name': 'Backscatter',
169                         'standard_name': 'back_scatter',                   
170                         'units': 'decibels',
171                         },
172         'wtemp': {'long_name': 'Water Temperature',
173                   'standard_name': 'water_temperature',
174                   'units': 'degrees Celsius',
175                   },
176         }
177
178
179     # integer values
180     ntime=NC.UNLIMITED
181     nlat=1
182     nlon=1
183     nz=sensor_info['nbins']
184    
185     # dimension names use tuple so order of initialization is maintained
186     dimensions = ('ntime', 'nlat', 'nlon', 'nz')
187    
188     # using tuple of tuples so order of initialization is maintained
189     # using dict for attributes order of init not important
190     # use dimension names not values
191     # (varName, varType, (dimName1, [dimName2], ...))
192     var_inits = (
193         # coordinate variables
194         ('time', NC.INT, ('ntime',)),
195         ('lat', NC.FLOAT, ('nlat',)),
196         ('lon', NC.FLOAT, ('nlon',)),
197         ('z',  NC.FLOAT, ('nz',)),
198         # data variables
199         ('u', NC.FLOAT, ('ntime', 'nz')),
200         ('v', NC.FLOAT, ('ntime', 'nz')),
201         ('w', NC.FLOAT, ('ntime', 'nz')),
202         ('back_scatter', NC.FLOAT, ('ntime', 'nz')),
203         ('wtemp', NC.FLOAT, ('ntime',)),
204         )
205    
206     # var data
207     var_data = (
208         ('lat',  platform_info['lat']),
209         ('lon', platform_info['lon']),
210         ('z', []),
211         ('u', []),
212         ('v', []),
213         ('w', []),
214         ('back_scatter', []),
215         ('wtemp', []),
216         )
217
218     return (global_atts, dimensions, var_inits, var_data)
219
220 def updater(platform_info, sensor_info, data):
221     #
222     global_atts = {
223         # timeframe of data contained in file yyyy-mm-dd HH:MM:SS
224         'end_date' : data['sample_dt'].strftime("%Y-%m-%d %H:%M:%S"),
225         'release_date' : now.strftime("%Y-%m-%d %H:%M:%S"),
226         #
227         'creation_date' : now.strftime("%Y-%m-%d %H:%M:%S"),
228         'modification_date' : now.strftime("%Y-%m-%d %H:%M:%S"),
229         }
230     # var data
231     var_data = (
232         ('u', data['u']),
233         ('v', data['v']),
234         ('w',  data['w']),
235         ('back_scatter', data['back_scatter']),
236         ('wtemp', data['wtemp']),
237         )
238     return (global_atts, var_data)
239 #
240
Note: See TracBrowser for help on using the browser.