-
Notifications
You must be signed in to change notification settings - Fork 1
/
Function.py
87 lines (77 loc) · 3.94 KB
/
Function.py
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
from pyabf import ABF
import os
import eventDetect
from datetime import datetime
import sys
import time
from multiprocessing import Pool
def detectMainFast(fileList, pattern, startCoeff, endCoeff, filterCoeff, minDuration, maxDuration):
start = time.clock()
fileName = fileList
nowTime = datetime.now().strftime('%Y-%m-%d-%H-%M-%S')
if not os.path.exists('result/'):
os.makedirs('result/')
resultName = 'result/' + nowTime + '.txt'
po = Pool(8)
fileNumber = 0
for i in range(len(fileName)):
abf = ABF(fileName[i])
fileNumber += 1
current = abf.data[0]
iterNumber = int(len(current) / (abf.dataRate * 10)) + 1
if (pattern == "down") or (pattern == "DOWN"):
for i in range(iterNumber):
if i == 0:
po.apply_async(eventDetect.eventDownFast,
(current[i * abf.dataRate * 10:i * abf.dataRate * 10 + abf.dataRate * 10], startCoeff, endCoeff,
filterCoeff, minDuration, maxDuration, resultName, abf.dataRate, fileNumber, i,))
elif i != iterNumber - 1:
po.apply_async(eventDetect.eventDownFast,
(current[i * abf.dataRate * 10 - 1000:i * abf.dataRate * 10 + abf.dataRate * 10], startCoeff, endCoeff,
filterCoeff, minDuration, maxDuration, resultName, abf.dataRate, fileNumber, i,))
else:
po.apply_async(eventDetect.eventDownFast,
(current[i * abf.dataRate * 10:], startCoeff, endCoeff, filterCoeff, minDuration, maxDuration,
resultName, abf.dataRate, fileNumber, i,))
elif (pattern == "up") or (pattern == "UP"):
for i in range(iterNumber):
if i == 0:
po.apply_async(eventDetect.eventUpFast,
(current[i * abf.dataRate * 10:i * abf.dataRate * 10 + abf.dataRate * 10], startCoeff,
endCoeff, filterCoeff, minDuration, maxDuration, resultName, abf.dataRate, fileNumber, i,))
elif i != iterNumber - 1:
po.apply_async(eventDetect.eventUpFast,
(current[i * abf.dataRate * 10 - 1000:i * abf.dataRate * 10 + abf.dataRate * 10],
startCoeff, endCoeff,
filterCoeff, minDuration, maxDuration, resultName, abf.dataRate, fileNumber, i,))
else:
po.apply_async(eventDetect.eventUpFast,
(current[i * abf.dataRate * 10:], startCoeff, endCoeff, filterCoeff, minDuration, maxDuration,
resultName, abf.dataRate, fileNumber, i,))
else:
po.close()
sys.exit(1)
po.close()
po.join()
elapsed = (time.clock() - start)
print("Time used:", elapsed)
print('finish')
def detectMain(pattern, startCoeff, endCoeff, filterCoeff, minDuration, maxDuration):
path = "data/"
fileName = os.listdir(path)
nowTime = datetime.now().strftime('%Y-%m-%d-%H-%M-%S')
if not os.path.exists('result/'):
os.makedirs('result/')
resultName = 'result/' + nowTime + '.txt'
for i in range(len(fileName)):
abf = ABF(path + fileName[i])
current = abf.data[0]
if pattern == "down":
eventDetect.eventDownFast(current, startCoeff, endCoeff, filterCoeff, minDuration, maxDuration, resultName,
abf.dataRate)
elif pattern == "up":
eventDetect.eventUpFast(current, startCoeff, endCoeff, filterCoeff, minDuration, maxDuration, resultName,
abf.dataRate)
else:
sys.exit(1)
print('finish')