Until recently, the code I used to calculate the elevation and azimuth of a satellite from one particular site appeared to work. Then I used a different file from a site, not in the northern but in the southern hemisphere. The elevation angles calculated were sometimes negative i.e. the satellite was below the horizon. This is incorrect, so either the file parameters to be used for the satellite position are false (less likely), or my code below is incorrect (more likely).
rx_position = (self.X_rx, self.Y_rx, self.Z_rx)
diff_position = satellite_carteisan_coords - rx_position
diff_position_individual = diff_position[0]
rho = np.sqrt(diff_position_individual[0]**2 + diff_position_individual[1]**2 + diff_position_individual[2]**2)
dphi, dlambda, h = self.cartesian_to_geoid(rx_position)
slat = np.sin(np.radians(dphi))
slon = np.sin(np.radians(dlambda))
clat = np.cos(np.radians(dphi))
clon = np.cos(np.radians(dlambda))
F = np.array([[-slon, -slat*clon, clat*clon],
[clon, -slat*slon, clat*slon],
[0, clat, slat ]])
np.split(diff_position_individual, 3)
local_vector = np.dot(F.T, diff_position_individual)
E = local_vector[0]
N = local_vector[1]
U = local_vector[2]
hor_dis = np.sqrt(E**2 + N**2)
if hor_dis < 1e-20:
Azi = 0
Ele = 90
else:
Azi = np.rad2deg(math.atan2(E, N))
Ele = np.rad2deg(math.atan2(U, hor_dis))
if Azi < 0:
Azi = Azi + 360
return Azi, Ele
How can I ensure that the code above does not end up calculating elevation angles that are negative?