| @@ 20-47 (lines=28) @@ | ||
| 17 | return vector1, vector2 |
|
| 18 | ||
| 19 | ||
| 20 | def critical_idx(x, y): ## Finds index where data set is no longer linear |
|
| 21 | """ |
|
| 22 | This function takes x and y values callculate the derrivative of x and y, and calculate moving average of 5 and 15 points. |
|
| 23 | Finds intercepts of different moving average curves and return the indexs of the first intercepts. |
|
| 24 | """ |
|
| 25 | k = np.diff(y)/(np.diff(x)) #calculated slops of x and y |
|
| 26 | ## Calculate moving average for 5 and 15 points. |
|
| 27 | ## This two arbitrary number can be tuned to get better fitting. |
|
| 28 | ave10 = [] |
|
| 29 | ave15 = [] |
|
| 30 | for i in range(len(k)-10): # The reason to minus 5 is to prevent j from running out of index. |
|
| 31 | a = 0 |
|
| 32 | for j in range(0,5): |
|
| 33 | a = a + k[i+j] |
|
| 34 | ave10.append(round(a/5, 5)) # keeping 9 desimal points for more accuracy |
|
| 35 | ||
| 36 | for i in range(len(k)-15): |
|
| 37 | b = 0 |
|
| 38 | for j in range(0,10): |
|
| 39 | b = b + k[i+j] |
|
| 40 | ave15.append(round(b/10, 5)) |
|
| 41 | ave10i = np.asarray(ave5) |
|
| 42 | print(ave10i) |
|
| 43 | ave15i = np.asarray(ave15) |
|
| 44 | print(ave15i) |
|
| 45 | ## Find intercepts of different moving average curves |
|
| 46 | idx = np.argwhere(np.diff(np.sign(ave15i - ave10i[:len(ave15i)])!= 0)).reshape(-1)+0 #reshape into one row. |
|
| 47 | return idx[1] |
|
| 48 | ||
| 49 | # This is based on the method 1 where user can't choose the baseline. |
|
| 50 | # If wanted to add that, choose method2. |
|
| @@ 147-172 (lines=26) @@ | ||
| 144 | vector2 = np.array(vector)[split:end] |
|
| 145 | return vector1, vector2 |
|
| 146 | ||
| 147 | def critical_idx(x, y): ## Finds index where data set is no longer linear |
|
| 148 | """ |
|
| 149 | This function takes x and y values callculate the derrivative of x and y, and calculate moving average of 5 and 15 points. |
|
| 150 | Finds intercepts of different moving average curves and return the indexs of the first intercepts. |
|
| 151 | """ |
|
| 152 | k = np.diff(y)/(np.diff(x)) #calculated slops of x and y |
|
| 153 | ||
| 154 | ## Calculate moving average for 5 and 15 points. |
|
| 155 | ## This two arbitrary number can be tuned to get better fitting. |
|
| 156 | ave5 = [] |
|
| 157 | ave15 = [] |
|
| 158 | for i in range(len(x)-5): # The reason to minus 5 is to prevent j from running out of index. |
|
| 159 | a = 0 |
|
| 160 | for j in range(0,5): |
|
| 161 | a = a + k[i+j] |
|
| 162 | ave5.append(round(a/5, 5)) # keeping 9 desimal points for more accuracy |
|
| 163 | ave5 = np.asarray(ave5) |
|
| 164 | for i in range(len(x)-15): |
|
| 165 | b = 0 |
|
| 166 | for j in range(0,15): |
|
| 167 | b = b + k[i+j] |
|
| 168 | ave15.append(round(b/15, 5)) |
|
| 169 | ave15 = np.asarray(ave15) |
|
| 170 | ## Find intercepts of different moving average curves |
|
| 171 | idx = np.argwhere(np.diff(np.sign(ave15 - ave5[:len(ave15)])!= 0)).reshape(-1) #reshape into one row. |
|
| 172 | return int(idx[0]) |
|
| 173 | ||
| 174 | def mean(vector): |
|
| 175 | """ |
|
| @@ 24-49 (lines=26) @@ | ||
| 21 | vector2 = np.array(vector)[split:end] |
|
| 22 | return vector1, vector2 |
|
| 23 | ||
| 24 | def critical_idx(x, y): ## Finds index where data set is no longer linear |
|
| 25 | """ |
|
| 26 | This function takes x and y values callculate the derrivative of x and y, and calculate moving average of 5 and 15 points. |
|
| 27 | Finds intercepts of different moving average curves and return the indexs of the first intercepts. |
|
| 28 | """ |
|
| 29 | k = np.diff(y)/(np.diff(x)) #calculated slops of x and y |
|
| 30 | ||
| 31 | ## Calculate moving average for 5 and 15 points. |
|
| 32 | ## This two arbitrary number can be tuned to get better fitting. |
|
| 33 | ave5 = [] |
|
| 34 | ave15 = [] |
|
| 35 | for i in range(len(k)-5): # The reason to minus 5 is to prevent j from running out of index. |
|
| 36 | a = 0 |
|
| 37 | for j in range(0,5): |
|
| 38 | a = a + k[i+j] |
|
| 39 | ave5.append(round(a/5, 4)) # keeping 9 desimal points for more accuracy |
|
| 40 | ave5 = np.asarray(ave5) |
|
| 41 | for i in range(len(k)-15): |
|
| 42 | b = 0 |
|
| 43 | for j in range(0,15): |
|
| 44 | b = b + k[i+j] |
|
| 45 | ave15.append(round(b/15, 5)) |
|
| 46 | ave15 = np.asarray(ave15) |
|
| 47 | ## Find intercepts of different moving average curves |
|
| 48 | idx = np.argwhere(np.diff(np.sign(ave15 - ave5[:len(ave15)])!= 0)).reshape(-1) #reshape into one row. |
|
| 49 | return int(idx[0]) |
|
| 50 | ||
| 51 | def mean(vector): |
|
| 52 | """ |
|