Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ValueError in case of empty or missing TLE files #74

Open
gerritholl opened this issue Mar 5, 2021 · 0 comments
Open

ValueError in case of empty or missing TLE files #74

gerritholl opened this issue Mar 5, 2021 · 0 comments

Comments

@gerritholl
Copy link
Member

Code Sample, a minimal, complete, and verifiable piece of code

import os
import pyorbital.tlefile

os.environ["TLES"] = "/no/tles/found/here*"
pyorbital.tlefile.Tle("NOAA-18")

Problem description

When the environment variable TLES contains a globbing pattern that does not match any results, constructing the Tle class fails with ValueError. This crashes the gatherer script from pytroll-collectors. Either pyorbital should have some fallback option, or it should raise an exception that can be caught by gatherer which will then try to give up gracefully without crashing.

Expected Output

I expect that this code either decides to download TLEs as a fallback option when no TLEs are found locally, or raises a sufficiently specific exception that could then be caught by client libraries (such as pytroll-collectors) which can then implement their own fallback alternative.

Actual Result, Traceback if applicable

For the MCVE:

Traceback (most recent call last):
  File "tle-valueerror.py", line 5, in <module>
    pyorbital.tlefile.Tle("NOAA-18")
  File "/data/gholl/miniconda3/envs/py38b/lib/python3.8/site-packages/pyorbital/tlefile.py", line 154, in __init__
    self._read_tle()
  File "/data/gholl/miniconda3/envs/py38b/lib/python3.8/site-packages/pyorbital/tlefile.py", line 200, in _read_tle
    urls = (max(glob.glob(os.environ["TLES"]),
ValueError: max() arg is an empty sequence

From my gatherer log:

Exception in thread Thread-1:
Traceback (most recent call last):
  File "/opt/pytroll/pytroll_inst/miniconda3/envs/pytroll-py38/lib/python3.8/threading.py", line 932, in _bootstrap_inner
    self.run()
  File "/opt/pytroll/pytroll_inst/miniconda3/envs/pytroll-py38/lib/python3.8/site-packages/pytroll_collectors/trigger.py", line 397, in run                                                                                                                  
    self.process(msg)
  File "/opt/pytroll/pytroll_inst/miniconda3/envs/pytroll-py38/lib/python3.8/site-packages/pytroll_collectors/trigger.py", line 111, in add_file                                                                                                             
    self._do(pathname)
  File "/opt/pytroll/pytroll_inst/miniconda3/envs/pytroll-py38/lib/python3.8/site-packages/pytroll_collectors/trigger.py", line 107, in _do                                                                                                                  
    Trigger._do(self, mda)
  File "/opt/pytroll/pytroll_inst/miniconda3/envs/pytroll-py38/lib/python3.8/site-packages/pytroll_collectors/trigger.py", line 86, in _do                                                                                                                   
    res = collector(metadata.copy())
  File "/opt/pytroll/pytroll_inst/miniconda3/envs/pytroll-py38/lib/python3.8/site-packages/pytroll_collectors/region_collector.py", line 65, in __call__                                                                                                     
    return self.collect(granule_metadata)
  File "/opt/pytroll/pytroll_inst/miniconda3/envs/pytroll-py38/lib/python3.8/site-packages/pytroll_collectors/region_collector.py", line 147, in collect                                                                                                     
    granule_pass = Pass(platform, start_time, end_time,
  File "/opt/pytroll/pytroll_inst/miniconda3/envs/pytroll-py38/lib/python3.8/site-packages/trollsched/satpass.py", line 176, in __init__                                                                                                                     
    self.orb = orbital.Orbital(satellite, line1=tle1, line2=tle2)
  File "/opt/pytroll/pytroll_inst/miniconda3/envs/pytroll-py38/lib/python3.8/site-packages/pyorbital/orbital.py", line 164, in __init__                                                                                                                      
    self.tle = tlefile.read(satellite, tle_file=tle_file,
  File "/opt/pytroll/pytroll_inst/miniconda3/envs/pytroll-py38/lib/python3.8/site-packages/pyorbital/tlefile.py", line 106, in read                                                                                                                          
    return Tle(platform, tle_file=tle_file, line1=line1, line2=line2)
  File "/opt/pytroll/pytroll_inst/miniconda3/envs/pytroll-py38/lib/python3.8/site-packages/pyorbital/tlefile.py", line 154, in __init__                                                                                                                      
    self._read_tle()
  File "/opt/pytroll/pytroll_inst/miniconda3/envs/pytroll-py38/lib/python3.8/site-packages/pyorbital/tlefile.py", line 200, in _read_tle                                                                                                                     
    urls = (max(glob.glob(os.environ["TLES"]),
ValueError: max() arg is an empty sequence

Versions of Python, package at hand and relevant dependencies

  • pyorbital 1.6.0+11.gf1e50fc
  • pytroll-collectors 0.10.0+5.g2ecd079
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant