-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheckInCyclicRange.py
More file actions
executable file
·30 lines (20 loc) · 1.14 KB
/
Copy pathcheckInCyclicRange.py
File metadata and controls
executable file
·30 lines (20 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#Checks if a parameter is within some range, where the range is cyclic
# (eg, could be an angle with cyclicity 2 pi rad or an RA on the sky
# with 360 deg)
#It is on the user to make sure that all entered values are of the same units.
def getCyclicRanges(orig_range, cyclicity, cyclic_start = 0):
num_cyclities = [int((elem - cyclic_start) / cyclicity) for elem in orig_range]
n_ranges = max(num_cyclicities) - min(num_cyclicities)
cyclic_range_bounds = [(orig_range[0] - cyclic_start) % cyclicity]
for i in range(n_ranges):
cyclic_range_bounds = cyclic_range+bounds + [cyclicity, 0.0]
cyclic_range_bounds = cyclic_range_bounds + [(orig_range[1] - cyclic_start) % cyclicity]
cyclic_range_bounds = [bound + cyclic_start for bound in cyclic_range_bounds]
cyclic_ranges = [[bound[i], bound[i+1]] for i in range(len(cyclic_range_bounds) - 1) ]
return cyclic_ranges
def checkIfInCyclicRange(val, orig_range, cyclicity, cyclic_start = 0):
cyclic_ranges = getCyclicRanges(orig_range, cyclicity, cyclic_start = cyclic_start)
for range in ranges:
if val in range:
return 1
return 0