diff --git a/doc/source/index.rst b/doc/source/index.rst index 6ae7be78..45aee1ed 100644 --- a/doc/source/index.rst +++ b/doc/source/index.rst @@ -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. @@ -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. diff --git a/pyorbital/tests/test_tlefile.py b/pyorbital/tests/test_tlefile.py index 89698c8a..b7eccc36 100644 --- a/pyorbital/tests/test_tlefile.py +++ b/pyorbital/tests/test_tlefile.py @@ -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): @@ -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): @@ -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() diff --git a/pyorbital/tlefile.py b/pyorbital/tlefile.py index 9b814129..d2f04100 100644 --- a/pyorbital/tlefile.py +++ b/pyorbital/tlefile.py @@ -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