1 |
|
---|
2 |
|
---|
3 |
""" |
---|
4 |
parse ascii text file of YSI 6600 V2 water quality data (.dat) |
---|
5 |
|
---|
6 |
load data file |
---|
7 |
parse data into variables for appending to netCDF data |
---|
8 |
|
---|
9 |
water depth is read from the file but stored in separate netCDF |
---|
10 |
because of different sample interval |
---|
11 |
|
---|
12 |
""" |
---|
13 |
|
---|
14 |
REAL_RE_STR = '\\s*(-?\\d(\\.\\d+|)[Ee][+\\-]\\d\\d?|-?(\\d+\\.\\d*|\\d*\\.\\d+)|-?\\d+)\\s*' |
---|
15 |
|
---|
16 |
import sys |
---|
17 |
import os |
---|
18 |
import re |
---|
19 |
|
---|
20 |
def parse_avp_YSI_6600V2(fn, lines): |
---|
21 |
""" |
---|
22 |
parse Automated Vertical Profile Station (AVP) Water Quality Data |
---|
23 |
|
---|
24 |
month, day, year, hour, min, sec, temp (deg. C), conductivity |
---|
25 |
(mS/cm), salinity (ppt or PSU), depth (meters), pH, turbidity (NTU), |
---|
26 |
chlorophyll (micrograms per liter), DO (micrograms per liter) |
---|
27 |
|
---|
28 |
Notes |
---|
29 |
----- |
---|
30 |
1. Column Format |
---|
31 |
|
---|
32 |
temp, cond, salin, depth, pH, turb, chl, DO |
---|
33 |
(C), (mS/cm), (ppt), (m), pH, (NTU), (ug/l), (ug/l) |
---|
34 |
|
---|
35 |
Profile Time: 00:30:00 |
---|
36 |
Profile Date: 08/18/2008 |
---|
37 |
Profile Depth: 255.0 cm |
---|
38 |
Profile Location: Stones Bay Serial No: 00016B79, ID: AVP1_SERDP |
---|
39 |
08/18/08 00:30:06 26.94 41.87 26.81 0.134 8.00 3.4 4.5 6.60 |
---|
40 |
08/18/08 00:30:07 26.94 41.87 26.81 0.143 8.00 3.4 4.8 6.59 |
---|
41 |
08/18/08 00:30:08 26.94 41.87 26.81 0.160 8.00 3.4 4.8 6.62 |
---|
42 |
08/18/08 00:30:09 26.94 41.87 26.81 0.183 8.00 3.4 4.8 6.66 |
---|
43 |
|
---|
44 |
2. read each sample and create timeseries for each parameter along |
---|
45 |
with the recorded depth of each sample, z(t) |
---|
46 |
|
---|
47 |
""" |
---|
48 |
import numpy |
---|
49 |
from datetime import datetime |
---|
50 |
from time import strptime |
---|
51 |
|
---|
52 |
|
---|
53 |
|
---|
54 |
sample_dt_start = filt_datetime(fn)[0] |
---|
55 |
|
---|
56 |
|
---|
57 |
nsamp = 0 |
---|
58 |
for line in lines: |
---|
59 |
m=re.search("^\d{2}\/\d{2}\/\d{2}", line) |
---|
60 |
if m: |
---|
61 |
nsamp=nsamp+1 |
---|
62 |
|
---|
63 |
N = nsamp |
---|
64 |
data = { |
---|
65 |
'dt' : numpy.array(numpy.ones((N,), dtype=object)*numpy.nan), |
---|
66 |
'time' : numpy.array(numpy.ones((N,), dtype=long)*numpy.nan), |
---|
67 |
'wtemp' : numpy.array(numpy.ones((N,), dtype=float)*numpy.nan), |
---|
68 |
'cond' : numpy.array(numpy.ones((N,), dtype=float)*numpy.nan), |
---|
69 |
'salin' : numpy.array(numpy.ones((N,), dtype=float)*numpy.nan), |
---|
70 |
'depth' : numpy.array(numpy.ones((N,), dtype=float)*numpy.nan), |
---|
71 |
'turb' : numpy.array(numpy.ones((N,), dtype=float)*numpy.nan), |
---|
72 |
'ph' : numpy.array(numpy.ones((N,), dtype=float)*numpy.nan), |
---|
73 |
'chl' : numpy.array(numpy.ones((N,), dtype=float)*numpy.nan), |
---|
74 |
'do' : numpy.array(numpy.ones((N,), dtype=float)*numpy.nan), |
---|
75 |
} |
---|
76 |
|
---|
77 |
|
---|
78 |
i = 0 |
---|
79 |
|
---|
80 |
for line in lines: |
---|
81 |
ysi = [] |
---|
82 |
|
---|
83 |
sw = re.split('[\s/\:]*', line) |
---|
84 |
for s in sw: |
---|
85 |
m = re.search(REAL_RE_STR, s) |
---|
86 |
if m: |
---|
87 |
ysi.append(float(m.groups()[0])) |
---|
88 |
|
---|
89 |
if len(ysi)==14: |
---|
90 |
|
---|
91 |
sample_str = '%02d-%02d-%2d %02d:%02d:%02d' % tuple(ysi[0:6]) |
---|
92 |
|
---|
93 |
|
---|
94 |
|
---|
95 |
|
---|
96 |
sample_dt = scanf_datetime(sample_str, fmt='%m-%d-%y %H:%M:%S') |
---|
97 |
|
---|
98 |
wtemp[i] = ysi[6] |
---|
99 |
cond[i] = ysi[7] |
---|
100 |
salin[i] = ysi[8] |
---|
101 |
depth[i] = ysi[9] |
---|
102 |
|
---|
103 |
ph[i] = ysi[10] |
---|
104 |
turb[i] = ysi[11] |
---|
105 |
chl[i] = ysi[12] |
---|
106 |
do[i] = ysi[13] |
---|
107 |
|
---|
108 |
data['dt'][i] = sample_dt |
---|
109 |
data['time'][i] = dt2es(sample_dt) |
---|
110 |
|
---|
111 |
data['wtemp'][i] = wtemp |
---|
112 |
data['cond'][i] = cond |
---|
113 |
data['salin'][i] = salin |
---|
114 |
data['depth'][i] = depth |
---|
115 |
data['turb'][i] = turb |
---|
116 |
data['ph'][i] = ph |
---|
117 |
data['chl'][i] = chl |
---|
118 |
data['do'][i] = do |
---|
119 |
|
---|
120 |
i=i+1 |
---|
121 |
|
---|
122 |
|
---|
123 |
|
---|
124 |
|
---|
125 |
return data |
---|
126 |
|
---|
127 |
|
---|
128 |
def load_data(inFile): |
---|
129 |
lines=None |
---|
130 |
if os.path.exists(inFile): |
---|
131 |
f = open(inFile, 'r') |
---|
132 |
lines = f.readlines() |
---|
133 |
f.close() |
---|
134 |
if len(lines)<=0: |
---|
135 |
print 'Empty file: '+ inFile |
---|
136 |
else: |
---|
137 |
print 'File does not exist: '+ inFile |
---|
138 |
return lines |
---|
139 |
|
---|
140 |
|
---|
141 |
from raw2proc import * |
---|
142 |
|
---|
143 |
def test1(fn): |
---|
144 |
lines = load_data(fn) |
---|
145 |
return parse_avp_YSI_6600V2(fn, lines) |
---|
146 |
|
---|
147 |
def test2(logFile): |
---|
148 |
pi = get_config('stones_config_YYYYMMDD.platform_info') |
---|
149 |
asi = get_config('stones_config_YYYYMMDD.sensor_info') |
---|
150 |
si = asi['met'] |
---|
151 |
lines = load_data(logFile) |
---|
152 |
si['fn'] = logFile |
---|
153 |
(parse, create, update) = import_processors(si['process_module']) |
---|
154 |
return parse(pi, si, logFile) |
---|
155 |
|
---|
156 |
if __name__ == '__main__': |
---|
157 |
fn = '/seacoos/data/nccoos/level0/stones/avp/2008_08/AVP1_20080811.dat' |
---|
158 |
|
---|
159 |
|
---|
160 |
|
---|
161 |
try: |
---|
162 |
data = test1(fn) |
---|
163 |
except: |
---|
164 |
pass |
---|
165 |
|
---|