Skip to content

Instantly share code, notes, and snippets.

@emunsing
Created June 16, 2020 19:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save emunsing/0d804bd2ce059eb7e460560f303ecc2f to your computer and use it in GitHub Desktop.
Save emunsing/0d804bd2ce059eb7e460560f303ecc2f to your computer and use it in GitHub Desktop.
x = np.arange(0, 12.1, 0.1)
y = range(0,10)
activate_threshold = 1.0
deactivate_threshold = -1.0
data = pd.DataFrame({k: (np.sin(x+k) + 0.5 * np.sin(10*x+k)) for k in y})
activation = (data > activate_threshold).astype('float').diff()
activation.iloc[0,:] = (data.iloc[0,:] > activate_threshold).astype('float')
activation = activation.replace(-1, 0)
deactivation = (data < deactivate_threshold).astype('float').diff().fillna(0.0)
deactivation = deactivation.replace(-1, 0)
signal = activation - deactivation
signal = signal.replace(0,np.nan).ffill().replace(-1,0).replace(np.nan,0)
sns.heatmap(data)
plt.show()
plt.close()
sns.heatmap(signal)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment