"""parseWXTFiles.py Parses data from Vaisala WXT saved on the PSD data system during FATIMA 2022. Data lines have the following formats: 0013354 2R0,Dm=223D,Sm=7.2M,Ta=16.9C,Ua=97.0P,Pa=1008.1H,Rc=0.00M,Rd=0s,Ri=0.0M,Hc=0.0M ,Hd=0s,Hi=0.0M ,wdir ,wspd ,Tair ,RH ,Pmb cum_rain,dur ,mm/hr ,cum_hail,dur ,intens 0014161 2R1,Dm=223D,Sm=7.1M wdirMax,wdir 0014216 2R2,Ta=16.9C,Ua=97.0P,Pa=1008.1H Tair ,RH ,Pmb Fields from 2R0 lines are parsed and saved to a single output file. source file names follow the convention: wxt0yydddhh_raw.txt output file names follow the convention: wxt_parsed_yydddhh_raw.txt Byron Blomquist, NOAA/ESRL/PSD, July 2022 2016 """ import os import string # assume current directory contains raw met3 files, # dump list of data file names into a list variable files = [f for f in os.listdir('.') if f.startswith('wxt0')] # parse data files and save into txt files for file in files: # open output file, new name begins with wxt0 outp = 'wxt_parsed_'+file[4:] fwxt = open(outp, 'w') print(file) fin = open(file) for line in fin: cleanLine = line.strip() fields = cleanLine.split(',') if '2R0' in fields[0]: # select PSD timecode from field[0] lineOut = fields[0][0:7]+',' raw = fields[1:] # remaining fields # strip all alphabet and '=' characters data = [y.strip('=#'+string.ascii_letters) for y in raw] for item in data: # concatenate numeric fields to output lineOut += item + ',' printLine = lineOut[0:-1] + '\n' # add return character fwxt.write(printLine) print(outp+' finished') fwxt.close() # end