Skip to content

Instantly share code, notes, and snippets.

@grandadmiral-thrawn
Created August 13, 2015 15:19
Show Gist options
  • Save grandadmiral-thrawn/3c300d051b8479d8844b to your computer and use it in GitHub Desktop.
Save grandadmiral-thrawn/3c300d051b8479d8844b to your computer and use it in GitHub Desktop.
A quick script to convert Sherri's Hobo Logger Data to the accepted WaTeR.py format

convert sherri's data

In the first line of the file you will see a list called "myfiles". For the streams there are only 5 or 6 files, so instead of iterating over a big list its much easier to just put them in there.

Put your files in that list.

You can see down below that I have built a constructor based on the name coming in to extract the "E1" etc. from the name of the original file and pass it to the output file which is very picky about having the word reformatted in it. You might be good to keep the naming convention in the "my files" list if you are confused by the conversion.

import csv
import datetime
"""
This program will convert Sherri's HOBO logger files to the format that water likes
It likes
1 row headers
date as mm/dd/yy
time as hh:mm
temp with 3 decimals
no quotes, ever
"""
myfiles = ['HJA_PC_E1.csv', 'HJA_PC_E2.csv', 'HJA_PC_E3.csv','HJA_PC_E5.csv', 'HJA_PC_E6.csv']
for each_file in myfiles:
nr = []
with open(each_file, 'rb') as readfile:
reader = csv.reader(readfile)
reader.next()
reader.next()
for row in reader:
datetime1 = datetime.datetime.strptime(str(row[1]), '%m/%d/%y %I:%M:%S %p')
temp = str(row[2])
write_date = datetime.datetime.strftime(datetime1, '%m/%d/%y')
write_time = datetime.datetime.strftime(datetime1, '%H:%M')
new_row = [write_date, write_time, temp]
nr.append(new_row)
writefile = each_file[4:9] + "_reformatted.csv"
header = ["DATEPC" + each_file[7:9], "TIMEPC" + each_file[7:9], "TEMPPC" + each_file[7:9]]
with open(writefile,'wb') as writefile:
writer = csv.writer(writefile)
writer.writerow(header)
for each_item in nr:
writer.writerow(each_item)
print "Finished converting raw files to WaTeR format!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment