def test_flat_line(self): arr = [ 1, 2, 2.0001, 2, 2.0001, 2, 2.0001, 2, 4, 5, 3, 3.0001, 3.0005, 3.00001 ] expected = [1, 1, 1, 1, 3, 3, 4, 4, 1, 1, 1, 1, 1, 3] inputs = [ arr, np.asarray(arr, dtype=np.floating), dask_arr(np.asarray(arr, dtype=np.floating)) ] for i in inputs: result = qartod.flat_line_test( inp=i, tinp=self.times, suspect_threshold=self.suspect_threshold, fail_threshold=self.fail_threshold, tolerance=self.tolerance) npt.assert_array_equal(result, expected) # test epoch secs - should return same result npt.assert_array_equal( qartod.flat_line_test(inp=arr, tinp=self.times_epoch_secs, suspect_threshold=self.suspect_threshold, fail_threshold=self.fail_threshold, tolerance=self.tolerance), expected) # test negative array - should return same result arr = [-1 * x for x in arr] npt.assert_array_equal( qartod.flat_line_test(inp=arr, tinp=self.times, suspect_threshold=self.suspect_threshold, fail_threshold=self.fail_threshold, tolerance=self.tolerance), expected) # test empty array - should return empty result arr = np.array([]) expected = np.array([]) npt.assert_array_equal( qartod.flat_line_test(inp=arr, tinp=self.times, suspect_threshold=self.suspect_threshold, fail_threshold=self.fail_threshold, tolerance=self.tolerance), expected) # test nothing fails arr = np.random.random(len(self.times)) expected = np.ones_like(arr) npt.assert_array_equal( qartod.flat_line_test(inp=arr, tinp=self.times, suspect_threshold=self.suspect_threshold, fail_threshold=self.fail_threshold, tolerance=0.00000000001), expected)
def check(time, arr, expected): result = qartod.flat_line_test(inp=arr, tinp=time, suspect_threshold=3, fail_threshold=5, tolerance=0.1) npt.assert_array_equal(result, expected)
def test_flat_line_with_spike(self): tolerance = 4 suspect_threshold = 3 fail_threshold = 6 time = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] arr = [1, 1, 1, 1, 1, 6, 5, 4, 3, 2] expected = [1, 1, 1, 3, 3, 1, 1, 1, 3, 3] result = qartod.flat_line_test(inp=arr, tinp=time, suspect_threshold=suspect_threshold, fail_threshold=fail_threshold, tolerance=tolerance) npt.assert_array_equal(result, expected)
def test_flat_line_missing_values(self): arr = [ 1, None, np.ma.masked, 2, 2.0001, 2, 2.0001, 2, 4, None, 3, None, None, 3.00001 ] expected = [1, 9, 9, 1, 3, 3, 4, 4, 1, 9, 1, 9, 9, 3] with warnings.catch_warnings(): warnings.simplefilter("ignore") inputs = [ arr, np.asarray(arr, dtype=np.floating), dask_arr(np.asarray(arr, dtype=np.floating)) ] for i in inputs: result = qartod.flat_line_test( inp=i, tinp=self.times, suspect_threshold=self.suspect_threshold, fail_threshold=self.fail_threshold, tolerance=self.tolerance) npt.assert_array_equal(result, expected)
def test_flat_line_starting_from_beginning(self): arr = [ 2, 2.0001, 2, 2.0001, 2, 2.0001, 2, 4, 5, 3, 3.0001, 3.0005, 3.00001 ] expected = [1, 1, 1, 3, 3, 4, 4, 1, 1, 1, 1, 1, 3] with warnings.catch_warnings(): warnings.simplefilter("ignore") inputs = [ arr, np.asarray(arr, dtype=np.float64), dask_arr(np.asarray(arr, dtype=np.float64)) ] for i in inputs: result = qartod.flat_line_test( inp=i, tinp=self.times, suspect_threshold=self.suspect_threshold, fail_threshold=self.fail_threshold, tolerance=self.tolerance) npt.assert_array_equal(result, expected)