Skip to content

Instantly share code, notes, and snippets.

@dvgodoy
Created October 8, 2022 19:54
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 dvgodoy/f9e107054ab2931aad88fbfc0599051d to your computer and use it in GitHub Desktop.
Save dvgodoy/f9e107054ab2931aad88fbfc0599051d to your computer and use it in GitHub Desktop.
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