satellogic / orbit-predictor

Python library to propagate satellite orbits.
MIT License
140 stars 43 forks source link

get_predictor only find the first satellite in the TLE file #57

Closed robbo4 closed 5 years ago

robbo4 commented 5 years ago

Hiya,

I'm trying to write some code to see what satellites are overhead. So the idea is to have a large TLE file with multiple spacecraft in. Then get the next aos and los of each one, checking to see if the current time is within the aos and los. However, I seem to have an issue when trying to look at anything other than the first spacecraft in the TLE file.

Example code:

from orbit_predictor.sources import EtcTLESource
from orbit_predictor.locations import ARG
from datetime import datetime

TLE_file = "/home/abc/tle.txt"
source = EtcTLESource(filename=TLE_file)

spacecraft_names = []
line_count = 0
with open(TLE_file) as tle:
  for line in tle:
    if line.rstrip():
      if line_count==0:
        spacecraft_names.append(line.rstrip())
      elif line_count==2:
        line_count=-1
      line_count += 1 

for spacecraft in spacecraft_names:
  print (spacecraft)
  predictor = source.get_predictor(spacecraft)

  predicted_pass = predictor.get_next_pass(ARG)
  print (predicted_pass)

  now = datetime.utcnow()
  if now < predicted_pass.aos:
    print ('not yet')
  elif predicted_pass.aos < now < predicted_pass.los:
    print (spacecraft, ' currently overhead')

Any ideas if this is something I'm doing wrong or an issue?

Thanks

(Edit: Code formatting)

astrojuanlu commented 5 years ago

Hi @robbo4, thanks for your interest in orbit-predictor? Could you please tell us what's the issue you're finding?

luciotorre commented 5 years ago

The issue is that EtcTLESource just reads the first 3 lines for a TLE, as it is meant to be used on board to know what the current TLE is. To support mutltiple satellites in one file please use NoradTLESource.

I will close the issue now, re open it if it does not work.

robbo4 commented 5 years ago

Ahh yes. You are correct. Thank you.

Can anyone give me an example of how NoradTLESource can be used? I'm currently not sure what 'content' is.

Thanks

luciotorre commented 5 years ago

Try using one of the two constructor class methods: NoradTLESource.from_url(url) or NoradTLESource.from_file(filename)

You can see from the code that content is a list of lines(strings) of a norad like tle file.

robbo4 commented 5 years ago

Ahhh. Perfect, thanks.