-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproc_remtech_rawdata_pa0.py
More file actions
479 lines (442 loc) · 19.7 KB
/
proc_remtech_rawdata_pa0.py
File metadata and controls
479 lines (442 loc) · 19.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
#!/usr/bin/env python
"""
Parse data and assert what data creates and updates monthly NetCDF files.
Remtech PA0 processed sodar wind profile data.
"""
import math
import numpy as n
import pycdf
import datetime
import procutil
from sodar.remtech import rawData
INVALID = '-9999'
nowDt = datetime.datetime.utcnow().replace(microsecond=0)
def parser(platform_info, sensor_info, lines):
"""
Parse and assign wind profile data from raw Sodar file.
"""
rawDataObject = rawData.RawData(''.join(lines))
numSamples = len(rawDataObject)
minAltitude = sensor_info['min_altitude']
altitudeInterval = sensor_info['altitude_interval']
numAltitudes = sensor_info['num_altitudes']
sensorElevation = sensor_info['sensor_elevation']
altitudes = [(altitudeNum * altitudeInterval) + minAltitude
for altitudeNum in range(numAltitudes)]
elevations = [altitude + sensorElevation for altitude in altitudes]
altitudes = [str(altitude) for altitude in altitudes]
data = {
'block' : n.array(n.ones((numSamples,), dtype=int) * n.nan),
'dt' : n.array(n.ones((numSamples,), dtype=object) * n.nan),
'time' : n.array(n.ones((numSamples,), dtype=long) * n.nan),
'val1' : n.array(n.ones((numSamples,), dtype=int) * n.nan),
'val2' : n.array(n.ones((numSamples,), dtype=int) * n.nan),
'val3' : n.array(n.ones((numSamples,), dtype=int) * n.nan),
'val4' : n.array(n.ones((numSamples,), dtype=int) * n.nan),
'spu1' : n.array(n.ones((numSamples,), dtype=int) * n.nan),
'spu2' : n.array(n.ones((numSamples,), dtype=int) * n.nan),
'spu3' : n.array(n.ones((numSamples,), dtype=int) * n.nan),
'spu4' : n.array(n.ones((numSamples,), dtype=int) * n.nan),
'nois1' : n.array(n.ones((numSamples,), dtype=int) * n.nan),
'nois2' : n.array(n.ones((numSamples,), dtype=int) * n.nan),
'nois3' : n.array(n.ones((numSamples,), dtype=int) * n.nan),
'nois4' : n.array(n.ones((numSamples,), dtype=int) * n.nan),
'femax' : n.array(n.ones((numSamples,), dtype=int) * n.nan),
'softw' : n.array(n.ones((numSamples,), dtype=int) * n.nan),
'fe11' : n.array(n.ones((numSamples,), dtype=int) * n.nan),
'fe12' : n.array(n.ones((numSamples,), dtype=int) * n.nan),
'fe21' : n.array(n.ones((numSamples,), dtype=int) * n.nan),
'fe22' : n.array(n.ones((numSamples,), dtype=int) * n.nan),
'snr1' : n.array(n.ones((numSamples,), dtype=int) * n.nan),
'snr2' : n.array(n.ones((numSamples,), dtype=int) * n.nan),
'snr3' : n.array(n.ones((numSamples,), dtype=int) * n.nan),
'snr4' : n.array(n.ones((numSamples,), dtype=int) * n.nan),
'check' : n.array(n.ones((numSamples,), dtype=int) * n.nan),
'jam' : n.array(n.ones((numSamples,), dtype=int) * n.nan),
'z' : n.array(elevations, dtype=float),
'u' : n.array(n.ones((numSamples,
numAltitudes), dtype=float) * n.nan),
'v' : n.array(n.ones((numSamples,
numAltitudes), dtype=float) * n.nan),
'w' : n.array(n.ones((numSamples,
numAltitudes), dtype=float) * n.nan),
'echo' : n.array(n.ones((numSamples,
numAltitudes), dtype = int) * n.nan),
}
for sample in rawDataObject:
sampleIndex = rawDataObject.index(sample)
data['block'][sampleIndex] = int(sample['BL#'])
dt = {'month' : int(sample['MONTH']),
'day' : int(sample['DAY']),
'year' : int(sample['YEAR']),
'hour' : int(sample['HOUR']),
'min' : int(sample['MIN']),
}
dt = '%(month)02d-%(day)02d-%(year)04d %(hour)02d:%(min)02d' % dt
dt = procutil.scanf_datetime(dt, fmt='%m-%d-%Y %H:%M')
if sensor_info['utc_offset']:
dt = dt + datetime.timedelta(hours=sensor_info['utc_offset'])
data['dt'][sampleIndex] = dt
data['time'][sampleIndex] = procutil.dt2es(dt)
data['val1'][sampleIndex] = int(sample['VAL1'])
data['val2'][sampleIndex] = int(sample['VAL2'])
data['val3'][sampleIndex] = int(sample['VAL3'])
data['val4'][sampleIndex] = int(sample['VAL4'])
data['spu1'][sampleIndex] = int(sample['SPU1'])
data['spu2'][sampleIndex] = int(sample['SPU2'])
data['spu3'][sampleIndex] = int(sample['SPU3'])
data['spu4'][sampleIndex] = int(sample['SPU4'])
data['nois1'][sampleIndex] = int(sample['NOIS1'])
data['nois2'][sampleIndex] = int(sample['NOIS2'])
data['nois3'][sampleIndex] = int(sample['NOIS3'])
data['nois4'][sampleIndex] = int(sample['NOIS4'])
data['femax'][sampleIndex] = int(sample['FEMAX'])
data['softw'][sampleIndex] = int(sample['SOFTW'])
data['fe11'][sampleIndex] = int(sample['FE11'])
data['fe12'][sampleIndex] = int(sample['FE12'])
data['fe21'][sampleIndex] = int(sample['FE21'])
data['fe22'][sampleIndex] = int(sample['FE22'])
data['snr1'][sampleIndex] = int(sample['SNR1'])
data['snr2'][sampleIndex] = int(sample['SNR2'])
data['snr3'][sampleIndex] = int(sample['SNR3'])
data['snr4'][sampleIndex] = int(sample['SNR4'])
data['check'][sampleIndex] = int(sample['CHECK'])
data['jam'][sampleIndex] = int(sample['JAM'])
for altitude,altitudeIndex in zip(altitudes, range(len(altitudes))):
echo = sample[altitude]['CT']
radial = sample[altitude]['SPEED']
theta = sample[altitude]['DIR']
vertical = sample[altitude]['W']
if radial != INVALID and theta != INVALID:
theta = math.pi * float(theta) / 180.0
radial = float(radial)
data['u'][sampleIndex][altitudeIndex] = radial * math.sin(theta)
data['v'][sampleIndex][altitudeIndex] = radial * math.cos(theta)
if echo != INVALID:
data['echo'][sampleIndex][altitudeIndex] = echo
if vertical != INVALID:
data['w'][sampleIndex][altitudeIndex] = vertical
return data
def creator(platform_info, sensor_info, data):
#
#
title_str = sensor_info['description']+' at '+ platform_info['location']
global_atts = {
'title' : title_str,
'institution' : 'Unversity of North Carolina at Chapel Hill (UNC-CH)',
'institution_url' : 'http://nccoos.unc.edu',
'institution_dods_url' : 'http://nccoos.unc.edu',
'metadata_url' : 'http://nccoos.unc.edu',
'references' : 'http://nccoos.unc.edu',
'contact' : 'cbc (cbc@unc.edu)',
#
'source' : 'fixed-profiler (acoustic doppler) observation',
'history' : 'raw2proc using ' + sensor_info['process_module'],
'comment' : 'File created using pycdf'+pycdf.pycdfVersion()+' and numpy '+pycdf.pycdfArrayPkg(),
# conventions
'Conventions' : 'CF-1.0; SEACOOS-CDL-v2.0',
# SEACOOS CDL codes
'format_category_code' : 'fixed-profiler',
'institution_code' : platform_info['institution'],
'platform_code' : platform_info['id'],
'package_code' : sensor_info['id'],
# institution specific
'project' : 'North Carolina Coastal Ocean Observing System (NCCOOS)',
'project_url' : 'http://nccoos.unc.edu',
# timeframe of data contained in file yyyy-mm-dd HH:MM:SS
# first date in monthly file
'start_date' : data['dt'][0].strftime("%Y-%m-%d %H:%M:%S"),
# last date in monthly file
'end_date' : data['dt'][-1].strftime("%Y-%m-%d %H:%M:%S"),
'release_date' : nowDt.strftime("%Y-%m-%d %H:%M:%S"),
#
'creation_date' : nowDt.strftime("%Y-%m-%d %H:%M:%S"),
'modification_date' : nowDt.strftime("%Y-%m-%d %H:%M:%S"),
'process_level' : 'level1',
#
# must type match to data (e.g. fillvalue is real if data is real)
'_FillValue' : -99999.,
}
var_atts = {
# coordinate variables
'time' : {'short_name': 'time',
'long_name': 'Time',
'standard_name': 'time',
'units': 'seconds since 1970-1-1 00:00:00 -0', # UTC
'axis': 'T',
},
'lat' : {'short_name': 'lat',
'long_name': 'Latitude',
'standard_name': 'latitude',
'reference':'geographic coordinates',
'units': 'degrees_north',
'valid_range':(-90.,90.),
'axis': 'Y',
},
'lon' : {'short_name': 'lon',
'long_name': 'Longtitude',
'standard_name': 'longtitude',
'reference':'geographic coordinates',
'units': 'degrees_east',
'valid_range':(-180.,180.),
'axis': 'Y',
},
'z' : {'short_name': 'z',
'long_name': 'Height',
'standard_name': 'height',
'reference':'zero at sea-surface',
'positive' : 'up',
'units': 'm',
'axis': 'Z',
},
# data variables
'u': {'short_name' : 'u',
'long_name': 'East/West Component of Wind',
'standard_name': 'eastward_wind',
'units': 'cm s-1',
},
'v': {'short_name' : 'v',
'long_name': 'North/South Component of Wind',
'standard_name': 'northward_wind',
'units': 'cm s-1',
},
'w': {'short_name' : 'w',
'long_name': 'Vertical Component of Wind',
'standard_name': 'upward_wind',
'units': 'cm s-1',
},
'echo': {'short_name' : 'echo',
'long_name': 'Echo Stength',
'standard_name': 'echo_strenth',
},
'block' : {'short_name': 'block',
'long_name': 'Block Number',
'standard_name': 'block_number'
},
'val1': {'short_name' : 'val1',
'long_name': 'Number of Beam Validations 1',
'standard_name': 'validations_1',
},
'val2': {'short_name' : 'val2',
'long_name': 'Number of Beam Validations 2',
'standard_name': 'validations_2',
},
'val3': {'short_name' : 'val3',
'long_name': 'Number of Beam Validations 3',
'standard_name': 'validations_3',
},
'val4': {'short_name' : 'val4',
'long_name': 'Number of Beam Validations 4',
'standard_name': 'validations_4',
},
'spu1': {'short_name' : 'spu1',
'long_name': 'Normalized Probability of False Signal 1',
'standard_name': 'probability_1',
},
'spu2': {'short_name' : 'spu2',
'long_name': 'Normalized Probability of False Signal 1',
'standard_name': 'probability_2',
},
'spu3': {'short_name' : 'spu3',
'long_name': 'Normalized Probability of False Signal 3',
'standard_name': 'probability_3',
},
'spu4': {'short_name' : 'spu4',
'long_name': 'Normalized Probability of False Signal 4',
'standard_name': 'probability_4',
},
'nois1': {'short_name' : 'nois1',
'long_name': 'Environmental Noise 1',
'standard_name': 'ambient_1',
'units': 'dB',
},
'nois2': {'short_name' : 'nois2',
'long_name': 'Environmental Noise 2',
'standard_name': 'ambient_2',
'units': 'dB',
},
'nois3': {'short_name' : 'nois3',
'long_name': 'Environmental Noise 3',
'standard_name': 'ambient_3',
'units': 'dB',
},
'nois4': {'short_name' : 'nois4',
'long_name': 'Environmental Noise 4',
'standard_name': 'ambient_4',
'units': 'dB',
},
'femax': {'short_name': 'femax',
'long_name': 'Maximum Ground Clutter',
'standard_name': 'max_clutter',
},
'softw': {'short_name': 'softw',
'long_name': 'Software Version',
'standard_name': 'software',
},
'fe11': {'short_name': 'fe11',
'long_name': 'Number of Frequencies Emitted 11',
'standard_name': 'frequencies_11',
},
'fe12': {'short_name': 'fe12',
'long_name': 'Number of Frequencies Emitted 12',
'standard_name': 'frequencies_12',
},
'fe21': {'short_name': 'fe21',
'long_name': 'Number of Frequencies Emitted 21',
'standard_name': 'frequencies_21',
},
'fe22': {'short_name': 'fe22',
'long_name': 'Number of Frequencies Emitted 22',
'standard_name': 'frequencies_22',
},
'snr1': {'short_name' : 'snr1',
'long_name': 'Average Signal To Noise Ratio 1',
'standard_name': 'signal_to_noise_1',
'units': 'dB',
},
'snr2': {'short_name' : 'snr2',
'long_name': 'Average Signal To Noise Ratio 2',
'standard_name': 'signal_to_noise_2',
'units': 'dB',
},
'snr3': {'short_name' : 'snr3',
'long_name': 'Average Signal To Noise Ratio 3',
'standard_name': 'signal_to_noise_3',
'units': 'dB',
},
'snr4': {'short_name' : 'snr4',
'long_name': 'Average Signal To Noise Ratio 4',
'standard_name': 'signal_to_noise_4',
'units': 'dB',
},
}
# dimension names use tuple so order of initialization is maintained
dim_inits = (
('ntime', pycdf.NC.UNLIMITED),
('nlat', 1),
('nlon', 1),
('nz', sensor_info['num_altitudes'])
)
# using tuple of tuples so order of initialization is maintained
# using dict for attributes order of init not important
# use dimension names not values
# (varName, varType, (dimName1, [dimName2], ...))
var_inits = (
# coordinate variables
('time', pycdf.NC.INT, ('ntime',)),
('lat', pycdf.NC.FLOAT, ('nlat',)),
('lon', pycdf.NC.FLOAT, ('nlon',)),
('z', pycdf.NC.FLOAT, ('nz',)),
# data variables
('u', pycdf.NC.FLOAT, ('ntime', 'nz')),
('v', pycdf.NC.FLOAT, ('ntime', 'nz')),
('w', pycdf.NC.FLOAT, ('ntime', 'nz')),
('echo', pycdf.NC.FLOAT, ('ntime', 'nz')),
('block', pycdf.NC.INT, ('ntime',)),
('val1', pycdf.NC.INT, ('ntime',)),
('val2', pycdf.NC.INT, ('ntime',)),
('val3', pycdf.NC.INT, ('ntime',)),
('val4', pycdf.NC.INT, ('ntime',)),
('spu1', pycdf.NC.INT, ('ntime',)),
('spu2', pycdf.NC.INT, ('ntime',)),
('spu3', pycdf.NC.INT, ('ntime',)),
('spu4', pycdf.NC.INT, ('ntime',)),
('nois1', pycdf.NC.INT, ('ntime',)),
('nois2', pycdf.NC.INT, ('ntime',)),
('nois3', pycdf.NC.INT, ('ntime',)),
('nois4', pycdf.NC.INT, ('ntime',)),
('femax', pycdf.NC.INT, ('ntime',)),
('softw', pycdf.NC.INT, ('ntime',)),
('fe11', pycdf.NC.INT, ('ntime',)),
('fe12', pycdf.NC.INT, ('ntime',)),
('fe21', pycdf.NC.INT, ('ntime',)),
('fe22', pycdf.NC.INT, ('ntime',)),
('snr1', pycdf.NC.INT, ('ntime',)),
('snr2', pycdf.NC.INT, ('ntime',)),
('snr3', pycdf.NC.INT, ('ntime',)),
('snr4', pycdf.NC.INT, ('ntime',)),
)
# subset data only to month being processed (see raw2proc.process())
i = data['in']
# var data
var_data = (
('time', data['time'][i]),
('lat', platform_info['lat']),
('lon', platform_info['lon']),
('z', data['z']),
('u', data['u'][i]),
('v', data['v'][i]),
('w', data['w'][i]),
('echo', data['echo'][i]),
('block', data['block'][i]),
('val1', data['val1'][i]),
('val2', data['val1'][i]),
('val3', data['val1'][i]),
('val4', data['val1'][i]),
('spu1', data['spu1'][i]),
('spu2', data['spu2'][i]),
('spu3', data['spu3'][i]),
('spu4', data['spu4'][i]),
('nois1', data['nois1'][i]),
('nois2', data['nois2'][i]),
('nois3', data['nois3'][i]),
('nois4', data['nois4'][i]),
('femax', data['femax'][i]),
('softw', data['softw'][i]),
('fe11', data['fe11'][i]),
('fe12', data['fe12'][i]),
('fe21', data['fe21'][i]),
('fe22', data['fe22'][i]),
('snr1', data['snr1'][i]),
('snr2', data['snr2'][i]),
('snr3', data['snr3'][i]),
('snr4', data['snr4'][i]),
)
return (global_atts, var_atts, dim_inits, var_inits, var_data)
def updater(platform_info, sensor_info, data):
#
global_atts = {
# update times of data contained in file (yyyy-mm-dd HH:MM:SS)
# last date in monthly file
'end_date' : data['dt'][-1].strftime("%Y-%m-%d %H:%M:%S"),
'release_date' : nowDt.strftime("%Y-%m-%d %H:%M:%S"),
#
'modification_date' : nowDt.strftime("%Y-%m-%d %H:%M:%S"),
}
# data variables
# update any variable attributes like range, min, max
var_atts = {}
# subset data only to month being processed (see raw2proc.process())
i = data['in']
# data
var_data = (
('time', data['time'][i]),
('u', data['u'][i]),
('v', data['v'][i]),
('w', data['w'][i]),
('echo', data['echo'][i]),
('block', data['block'][i]),
('val1', data['val1'][i]),
('val2', data['val1'][i]),
('val3', data['val1'][i]),
('val4', data['val1'][i]),
('spu1', data['spu1'][i]),
('spu2', data['spu2'][i]),
('spu3', data['spu3'][i]),
('spu4', data['spu4'][i]),
('nois1', data['nois1'][i]),
('nois2', data['nois2'][i]),
('nois3', data['nois3'][i]),
('nois4', data['nois4'][i]),
('femax', data['femax'][i]),
('softw', data['softw'][i]),
('fe11', data['fe11'][i]),
('fe12', data['fe12'][i]),
('fe21', data['fe21'][i]),
('fe22', data['fe22'][i]),
('snr1', data['snr1'][i]),
('snr2', data['snr2'][i]),
('snr3', data['snr3'][i]),
('snr4', data['snr4'][i]),
)
return (global_atts, var_atts, var_data)