Skip to content

Commit

Permalink
Merge pull request #143 from pnuu/bugfix-local-tles
Browse files Browse the repository at this point in the history
Fix a bug in using TLES env variable
  • Loading branch information
mraspaud authored Feb 5, 2024
2 parents 2c06303 + 97df4c1 commit 453218b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
17 changes: 11 additions & 6 deletions doc/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,14 @@ Pyorbital has a module for parsing NORAD TLE-files
>>> tle.inclination
99.043499999999995

If no path is provided pyorbital first tries to read any local TLE files in the
directory given by the environment variable :envvar:`TLES`. If this variable is not
set Pyorbital will try get the earth observation TLE files over the internet
If no path is provided pyorbital first tries to read any local TLE files defined by the
environment variable :envvar:`TLES` giving a glob pattern that can be used to retrieve all relevant files:

.. code::
TLES=/path/to/tle_files/*/tle*txt
If this variable is not set Pyorbital will try get the earth observation TLE files over the internet
from `celestrak`_. Note this downloading only happens if no
specific TLE file is provided or if the :envvar:`TLES` environment variable is not set.

Expand Down Expand Up @@ -179,9 +184,9 @@ The astronomy module enables computation of certain parameters of interest for s
for instance. Also, it may not be sustainable in a production environment.

However, it is possible to let Pyorbital look for the necessary and more
optimal TLE data locally, by specifying the directory where such local TLE
files are located. If the TLES environment variable is set to point at an
existing local directory Pyorbital will first search for the needed TLEs
optimal TLE data locally, by specifying locations where such local TLE
files are located. If the TLES environment variable is set to a glob pattern to
local locations, Pyorbital will first search for the needed TLEs
there. This can both be useful in an operational setup where access to the
internet is restricted, and when processing old/historic satellite data.

Expand Down
10 changes: 5 additions & 5 deletions pyorbital/tests/test_tlefile.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,9 @@ def mock_env_tles_missing(monkeypatch):


@pytest.fixture
def mock_env_tles(monkeypatch):
def mock_env_tles(monkeypatch, fake_local_tles_dir):
"""Mock environment variable TLES."""
monkeypatch.setenv('TLES', '/path/to/local/tles')
monkeypatch.setenv('TLES', os.path.join(fake_local_tles_dir, '*'))


def test_get_config_path_no_env_defined(caplog, mock_env_ppp_config_dir_missing):
Expand Down Expand Up @@ -264,10 +264,10 @@ def test_get_local_tle_path_tle_env_missing(mock_env_tles_missing):
assert res is None


def test_get_local_tle_path(mock_env_tles):
def test_get_local_tle_path(mock_env_tles, fake_local_tles_dir):
"""Test getting the path to local TLE files."""
res = _get_local_tle_path_from_env()
assert res == '/path/to/local/tles'
assert res == os.path.join(fake_local_tles_dir, "*")


def test_get_uris_and_open_func_using_tles_env(caplog, fake_local_tles_dir, monkeypatch):
Expand All @@ -277,7 +277,7 @@ def test_get_uris_and_open_func_using_tles_env(caplog, fake_local_tles_dir, monk
"""
from collections.abc import Sequence

monkeypatch.setenv('TLES', str(fake_local_tles_dir))
monkeypatch.setenv('TLES', str(os.path.join(fake_local_tles_dir, "*")))
with caplog.at_level(logging.DEBUG):
uris, _ = _get_uris_and_open_func()

Expand Down
2 changes: 1 addition & 1 deletion pyorbital/tlefile.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ def _open(filename):
elif local_tle_path:
# TODO: get the TLE file closest in time to the actual satellite
# overpass, NOT the latest!
list_of_tle_files = glob.glob(os.path.join(local_tle_path, '*'))
list_of_tle_files = glob.glob(local_tle_path)
uris = (max(list_of_tle_files, key=os.path.getctime), )
LOGGER.debug("Reading TLE from %s", uris[0])
open_func = _open
Expand Down

0 comments on commit 453218b

Please sign in to comment.