question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

sgp4.wrapper.Satrec objects can't be pickled

See original GitHub issue

…but sgp4.model.Satrec objects can:

In [1]: from sgp4.api import Satrec

In [2]: Satrec
Out[2]: sgp4.wrapper.Satrec

In [3]: line1, line2 = (
   ...:   "1 00005U 58002B   00179.78495062  .00000023  00000-0  28098-4 0  4753",
   ...:   "2 00005  34.2682 348.7242 1859667 331.7664  19.3264 10.82419157413667",
   ...: )
   ...: sat = Satrec.twoline2rv(line1, line2)
   ...: 

In [4]: sat
Out[4]: <sgp4.wrapper.Satrec at 0x5649605d0430>

In [5]: import pickle

In [6]: with open("/tmp/save.pkl", "wb") as fp:
   ...:     pickle.dump(sat, fp)
   ...: 
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-6-f3c37eb8fd19> in <module>
      1 with open("/tmp/save.pkl", "wb") as fp:
----> 2     pickle.dump(sat, fp)
      3 

TypeError: cannot pickle 'Satrec' object

In [7]: from sgp4.model import Satrec

In [8]: sat = Satrec.twoline2rv(line1, line2)

In [9]: with open("/tmp/save.pkl", "wb") as fp:
   ...:     pickle.dump(sat, fp)

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
brandon-rhodescommented, Jan 8, 2021

In summary: the lack of pickling support for sgp4.wrapper.Satrec objects is not affecting me (personally) at the moment, and quite probably adding some boilerplate code using TLEs or OMMs is good enough for serialization.

That’s my guess as well! For the moment, then, I am going to close this, as I don’t ever expect that we’ll add full pickling support for the Satrec C-language objects because of the issues mentioned above. But if you ever find a satellite that won’t correctly round-trip through OMM export and then OMM import, then simply open a new issue describing the problem, and we’ll get it fixed. Thanks!

0reactions
astrojuanlucommented, Jan 8, 2021

Until you commented here I had not considered the idea of using OMMs (or even TLEs) as the serialization format (silly, I know!) but it’s probably the way to go. I found this in https://github.com/satellogic/orbit-predictor/issues/117, but through two very simple __setstate__ and __getstate__ methods I worked around the pickling issue.

…But that was before reading your comment https://github.com/brandon-rhodes/python-sgp4/issues/80#issuecomment-748492738 here, so I’d also like to do some actual benchmarking and see if my solution was good enough or could be improved.

In summary: the lack of pickling support for sgp4.wrapper.Satrec objects is not affecting me (personally) at the moment, and quite probably adding some boilerplate code using TLEs or OMMs is good enough for serialization.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Establishing why an object can't be pickled - Stack Overflow
I would use dill , which has tools to investigate what inside an object causes your target object to not be picklable. See...
Read more >
sgp4 - PyPI
This Python package computes the position and velocity of an earth-orbiting satellite, given the satellite's TLE orbital elements from a source like ...
Read more >
Issues With Pickle Module — mod_wsgi 4.9.4 documentation
As can be seen, it is possible to pickle a function object. This can be done even through a copy of the function...
Read more >
vocab.txt - Hugging Face
... internal ##arg rol ##object attempt ##ined ##pec ##pol different eng methods angle instances slice dri gp await fp subelement wrapper equal ##ton...
Read more >
How to use Python's pickle module - YouTube
Python's built-in pickle library lets you take nearly any Python object, serialize it to a bytestream that can be saved to disk or...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found