Skip to content

Commit

Permalink
Support satellite lookup by integer ID
Browse files Browse the repository at this point in the history
Fixes #167. Thanks for the good idea, @Tarlan0001!
  • Loading branch information
brandon-rhodes committed May 16, 2018
1 parent 4536fe1 commit fa34578
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.rst
Expand Up @@ -3,6 +3,13 @@ Changelog

.. currentmodule:: skyfield.positionlib

1.4 — 2018 ?
------------

* The dictionary of satellites returned when you read a TLE file
now supports lookup by integer satellite ID, not just by name.
`#167 <https://github.com/skyfielders/python-skyfield/issues/167>`_

1.3 — 2018 April 15
-------------------

Expand Down
1 change: 1 addition & 0 deletions skyfield/iokit.py
Expand Up @@ -354,6 +354,7 @@ def parse_celestrak_tle(fileobj):
line1 = next(lines).decode('ascii')
line2 = next(lines).decode('ascii')
sat = EarthSatellite(line1, line2, name)
yield sat.model.satnum, sat
yield name, sat
if ' (' in name:
# Given `ISS (ZARYA)` or `HTV-6 (KOUNOTORI 6)`, also support
Expand Down
7 changes: 4 additions & 3 deletions skyfield/tests/test_io_parsing.py
Expand Up @@ -15,6 +15,7 @@
def test_celestrak():
f = BytesIO(sample_celestrak_text)
d = dict(parse_celestrak_tle(f))
assert len(d) == 4
assert d['ISS'] == d['ISS (ZARYA)'] == d['ZARYA']
assert d['FLOCK 2E-1']
assert len(d) == 6
assert d[25544] is d['ISS'] is d['ISS (ZARYA)'] is d['ZARYA']
assert d[41483] is d['FLOCK 2E-1']
assert d[25544] is not d[41483]

5 comments on commit fa34578

@jak574
Copy link

@jak574 jak574 commented on fa34578 May 23, 2018

Choose a reason for hiding this comment

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

So how do we look up satellites by name now? My after updating to 1.4 my code now just gives a keyerror for referencing by name.

@brandon-rhodes
Copy link
Member Author

Choose a reason for hiding this comment

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

What does your code look like? The main routine for loading satellites still stores them in a dictionary by name as well as satellite ID, I think?

@jak574
Copy link

@jak574 jak574 commented on fa34578 May 23, 2018

Choose a reason for hiding this comment

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

science_url = 'http://celestrak.com/NORAD/elements/science.txt'
satellites = load.tle(science_url)
self.satellite = satellites['SWIFT']

I get "KeyError: 'SWIFT'"

@brandon-rhodes
Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks, I'll try looking at it this evening — feel free to create an Issue if you want a higher chance that I won't forget :)

@jak574
Copy link

@jak574 jak574 commented on fa34578 May 23, 2018

Choose a reason for hiding this comment

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

Great. I opened an issue just in case.

Please sign in to comment.