Skip to content

Commit

Permalink
Merge pull request #2 from arkwave/function3and4
Browse files Browse the repository at this point in the history
finished functions 3 and 4, testing pending
  • Loading branch information
Christopher-Tennant committed Mar 14, 2016
2 parents d8cfcb2 + eafa0d7 commit 5cede64
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
27 changes: 27 additions & 0 deletions function3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import numpy as np
from function4 import getSkipMean
def removePeriodicMean(signalMat, period, sliderWidth, NoDataCode):
"""
:param signalMat: n - column matrix where variables represent timeseries
:param period: length of repeating pattern of data (i.e. seasons, years, etc).
:param sliderWidth: Number of periods to base the anomaly on.
:param NoDatCode: data value to be ignored
:return: matrix of values that accounts for periodic averages
"""
nData, nSignals = np.shape(signalMat)
newLength = nData - period * (sliderWidth - 1)
anomalyMat = np.nan * np.zeros(shape = (newLength, nSignals))
avg = np.nan * np.zeros(shape=(nData, nSignals))

for i in range(newLength):
for j in range(nSignals):
end = i + (sliderWidth*period) - 1
avg[i,j] = getSkipMean(signalMat[i:end:period, j], NoDataCode)

if avg[i,j] == NoDataCode or signalMat[i,j] == NoDataCode:
anomalyMat[i,j] = NoDataCode
else:
anomalyMat[i,j] = signalMat[i,j] - avg[i,j]

return anomalyMat

19 changes: 19 additions & 0 deletions function4.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import numpy as np
def getSkipMean(vector, NoDataCode):
"""
:param vector: vector of values.
:param NoDataCode: indicates value to be ignored
:return: average of the values in the vector ignoring NoData values
"""
N, _ = np.shape(vector)
sum = 0
nVals = 0
for i in range(N):
if vector[i] != NoDataCode:
sum+=vector[i]
nVals += 1
if nVals > 0:
avg = sum/nVals
else:
avg = NoDataCode
return avg

0 comments on commit 5cede64

Please sign in to comment.