shashwatak / satellite-js

Modular set of functions for SGP4 and SDP4 propagation of TLEs.
MIT License
902 stars 145 forks source link

Added function `json2satrec` in `io.js` #122

Open spacenewb opened 1 year ago

spacenewb commented 1 year ago

Added function json2satrec in io.js to initialise sgp4init object and build satrec object from OMM data in JSON format. Ref: A New Way to Obtain GP Data (aka TLEs).

This is the new way of distributing TLEs and would become the new standard soon. It is better to port our functions slowly for compatibility.

105

thkruz commented 1 year ago

Thanks for taking the time to help future proof this library!

We need to add some unit tests for this new function. Might be smart to have at least a few that make sure it is getting the same answer as the original function.

I'll take a look in the airport tomorrow, but the comment block on this looks incorrect. It mentions more input functions than are available. Additionally there are a lot of leftover comments from copying the original function - if we are modernizing the library there is no benefit of keeping old comments that don't apply.

spacenewb commented 1 year ago

Overall I think this is in the right direction. It needs a little polish. I will try to find some time to write tests in the near future, but if anyone else can it would be great. We need to validate that it makes the same satrec object as the main function.

I did perform some basic tests, but I am not so proficient in JS, to write unit tests. But there seems to be a way to compare two objects using a method named _.isEqual from a library called Lodash. Everything seemed to be exactly the same except for the difference in the satrec.epoch.

The old and the new methods seemed to vary in the 8th decimal place due to some floating point magic which was beyond my understanding as a non-CS background person. this translates to a difference in a couple of milliseconds.

If there are ways to check if these are within a certain tolerance while writing the tests, that would be optimal.

thkruz commented 1 year ago

I opened a PR (https://github.com/spacenewb/satellite-js/pull/1) on your PR to incorporate the changes I suggested and add the testing.