def test_elev_gradient(self): elevs0 = [0] * 9 + [-153.8] points0 = titanlib.Points(lats, lons, elevs0) flags = titanlib.buddy_check(points0, values, radius, num_min, threshold, max_elev_diff, 0, min_std, num_iterations) np.testing.assert_array_equal(flags, [0] * 8 + [1, 1]) flags = titanlib.buddy_check(points0, values, radius, num_min, threshold, max_elev_diff, elev_gradient, min_std, num_iterations) np.testing.assert_array_equal(flags, [0] * 8 + [1, 0])
def test_missing(self): values0 = np.copy(values) values0[0] = np.nan # Check that NaNs are still flagged, eventhough they are not checked flags = titanlib.buddy_check(points, values0, radius, num_min, 0.0001, 1, elev_gradient, min_std, num_iterations) np.testing.assert_array_equal(flags, [1] * 10)
def test_max_elev_diff(self): """Check that test is not run on a point which has no other points within the elevation range""" elevs0 = [0]*9 + [100] points0 = titanlib.Points(lats, lons, elevs0) flags = titanlib.buddy_check(points0, values, radius, num_min, threshold, 1, elev_gradient, min_std, num_iterations) np.testing.assert_array_equal(flags, [0]*8 + [1, 0])
def test_1(self): """Check that the test doesn't fail""" lats, lons, elevs, values = util.summer_temperature_example() I = slice(0, len(lats)) lats = lats[I] lons = lons[I] elevs = elevs[I] values = values[I] s_time = time.time() flags = titanlib.buddy_check(lats, lons, elevs, values, [10000], [5], [2], 5, 0.0065, 1, 1) e_time = time.time() print(e_time - s_time) print("Fraction of stations removed: %.1f %%" % (np.mean(flags) * 100))
def test(self, dataset, mask, code=104): if tit is None: raise ModuleNotFoundError("titanlib was not loaded properly") global_flags = dataset.flags # Buddy does not work properly for dataset. Also without data set the values must be set without subscripts # status = dataset.buddy_check(self.distance_lim, self.priorities, self.buddies_min, self.thresholds, # self.diff_elev_max, self.adjust_for_elev_diff, self.obs_to_check, mask) lons = [] lats = [] elevs = [] values = [] for i in range(0, len(mask)): lons.append(dataset.lons[i]) lats.append(dataset.lats[i]) elevs.append(dataset.elevs[i]) values.append(dataset.values[i]) status, flags = tit.buddy_check(lats, lons, elevs, values, self.distance_lim, self.priorities, self.buddies_min, self.thresholds, self.diff_elev_max, self.adjust_for_elev_diff, self.obs_to_check) if not status: raise Exception("Buddy check failed!") for i in range(0, len(mask)): if global_flags[mask[i]] == 0 and flags[i] == 1: global_flags[mask[i]] = code if self.debug: for i in range(0, len(mask)): print(self.name, i, dataset.values[i], dataset.flags[i], global_flags[i]) return global_flags
def test_num_iterations(self): """Check that num_iterations affects the flags""" flags = titanlib.buddy_check(points, values, radius, num_min, threshold, max_elev_diff, elev_gradient, min_std, 1) np.testing.assert_array_equal(flags, [0] * 9 + [1])
def test_min_num(self): """Check that when min_num is high enough, nothing is flagged""" flags = titanlib.buddy_check(points, values, radius, [20], threshold, max_elev_diff, elev_gradient, min_std, num_iterations) np.testing.assert_array_equal(flags, [0] * N)
def test_1(self): flags = titanlib.buddy_check(points, values, radius, num_min, threshold, max_elev_diff, elev_gradient, min_std, num_iterations) np.testing.assert_array_equal(flags, [0] * 8 + [1] * 2)