Skip to content

Instantly share code, notes, and snippets.

@randomboolean
Last active April 12, 2019 13:27
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 randomboolean/7cb549ce4c6a1b1cc47e9ba6d0a8d27c to your computer and use it in GitHub Desktop.
Save randomboolean/7cb549ce4c6a1b1cc47e9ba6d0a8d27c to your computer and use it in GitHub Desktop.
Outputs a boolean GTS with ticks labeled with true where anomalies are detected. Detection is done with a moving ZSCORETEST within a custom mapper.
<%
// Store the argument that will be passed to MAP
[ 'gts' 'pre' 'post' 'occ' 'steps' ] STORE
// Build the custom mapper
<%
// Make a GTS from the moving window
LIST-> DROP [ 'cur' 'c' 'l' 't' 'lat' 'lon' 'elev' 'v' ] STORE
$t [] [] [] $v MAKEGTS
// Apply the anomaly detection test
true 3.0 ZSCORETEST
// Output one value per anomalous tick found
0 'i' STORE
{ SWAP <% $i TOSTRING [ 3 ROLL NaN NaN NaN true ] $i 1 + 'i' STORE %> FOREACH }
%>
MACROMAPPER 3 MAXLONG STRICTMAPPER 'mapper_zscore_test' STORE
// call MAP to create the boolean GTS with the flagged anomalies
[ $gts $mapper_zscore_test $pre $post $occ $steps true ] MAP MERGE 'anomalies' RENAME
%>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment