FedericoStra / tletools

Library to work with two-line element set files
MIT License
23 stars 13 forks source link

Development roadmap #1

Open FedericoStra opened 5 years ago

FedericoStra commented 5 years ago
kerel-fs commented 4 years ago

Hi Federico, thanks for this great library!

Fix support to convert a TLE to a poliastro.Orbit

I'm especially interested in improving the interoperability with poliastro and beyond as well. How do you like the following syntax (I didn't look into the details how to implement this yet though):

tle = TLE.from_lines(*tle_lines)
Orbit.from_classical(**tle)

This method allows tletools to be interoperable with all astrodynamics libraries which have the same naming convention as poliastro for classical elements.

edit: added some reasoning. :)

FedericoStra commented 4 years ago

Dear Fabian, thanks a lot for the interest in the library!

I didn't know about beyond, so I will have to research into it first.

Right now, the class tletools.tle.TLE has a method to_orbit which converts the TLE to a poliastro.twobody.orbit.Orbit. You can use it like this:

from tletools import TLE

tle_string = """ISS (ZARYA)
1 25544U 98067A   19249.04864348  .00001909  00000-0  40858-4 0  9990
2 25544  51.6464 320.1755 0007999  10.9066  53.2893 15.50437522187805"""

tle = TLE.from_lines(*tle_string.splitlines())
tle.to_orbit()

In this sense, the section Poliastro Interoperability in the documentation is a bit misleading, because the basic functionality is already present (now I have updated it).

What you suggest (Orbit.from_classical(**tle)) requires making tletools.tle.TLE a subclass of collections.abc.Mapping by implementing __getitem__, __iter__ and __len__. Once this is done, a tletools.tle.TLE instance can then be used in dictionary unpacking. The problem I see with this approach is that the returned mapping should contain only the keys attractor, a, ecc, inc, raan, argp and nu. A tletools.tle.TLE instance already has a way to be converted explicitly to a dict (check the asdict method), but the returned dictionary contains a lot more keys. You also see that the attractor key is necessary to work with poliastro, but maybe not with beyond.

In my opinion, any dict-like appearance of tletools.tle.TLE should reflect the structure of TLE, not what is required by poliastro to build an orbit. In particular, a TLE does not contain neither a nor nu, and this is reflected by tle.asdict() not returning those. Since it is so common to need a and nu, you can instead call tle.asdict(computed=True) to get a dictionary that contains also the computed values a and nu.

In conclusion, regarding the support for poliastro, for the moment I would stick with tle.to_orbit(). It is explicit and avoids implementing inheritance of Mapping which is in conflict with asdict.

FedericoStra commented 4 years ago

What I would like to do in the long term to support interoperability better is to

This way you could for instance pip install tletools[poliastro] to have poliastro interoperability and not worry about pandas if you don't need it.

This is probably overkill for such a small project.

astrojuanlu commented 4 years ago

Hi @FedericoStra! @kerel-fs brought me here, I'm the author of poliastro :) I've been thinking about integrating TLE reading in poliastro for quite some time and I'm happy someone else is doing it. Let me know if I can be of any help!

astrojuanlu commented 4 years ago

I also took the liberty to add your repo here, hope you don't mind! https://github.com/poliastro/poliastro/wiki/Projects-using-or-citing-poliastro