Coverage for pyguymer3/geo/find_middle_of_locsSrc/find_middle_of_locs_euclideanBox.py: 75%

20 statements  

« prev     ^ index     » next       coverage.py v7.9.2, created at 2025-07-08 18:47 +0000

1#!/usr/bin/env python3 

2 

3# Define function ... 

4def find_middle_of_locs_euclideanBox( 

5 lons, 

6 lats, 

7 /, 

8 *, 

9 debug = __debug__, 

10 pad = 0.1, 

11): 

12 """Find the middle of some locations such that: a) the Euclidean distance to 

13 the most Northern point is the same as the Euclidean distance to the most 

14 Southern point; and b) the Euclidean distance to the most Eastern point is 

15 the same as the Euclidean distance to the most Western point. 

16 """ 

17 

18 # Import special modules ... 

19 try: 

20 import numpy 

21 except: 

22 raise Exception("\"numpy\" is not installed; run \"pip install --user numpy\"") from None 

23 

24 # Import sub-functions ... 

25 from ..max_dist import max_dist 

26 

27 # ************************************************************************** 

28 

29 # Check arguments ... 

30 assert isinstance(lons, numpy.ndarray), "\"lons\" is not a NumPy array" 

31 assert isinstance(lats, numpy.ndarray), "\"lats\" is not a NumPy array" 

32 

33 # ************************************************************************** 

34 

35 # Calculate the middle of the Euclidean bounding box ... 

36 midLon = 0.5 * (lons.min() + lons.max()) # [°] 

37 midLat = 0.5 * (lats.min() + lats.max()) # [°] 

38 

39 if debug: 

40 print(f"INFO: The middle is ({midLon:.6f}°, {midLat:.6f}°).") 

41 

42 # Find the maximum Euclidean distance from the middle to any location ... 

43 maxDist = max_dist( 

44 lons, 

45 lats, 

46 midLon, 

47 midLat, 

48 eps = None, 

49 nIter = None, 

50 space = "EuclideanSpace", 

51 ) # [°] 

52 

53 if debug: 

54 print(f"INFO: Maximum Euclidean distance is {maxDist:.6f}°.") 

55 

56 # ************************************************************************** 

57 

58 # Check if a padding needs to be added ... 

59 if pad > 0.0: 

60 # Add padding ... 

61 maxDist += pad # [°] 

62 

63 if debug: 

64 print(f"INFO: Maximum (padded) Euclidean distance is {maxDist:.6f}°.") 

65 

66 # Return answer ... 

67 return midLon, midLat, maxDist