Giter Club home page Giter Club logo

pypredict's Introduction

ci

PyPredict

NOTE: To preserve compatibility with predict, pypredict uses north latitude and west longitude for terrestrial coordinates.

Do you want accurate and time-tested satellite tracking and pass prediction in a convenient python wrapper? You're in the right place.

PyPredict is a C Python extension directly adapted from the ubiquitous predict satellite tracking command line application. Originally written for the commodore 64, predict has a proven pedigree; We just aim to provide a convenient API. PyPredict is a port of the predict codebase and should yield identical results.

If you think you've found an error in pypredict, please include output from predict on same inputs to the bug report.
If you think you've found a bug in predict, please report and we'll coordinate with upstream.

Installation

sudo apt-get install python-dev
sudo python setup.py install

Usage

Observe a satellite (relative to a position on earth)

import predict
tle = """0 LEMUR 1
1 40044U 14033AL  15013.74135905  .00002013  00000-0  31503-3 0  6119
2 40044 097.9584 269.2923 0059425 258.2447 101.2095 14.72707190 30443"""
qth = (37.771034, 122.413815, 7)  # lat (N), long (W), alt (meters)
predict.observe(tle, qth) # optional time argument defaults to time.time()
# => {'altitude': 676.8782276657903,
#     'azimuth': 96.04762045174824,
#     'beta_angle': -27.92735429908726,
#     'decayed': 0,
#     'doppler': 1259.6041017128405,
#     'eci_obs_x': -2438.227652191655,
#     'eci_obs_y': -4420.154476060397,
#     'eci_obs_z': 3885.390601342013,
#     'eci_sun_x': 148633398.020844,
#     'eci_sun_y': -7451536.44122029,
#     'eci_sun_z': -3229999.50056359,
#     'eci_vx': 0.20076213530665032,
#     'eci_vy': -1.3282146055077213,
#     'eci_vz': 7.377067234096598,
#     'eci_x': 6045.827328897242,
#     'eci_y': -3540.5885778261277,
#     'eci_z': -825.4065096776636,
#     'eclipse_depth': -87.61858291647795,
#     'elevation': -43.711904591801726,
#     'epoch': 1521290038.347793,
#     'footprint': 5633.548906707907,
#     'geostationary': 0,
#     'has_aos': 1,
#     'latitude': -6.759563817939698,
#     'longitude': 326.1137007912563,
#     'name': '0 LEMUR 1',
#     'norad_id': 40044,
#     'orbit': 20532,
#     'orbital_model': 'SGP4',
#     'orbital_phase': 145.3256815318047,
#     'orbital_velocity': 26994.138671706416,
#     'slant_range': 9743.943478523843,
#     'sunlit': 1,
#     'visibility': 'D'
#    }

Show upcoming transits of satellite over ground station

# start and stop transit times as UNIX timestamp
transit_start = 1680775200
transit_stop = 1681034400

p = predict.transits(tle, qth, transit_start, transit_stop)

print("Start of Transit\tTransit Duration (s)\tPeak Elevation")
for transit in p:
    print(f"{transit.start}\t{transit.duration()}\t{transit.peak()['elevation']}")

Modeling an entire constellation

Generating transits for a lot of satellites over a lot of ground stations can be slow. Luckily, generating transits for each satellite-groundstation pair can be parallelized for a big speed-up.

import itertools
from multiprocessing.pool import Pool
import time

import predict
import requests

# Define a function that returns arguments for all the transits() calls you want to make
def _transits_call_arguments():
    now = time.time()
    tle = requests.get('http://tle.spire.com/25544').text.rstrip()
    for latitude in range(-90, 91, 15):
        for longitude in range(-180, 181, 15):
            qth = (latitude, longitude, 0)
            yield {'tle': tle, 'qth': qth, 'ending_before': now+60*60*24*7}

# Define a function that calls the transit function on a set of arguments and does per-transit processing
def _transits_call_fx(kwargs):
    try:
        transits = list(predict.transits(**kwargs))
        return [t.above(10) for t in transits]
    except predict.PredictException:
        pass

# Map the transit() caller across all the arguments you want, then flatten results into a single list
pool = Pool(processes=10)
array_of_results = pool.map(_transits_call_fx, _transits_call_arguments())
flattened_results = list(itertools.chain.from_iterable(filter(None, array_of_results)))
transits = flattened_results

NOTE: If precise accuracy isn't necessary (for modeling purposes, for example) setting the tolerance argument to the above call to a larger value, say 1 degree, can provide a significant performance boost.

Call predict analogs directly

predict.quick_find(tle.split('\n'), time.time(), (37.7727, 122.407, 25))
predict.quick_predict(tle.split('\n'), time.time(), (37.7727, 122.407, 25))

API

observe(tle, qth[, at=None])  
    Return an observation of a satellite relative to a groundstation.
    qth groundstation coordinates as (lat(N),long(W),alt(m))
    If at is not defined, defaults to current time (time.time())
    Returns an "observation" or dictionary containing:  
        altitude _ altitude of satellite in kilometers
        azimuth - azimuth of satellite in degrees from perspective of groundstation.
        beta_angle
        decayed - 1 if satellite has decayed out of orbit, 0 otherwise.
        doppler - doppler shift between groundstation and satellite.
        eci_obs_x
        eci_obs_y
        eci_obs_z
        eci_sun_x
        eci_sun_y
        eci_sun_z
        eci_vx
        eci_vy
        eci_vz
        eci_x
        eci_y
        eci_z
        eclipse_depth
        elevation - elevation of satellite in degrees from perspective of groundstation.
        epoch - time of observation in seconds (unix epoch)
        footprint
        geostationary - 1 if satellite is determined to be geostationary, 0 otherwise.
        has_aos - 1 if the satellite will eventually be visible from the groundstation
        latitude - north latitude of point on earth directly under satellite.
        longitude - west longitude of point on earth directly under satellite.
        name - name of satellite from first line of TLE.
        norad_id - NORAD id of satellite.
        orbit
        orbital_phase
        orbital_model
        orbital_velocity
        slant_range - distance to satellite from groundstation in meters.
        sunlit - 1 if satellite is in sunlight, 0 otherwise.
        visibility
transits(tle, qth[, ending_after=None][, ending_before=None])  
    Returns iterator of Transit objects representing passes of tle over qth.  
    If ending_after is not defined, defaults to current time  
    If ending_before is not defined, the iterator will yield until calculation failure.

NOTE: We yield passes based on their end time. This means we'll yield currently active passes in the two-argument invocation form, but their start times will be in the past.

Transit(tle, qth, start, end)  
    Utility class representing a pass of a satellite over a groundstation.
    Instantiation parameters are parsed and made available as fields.
    duration()  
        Returns length of transit in seconds
    peak(epsilon=0.1)  
        Returns epoch time where transit reaches maximum elevation (within ~epsilon)
    at(timestamp)  
        Returns observation during transit via quick_find(tle, timestamp, qth)
    aboveb(elevation, tolerance)
        Returns portion of transit above elevation. If the entire transit is below the target elevation, both
        endpoints will be set to the peak and the duration will be zero. If a portion of the transit is above
        the elevation target, the endpoints will be between elevation and elevation + tolerance (unless
        endpoint is already above elevation, in which case it will be unchanged)
quick_find(tle[, time[, (lat, long, alt)]])  
    time defaults to current time   
    (lat, long, alt) defaults to values in ~/.predict/predict.qth  
    Returns observation dictionary equivalent to observe(tle, time, (lat, long, alt))
quick_predict(tle[, time[, (lat, long, alt)]])  
        Returns an array of observations for the next pass as calculated by predict.
        Each observation is identical to that returned by quick_find.

pypredict's People

Contributors

bjorn-spire avatar bordicon avatar echelon9 avatar hefnawi7 avatar jerematt avatar jtrutna avatar nick-pascucci-spire avatar vinnyfuria avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pypredict's Issues

Small memory leak in PyList_Append error handler

As per mconst's comment in #6

"Cool, this looks good to me. (In theory I think you're also supposed to free your new py_obs reference if the subsequent PyList_Append fails, but I can't imagine that ever being a problem in practice -- it's a tiny memory leak, and it'll only happen if you're already out of memory for other reasons. Manual memory management sucks.)"

gpredict values don't match pypredict for live observation

The azimuth and elevation returned by pypredict.observe don't seem to be the same as those outputted by gpredict in the live view. The pypredict orbit number is also one more than gpredict. The latitude and longitude values do seem to match up.

I've checked a few different ground station/satellite combos and made sure the TLEs match; they all return the +1 orbit difference as well as different az/el numbers.

Below is a screenshot of a predict.observe output between SFGS and Lemur 1 and the gpredict screen at the same time:

image

Is this a bug or am I using pypredict.observe incorrectly? Thanks!

Unable to process TLE's with recent epochs

I have been unable to parse this TLE:

VIGORIDE 6
1 70335C 23054AL 23105.34038169 -.00032587 00000+0 -14314-2 0 01
2 70335 97.4114 1.1880 0010120 235.8387 209.1455 15.21961743 10

getting the PredictException: Unable to process TLE.

By changing a few things, such as setting 70335C -> 70335U and 23105.x to 15013.x it is willing to parse, but of course this does not give the desired results. What gives?

FindLOS can fail

If we step over end of transit, original code calls FindLOS to determine end time. But FindLOS can fail which generates a spurious endpoint at the epoch.

For now we just eliminate that point, but this means the end of predict transits may not be at 0 elevation.

Locate Satellite at the time of TLE

Hi, I was wondering about the way how can I get the location of a satellite at the time of it's TLE? (i.e. I am not interested in modelling the orbital trajectory, rather just the location when the TLE was recorded. Thanks.

Longitude is provided inverse to every other API and software

Awesome software, but myself (and several other users based on issues in this repo) have wasted time debugging all to find out that the longitude needs to be provided with west positive. This is mentioned in the docs, but the issue is it's the opposite from every other piece of software and API out there. Not only that but in the first paragraph on the Wikipedia page for Longitude - https://en.wikipedia.org/wiki/Longitude it mentions east being positive. I know you don't want to make an API change at this point but surely there is a solution here so more folks don't get caught up in this issue.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.