-
Notifications
You must be signed in to change notification settings - Fork 0
/
exploring.py
71 lines (51 loc) · 1.76 KB
/
exploring.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
import numpy as np
import matplotlib.pylab as plt
import problem_set1 as ps1
# -----------------------------------------------------------------------------
filename = "spikes_example.npy"
answersFile = "spikes_example_answers.npy"
# -----------------------------------------------------------------------------
plt.close('all')
data = np.load(filename)[()];
t = data['time']
v = data['voltage']
plt.figure()
plt.plot(t, v)
plt.xlabel('Time (s)')
plt.ylabel('Voltage (uV)')
plt.title('Spikes in Raw Signal')
plt.show()
vClipped = np.copy(v)
threshold = max(v)*1.45/4
for ix in range(len(vClipped)):
if (vClipped[ix] < threshold):
vClipped[ix] = 0
plt.hold = True
APTimes = []
for ix in range(len(vClipped)-1):
if (vClipped[ix+1] > vClipped[ix]):
currentMax = ix+1
elif (vClipped[ix+1] < vClipped[ix]):
APTimes.append(t[currentMax])
APTimes = np.unique(APTimes)
APMarks = np.ones(len(APTimes)) * max(v) + max(v)/4
plt.plot(APTimes, APMarks, 'rv', linewidth=50)
actualTimes = ps1.get_actual_times(answersFile)
ps1.detector_tester(APTimes, actualTimes)
plt.figure()
plt.xlabel('Time (s)')
plt.ylabel('Voltage (uV)')
plt.title('Spike waveforms')
halfWindow = 0.003 # in seconds
samplingTime = np.absolute(np.diff(t)[0])
numOfSamplesInHalfWindow = halfWindow//samplingTime
spikeWindow = np.arange(-halfWindow, halfWindow+samplingTime, samplingTime)
for APtime in APTimes:
for idx in range(len(t)):
if (t[idx] == APtime):
spikeIndex = idx
startIndex = spikeIndex-numOfSamplesInHalfWindow
endIndex = startIndex + len(spikeWindow)
spikeVoltage = v[startIndex:endIndex]
plt.plot(spikeWindow, spikeVoltage)
# -----------------------------------------------------------------------------