I have the following sample dataset:
In [222]: df
Out[222]:
ci_low circ_time_angle ci_high
0 30 30 30
1 10 0 20
2 -188 143 207
3 -188 4 207
4 -188 8 207
5 -188 14 207
6 -188 327 207
7 242 57 474
8 242 283 474
9 242 4 474
10 -190 200 -1
11 -90 300 0
12 -25 15 60
13 -30 349 350
14 420 30 600
15 -100 23 719
16 -100 23 259
17 -350 5 -10
18 -350 11 -10
where:
ci_low
- is a lower bound of a circular confidence interval (CI)circ_time_angle
- is an angle that I want to check whether it falls into CI or notci_high
- is an upper bound of a circular confidence interval (CI)
Constraints:
0 <= circ_time_angle <= 360
ci_high >= ci_low
ci_low
andci_high
do NOT necessarily belong to[0, 360]
(see rows[2-18]
in the sample dataset).
Question: what would be the elegant way to check whether the angle circ_time_angle
falls into circular confidence interval: [ci_low, ci_high]
?
Or do I need to check separately all the edge cases?
Desired / resulting dataset:
In [224]: res
Out[224]:
ci_low circ_time_angle ci_high falls_into_CI
0 30 30 30 True
1 10 0 20 False
2 -188 143 207 True
3 -188 4 207 True
4 -188 8 207 True
5 -188 14 207 True
6 -188 327 207 True
7 242 57 474 True
8 242 283 474 True
9 242 4 474 True
10 -190 200 -1 True
11 -90 300 0 True
12 -25 15 60 True
13 -30 349 350 True
14 420 30 600 False
15 -100 23 719 True
16 -100 23 259 True
17 -350 5 -10 False
18 -350 11 -10 True
I also tried to convert CI boundaries to [0, 360]
and to [-180, 180]
, but it still didn't help me to find an elegant formula.
Sample dataset setup:
data = {
'ci_low': [30,
10,
-188,
-188,
-188,
-188,
-188,
242,
242,
242,
-190,
-90,
-25,
-30,
420,
-100,
-100,
-350,
-350],
'circ_time_angle': [30,
0,
143,
4,
8,
14,
327,
57,
283,
4,
200,
300,
15,
349,
30,
23,
23,
5,
11],
'ci_high': [30,
20,
207,
207,
207,
207,
207,
474,
474,
474,
-1,
0,
60,
350,
600,
719,
259,
-10,
-10]}
df = pd.DataFrame(data)