skyfielders / python-skyfield

Elegant astronomy for Python
MIT License
1.38k stars 208 forks source link

Elevation angle #935

Closed vishalmathkumar closed 5 months ago

vishalmathkumar commented 5 months ago

I am using the following code to get the elevation angle with respect to a gs(ground station) but I am not getting the correct elevation angles values. Can you please tell where I am going wrong? def get_visibility_and_elevation_angle(satellite,gs_pos,time,min_elevation_angle): difference = satellite - gs_pos topocentric = difference.at(time) alt, az, distance = topocentric.altaz() if(alt.degrees>min_elevation_angle): vis=1 else: vis=0 return vis,alt.degrees

The elevation angles I am getting here are not correct as I compared to real time online sites

brandon-rhodes commented 5 months ago

Your code looks good, so the problem might be elsewhere. To track it down, I need a small example script that prints out an angle, and to compare it with, I need to know the angle you wanted, and how you determined that angle. Otherwise, I won't be able to guess what's gone wrong. Thanks!

vishalmathkumar commented 5 months ago

Your code looks good, so the problem might be elsewhere. To track it down, I need a small example script that prints out an angle, and to compare it with, I need to know the angle you wanted, and how you determined that angle. Otherwise, I won't be able to guess what's gone wrong. Thanks!

I am attaching an example in which I am finding the elevation angle, the python is giving me 61.7 degrees whereas when I calculated the same using the satellite position and gs_pos(ground station) in matlab using lookangles() function I am getting 106 degrees and the online live tracking site also giving me around 106 only. I couldn't find out where things are going wrong? I had also output the satellite position which I than used in matlab. Please check this.

from skyfield.api import EarthSatellite,load, Topos,wgs84
line1='1 24876U 97035A   23182.78110591  .00000038  00000+0  00000+0 0  9998'
line2='2 24876  55.5770 140.8664 0069447  51.0372 309.5417  2.00563923190060'
ts = load.timescale()

satellite = EarthSatellite(line1, line2, 'GPS 13', ts)

time_str = '2024-01-01 12:00:00'

time = ts.utc(int(time_str[:4]), int(time_str[5:7]), int(time_str[8:10]),
              int(time_str[11:13]), int(time_str[14:16]), int(time_str[17:19]))

print("The satellite position in ecef=",satellite.at(time).itrf_xyz().m)

#def get_visibility_and_elevation_angle(satellite,gs_pos,time,min_elevation_angle):

min_elevation_angle=5

gs_pos=gs_pos=wgs84.latlon(10,10,0)
difference = satellite - gs_pos
topocentric = difference.at(time)
alt, az, distance = topocentric.altaz()
if(alt.degrees>min_elevation_angle):
    vis=1
else:
    vis=0

print('elevation angle',alt.degrees)
brandon-rhodes commented 5 months ago

matlab using lookangles() function I am getting 106 degrees…

Thank you for providing a specific example! To help Skyfield's contributors read your code, you might want to hit the Edit button on your post and use backticks to format it as code, since Python is sensitive to indentation:

https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax#quoting-code

Before I look more closely at the script, could you explain what the 106° means? The way I use elevation, it goes from 0° at the horizon to +90° at the zenith, so matlab must be using a different definition?

vishalmathkumar commented 5 months ago

Thank you for suggestion for indentation and your quick reply. Actually I mistook the azimuth angle as elevation angle while taking output from the function in matlab due to it's different order, upon your suggestion I re checked now it is working fine. Thank you once again

brandon-rhodes commented 5 months ago

I'm glad the two libraries are now within tolerable agreement!