colindex2 2.9.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
colindex2/__init__.py ADDED
@@ -0,0 +1,11 @@
1
+ from .colindex2 import Detect
2
+ from .commands import detect, track, gen_data_settings, find_track
3
+ from .tracking_overlap2 import Track
4
+ from .get_IDfile import Finder
5
+ from .draw_map import _draw_map
6
+
7
+ from .modules import great_circle_distance_numba
8
+ from .modules import great_circle_distance # for arrays
9
+ from .modules import invert_gcd2
10
+ from .modules import moving_direction
11
+ from .modules import bilinear_interp
@@ -0,0 +1,122 @@
1
+ #!/usr/bin/env python3
2
+ import numpy as np
3
+ import pandas as pd
4
+
5
+
6
+ def area_heron(a, b, c):
7
+ s = (a+b+c)/2
8
+ if min(s-a, s-b, s-c) <= 0:
9
+ return np.nan
10
+ else:
11
+ return np.sqrt(s*(s-a)*(s-b)*(s-c))
12
+
13
+
14
+ class circle:
15
+ def __init__(self, r, x):
16
+ self.r = r
17
+ self.x = x
18
+ self.S = np.pi * r * r
19
+
20
+
21
+ class circle_overlap:
22
+ def __init__(self, c1, c2):
23
+
24
+ fct = 1
25
+ d = np.abs(c1.x - c2.x)
26
+ S = area_heron(c1.r, c2.r, d)
27
+
28
+ if np.isnan(S): # cannot make inner triangle
29
+
30
+ alpha1 = np.nan
31
+ d1 = np.nan
32
+ h = np.nan
33
+
34
+ if d < c1.r:
35
+ overlap = 1.
36
+ else:
37
+ overlap = 0.
38
+
39
+ else: # can make inner triangle
40
+
41
+ alpha1 = np.arcsin(2 * S / c1.r / d)
42
+ h = S / d * 2
43
+ d1 = c1.r * np.cos(alpha1)
44
+
45
+ fan = c1.r**2 * alpha1 / 2
46
+ tri = d1 * h / 2
47
+
48
+ if c2.r > np.sqrt(c1.r**2+d**2):
49
+ fct = -1
50
+ left = fan - tri
51
+ right = c1.S / 2 - left
52
+ else:
53
+ right = fan - tri
54
+
55
+ overlap = min(right / c1.S * 2, 1)
56
+
57
+ self.d = d
58
+ self.S = S
59
+ self.overlap = overlap
60
+ self.alpha1 = alpha1
61
+ self.d1 = d1*fct
62
+ self.h = h
63
+
64
+
65
+ def test():
66
+
67
+ import matplotlib.pyplot as plt
68
+ import matplotlib.patches as patches
69
+
70
+ r1, r2 = 500, 600
71
+
72
+ ds = np.arange(100, 1151, 50)
73
+ overs = []
74
+ alpha1s = []
75
+ d1s = []
76
+ hs = []
77
+
78
+ for d in ds:
79
+
80
+ c1 = circle(r=r1, x=0)
81
+ c2 = circle(r=r2, x=d)
82
+ o = cirlce_overlap(c1, c2)
83
+ overs.append(o.overlap)
84
+ alpha1s.append(o.alpha1)
85
+ d1s.append(o.d1)
86
+ hs.append(o.h)
87
+
88
+
89
+ for i, d in enumerate(ds):
90
+
91
+ print(f'{d=}')
92
+
93
+ ax = plt.axes()
94
+ C1 = patches.Circle(xy=(0, 500), radius=r1, fc='none', ec='tab:blue')
95
+ C2 = patches.Circle(xy=(d, 500), radius=r2, fc='none', ec='tab:blue')
96
+ ax.add_patch(C1)
97
+ ax.add_patch(C2)
98
+ ax.plot(0, 500, marker='.', c='tab:blue')
99
+ ax.plot(d, 500, marker='.', c='tab:blue')
100
+ ax.plot([d1s[i], d1s[i]], [500-hs[i], 500+hs[i]], c='r')
101
+ ax.set_aspect('equal')
102
+ ax.set_xlim([-700,1250])
103
+ ax.set_ylim([-200, 1200])
104
+ ax.set_title(f'O={overs[i]:.3f}')
105
+ plt.savefig(f'fig/cc_d{d}.png')
106
+ plt.close()
107
+
108
+ ax = plt.axes()
109
+ ax.plot(ds, overs)
110
+ ax.plot(ds[i], overs[i], '.r')
111
+ plt.savefig(f'fig/overs_{d}.png')
112
+ plt.close()
113
+
114
+ '''ax = plt.axes()
115
+ ax.plot(ds, np.array(alpha1s)/np.pi)
116
+ ax.plot(ds[i], alpha1s[i]/np.pi, '.r')
117
+ plt.savefig(f'fig/alpha1s_d{d}.png')
118
+ plt.close()'''
119
+
120
+
121
+ if __name__ == '__main__':
122
+ test()