Coverage for /usr/local/lib/python3.11/dist-packages/grond/stats.py: 29%

35 statements  

« prev     ^ index     » next       coverage.py v6.5.0, created at 2023-10-27 13:25 +0000

1import numpy as num 

2from pyrocko import orthodrome as od 

3 

4 

5def get_mean_x(xs): 

6 return num.mean(xs, axis=0) 

7 

8 

9def get_mean_x_and_gm(problem, xs, misfits): 

10 gms = problem.combine_misfits(misfits) 

11 return num.mean(xs, axis=0), num.mean(gms) 

12 

13 

14def get_best_x(problem, xs, misfits): 

15 gms = problem.combine_misfits(misfits) 

16 ibest = num.argmin(gms) 

17 return xs[ibest, :] 

18 

19 

20def get_best_x_and_gm(problem, xs, misfits): 

21 gms = problem.combine_misfits(misfits) 

22 ibest = num.argmin(gms) 

23 return xs[ibest, :], gms[ibest] 

24 

25 

26def get_mean_source(problem, xs): 

27 x_mean = get_mean_x(xs) 

28 source = problem.get_source(x_mean) 

29 return source 

30 

31 

32def get_best_source(problem, xs, misfits): 

33 x_best = get_best_x(problem, xs, misfits) 

34 source = problem.get_source(x_best) 

35 return source 

36 

37 

38def mean_latlondist(lats, lons): 

39 if len(lats) == 0: 

40 return 0., 0., 1000. 

41 else: 

42 ns, es = od.latlon_to_ne_numpy(lats[0], lons[0], lats, lons) 

43 n, e = num.mean(ns), num.mean(es) 

44 dists = num.sqrt((ns-n)**2 + (es-e)**2) 

45 lat, lon = od.ne_to_latlon(lats[0], lons[0], n, e) 

46 return float(lat), float(lon), float(num.max(dists)) 

47 

48 

49def stations_mean_latlondist(stations): 

50 lats = num.array([s.lat for s in stations]) 

51 lons = num.array([s.lon for s in stations]) 

52 return mean_latlondist(lats, lons)