| @@ 188-215 (lines=28) @@ | ||
| 185 | return vector1, vector2 |
|
| 186 | ||
| 187 | ||
| 188 | def critical_idx(x, y): ## Finds index where data set is no longer linear |
|
| 189 | """ |
|
| 190 | This function takes x and y values callculate the derrivative of x and y, and calculate moving average of 5 and 15 points. |
|
| 191 | Finds intercepts of different moving average curves and return the indexs of the first intercepts. |
|
| 192 | """ |
|
| 193 | k = np.diff(y)/(np.diff(x)) #calculated slops of x and y |
|
| 194 | ## Calculate moving average for 5 and 15 points. |
|
| 195 | ## This two arbitrary number can be tuned to get better fitting. |
|
| 196 | ave5 = [] |
|
| 197 | ave15 = [] |
|
| 198 | for i in range(len(k)-10): # The reason to minus 5 is to prevent j from running out of index. |
|
| 199 | a = 0 |
|
| 200 | for j in range(0,10): |
|
| 201 | a = a + k[i+j] |
|
| 202 | ave5.append(round(a/10, 5)) # keeping 9 desimal points for more accuracy |
|
| 203 | ||
| 204 | for i in range(len(k)-15): |
|
| 205 | b = 0 |
|
| 206 | for j in range(0,15): |
|
| 207 | b = b + k[i+j] |
|
| 208 | ave15.append(round(b/15, 5)) |
|
| 209 | ave5i = np.asarray(ave5) |
|
| 210 | #print(ave10i) |
|
| 211 | ave15i = np.asarray(ave15) |
|
| 212 | #print(ave15i) |
|
| 213 | ## Find intercepts of different moving average curves |
|
| 214 | idx = np.argwhere(np.diff(np.sign(ave15i - ave5i[:len(ave15i)])!= 0)).reshape(-1)+0 #reshape into one row. |
|
| 215 | return idx[5] |
|
| 216 | ||
| 217 | # This is based on the method 1 where user can't choose the baseline. |
|
| 218 | # If wanted to add that, choose method2. |
|
| @@ 188-215 (lines=28) @@ | ||
| 185 | return vector1, vector2 |
|
| 186 | ||
| 187 | ||
| 188 | def critical_idx(x, y): ## Finds index where data set is no longer linear |
|
| 189 | """ |
|
| 190 | This function takes x and y values callculate the derrivative of x and y, and calculate moving average of 5 and 15 points. |
|
| 191 | Finds intercepts of different moving average curves and return the indexs of the first intercepts. |
|
| 192 | """ |
|
| 193 | k = np.diff(y)/(np.diff(x)) #calculated slops of x and y |
|
| 194 | ## Calculate moving average for 5 and 15 points. |
|
| 195 | ## This two arbitrary number can be tuned to get better fitting. |
|
| 196 | ave5 = [] |
|
| 197 | ave15 = [] |
|
| 198 | for i in range(len(k)-10): # The reason to minus 5 is to prevent j from running out of index. |
|
| 199 | a = 0 |
|
| 200 | for j in range(0,10): |
|
| 201 | a = a + k[i+j] |
|
| 202 | ave5.append(round(a/10, 5)) # keeping 9 desimal points for more accuracy |
|
| 203 | ||
| 204 | for i in range(len(k)-15): |
|
| 205 | b = 0 |
|
| 206 | for j in range(0,15): |
|
| 207 | b = b + k[i+j] |
|
| 208 | ave15.append(round(b/15, 5)) |
|
| 209 | ave5i = np.asarray(ave5) |
|
| 210 | #print(ave10i) |
|
| 211 | ave15i = np.asarray(ave15) |
|
| 212 | #print(ave15i) |
|
| 213 | ## Find intercepts of different moving average curves |
|
| 214 | idx = np.argwhere(np.diff(np.sign(ave15i - ave5i[:len(ave15i)])!= 0)).reshape(-1)+0 #reshape into one row. |
|
| 215 | return idx[5] |
|
| 216 | ||
| 217 | # This is based on the method 1 where user can't choose the baseline. |
|
| 218 | # If wanted to add that, choose method2. |
|