-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
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 | ||
|
This file contains 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
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 |
This file contains 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
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.