-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcleaner.py
More file actions
36 lines (30 loc) · 1.07 KB
/
cleaner.py
File metadata and controls
36 lines (30 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/env python
import os
import sys
import afitter as fitter
DEFAULT_THRESHOLD = 25
def main(args):
if len(args) < 1:
print >> sys.stderr, "Usage: %s <csv file path> (<threshold>)" % sys.argv[0]
return 1
threshold = DEFAULT_THRESHOLD if len(args) < 2 else int(args[1])
# read & fit data
data = fitter.parse_fluorometer_csv(args[0])
sim_data = fitter.fit_data(data)
# find basal level
baseline = fitter.find_absolute_baseline(data)
# run fitting
sim_data, params = fitter.fit_data(data)
# clean data
print 'threshold:', threshold
new_data = filter(lambda (t,v): v-sim_data[int(t*2)] < threshold, data)
# write to new file
new_path = args[0].rsplit('.',1)[0] + '_clean.csv'
w = file(new_path, 'w')
w.write('Time (s),Light Scattering (A.U.)\n')
w.writelines(['%.1f,%f\n' % (point[0], point[1]-baseline) for point in new_data])
w.close()
print "\nWRITTEN CLEAN DATA TO %s" % new_path
return 0
if __name__ == '__main__':
sys.exit(main(sys.argv[1:]))