| @@ 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. |
|
| @@ 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. |
|
| @@ 144-171 (lines=28) @@ | ||
| 141 | return vector1, vector2 |
|
| 142 | ||
| 143 | ||
| 144 | def critical_idx(x, y): ## Finds index where data set is no longer linear |
|
| 145 | """ |
|
| 146 | This function takes x and y values callculate the derrivative of x and y, and calculate moving average of 5 and 15 points. |
|
| 147 | Finds intercepts of different moving average curves and return the indexs of the first intercepts. |
|
| 148 | """ |
|
| 149 | k = np.diff(y)/(np.diff(x)) #calculated slops of x and y |
|
| 150 | ## Calculate moving average for 5 and 15 points. |
|
| 151 | ## This two arbitrary number can be tuned to get better fitting. |
|
| 152 | ave5 = [] |
|
| 153 | ave15 = [] |
|
| 154 | for i in range(len(k)-10): # The reason to minus 5 is to prevent j from running out of index. |
|
| 155 | a = 0 |
|
| 156 | for j in range(0,10): |
|
| 157 | a = a + k[i+j] |
|
| 158 | ave5.append(round(a/10, 5)) # keeping 9 desimal points for more accuracy |
|
| 159 | ||
| 160 | for i in range(len(k)-15): |
|
| 161 | b = 0 |
|
| 162 | for j in range(0,15): |
|
| 163 | b = b + k[i+j] |
|
| 164 | ave15.append(round(b/15, 5)) |
|
| 165 | ave5i = np.asarray(ave5) |
|
| 166 | #print(ave10i) |
|
| 167 | ave15i = np.asarray(ave15) |
|
| 168 | #print(ave15i) |
|
| 169 | ## Find intercepts of different moving average curves |
|
| 170 | idx = np.argwhere(np.diff(np.sign(ave15i - ave5i[:len(ave15i)])!= 0)).reshape(-1)+0 #reshape into one row. |
|
| 171 | return idx[5] |
|
| 172 | ||
| 173 | # This is based on the method 1 where user can't choose the baseline. |
|
| 174 | # If wanted to add that, choose method2. |
|
| @@ 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. |
|