Don't know if there's a "standard" but this should work:
np.where(np.all(np.sign(np.diff(x)).reshape(-1, 10) == -1, axis=-1))[0][0] * 10
diffs = np.sign(np.diff(x))
Take derivative as finite difference. Region of interest changes monotonically so derivative is either +
or -
.
bools = diffs.reshape(-1, 10) == -1
Here it decays so it's -
. We want to find 10
consecutive points where the derivative is negative, or whatever other "tolerance", until we declare "this is where decay begins". A fast way to do this in Python is by vectorizing via a reshape, but for-loop is also an option. If we can't reshape, then pad from left.
bools_rows = np.all(bools, axis=-1)
is how we check the entire row is -
.
np.where(bools_rows)[0][0]
gives the earliest match, *10
converts it back to original length. This gives an answer within 10 points, then we can apply for-loop over the smaller interval of diffs
to find the exact index.
Example w/ code
import numpy as np
import matplotlib.pyplot as plt
x = np.hstack([np.random.randn(30)/10 + 1,
np.exp(-np.linspace(0, 5, 51))])
out = np.where(np.all(np.sign(np.diff(x)).reshape(-1, 10) == -1, axis=-1))[0][0] * 10
plt.plot(x)
plt.scatter(out, x[out], color='r', s=20)
plt.axvline(out, color='tab:red', linewidth=1)
plt.show()