-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
125 lines (100 loc) · 3.34 KB
/
utils.py
File metadata and controls
125 lines (100 loc) · 3.34 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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
import math
import numpy as np
def string_to_hours(time_string):
"""
Converts Hours string to float
:param time_string: Hours String (hh:mm:ss.ss)
"""
# Verify separator
separators = [':', ' ']
separator = None
for sep in separators:
if sep in time_string:
separator = sep
break
if separator is None:
raise ValueError("Invalid string format. No recognized separator found.")
components = time_string.split(separator)
# Check for correct format
if len(components) != 3:
raise ValueError(f"Invalid string format. Expected hh{separator}mm{separator}ss.ss")
hours = abs(int(components[0]))
minutes = int(components[1])
seconds = float(components[2])
total_hours = hours + minutes / 60 + seconds / 3600
sign = -1 if "-" in time_string else 1
return sign*total_hours
def string_to_degrees(degrees_string):
"""
Converts Degrees string to float
:param degrees_string: Degrees String (dd:mm:ss.ss)
"""
# Verify separator
separators = [':', ' ']
separator = None
for sep in separators:
if sep in degrees_string:
separator = sep
break
if separator is None:
raise ValueError("Invalid string format. No recognized separator found.")
components = degrees_string.split(separator)
# Check for correct format
if len(components) != 3:
raise ValueError("Invalid string format. Expected dd:mm:ss.ss")
degrees_int = abs(int(components[0]))
minutes = int(components[1])
seconds = float(components[2])
degrees = degrees_int + minutes / 60 + seconds / 3600
sign = -1 if "-" in degrees_string else 1
return sign*degrees
def calc_ah(ra, lst):
"""Calculates hour angle from RA and Sidereal"""
ah = 0.2618*(lst - ra)
if ah > math.pi:
ah -= 2 * math.pi
if ah < -math.pi:
ah += 2 * math.pi
ah = ah/0.2618
return ah
def get_az_alt(ra, dec, lst, latitude):
"""Convert equatorial coordinates to horizontal"""
DEG = 180 / math.pi
RAD = math.pi / 180.0
H = (lst-ra) * 15
#altitude calc
sinAltitude = (np.sin(dec * RAD)) * (np.sin(latitude * RAD)) + (np.cos(dec * RAD) * np.cos(latitude * RAD) * np.cos(H * RAD))
elevation = np.arcsin(sinAltitude) * DEG #altura em graus
#azimuth calc
y = -1 * np.sin(H * RAD)
x = (np.tan(dec * RAD) * np.cos(latitude * RAD)) - (np.cos(H * RAD) * np.sin(latitude * RAD))
#Azimuth calc
azimuth = np.arctan2(y, x) * DEG
#converting neg values to pos
if (azimuth.any() < 0):
azimuth = azimuth + 360
if isinstance(azimuth, float):
if (azimuth < 0):
azimuth = azimuth + 360
return(azimuth,elevation)
def pol2cart(rho, phi, allsky_angle):
"""Convert polar coordinates to cartesian"""
"""rho: zenith | phi: azimuth"""
# x=f*rho*cos(A-?)+x0
# y=f*rho*sin(A-?)+y0
# f = 3.365 piexels/degree
# rho = star zenith
# phi = star azimuth
# allsky_angle = camera rotation
# x0 e y0 = coordinates of cameras zenith
x = rho * np.cos(np.radians(phi+allsky_angle))
y = rho * np.sin(np.radians(phi+allsky_angle))
if allsky_angle<0:
x0 = 1.8
y0 = -7.5
else:
x0 = 9.2
y0 = -0.5
x=3.365*x+x0
y=3.365*y+y0
return(x, y)