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

Add parser to read TLEs from Multi Mission Administrative Messages #78

Merged
merged 45 commits into from
Nov 29, 2021

Conversation

pnuu
Copy link
Member

@pnuu pnuu commented Apr 22, 2021

This PR adds a parser that can read TLE data from MMAM XML files.

  • Tests added
  • Tests passed
  • Passes flake8 pyorbital
  • Fully documented

@pnuu pnuu requested review from mraspaud and adybbroe April 22, 2021 06:37
@pnuu pnuu self-assigned this Apr 22, 2021
@codecov
Copy link

codecov bot commented Apr 22, 2021

Codecov Report

Merging #78 (89d6935) into main (6b7e685) will increase coverage by 1.01%.
The diff coverage is 93.82%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main      #78      +/-   ##
==========================================
+ Coverage   85.31%   86.32%   +1.01%     
==========================================
  Files          13       13              
  Lines        1893     1967      +74     
==========================================
+ Hits         1615     1698      +83     
+ Misses        278      269       -9     
Flag Coverage Δ
unittests 86.32% <93.82%> (+1.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
pyorbital/tlefile.py 91.03% <89.90%> (+3.61%) ⬆️
pyorbital/tests/test_tlefile.py 97.83% <100.00%> (+0.39%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6b7e685...89d6935. Read the comment docs.

Copy link
Member

@mraspaud mraspaud left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add the new xml reading to the TLE class?

@ghost
Copy link

ghost commented May 20, 2021

DeepCode's analysis on #89d693 found:

  • ℹ️ 1 minor issue. 👇
  • ✔️ 1 issue was fixed.

Top issues

Description Example fixes
The call to next should be guarded with a try/except block Occurrences: 🔧 Example fixes

👉 View analysis in DeepCode’s Dashboard | Configure the bot

@pnuu
Copy link
Member Author

pnuu commented May 20, 2021

I'll be ignoring the Deepcode warning about using next() without an optional default value.

Copy link
Member

@mraspaud mraspaud left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding MMAM functionality and taking the time to refactor!

I think the tests are missing the case of passing the MMAM to the TLE class instance directly, right?
Otherwise, a few comments inline

Comment on lines +78 to +79
platform = ' '.join(parts[:-1])
num = parts[-1]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't work I think, examples from http://celestrak.com/NORAD/elements/weather.txt :
DMSP 5D-3 F16 (USA 172)
EWS-G1 (GOES 13)
I'm not saying it was working better before though...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will. The parts[-1] is the platform number defined in platforms.txt.

Comment on lines +416 to +417
return [Tle('', tle_file=io.StringIO(tle)) for tle in
_get_tles_from_uris(item, open_func, platform='', only_first=False)]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why the call to StringIO here? isn't open_func taking care of that?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was the only way of distinguishing between a filename str and data already read from the XML file as str in _get_uris_and_open_func(). Suggestions for a better way are wellcome.

return "\n".join(data)


def _grouper(n, iterable, fillvalue=None):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function name could be improved, maybe matching the docstring more?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do. The naming was taken from itertools examples.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

pyorbital/tlefile.py Outdated Show resolved Hide resolved
@pnuu
Copy link
Member Author

pnuu commented May 21, 2021

I think the tests are missing the case of passing the MMAM to the TLE class instance directly, right?

Like this one? 😁

def test_from_mmam_xml(self):
"""Test reading from an MMAM XML file."""
from tempfile import TemporaryDirectory
save_dir = TemporaryDirectory()
with save_dir:
fname = os.path.join(save_dir.name, '20210420_Metop-B_ADMIN_MESSAGE_NO_127.xml')
with open(fname, 'w') as fid:
fid.write(tle_xml)
tle = Tle("", tle_file=fname)
self.check_example(tle)

@mraspaud
Copy link
Member

Ah, sorry, missed it!

@pnuu pnuu merged commit cbe67e2 into pytroll:main Nov 29, 2021
@pnuu pnuu deleted the feature-tle-admin-messages branch November 29, 2021 11:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants