Index: raw2proc/trunk/raw2proc/proc_avp_ascii_met.py =================================================================== --- raw2proc/trunk/raw2proc/proc_avp_ascii_met.py (revision 218) +++ raw2proc/trunk/raw2proc/proc_avp_ascii_met.py (revision 220) @@ -1,4 +1,4 @@ #!/usr/bin/env python -# Last modified: Time-stamp: <2008-11-13 11:55:34 haines> +# Last modified: Time-stamp: <2009-01-08 15:27:29 haines> """ how to parse data, and assert what data and info goes into @@ -58,4 +58,12 @@ fn = sensor_info['fn'] sample_dt_start = filt_datetime(fn)[0] + + # if line has weird ascii chars -- remove it + for index, line in enumerate(lines): + if re.search(r"[\x1a]", line): + # print '... ... remove unexpected ... ' + str(line) + lines.pop(index) + + lines.sort() N = len(lines) data = { @@ -71,14 +79,16 @@ i = 0 - lines.sort() - mvar = platform_info['mvar'] # Magnetic Variation at station - # mvar = -8.0 # (??????) - - wnd = [] + for line in lines: + # if line has weird ascii chars -- skip it and iterate to next line + if re.search(r"[\x1a]", line): + print 'skipping bad data line ... ' + str(line) + continue + wnd = [] + # split line and parse float and integers - sw = re.split('[\s/\:]*', line) + sw = re.split('[\s\/\:]*', line) for s in sw: m = re.search(REAL_RE_STR, s) @@ -86,5 +96,5 @@ wnd.append(float(m.groups()[0])) - if len(wnd)==12: + if len(wnd)>=11: # get sample datetime from data sample_str = '%02d-%02d-%4d %02d:%02d:%02d' % tuple(wnd[0:6]) @@ -100,6 +110,10 @@ u = wnd[9] # Easterly (?) Component (m/s) (mag or true??) v = wnd[10] # Northerly (?) Component (m/s) (mag or true??) - nwnd = int(wnd[11]) # Number of samples in wind average - + if len(wnd)>=12: + nwnd = int(wnd[11]) + else: + nwnd = numpy.nan # Number of samples in wind average + # prior to Sep 2008 number of samples were not recorded + # combine wind dir and buoy compass direction # correct direction from magnetic N to true N @@ -119,5 +133,5 @@ i=i+1 - # if len(wnd)==12 + # if len(wnd)>=11 # for line @@ -126,4 +140,7 @@ def creator(platform_info, sensor_info, data): # + # subset data only to month being processed (see raw2proc.process()) + i = data['in'] + dt = data['dt'][i] # title_str = sensor_info['description']+' at '+ platform_info['location'] @@ -151,6 +168,6 @@ 'project_url' : 'http://nccoos.org', # timeframe of data contained in file yyyy-mm-dd HH:MM:SS - 'start_date' : data['dt'][0].strftime("%Y-%m-%d %H:%M:%S"), - 'end_date' : data['dt'][-1].strftime("%Y-%m-%d %H:%M:%S"), + 'start_date' : dt[0].strftime("%Y-%m-%d %H:%M:%S"), + 'end_date' : dt[-1].strftime("%Y-%m-%d %H:%M:%S"), 'release_date' : now_dt.strftime("%Y-%m-%d %H:%M:%S"), # @@ -160,5 +177,5 @@ # # must type match to data (e.g. fillvalue is real if data is real) - '_FillValue' : -99999., + '_FillValue' : numpy.nan, } @@ -269,7 +286,4 @@ ) - # subset data only to month being processed (see raw2proc.process()) - i = data['in'] - # var data var_data = ( @@ -291,8 +305,12 @@ def updater(platform_info, sensor_info, data): # + # subset data only to month being processed (see raw2proc.process()) + i = data['in'] + dt = data['dt'][i] + # 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"), + 'end_date' : dt[-1].strftime("%Y-%m-%d %H:%M:%S"), 'release_date' : now_dt.strftime("%Y-%m-%d %H:%M:%S"), #