def test_vector_version(self): lats = [60, 60, 60, 60, 60, 70] lons = [10,10.1,10.2,10.3,10.4, 10] elevs = [0, 100, 200, 100, 0, 100] N = len(lats) points = titanlib.Points(lats, lons, elevs) radius = [12000, 8000, 12000, 8000, 12000, 10000000] vertical_radius = [110, 110, 110, 200, 100, 50] # Expected num neighbours: expected_num = np.array([1, 2, 2, 2, 1, 2]) num_min = np.array([3, 4, 4, 4, 3, 4]) flags = titanlib.isolation_check(points, num_min, radius, vertical_radius) np.testing.assert_array_almost_equal(list(flags), expected_num < num_min) num_min = np.array([1, 2, 2, 2, 1, 2]) flags = titanlib.isolation_check(points, num_min, radius, vertical_radius) np.testing.assert_array_almost_equal(list(flags), expected_num < num_min) num_min = expected_num flags = titanlib.isolation_check(points, num_min, radius, vertical_radius) np.testing.assert_array_almost_equal(list(flags), expected_num < num_min) num_min = np.array([1, 1, 1, 1, 1, 1]) flags = titanlib.isolation_check(points, num_min, radius, vertical_radius) np.testing.assert_array_almost_equal(list(flags), expected_num < num_min)
def test_no_elevation(self): # These points are roughly 5 km apart, except for the last lats = [60, 60, 60, 60, 60, 70] lons = [10,10.1,10.2,10.3,10.4, 10] elevs = [0, 50, 50, 50, 400, 500] points = titanlib.Points(lats, lons, elevs) radius = 15000 # All except the last one have at least 2 neighbours flags = titanlib.isolation_check(points, 2, radius) self.assertListEqual(list(flags), [0, 0, 0, 0, 0, 1]) # Test restricting by vertical radius vertical_radius = 100 flags = titanlib.isolation_check(points, 2, radius, vertical_radius) self.assertListEqual(list(flags), [0, 0, 0, 0, 1, 1]) vertical_radius = 0 flags = titanlib.isolation_check(points, 2, radius, vertical_radius) self.assertListEqual(list(flags), [1, 0, 0, 0, 1, 1]) # Only the middle one has 4 neighbours flags = titanlib.isolation_check(points, 4, radius) self.assertListEqual(list(flags), [1, 1, 0, 1, 1, 1]) # None have neighbours within 1 km flags = titanlib.isolation_check(points, 1, 1000) self.assertListEqual(list(flags), [1, 1, 1, 1, 1, 1])
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_simple(self): elevs0 = [0, 0, 0] values0 = [0, 1, 100] points0 = titanlib.Points(lats, lons, elevs0) flags, sct, rep = titanlib.sct(points0, values0, num_min, num_max, inner_radius, outer_radius, num_iterations, num_min_prof, min_elev_diff, min_horizontal_scale, vertical_scale, pos, neg, eps2) np.testing.assert_array_equal(flags, [0, 0, 1])
def test_obs_to_check(self): elevs0 = [0, 0, 0, 0, 0, 0] values0 = [0, 1, 1, 1, 100, 100] points0 = titanlib.Points(lats*2, lons*2, elevs0) obs_to_check0 = [0, 1, 1, 1, 1, 0] flags, sct, rep = titanlib.sct(points0, values0, num_min, num_max, inner_radius, outer_radius, num_iterations, num_min_prof, min_elev_diff, min_horizontal_scale, vertical_scale, np.ones(6), np.ones(6), 0.5 * np.ones(6), obs_to_check0) np.testing.assert_array_equal(flags, [0, 0, 0, 0, 1, 0])
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 get_dataset(self): N = 5 np.random.seed(0) lats = np.random.randn(N) * 10000; lons = np.random.randn(N) * 10000; elevs = np.random.rand(N) * 100; points = titanlib.Points(lats, lons, elevs) values = np.zeros(N); dataset = titanlib.Dataset(points, values); return dataset
def test_sct_identical_elevations(self): lats = [0, 0] lons = [0, 0] elevs = [0, 0] values = [0, 0] num_min_prof = 0 min_elev_diff = 0 points = titanlib.Points(lats, lons, elevs) t2pos = [1, 1] t2neg = [1, 1] eps2 = [1, 1]
def get_points(self, dataset): args = [dataset["lats"], dataset["lons"]] if "elevs" in dataset: args += [dataset["elevs"]] if "lafs" in dataset: if "elevs" not in dataset: args += [np.nan * np.zeros(len(dataset["lafs"]))] args += [dataset["lafs"]] assert (len(args) <= 4) return titanlib.Points(*args)
def test_1(self): """Check that the test doesn't fail""" N = 5 np.random.seed(0) lats = np.random.randn(N) * 10000 lons = np.random.randn(N) * 10000 elevs = np.random.rand(N) * 100 points = titanlib.Points(lats, lons, elevs) values = np.random.randn(N) * 6 dataset = titanlib.Dataset(points, values) dataset.range_check([-100], [-100], [0, 1, 2]) dataset.range_check([-100], [-100], [1, 2, 4]) self.assertListEqual([i for i in dataset.flags], [1, 1, 1, 0, 1])
def test_time(self): s_time = time.time() N = 3000 lats = np.random.randn(N) * 1; lons = np.random.randn(N) * 1; elevs = np.random.rand(N) * 100; points = titanlib.Points(lats, lons, elevs) values = np.random.randn(N) * 6; pos = np.ones(N) * 4; neg = np.ones(N) * 4; eps2 = np.ones(N) * 0.5; flags, sct, rep = titanlib.sct(points, values, 5, 100, 4000, 10000, 2, 30, 100, 1000, 100, pos, neg, eps2) print("%.1fs" % (time.time() - s_time))
def test_invalid_arguments(self): points = titanlib.Points(lats, lons, elevs) N = 3 args0 = [points, values, num_min, num_max, inner_radius, outer_radius, num_iterations, num_min_prof, min_elev_diff, min_horizontal_scale, vertical_scale, pos, neg, eps2] invalid_arguments = [(2, -1), (3, -1), (4, -1000), (5, -1000), (6, -1), (7, -1), (8, -1), (9, -1), (10, -1), (11, [-1] * N), (12, [-1] * N), (13, [-1] * N), (13, [0] * N)] for invalid_argument in invalid_arguments: with self.subTest(argument=invalid_argument[0]): with self.assertRaises(ValueError): args = args0 args[invalid_argument[0]] = invalid_argument[1] titanlib.sct(*args)
def test_summer_case(self): """Check that the test doesn't fail""" nmin = 5 radius = 15000 lats, lons, elevs, values = util.summer_temperature_example() points = titanlib.Points(lats, lons, elevs) dz = 100 s_time = time.time() flags = titanlib.isolation_check(points, nmin, radius, dz) e_time = time.time() print("%.2f %d" %(e_time - s_time, np.sum(flags))) s_time = time.time() flags = titanlib.isolation_check(points, nmin, radius) e_time = time.time() print("%.2f %d" %(e_time - s_time, np.sum(flags))) print(np.sum(flags))
def test_2(self): N = 10 lats = [60] * N lons = np.linspace(60, 60.001, N) points = titanlib.Points(lats, lons) values = [0, 0, 0, 0, 0, 0, 0, 0, 1, 1] radius = [10000] num_min = [1] event_threshold = 0.5 threshold = 0.2 elev_gradient = 0 max_elev_diff = -1 num_iterations = 1 flags = titanlib.buddy_event_check(points, values, radius, num_min, event_threshold, threshold, max_elev_diff, elev_gradient, num_iterations) np.testing.assert_array_equal(flags, [0] * 8 + [1] * 2)
def test_get_values(self): N = 10 lats = [60]*N lons = np.linspace(60, 60.001, N) elevs = [0]*10 points = titanlib.Points(lats, lons, elevs) values = [0, 0, 0, 0, 0, 0, 0, 0, 0.1, 1] N = len(lats) radius = [10000] num_min = [1] threshold = 1 elev_gradient = -0.0065 max_elev_diff = 200 min_std = 0.01 num_iterations = 2 dataset = titanlib.Dataset(points, values) dataset.values[:] = [1] print(dataset.get_values()) dataset.points = points
def test_buddy_check(self): N = 10 lats = [60]*N lons = np.linspace(60, 60.001, N) elevs = [0]*10 points = titanlib.Points(lats, lons, elevs) values = [0, 0, 0, 0, 0, 0, 0, 0, 0.1, 1] N = len(lats) radius = [10000] num_min = [1] threshold = 1 elev_gradient = -0.0065 max_elev_diff = 200 min_std = 0.01 num_iterations = 2 dataset = titanlib.Dataset(points, values) dataset.buddy_check(radius, num_min, threshold, max_elev_diff, elev_gradient, min_std, num_iterations) np.testing.assert_array_equal(dataset.flags, [0]*8 + [1]*2)
def test_missing(self): values = [0, 0, 0, 0, 0, 0, 0, 0, 1, 1.0] values[0] = np.nan N = 10 lats = [60] * N lons = np.linspace(60, 60.001, N) points = titanlib.Points(lats, lons) radius = [10000] num_min = [1] event_threshold = 0.5 threshold = 0.2 elev_gradient = 0 max_elev_diff = -1 num_iterations = 1 # Check that NaNs are still flagged, eventhough they are not checked flags = titanlib.buddy_event_check(points, values, radius, num_min, event_threshold, 0.9, max_elev_diff, elev_gradient, num_iterations) np.testing.assert_array_equal(flags, [1] * 10)
def test_vector_invalid_arguments(self): lats = [60, 60, 60, 60, 60, 70] lons = [10,10.1,10.2,10.3,10.4, 10] elevs = [0, 100, 200, 100, 0, 100] N = len(lats) points = titanlib.Points(lats, lons, elevs) num_min = np.full(N, 2) radius = np.full(N, 15000) vertical_radius = np.full(N, 100) with self.assertRaises(ValueError): flags = titanlib.isolation_check(points, num_min, radius, [1]) with self.assertRaises(ValueError): flags = titanlib.isolation_check(points, [1], radius, vertical_radius) with self.assertRaises(ValueError): flags = titanlib.isolation_check(points, num_min, [1], vertical_radius)
def test_1(self): """Check that the test doesn't fail""" lats, lons, elevs, values = util.summer_temperature_example() points = titanlib.Points(lats, lons, elevs) I = slice(0, len(lats)) lats = lats[I] lons = lons[I] elevs = elevs[I] values = values[I] s_time = time.time() event_thr = 0.2 thr = 0.25 elev_gradient = -0.0065 num_iterations = 1 flags = titanlib.buddy_event_check(points, values, [10000], [5], event_thr, thr, 5, elev_gradient, num_iterations) e_time = time.time() print(e_time - s_time) print("Fraction of stations removed: %.1f %%" % (np.mean(flags) * 100))
def main(): parser = argparse.ArgumentParser(description='Runs titanlib benchmarks for processing performance') parser.add_argument('-j', type=int, help='Do a scaling test, by running on multiple cores (>= 2)', dest='num_cores') parser.add_argument('-s', type=int, default=1, help='Enlarge the inputs by this scaling factor to run a bigger test', dest='scaling') parser.add_argument('-n', type=int, default=1, help='Number of iterations to average over', dest='iterations') parser.add_argument('-t', help='Run only this function', dest="function") args = parser.parse_args() if args.num_cores is not None and args.num_cores < 2: print("Error: Number of cores must be 2 or more") sys.exit(1) input = dict() points = dict() np.random.seed(1000) N = 10000 for i in [1000, N]: input[i] = np.random.rand(i * args.scaling)*3 for i in [1000, N]: # points[i] = titanlib.Points(np.linspace(0, 1, i * args.scaling), np.linspace(0, 1, i * args.scaling), np.zeros(i * args.scaling)) points[i] = titanlib.Points(np.random.rand(i * args.scaling) * args.scaling, np.random.rand(i * args.scaling) * args.scaling, np.random.rand(i * args.scaling)) run = dict() radius = 10000 run[(titanlib.Points, "1e6")] = {"expected": 0.82, "args":(np.linspace(0, 1, int(1e6) * args.scaling), np.linspace(0, 1, int(1e6) * args.scaling), np.zeros(int(1e6) * args.scaling))} run[(titanlib.buddy_check, "1e4")] = {"expected": 0.71, "args":(points[N], input[N], np.full(N * args.scaling, radius, float), np.ones(N * args.scaling, int) * 10, 0.3, 100.0, 0.0, 1.0, 1)} run[(titanlib.isolation_check, "1e4")] = {"expected": 0.71, "args":(points[N], 15, 3000)} num_min = 10 num_max = 50 inner_radius = 5000 outer_radius = 50000 num_iterations = 1 num_min_prof = 50 min_elev_diff = 100 min_horizontal_scale = 10000 vertical_scale = 200 Nsct = 1000 run[(titanlib.sct, "1000 in 100 km2")] = {"expected": 3.37, "args":(points[Nsct], input[Nsct], num_min, num_max, inner_radius, outer_radius, num_iterations, num_min_prof, min_elev_diff, min_horizontal_scale, vertical_scale, np.full(Nsct * args.scaling, 4), np.full(Nsct * args.scaling, 4), np.full(Nsct * args.scaling, 0.5))} print("Titanlib benchmark (expected results from Intel i7 3.40 Ghz)") print("Titanlib version %s" % titanlib.version()) if args.num_cores is not None and args.num_cores != 1: print("Function Expected Time Diff Scaling") else: print("Function Expected Time Diff") num_cores = [1] if args.num_cores is not None: num_cores += [args.num_cores] for key in run.keys() : timings = dict() for num_core in num_cores: timings[num_core] = 0 if isinstance(key, tuple): name = key[0].__name__ + " " + str(key[1]) func = key[0] else: name = key.__name__ func = key if args.function is not None: if func.__name__ != args.function: continue for num_core in num_cores: titanlib.set_omp_threads(num_core) for it in range(args.iterations): s_time = time.time() results = func(*run[key]["args"]) e_time = time.time() # print(np.mean(results)) curr_time = e_time - s_time timings[num_core] += curr_time # print("%s() Expected: %.2f s Time: %.2f s" % (func.__name__, run[key]["expected"], e_time - s_time)) for num_core in num_cores: timings[num_core] /= args.iterations diff = (timings[1] - run[key]["expected"] * args.scaling) / (run[key]["expected"] * args.scaling) * 100 string = "%-36s %8.2f %8.2f %8.2f %%" % (name, run[key]["expected"] * args.scaling, timings[1], diff) if args.num_cores is not None: scaling = timings[1] / timings[args.num_cores] / args.num_cores expected = timings[1] / args.num_cores scaling = 1 - (timings[args.num_cores] - expected) / (timings[1] - expected) # scaling = (1 - timings[args.num_cores] / timings[1]) * (args.num_cores + 1) string += " %8.2f %%" % (scaling * 100) print(string)
def test_time(self): s_time = time.time() N = 100000 print(" -- Test over", N, "observations --") lats = np.ones(N) * 55 + np.random.random(N) * (70 - 55) lons = np.ones(N) * 5 + np.random.random(N) * (30 - 5) elevs = np.random.random(N) * 2500 values = np.ones(N) * 10 for i in range(1, N): if (lons[i] >= 17.5): values[i] = 0 pGE = 0.01 nGE = int(np.ceil(N * pGE)) idx = np.random.randint(0, high=(N - 1), size=nGE) obs_to_check = [1] * N true_GE = [0] * N for i in idx: if (values[i] == 10): values[i] = 0 if (values[i] == 0): values[i] = 10 true_GE[i] = 1 for i in range(1, N): obs_to_check[i] = int(1) event_thresholds = np.ones(N) * 0.1 condition = titanlib.Gt test_thresholds = np.ones(N) * 0.5 num_min_outer = 3 num_max_outer = 50 inner_radius = 30000 outer_radius = 50000 num_iterations = 100 min_horizontal_scale = 500 max_horizontal_scale = 10000 kth_closest_obs_horizontal_scale = 3 vertical_scale = 600 debug = False flags = np.ones(N) * (-999.) points = titanlib.Points(lats, lons, elevs) flags = titanlib.sct_dual(points, values, obs_to_check, event_thresholds, condition, num_min_outer, num_max_outer, inner_radius, outer_radius, num_iterations, min_horizontal_scale, max_horizontal_scale, kth_closest_obs_horizontal_scale, vertical_scale, test_thresholds, debug) print("%.1fs" % (time.time() - s_time)) a = 0 b = 0 c = 0 d = 0 for i in range(1, N): if (flags[i] == 1 and true_GE[i] == 1): a = a + 1 if (flags[i] == 1 and true_GE[i] == 0): b = b + 1 if (flags[i] == 0 and true_GE[i] == 1): c = c + 1 if (flags[i] == 0 and true_GE[i] == 0): d = d + 1 # print( "flags[i] true_GE[i] a(bad) b c d:", flags[i], true_GE[i], a,"(",nGE,")", b, c, d, a+b+c+d) rand = (a + c) * (a + b) / (a + b + c + d) ets = (a - rand) / (a + b + c - rand) acc = (a + d) / (a + b + c + d) pod = a / (a + c) pofa = b / (b + d) print("a(bad) b c d:", a, "(", nGE, ")", b, c, d, a + b + c + d) # print( "acc pod pofa ets", acc, round(pod,2), round(pofa,2), round(ets,2)) print("acc pod pofa ets", round(acc, 2), pod, pofa, ets) print( "===============================================================")
from __future__ import print_function import unittest import titanlib import numpy as np import util import time """Convenient vectors used as inputs""" N = 10 lats = [60] * N lons = np.linspace(60, 60.001, N) elevs = [0] * 10 points = titanlib.Points(lats, lons, elevs) values = [0, 0, 0, 0, 0, 0, 0, 0, 0.1, 1] N = len(lats) radius = [10000] num_min = [1] threshold = 1 elev_gradient = -0.0065 max_elev_diff = 200 min_std = 0.01 num_iterations = 2 class BuddyCheckTest(unittest.TestCase): 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) def test_min_std(self):
def test_time(self): s_time = time.time() N = 5000 print(" -- Test over", N, "observations --") lats = np.ones(N) * 55 + np.random.random(N) * ( 70 - 55) lons = np.ones(N) * 5 + np.random.random(N) * ( 30 - 5) elevs = np.random.random(N) * 2500 values = np.ones(N) * 30 -0.0065 * elevs pGE = 0.3 nGE = int( np.ceil( N * pGE)) idx = np.random.randint(0, high=(N-1), size=nGE) obs_to_check = [1] * N true_GE = [0] * N for i in idx: values[i] = np.random.random(1) * 100 - 50 true_GE[i] = 1 for i in range(1, N): obs_to_check[i] = int(1) background_values = np.random.randn(N) * 6 background_elab_type = titanlib.VerticalProfileTheilSen num_min_outer = 3 num_max_outer = 50 inner_radius = 30000 outer_radius = 50000 num_iterations = 100 num_min_prof = 10 min_elev_diff = 500 min_horizontal_scale = 500 max_horizontal_scale = 10000 kth_closest_obs_horizontal_scale = 3 vertical_scale = 600 tpos = np.ones(N) * 3 tneg = np.ones(N) * 3 eps2 = np.ones(N) * 0.5 values_mina = values - 20 * np.ones(N) values_maxa = values + 20 * np.ones(N) values_minv = values - 1 * np.ones(N) values_maxv = values + 1 * np.ones(N) debug = False flags = np.ones(N) * (-999.) points = titanlib.Points(lats, lons, elevs) flags, score = titanlib.sct_resistant(points, values, obs_to_check, background_values, background_elab_type, num_min_outer, num_max_outer, inner_radius, outer_radius, num_iterations, num_min_prof, min_elev_diff, min_horizontal_scale, max_horizontal_scale, kth_closest_obs_horizontal_scale, vertical_scale, values_mina, values_maxa, values_minv, values_maxv, eps2, tpos, tneg, debug) print("%.1fs" % (time.time() - s_time)) a = 0 b = 0 c = 0 d = 0 for i in range(1, N): if ( flags[i] == 1 and true_GE[i] == 1): a = a + 1 if ( flags[i] == 1 and true_GE[i] == 0): b = b + 1 if ( flags[i] == 0 and true_GE[i] == 1): c = c + 1 if ( flags[i] == 0 and true_GE[i] == 0): d = d + 1 # print( "flags[i] true_GE[i] a(bad) b c d:", flags[i], true_GE[i], a,"(",nGE,")", b, c, d, a+b+c+d) rand = (a+c) * (a+b) / (a+b+c+d) ets = (a-rand) / (a+b+c-rand) acc = (a+d)/(a+b+c+d) pod = a/(a+c) pofa = b/(b+d) print( "a(bad) b c d:", a,"(",nGE,")", b, c, d, a+b+c+d) # print( "acc pod pofa ets", acc, round(pod,2), round(pofa,2), round(ets,2)) print( "acc pod pofa ets", round(acc,2), pod, pofa, ets) print("===============================================================")
def main(): parser = argparse.ArgumentParser( description='Runs titanlib benchmarks for processing performance') parser.add_argument( '-j', type=int, help='Do a scaling test, by running on multiple cores (>= 2)', dest='num_cores') parser.add_argument( '-s', type=float, default=1, help='Enlarge the inputs by this scaling factor to run a bigger test', dest='scaling') parser.add_argument('-n', type=int, default=1, help='Number of iterations to average over', dest='iterations') parser.add_argument('-t', help='Run only this function', dest="function") args = parser.parse_args() if args.num_cores is not None and args.num_cores < 2: raise Exception("Error: Number of cores must be 2 or more") input = dict() points = dict() np.random.seed(1000) N = 10000 for i in [1000, N]: input[i] = np.random.rand(int(i * args.scaling)) * 3 for i in [1000, N]: # points[i] = titanlib.Points(np.linspace(0, 1, i * args.scaling), np.linspace(0, 1, i * args.scaling), np.zeros(i * args.scaling)) points[i] = titanlib.Points( np.random.rand(int(i * args.scaling)) * args.scaling, np.random.rand(int(i * args.scaling)) * args.scaling, np.random.rand(int(i * args.scaling))) radius = 10000 run = collections.OrderedDict() run[("Points", "1e6")] = { "expected": 0.82, "args": (np.linspace(0, 1, int(1e6 * args.scaling)), np.linspace(0, 1, int(1e6 * args.scaling)), np.zeros(int(1e6 * args.scaling))) } run[("buddy_check", "1e4")] = { "expected": 0.64, "args": (points[N], input[N], np.full(int(N * args.scaling), radius, float), np.ones(int(N * args.scaling), int) * 10, 0.3, 100.0, 0.0, 1.0, 1) } run[("buddy_event_check", "1e4")] = { "expected": 0.64, "args": (points[N], input[N], np.full(int(N * args.scaling), radius, float), np.ones(int(N * args.scaling), int) * 10, 0.2, 0.1, 100.0, 0.0, 1) } run[("isolation_check", "1e4")] = { "expected": 0.57, "args": (points[N], 15, 3000) } num_min = 10 num_max = 50 inner_radius = 5000 outer_radius = 50000 num_iterations = 1 num_min_prof = 50 min_elev_diff = 100 min_horizontal_scale = 10000 vertical_scale = 200 Nsct = 1000 run[("sct", "1000 in 100 km2")] = { "expected": 2.94, "args": (points[Nsct], input[Nsct], num_min, num_max, inner_radius, outer_radius, num_iterations, num_min_prof, min_elev_diff, min_horizontal_scale, vertical_scale, np.full(int(Nsct * args.scaling), 4), np.full(int(Nsct * args.scaling), 4), np.full(int(Nsct * args.scaling), 0.5)) } if args.num_cores is not None: print("Titanlib parallelization test (titanlib version %s)" % titanlib.version()) else: print("Titanlib benchmark (titanlib version %s)" % titanlib.version()) print("Expected results from Intel i7 3.40 Ghz") print("-----------------------------------------------------------------") if args.num_cores is not None: print( "Function 1 core %2d cores Scaling" % args.num_cores) else: print( "Function Expected Time Diff") num_cores = [1] if args.num_cores is not None: num_cores += [args.num_cores] for key in run.keys(): try: timings = dict() for num_core in num_cores: timings[num_core] = 0 if isinstance(key, tuple): name = key[0] + " " + str(key[1]) func = eval("titanlib." + key[0]) else: name = key func = eval("titanlib." + key) if args.function is not None: if func.__name__ != args.function: continue # Allow functions to fail (useful when benchmarking older versions of gridpp # where functions may not be defined). for num_core in num_cores: titanlib.set_omp_threads(num_core) for it in range(args.iterations): s_time = time.time() func(*run[key]["args"]) e_time = time.time() curr_time = e_time - s_time timings[num_core] += curr_time except Exception as e: print("Could not run", key, e) continue for num_core in num_cores: timings[num_core] /= args.iterations if args.num_cores is None: diff = (timings[1] - run[key]["expected"] * args.scaling) / ( run[key]["expected"] * args.scaling) * 100 string = "%-36s %8.2f %8.2f %8.2f %%" % ( name, run[key]["expected"] * args.scaling, timings[1], diff) else: scaling = timings[1] / timings[args.num_cores] / args.num_cores expected = timings[1] / args.num_cores scaling = 1 - (timings[args.num_cores] - expected) / (timings[1] - expected) # scaling = (1 - timings[args.num_cores] / timings[1]) * (args.num_cores + 1) string = "%-36s %8.2f %8.2f %8.2f %%" % ( name, timings[1], timings[args.num_cores], scaling * 100) print(string)
from __future__ import print_function import unittest import titanlib """Convenient vectors used as inputs""" len3 = [1, 2, 3] len2 = [1, 2] len1 = [1] points3 = titanlib.Points(len3, len3) points2 = titanlib.Points(len2, len2) points1 = titanlib.Points(len1, len1) ut = 1546300800 class ClimatologyCheckTest(unittest.TestCase): def test_valid_input(self): """Check that the test doesn't fail""" # TODO: Reenable these #self.assertEqual(titanlib.range_check_climatology(len1, len1, len1, len1, ut, len1, len1)[0],0) #self.assertEqual(titanlib.range_check_climatology(len3, len3, len3, len3, ut, len1, len1)[0],0) #self.assertEqual(titanlib.range_check_climatology(len3, len3, len3, len3, ut, len1, len3)[0],0) #self.assertEqual(titanlib.range_check_climatology(len3, len3, len3, len3, ut, len1, len1)[0],0) pass def test_invalid_input(self): """Check that the test fails""" # TODO: Reenable these with self.assertRaises(RuntimeError): # Min/max inconsistent with inputs flags = titanlib.range_check_climatology(points3, len3, ut, len2, len2)