Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # encoding: utf-8
- """This is to parse the results from multiple files and pull them into one file"""
- from os import listdir
- from string import split
- PARSE_DIR = "C:/Users/jhaagsma/Dropbox (Personal)/JulianChrisShare/EIS/eisSaltData/2018-02-01/CaCl10wt"
- PREPEND_OF_INTEREST = 'phaseinfo'
- SUMMARY_FILE = 'summary.info.csv'
- # get the files in the dir
- PARSE_DIR = PARSE_DIR.rstrip("/") + '/'
- files = listdir(PARSE_DIR)
- wants = []
- for f in files:
- if f.startswith(PREPEND_OF_INTEREST):
- # add the file to our list...
- wants.append(f)
- print("There are {} files matching {}".format(len(wants), PREPEND_OF_INTEREST))
- if len(wants) <= 0:
- # exit the program
- exit(0)
- filepath = PARSE_DIR + SUMMARY_FILE
- print("Saving to: {}".format(filepath))
- fhandle = open(filepath, 'w')
- fhandle.write("Date,Time,Unix,Name,Frequency,"
- "Z-Magnitude,Z-Phase,Z-Real,Z-Imaginary,TemperatureStart,TemperatureEnd,Resistor,\n")
- for f in wants:
- name = date = time = unix = freq = zp = zx = zy = ts = te = r = None
- zm = -1
- fo = open(PARSE_DIR + f, 'r')
- line = "blah"
- for line in fo:
- if not line:
- break
- try:
- index, value = line.split(': ')
- except ValueError:
- break
- value = value.strip()
- if index == 'SampleName':
- name = value
- elif index == 'Date':
- date = value
- elif index == 'Unix':
- unix = value
- elif index == 'Frequency':
- freq = value
- elif index == 'Resistor':
- r = value
- elif index == 'Z_magnitude':
- zm = value
- elif index == 'Z_phase':
- zp = value
- elif index == 'Z_x':
- zx = value
- elif index == 'Z_y':
- zy = value
- elif index == 'StartTemperature':
- ts = value
- elif index == 'EndTemperature':
- te = value
- if date and time and unix and zm is not -1 and ts and te and r:
- break
- csvstring = "{},{},{},{},{},{},{},{},{},{},{},{}\n".format(date, time, unix, name, freq, zm, zp, zx, zy, ts, te, r)
- fhandle.write(csvstring)
- print("Wrote from {}".format(f))
- print("Finished writing")
- exit(0)
Add Comment
Please, Sign In to add comment