|
1
|
|
|
import numpy as np |
|
2
|
|
|
import pandas as pd |
|
3
|
|
|
|
|
4
|
|
|
|
|
5
|
|
|
def peak_detection_fxn(Dataframe_y): |
|
6
|
|
|
list = [0, 1] |
|
7
|
|
|
return list |
|
8
|
|
|
|
|
9
|
|
|
|
|
10
|
|
|
def split(vector): |
|
11
|
|
|
split = int(len(vector)/2) |
|
12
|
|
|
end = int(len(vector)) |
|
13
|
|
|
vector1 = np.array(vector)[0:split] |
|
14
|
|
|
vector2 = np.array(vector)[split:end] |
|
15
|
|
|
return vector1, vector2 |
|
16
|
|
|
|
|
17
|
|
|
|
|
18
|
|
|
def linear_background(x, y): |
|
19
|
|
|
fake_line_list = [1, 2, 3, 4] |
|
20
|
|
|
fake_line_array = np.array(fake_line_list) |
|
21
|
|
|
return fake_line_array |
|
22
|
|
|
|
|
23
|
|
|
|
|
24
|
|
|
def peak_values(DataFrame_x, DataFrame_y): |
|
25
|
|
|
"""Outputs x (potentials) and y (currents) values from data indices |
|
26
|
|
|
given by peak_detection function. |
|
27
|
|
|
|
|
28
|
|
|
---------- |
|
29
|
|
|
Parameters |
|
30
|
|
|
---------- |
|
31
|
|
|
DataFrame_x : should be in the form of a pandas DataFrame column. |
|
32
|
|
|
For example, df['potentials'] could be input as the column of x |
|
33
|
|
|
data. |
|
34
|
|
|
|
|
35
|
|
|
DataFrame_y : should be in the form of a pandas DataFrame column. |
|
36
|
|
|
For example, df['currents'] could be input as the column of y |
|
37
|
|
|
data. |
|
38
|
|
|
|
|
39
|
|
|
Returns |
|
40
|
|
|
------- |
|
41
|
|
|
Result : numpy array of coordinates at peaks in the following order: |
|
42
|
|
|
potential of peak on top curve, current of peak on top curve, |
|
43
|
|
|
potential of peak on bottom curve, current of peak on bottom curve""" |
|
44
|
|
|
index = peak_detection_fxn(DataFrame_y) |
|
45
|
|
|
potential1, potential2 = split(DataFrame_x) |
|
46
|
|
|
current1, current2 = split(DataFrame_y) |
|
47
|
|
|
Peak_values = [] |
|
48
|
|
|
Peak_values.append(potential2[(index[0])]) # TOPX (bottom part of curve is |
|
49
|
|
|
# the first part of DataFrame) |
|
50
|
|
|
Peak_values.append(current2[(index[0])]) # TOPY |
|
51
|
|
|
Peak_values.append(potential1[(index[1])]) # BOTTOMX |
|
52
|
|
|
Peak_values.append(current1[(index[1])]) # BOTTOMY |
|
53
|
|
|
Peak_array = np.array(Peak_values) |
|
54
|
|
|
return Peak_array |
|
55
|
|
|
|
|
56
|
|
|
|
|
57
|
|
|
def del_potential(DataFrame_x, DataFrame_y): |
|
58
|
|
|
"""Outputs the difference in potentials between anoidc and |
|
59
|
|
|
cathodic peaks in cyclic voltammetry data. |
|
60
|
|
|
|
|
61
|
|
|
Parameters |
|
62
|
|
|
---------- |
|
63
|
|
|
DataFrame_x : should be in the form of a pandas DataFrame column. |
|
64
|
|
|
For example, df['potentials'] could be input as the column of x |
|
65
|
|
|
data. |
|
66
|
|
|
|
|
67
|
|
|
DataFrame_y : should be in the form of a pandas DataFrame column. |
|
68
|
|
|
For example, df['currents'] could be input as the column of y |
|
69
|
|
|
data. |
|
70
|
|
|
|
|
71
|
|
|
Returns |
|
72
|
|
|
------- |
|
73
|
|
|
Results: difference in peak potentials.""" |
|
74
|
|
|
del_potentials = (peak_values(DataFrame_x, DataFrame_y)[0] - |
|
75
|
|
|
peak_values(DataFrame_x, DataFrame_y)[2]) |
|
76
|
|
|
return del_potentials |
|
77
|
|
|
|
|
78
|
|
|
|
|
79
|
|
|
def half_wave_potential(DataFrame_x, DataFrame_y): |
|
80
|
|
|
"""Outputs the half wave potential(redox potential) from cyclic |
|
81
|
|
|
voltammetry data. |
|
82
|
|
|
|
|
83
|
|
|
Parameters |
|
84
|
|
|
---------- |
|
85
|
|
|
DataFrame_x : should be in the form of a pandas DataFrame column. |
|
86
|
|
|
For example, df['potentials'] could be input as the column of x |
|
87
|
|
|
data. |
|
88
|
|
|
|
|
89
|
|
|
DataFrame_y : should be in the form of a pandas DataFrame column. |
|
90
|
|
|
For example, df['currents'] could be input as the column of y |
|
91
|
|
|
data. |
|
92
|
|
|
|
|
93
|
|
|
Returns |
|
94
|
|
|
------- |
|
95
|
|
|
Results : the half wave potential.""" |
|
96
|
|
|
half_wave_potential = (del_potential(DataFrame_x, DataFrame_y))/2 |
|
97
|
|
|
return half_wave_potential |
|
98
|
|
|
|
|
99
|
|
|
|
|
100
|
|
|
def peak_heights(DataFrame_x, DataFrame_y): |
|
101
|
|
|
"""Outputs heights of minimum peak and maximum |
|
102
|
|
|
peak from cyclic voltammetry data. |
|
103
|
|
|
|
|
104
|
|
|
Parameters |
|
105
|
|
|
---------- |
|
106
|
|
|
DataFrame_x : should be in the form of a pandas DataFrame column. |
|
107
|
|
|
For example, df['potentials'] could be input as the column of x |
|
108
|
|
|
data. |
|
109
|
|
|
|
|
110
|
|
|
DataFrame_y : should be in the form of a pandas DataFrame column. |
|
111
|
|
|
For example, df['currents'] could be input as the column of y |
|
112
|
|
|
data. |
|
113
|
|
|
|
|
114
|
|
|
Returns |
|
115
|
|
|
------- |
|
116
|
|
|
Results: height of maximum peak, height of minimum peak |
|
117
|
|
|
in that order in the form of a list.""" |
|
118
|
|
|
current_max = peak_values(DataFrame_x, DataFrame_y)[1] |
|
119
|
|
|
current_min = peak_values(DataFrame_x, DataFrame_y)[3] |
|
120
|
|
|
x1, x2 = split(DataFrame_x) |
|
121
|
|
|
y1, y2 = split(DataFrame_y) |
|
122
|
|
|
line_at_min = linear_background(x1, y1)[peak_detection_fxn(DataFrame_y)[1]] |
|
123
|
|
|
line_at_max = linear_background(x2, y2)[peak_detection_fxn(DataFrame_y)[0]] |
|
124
|
|
|
height_of_max = current_max - line_at_max |
|
125
|
|
|
height_of_min = abs(current_min - line_at_min) |
|
126
|
|
|
return [height_of_max, height_of_min] |
|
127
|
|
|
|
|
128
|
|
|
|
|
129
|
|
|
def peak_ratio(DataFrame_x, DataFrame_y): |
|
130
|
|
|
"""Outputs the peak ratios from cyclic voltammetry data. |
|
131
|
|
|
|
|
132
|
|
|
Parameters |
|
133
|
|
|
---------- |
|
134
|
|
|
DataFrame_x : should be in the form of a pandas DataFrame column. |
|
135
|
|
|
For example, df['potentials'] could be input as the column of x |
|
136
|
|
|
data. |
|
137
|
|
|
|
|
138
|
|
|
DataFrame_y : should be in the form of a pandas DataFrame column. |
|
139
|
|
|
For example, df['currents'] could be input as the column of y |
|
140
|
|
|
data. |
|
141
|
|
|
|
|
142
|
|
|
Returns |
|
143
|
|
|
------- |
|
144
|
|
|
Result : returns a the peak ratio.""" |
|
145
|
|
|
ratio = (peak_heights(DataFrame_x, DataFrame_y)[0] / |
|
146
|
|
|
peak_heights(DataFrame_x, DataFrame_y)[1]) |
|
147
|
|
|
return ratio |
|
148
|
|
|
|