Created
October 8, 2022 19:54
-
-
Save dvgodoy/f9e107054ab2931aad88fbfc0599051d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def series_changes(filled, model='l1', pen=3): | |
# Applies the change_points function over every filled series | |
changes = np.apply_along_axis(func1d=lambda s: change_points(s, model, pen), | |
arr=filled.reshape(filled.shape[0], -1).T, | |
axis=1) | |
changes = changes.reshape(*filled.shape[1:], 2) | |
return changes | |
def series_evolution(gridded, changes, offset=True, keep_missing=True): | |
# Applies the change_evolution function over every grid box | |
missing = np.isnan(gridded.reshape(gridded.shape[0], -1).T) | |
evolution = np.apply_along_axis(func1d=lambda s: change_evolution(s, offset), | |
arr=changes.reshape(-1, 2), | |
axis=1) | |
if keep_missing: | |
evolution[missing] = np.nan | |
evolution = evolution.T.reshape(gridded.shape) | |
return evolution |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment