-
-
Notifications
You must be signed in to change notification settings - Fork 217
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
Cannot use skyfield.api.load.tle .items() function #345
Comments
I am not sure that Python supports |
Yes, it does and I use it a lot, for instance for filtering. See the first example here. |
The first example says:
which is very different than |
True, I'll edit this in OP... In [1]: test = {"a": (1,2,3), "b": (4,5,6)}
In [2]: k, v = test.items()
In [3]: k
Out[3]: ('a', (1, 2, 3))
In [4]: v
Out[4]: ('b', (4, 5, 6)) It worked by accident because the two-item iterator was unpacked into two values. Not what I wanted to do. In [5]: for k, v in test.items():
...: print(k, v)
...:
a (1, 2, 3)
b (4, 5, 6) That's what I meant to show. And here's what is odd: In [8]: satellites[900]
Out[8]: <EarthSatellite 'CALSPHERE 1' number=900 epoch=2020-02-27T20:23:16Z>
In [9]: satellites["CALSPHERE 1"]
Out[9]: <EarthSatellite 'CALSPHERE 1' number=900 epoch=2020-02-27T20:23:16Z> both work, but the In [5]: import skyfield.api as skyapi
...: loader = skyapi.Loader(r"~/.skyfield-data")
...: active_satellites_url = "http://celestrak.com/NORAD/elements/active.txt"
...: satellites = loader.tle(active_satellites_url)
...:
...: for k, v in satellites.items():
...: print(type(v))
...: if "O3B" in k:
...: print(k, v)
...:
<class 'skyfield.sgp4lib.EarthSatellite'>
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-5-3eef8217fce2> in <module>
6 for k, v in satellites.items():
7 print(type(v))
----> 8 if "O3B" in k:
9 print(k, v)
10
TypeError: argument of type 'int' is not iterable So filtering is problematic because the IDs and string labels come interleaved. In [10]: for i, (k, v) in enumerate(satellites.items()):
...: print(k)
...: if i > 10: break
...:
900
CALSPHERE 1
902
CALSPHERE 2
1361
LCS 1
1512
TEMPSAT 1
1520
CALSPHERE 4A
2826
OPS 5712 (P/L 160) What kind of structure is below this? Is it simply a dict with two entries per satellite? |
It is a dictionary that allows lookup by satellite number or satellite name: https://rhodesmill.org/skyfield/api-iokit.html#skyfield.iokit.Loader.tle Would it help if I expanded the discussion in the main "Earth Satellites" document: https://rhodesmill.org/skyfield/earth-satellites.html — instead of relying on folks to click through to the |
No, don't regret it just because I didn't get it right away ^^. from collections import UserDict
class SatelliteList(UserDict):
"""Using `collections.UserDict`, this wrapper behaves mostly like
a dict but provides a couple of extra functions.
"""
def filter(self, pattern):
filtered_dict = {k: v for k, v in self.data.items() if isinstance(k, str) and pattern in k}
return filtered_dict It simply makes sure the pattern is only checked against I think it's not too difficult to include some added functionality. There are other prototypes in I've forked your repo and can provide you with a pull request if you're interested. |
That's an interesting idea! My first thoughts are:
So in a couple of weeks, when I'll have time to look over the code, I'll probably create a new replacement for At least I've learned a bit about programming since I wrote that function. Alas! |
Thanks for the fruitful discussion. Thats a good plan. |
There, that should help! The improved, simplified routine should be available the next time I release Skyfield. |
Thank you very much! :-) |
I came across a slightly odd behaviour when trying to filter the dict of objects loaded using
skyfield.api.load.tle
.Let's say, I want to load the list of active satellites from Celestrak and among them filter for a bunch of Cubesats (let's say AEROCUBE), I run in trouble:
results in
But it's listed as a
dict
and the.keys()
and.values()
functions work as expected. And.items()
does in fact return adict_items
object as expected:If I create a test
dict
, it works well:I am using
The text was updated successfully, but these errors were encountered: