Skip to content

Commit

Permalink
Merge pull request #34 from ioos/spike_test_initial_final_values_bugfix
Browse files Browse the repository at this point in the history
spike test bugfix: first & last values are unknown
  • Loading branch information
kwilcox authored Mar 27, 2020
2 parents e54b5e7 + fbbe296 commit c9c149e
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
4 changes: 4 additions & 0 deletions ioos_qc/qartod.py
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,10 @@ def spike_test(inp : Sequence[N],
with np.errstate(invalid='ignore'):
flag_arr[diff > fail_threshold] = QartodFlags.FAIL

# test is undefined for first and last values
flag_arr[0] = QartodFlags.UNKNOWN
flag_arr[-1] = QartodFlags.UNKNOWN

# If the value is masked or nan set the flag to MISSING
flag_arr[diff.mask] = QartodFlags.MISSING

Expand Down
2 changes: 1 addition & 1 deletion tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def test_run_with_agg(self):
}})
inp = [-1, 0, 1, 2, 10, 3]
expected_gross_range = np.array([4, 1, 1, 1, 1, 1])
expected_spike = np.array([1, 1, 1, 3, 3, 1])
expected_spike = np.array([2, 1, 1, 3, 3, 2])
expected_agg = np.array([4, 1, 1, 3, 3, 1])

r = qc.run(
Expand Down
24 changes: 20 additions & 4 deletions tests/test_qartod.py
Original file line number Diff line number Diff line change
Expand Up @@ -876,7 +876,7 @@ def test_spike(self):

# First and last elements should always be good data, unless someone
# has set a threshold to zero.
expected = [1, 4, 4, 4, 1, 3, 1, 1]
expected = [2, 4, 4, 4, 1, 3, 1, 2]

inputs = [
arr,
Expand All @@ -901,7 +901,7 @@ def test_spike_negative_vals(self):

# First and last elements should always be good data, unless someone
# has set a threshold to zero.
expected = [1, 4, 4, 4, 1, 3, 1, 1]
expected = [2, 4, 4, 4, 1, 3, 1, 2]

inputs = [
arr,
Expand All @@ -918,6 +918,22 @@ def test_spike_negative_vals(self):
expected
)

def test_spike_initial_final_values(self):
"""
The test is not defined for the initial and final values in the array
"""
arr = [-100, -99, -99, -98]
expected = [2, 1, 1, 2]

npt.assert_array_equal(
qartod.spike_test(
inp=arr,
suspect_threshold=self.suspect_threshold,
fail_threshold=self.fail_threshold
),
expected
)

def test_spike_masked(self):
"""
Test with missing data.
Expand All @@ -927,7 +943,7 @@ def test_spike_masked(self):

# First and last elements should always be good data, unless someone
# has set a threshold to zero.
expected = [1, 4, 4, 4, 1, 3, 1, 1, 9, 9, 4, 4, 4, 9]
expected = [2, 4, 4, 4, 1, 3, 1, 1, 9, 9, 4, 4, 4, 9]

inputs = [
arr,
Expand Down Expand Up @@ -955,7 +971,7 @@ def test_spike_realdata(self):
-0.3932, -0.3383, -0.2804, -0.2347, -0.2134, -0.2347, -0.2926, -0.3597, -0.442, -0.509, 0, -0.5944,
-0.57, -0.4267, -0.2926, -0.1585, -0.0945, -0.0762]

expected = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1, 1, 1]
expected = [2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1, 1, 2]

inputs = [
arr,
Expand Down

0 comments on commit c9c149e

Please sign in to comment.