Skip to content
This repository has been archived by the owner on Oct 9, 2019. It is now read-only.

Current direction test. #64

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion ioos_qartod/qc_tests/qc.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,8 @@ def flat_line_check(arr, low_reps, high_reps, eps, prev_qc=None):


@add_qartod_ident(16, 'Time Series Flat Line Test')
def time_series_flat_line_check(arr, low_reps=3, high_reps=5, eps=None, prev_qc=None):
def time_series_flat_line_check(arr, low_reps=3, high_reps=5, eps=None,
prev_qc=None):
"""
Check for invariate observations and can be applied to all bulk wave
parameters.
Expand Down Expand Up @@ -281,6 +282,19 @@ def attenuated_signal_check(arr, times, min_var_warn, min_var_fail,
return flag_arr


@add_qartod_ident(11, 'Current Direction')
def current_direction_check(arr, sensor_min=0.0, sensor_max=360.0):
"""
Ensure current direction values fall between 0 and 360 degrees.

"""
flag_arr = np.ones_like(arr, dtype='uint8')

flag_arr[(arr < sensor_min) |
(arr > sensor_max)] = QCFlags.BAD_DATA
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lukecampbell we can implement this a special case of range_check() the same way I did for #65. Let me know which style works best for your goals here.

return flag_arr


def qc_compare(vectors):
"""
Returns an array of flags that represent the aggregate of all the vectors.
Expand Down
32 changes: 32 additions & 0 deletions test/test_qartod_qc.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import numpy as np
import numpy.ma as ma
import numpy.testing as npt
import pandas as pd
from ioos_qartod.qc_tests import qc
Expand Down Expand Up @@ -200,3 +201,34 @@ def test_qc_compare(self):
primary_flags = qc.qc_compare([range_flags, spike_flags, grdtn_flags])
np.testing.assert_array_equal(primary_flags,
np.array([1, 3, 3, 4, 3, 1, 2, 9]))

def test_current_direction_check(self):
"""
See if user and current direction fall between a valid range for
float input.

"""
vals = np.array([0, -1, 5, 110, 360, 250, 360.01, 1e3, 1],
dtype=float)
expected = np.array([1, 4, 1, 1, 1, 1, 4, 4, 1])
npt.assert_array_equal(qc.current_direction_check(vals), expected)

def test_current_direction_check_ints(self):
"""
See if user and current direction fall between a valid range for
integer input.

"""
vals = np.array([0, -1, 5, 110, 360, 250, 360, 1000, 1], dtype=int)
expected = np.array([1, 4, 1, 1, 1, 1, 1, 4, 1])
npt.assert_array_equal(qc.current_direction_check(vals), expected)

def test_current_direction_check_invalid(self):
"""
See if user and current direction fall between a valid range for
invalid input. (Assumes NaNs should pass as "valid.")

"""
vals = np.array([0, np.NaN, 5, -np.inf, 360, 250, 360.5, np.inf, 1])
expected = np.array([1, 1, 1, 4, 1, 1, 4, 4, 1])
npt.assert_array_equal(qc.current_direction_check(vals), expected)