Skip to content

Commit

Permalink
renamed files, added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
arkwave committed Mar 14, 2016
1 parent 5cede64 commit bbc6b68
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 0 deletions.
27 changes: 27 additions & 0 deletions evenflow/3_removePeriodicMean.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 evenflow/4_getSkipMean.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
17 changes: 17 additions & 0 deletions evenflow/tests/test_2_trimNoData.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import numpy as np, nose
from function2 import trimNoData

def function2GeneralTest():
a = np.zeros(shape=(3,4))
a[0,0] = 1
a[1,0] = 1
a[2,1] = 1
b = trimNoData(a, 1)
x = np.zeros(shape=(3,4))
x[:] = 1
print(x == b)
y = np.zeros(shape=(3,4))
c = trimNoData(a, 0)
print(c==y)


Empty file.
Empty file.

0 comments on commit bbc6b68

Please sign in to comment.