Skip to content

Commit

Permalink
Merge pull request #43 from Juanlu001/minor-fixes
Browse files Browse the repository at this point in the history
Minor fixes
  • Loading branch information
astrojuanlu authored Apr 12, 2019
2 parents 994f550 + 867060d commit 7a75f6d
Show file tree
Hide file tree
Showing 24 changed files with 176 additions and 222 deletions.
13 changes: 1 addition & 12 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -80,23 +80,12 @@ Simplified creation of predictor from TLE lines:
velocity_ecef=(-2.4601788971676903, -0.47182217472755117, 7.167517631852518),
error_estimate=None)

`WSTLESource` needs the tle.satellogic.com service to be working. We are doing changes to have it public available.

Currently you have available these sources
------------------------------------------

- Memorytlesource: in memory storage.
- EtcTLESource: a uniq TLE is stored in `/etc/latest_tle`
- WSTLESource: It source is using the `TLE API. <http://tle.satellogics.com/api/tle/>`_


About HighAccuracyTLEPredictor
------------------------------

The default 'predictor' code is tunned to low CPU usage. (IE: a Satellite computer). The
error estimation is ~20 seconds. If you need more than that you can use the *HighAccuracyTLEPredictor*
passing `precise=True` to `get_predictor()`.

- WSTLESource: It reads a REST API currently used inside Satellogic. We are are working to make it publicly available.

How to contribute
-----------------
Expand Down
3 changes: 2 additions & 1 deletion orbit_predictor/accuratepredictor.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
from .predictors.accurate import HighAccuracyTLEPredictor, ONE_SECOND

warnings.warn(
"Use `from orbit_predictor.predictors import HighAccuracyTLEPredictor` instead",
"Use `from orbit_predictor.predictors import TLEPredictor` instead, "
"this module will be removed in the future",
FutureWarning,
)

Expand Down
1 change: 0 additions & 1 deletion orbit_predictor/angles.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# MIT License
#
# Copyright (c) 2017 Satellogic SA
Expand Down
2 changes: 1 addition & 1 deletion orbit_predictor/keplerian.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# MIT License
#
# Copyright (c) 2017 Satellogic SA
Expand All @@ -25,6 +24,7 @@
# https://github.com/poliastro/poliastro/blob/1d2f3ca/src/poliastro/twobody/classical.py
# https://github.com/poliastro/poliastro/blob/1d2f3ca/src/poliastro/twobody/rv.py
# Copyright (c) 2012-2017 Juan Luis Cano Rodríguez, MIT license

from math import cos, sin, sqrt

import numpy as np
Expand Down
4 changes: 2 additions & 2 deletions orbit_predictor/locations.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

import datetime
import datetime as dt
import importlib
from math import asin, cos, degrees, radians, sin, sqrt
import os
Expand All @@ -31,7 +31,7 @@
LIGHT_SPEED_KMS = 299792.458


class Location(object):
class Location:
def __init__(self, name, latitude_deg, longitude_deg, elevation_m):
self.name = name
self.latitude_deg = latitude_deg
Expand Down
9 changes: 5 additions & 4 deletions orbit_predictor/predictors/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from orbit_predictor.predictors.base import Position, PredictedPass # noqa
from orbit_predictor.exceptions import NotReachable # noqa
from orbit_predictor.predictors.tle import TLEPredictor # noqa
from orbit_predictor.predictors.accurate import HighAccuracyTLEPredictor # noqa
from orbit_predictor.predictors.base import Position, PredictedPass
from orbit_predictor.exceptions import NotReachable
from orbit_predictor.predictors.tle import TLEPredictor

__all__ = ["Position", "PredictedPass", "NotReachable", "TLEPredictor"]
6 changes: 2 additions & 4 deletions orbit_predictor/predictors/accurate.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
Some stuff won't be trivial to understand, but comments and fixes are welcome
"""
import datetime
import datetime as dt
from functools import lru_cache

from sgp4 import ext, model
Expand All @@ -56,8 +56,6 @@

from .base import CartesianPredictor, logger

ONE_SECOND = datetime.timedelta(seconds=1)

# Hack Zone be warned


Expand Down Expand Up @@ -85,7 +83,7 @@ class HighAccuracyTLEPredictor(CartesianPredictor):

@reify
def tle(self):
return self.source.get_tle(self.sate_id, datetime.datetime.utcnow())
return self.source.get_tle(self.sate_id, dt.datetime.utcnow())

@reify
def propagator(self):
Expand Down
16 changes: 8 additions & 8 deletions orbit_predictor/predictors/base.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# MIT License
#
# Copyright (c) 2017 Satellogic SA
Expand Down Expand Up @@ -36,7 +35,8 @@
reify,
vector_diff,
vector_norm,
gstime_from_datetime)
gstime_from_datetime
)

logger = logging.getLogger(__name__)

Expand All @@ -55,7 +55,7 @@ def position_llh(self):
return coordinate_systems.ecef_to_llh(self.position_ecef)


class PredictedPass(object):
class PredictedPass:
def __init__(self, location, sate_id,
max_elevation_deg,
aos, los, duration_s,
Expand Down Expand Up @@ -101,9 +101,9 @@ def off_nadir_deg(self):
location ``target`` in a common frame, off-nadir angle ``off_nadir_angle``
is given by:
t2b = sate_pos - target
cos(off_nadir_angle) = (target · t2b) # Vectorial dot product
_____________________
|| target || || t2b||
cos(off_nadir_angle) = (sate_pos · t2b) # Vectorial dot product
_______________________
|| sate_pos || || t2b||
Sign for the rotation is calculated this way
Expand All @@ -130,7 +130,7 @@ def off_nadir_deg(self):
return degrees(angle) * sign


class Predictor(object):
class Predictor:

def __init__(self, sate_id, source):
self.sate_id = sate_id
Expand Down Expand Up @@ -199,7 +199,7 @@ class GPSPredictor(Predictor):
pass


class LocationPredictor(object):
class LocationPredictor:
"""Predicts passes over a given location
Exposes an iterable interface
"""
Expand Down
3 changes: 1 addition & 2 deletions orbit_predictor/predictors/keplerian.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# MIT License
#
# Copyright (c) 2017 Satellogic SA
Expand All @@ -21,7 +20,7 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

import datetime
import datetime as dt
from math import degrees, radians, sqrt

import numpy as np
Expand Down
1 change: 0 additions & 1 deletion orbit_predictor/predictors/numerical.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# MIT License
#
# Copyright (c) 2017 Satellogic SA
Expand Down
27 changes: 12 additions & 15 deletions orbit_predictor/sources.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# MIT License
#
# Copyright (c) 2017 Satellogic SA
Expand All @@ -23,35 +22,29 @@

import logging
from collections import defaultdict, namedtuple
import warnings

import requests
from urllib import parse as urlparse
from urllib.parse import urlencode

from sgp4.earth_gravity import wgs84
from sgp4.io import twoline2rv

from orbit_predictor.accuratepredictor import HighAccuracyTLEPredictor
from orbit_predictor.predictors import TLEPredictor

try:
from urllib import parse as urlparse
from urllib.parse import urlencode
except ImportError:
# pytyhon2 support.
import urlparse # NOQA
from urllib import urlencode # NOQA

logger = logging.getLogger(__name__)

TLE = namedtuple('TLE',
['sate_id', 'lines', 'date'])


class GPSSource(object):
class GPSSource:
def get_position_ecef(self, sate_id, when_utc):
raise NotImplementedError("You have to implement it.")


class TLESource(object):
class TLESource:

def add_tle(self, sate_id, tle, epoch):
raise NotImplementedError("You have to implement it.")
Expand All @@ -64,10 +57,14 @@ def get_tle(self, sate_id, date):
lines = self._get_tle(sate_id, date)
return TLE(sate_id=sate_id, date=date, lines=lines)

def get_predictor(self, sate_id, precise=False):
def get_predictor(self, sate_id, precise=True):
"""Return a Predictor instance using the current storage."""
if precise:
return HighAccuracyTLEPredictor(sate_id, self)
if not precise:
warnings.warn(
"There is no `precise=False` predictor anymore "
"and the parameter will be removed in the future",
FutureWarning,
)

return TLEPredictor(sate_id, self)

Expand Down
7 changes: 3 additions & 4 deletions orbit_predictor/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# MIT License
#
# Copyright (c) 2017 Satellogic SA
Expand All @@ -23,7 +22,7 @@

import functools
from collections import namedtuple
from datetime import datetime
import datetime as dt
from math import asin, atan2, cos, degrees, floor, radians, sin, sqrt, modf

import numpy as np
Expand Down Expand Up @@ -232,7 +231,7 @@ def sun_azimuth_elevation(latitude_deg, longitude_deg, when=None):
:returns: an ``AzimuthElevation`` namedtuple
"""
if when is None:
when = datetime.utcnow()
when = dt.datetime.utcnow()

utc_time_tuple = when.timetuple()
utc_time_list = list(utc_time_tuple[:6])
Expand Down Expand Up @@ -339,7 +338,7 @@ def mean_motion(sma_km):
return sqrt(wgs84.mu / sma_km ** 3) # rad / s


class reify(object):
class reify:
"""
Use as a class method decorator. It operates almost exactly like the
Python ``@property`` decorator, but it puts the result of the method it
Expand Down
Loading

0 comments on commit 7a75f6d

Please sign in to comment.