Skip to content

Commit d27f4f0

Browse files
authored
Merge pull request #92 from pytroll/fix-tle-designator
Fix bogus designator assignment
2 parents 523099d + bf67403 commit d27f4f0

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

pyorbital/tests/test_tlefile.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@
3838
line1_2 = "1 38771U 12049A 21137.30264622 .00000000 00000+0 -49996-5 0 00017"
3939
line2_2 = "2 38771 98.7162 197.7716 0002383 106.1049 122.6344 14.21477797449453"
4040

41+
42+
NOAA19_2LINES = """1 33591U 09005A 21355.91138073 .00000074 00000+0 65091-4 0 9998
43+
2 33591 99.1688 21.1338 0013414 329.8936 30.1462 14.12516400663123
44+
"""
45+
NOAA19_3LINES = "NOAA 19\n" + NOAA19_2LINES
46+
4147
tle_xml = '\n'.join(
4248
('<?xml version="1.0" encoding="UTF-8"?>',
4349
'<multi-mission-administrative-message>',
@@ -117,6 +123,32 @@ def test_from_file(self):
117123
finally:
118124
remove(filename)
119125

126+
def test_from_file_with_hyphenated_platform_name(self):
127+
"""Test reading and parsing from a file with a slightly different name."""
128+
from tempfile import mkstemp
129+
from os import write, close, remove
130+
filehandle, filename = mkstemp()
131+
try:
132+
write(filehandle, NOAA19_3LINES.encode('utf-8'))
133+
close(filehandle)
134+
tle = Tle("NOAA-19", filename)
135+
assert tle.satnumber == "33591"
136+
finally:
137+
remove(filename)
138+
139+
def test_from_file_with_no_platform_name(self):
140+
"""Test reading and parsing from a file with a slightly different name."""
141+
from tempfile import mkstemp
142+
from os import write, close, remove
143+
filehandle, filename = mkstemp()
144+
try:
145+
write(filehandle, NOAA19_2LINES.encode('utf-8'))
146+
close(filehandle)
147+
tle = Tle("NOAA-19", filename)
148+
assert tle.satnumber == "33591"
149+
finally:
150+
remove(filename)
151+
120152
def test_from_mmam_xml(self):
121153
"""Test reading from an MMAM XML file."""
122154
from tempfile import TemporaryDirectory

pyorbital/tlefile.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ def _get_first_tle(uris, open_func, platform=''):
286286

287287
def _get_tles_from_uris(uris, open_func, platform='', only_first=True):
288288
tles = []
289-
designator = "1 " + platform
289+
designator = "1 " + SATELLITES.get(platform, '')
290290
for url in uris:
291291
fid = open_func(url)
292292
for l_0 in fid:
@@ -296,7 +296,7 @@ def _get_tles_from_uris(uris, open_func, platform='', only_first=True):
296296
l_1 = _decode(next(fid))
297297
l_2 = _decode(next(fid))
298298
tle = l_1.strip() + "\n" + l_2.strip()
299-
elif((platform in SATELLITES or not only_first) and l_0.strip().startswith(designator)):
299+
elif (platform in SATELLITES or not only_first) and l_0.strip().startswith(designator):
300300
l_1 = l_0
301301
l_2 = _decode(next(fid))
302302
tle = l_1.strip() + "\n" + l_2.strip()

0 commit comments

Comments
 (0)