示例#1
0
 def setUp(self):
     self.db = sources.MemoryTLESource()
示例#2
0
def update_passing_sats(dt=1):
    # Where am I?
    g = geocoder.ip('me')
    lat, lon = g.latlng
    me = locations.Location('me', lat, lon, 0)

    # Get the current time.
    now = datetime.utcnow()
    # Get tomorrow, as the limit on when to check
    tomorrow = now + timedelta(days=dt)
    print('I want to find satellites that pass overhead between:\n', now, '\n',
          tomorrow)

    # Get a database of satellites.
    fetch(TLE_URLS)
    created_files = glob.glob("TLE_data/*")
    print("TLE files:\n{}".format(created_files))

    # Now read that data into my TLE database
    database = sources.MemoryTLESource()
    # Also track all my satellite IDs
    sat_IDs = []
    print("Parsing TLE data...")
    for fname in created_files:
        with open(fname, 'r') as f:
            while True:
                name = f.readline().strip()
                if name == '':
                    break

                sat_IDs.append(name)
                tle_1 = f.readline().strip()
                tle_2 = f.readline().strip()

                tle = (tle_1, tle_2)

                database.add_tle(name, tle, now)
    print("Done!")

    print(
        "Checking all satellites to see which transit overhead in the next 24 hours..."
    )
    alt_lim = abs(90 - OVERHEAD_LIMIT)  # Degrees

    passes = []
    will_pass = []

    for ID in sat_IDs:
        try:
            predictor = predictors.TLEPredictor(ID, database)
            pred = predictor.get_next_pass(location=me,
                                           when_utc=now,
                                           aos_at_dg=alt_lim,
                                           limit_date=tomorrow)
            print("The object {} will pass over {} deg at:\n--> {}\n".format(
                ID, alt_lim, pred))
            will_pass.append(ID)
            passes.append(pred)
        except AssertionError as e:
            pass
            # print(e)
        except exceptions.NotReachable as e:
            pass
            # print(e)
        except exceptions.PropagationError as e:
            pass
            # print(e)

    # print(will_pass)
    print(
        "\n\nFound {} satellites that will pass through the top {} degrees above lat, lon: {}, {} within the next {} day(s)\n\n\n"
        .format(len(will_pass), 90 - alt_lim, lat, lon, dt))

    with open('passing_sats.txt', 'w') as f:
        to_write = '\n'.join(will_pass)
        f.write(to_write)

    for ID, pred in zip(will_pass, passes):
        print("{}\n\n".format(pred))

    return database