Skip to content

Commit

Permalink
Merge pull request #129 from adybbroe/fix-bug-local-tlefile
Browse files Browse the repository at this point in the history
Fix bug getting local tlefiles
  • Loading branch information
adybbroe authored Jul 6, 2023
2 parents 8d982a9 + 806ae12 commit 0cf8323
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 30 deletions.
80 changes: 72 additions & 8 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,28 @@ name: CI

on: [push, pull_request]

env:
CACHE_NUMBER: 1

jobs:
test:
runs-on: ${{ matrix.os }}
continue-on-error: ${{ matrix.experimental }}
strategy:
fail-fast: true
matrix:
os: ["ubuntu-latest", "macos-latest", "windows-latest"]
python-version: ["3.8", "3.9", "3.10"]
os: ["windows-latest", "ubuntu-latest", "macos-latest"]
python-version: ["3.9", "3.10", "3.11"]
experimental: [false]
include:
- python-version: "3.11"
os: "ubuntu-latest"
experimental: true

env:
PYTHON_VERSION: ${{ matrix.python-version }}
OS: ${{ matrix.os }}
UNSTABLE: ${{ matrix.experimental }}
ACTIONS_ALLOW_UNSECURE_COMMANDS: true

steps:
Expand All @@ -23,26 +33,80 @@ jobs:
- name: Setup Conda Environment
uses: conda-incubator/setup-miniconda@v2
with:
miniconda-version: "latest"
miniforge-variant: Mambaforge
miniforge-version: latest
use-mamba: true
python-version: ${{ matrix.python-version }}
mamba-version: "*"
channels: conda-forge,defaults
environment-file: continuous_integration/environment.yaml
activate-environment: test-environment

- name: Set cache environment variables
shell: bash -l {0}
run: |
echo "DATE=$(date +'%Y%m%d')" >> $GITHUB_ENV
CONDA_PREFIX=$(python -c "import sys; print(sys.prefix)")
echo "CONDA_PREFIX=$CONDA_PREFIX" >> $GITHUB_ENV
- uses: actions/cache@v3
with:
path: ${{ env.CONDA_PREFIX }}
key: ${{ matrix.os }}-${{matrix.python-version}}-conda-${{ hashFiles('continuous_integration/environment.yaml') }}-${{ env.DATE }}-${{matrix.experimental}}-${{ env.CACHE_NUMBER }}
id: cache

- name: Update environment
run: mamba env update -n test-environment -f continuous_integration/environment.yaml
if: steps.cache.outputs.cache-hit != 'true'

- name: Install unstable dependencies
if: matrix.experimental == true
shell: bash -l {0}
# We must get LD_PRELOAD for stdlibc++ or else the manylinux wheels
# may break the conda-forge libraries trying to use newer glibc versions
run: |
python -m pip install \
--index-url https://pypi.anaconda.org/scientific-python-nightly-wheels/simple/ \
--trusted-host pypi.anaconda.org \
--no-deps --pre --upgrade \
matplotlib \
numpy \
pandas \
scipy; \
python -m pip install \
--no-deps --upgrade \
git+https://github.com/dask/dask \
git+https://github.com/pydata/xarray;
LD_PRELOAD=$(python -c "import sys; print(sys.prefix)")/lib/libstdc++.so
echo "LD_PRELOAD=${LD_PRELOAD}" >> $GITHUB_ENV
- name: Install Pyorbital
shell: bash -l {0}
run: |
pip install --no-deps -e .
python -m pip install --no-deps -e .
- name: Run unit tests
shell: bash -l {0}
run: |
pytest --cov=pyorbital pyorbital/tests --cov-report=xml
export LD_PRELOAD=${{ env.LD_PRELOAD }};
pytest --cov=pyorbital pyorbital/tests --cov-report=xml --cov-report=
- name: Upload unittest coverage to Codecov
uses: codecov/codecov-action@v3
with:
flags: unittests
file: ./coverage.xml
env_vars: OS,PYTHON_VERSION,UNSTABLE

- name: Coveralls Parallel
uses: AndreMiras/coveralls-python-action@develop
with:
flag-name: run-${{ matrix.test_number }}
parallel: true
if: runner.os == 'Linux'

coveralls:
needs: [test]
runs-on: ubuntu-latest
steps:
- name: Coveralls Finished
uses: AndreMiras/coveralls-python-action@develop
with:
parallel-finished: true
8 changes: 4 additions & 4 deletions pyorbital/orbital.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

# Copyright (c) 2011, 2012, 2013, 2014, 2015.
# Copyright (c) 2011-2023 Pyorbital developers

# Author(s):

Expand Down Expand Up @@ -631,11 +631,11 @@ def __init__(self, orbit_elements):
self.xn_0 = orbit_elements.mean_motion
# A30 = -XJ3 * AE**3

if not(0 < self.eo < ECC_LIMIT_HIGH):
if not (0 < self.eo < ECC_LIMIT_HIGH):
raise OrbitalError('Eccentricity out of range: %e' % self.eo)
elif not((0.0035 * 2 * np.pi / XMNPDA) < self.xn_0 < (18 * 2 * np.pi / XMNPDA)):
elif not ((0.0035 * 2 * np.pi / XMNPDA) < self.xn_0 < (18 * 2 * np.pi / XMNPDA)):
raise OrbitalError('Mean motion out of range: %e' % self.xn_0)
elif not(0 < self.xincl < np.pi):
elif not (0 < self.xincl < np.pi):
raise OrbitalError('Inclination out of range: %e' % self.xincl)

if self.eo < 0:
Expand Down
8 changes: 4 additions & 4 deletions pyorbital/tests/test_aiaa.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

# Copyright (c) 2011 - 2022 Pytroll Community
# Copyright (c) 2011 - 2023 Pytroll Community

# Author(s):

Expand Down Expand Up @@ -55,10 +55,10 @@ def get_results(satnumber, delay):
path = os.path.dirname(os.path.abspath(__file__))
with open(os.path.join(path, "aiaa_results")) as f_2:
line = f_2.readline()
while(line):
while line:
if line.endswith(" xx\n") and int(line[:-3]) == satnumber:
line = f_2.readline()
while(not line.startswith("%.8f" % delay)):
while (not line.startswith("%.8f" % delay)):
line = f_2.readline()
sline = line.split()
if delay == 0:
Expand Down Expand Up @@ -94,7 +94,7 @@ def test_aiaa(self):
path = os.path.dirname(os.path.abspath(__file__))
with open(os.path.join(path, "SGP4-VER.TLE")) as f__:
test_line = f__.readline()
while(test_line):
while test_line:
if test_line.startswith("#"):
test_name = test_line
if test_line.startswith("1 "):
Expand Down
28 changes: 17 additions & 11 deletions pyorbital/tests/test_tlefile.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,21 +94,23 @@ def fake_platforms_file(tmp_path):
yield file_path


@pytest.fixture
def fake_local_tles_dir(tmp_path, monkeypatch):
@pytest.fixture(scope="session")
def fake_local_tles_dir(tmp_path_factory):
"""Make a list of fake tle files in a directory."""
file_path = tmp_path / 'tle-202211180230.txt'
tle_dir = tmp_path_factory.mktemp('tle_files')
file_path = tle_dir / 'tle-202211180230.txt'
file_path.touch()
file_path = tmp_path / 'tle-202211180430.txt'
time.sleep(1)
file_path = tle_dir / 'tle-202211180430.txt'
file_path.touch()
file_path = tmp_path / 'tle-202211180630.txt'
time.sleep(1)
file_path = tle_dir / 'tle-202211180630.txt'
file_path.touch()
file_path = tmp_path / 'tle-202211180830.txt'
time.sleep(1)
file_path = tle_dir / 'tle-202211180830.txt'
file_path.touch()

monkeypatch.setenv('TLES', str(file_path.parent))

yield file_path.parent
yield tle_dir


@pytest.fixture
Expand Down Expand Up @@ -268,15 +270,19 @@ def test_get_local_tle_path(mock_env_tles):
assert res == '/path/to/local/tles'


def test_get_uris_and_open_func_using_tles_env(caplog, fake_local_tles_dir):
def test_get_uris_and_open_func_using_tles_env(caplog, fake_local_tles_dir, monkeypatch):
"""Test getting the uris and associated open-function for reading tles.
Test providing no tle file but using the TLES env to find local tle files.
"""
from collections.abc import Sequence

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

assert uris[0] == str(fake_local_tles_dir)
assert isinstance(uris, Sequence)
assert uris[0] == str(fake_local_tles_dir / 'tle-202211180830.txt')
log_message = "Reading TLE from {msg}".format(msg=str(fake_local_tles_dir))
assert log_message in caplog.text

Expand Down
4 changes: 2 additions & 2 deletions pyorbital/tlefile.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,8 +323,8 @@ def _open(filename):
elif local_tle_path:
# TODO: get the TLE file closest in time to the actual satellite
# overpass, NOT the latest!
uris = (max(glob.glob(local_tle_path),
key=os.path.getctime), )
list_of_tle_files = glob.glob(os.path.join(local_tle_path, '*'))
uris = (max(list_of_tle_files, key=os.path.getctime), )
LOGGER.debug("Reading TLE from %s", uris[0])
open_func = _open
else:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,6 @@
package_data={'pyorbital': [os.path.join('etc', 'platforms.txt')]},
scripts=['bin/fetch_tles.py', ],
install_requires=['numpy>=1.19.0', 'scipy', 'requests'],
python_requires='>=3.8',
python_requires='>=3.9',
zip_safe=False,
)

0 comments on commit 0cf8323

Please sign in to comment.