galactics / beyond

Flight Dynamic Library
MIT License
49 stars 8 forks source link

Fix : convert orbit only if needed #34

Closed kerel-fs closed 2 years ago

kerel-fs commented 2 years ago

If the orbit was manually generated from a state vector, propagator-specific arguments have to be added manually. Converting the orbit drops those issues, making it impossible to output TLEs from manually created orbit objects.

After applying the given patch, the following script can be used to generate TLEs from a given state vector in keplarian form (and additionally needed values):

#!/usr/bin/env python3
# Script to generate a TLE from state vector of Keplarian form in TEME

import numpy as np
from beyond.io.tle import Tle
from beyond import dates, orbits, frames

data = {
'sv': {
    'a':  6783984.563, # m
    'e':  0.0002419,
    'incl':  0.9013159509979036, # rad
    'raan':  1.6582443036368206, # rad
    'omega': 4.122788833792973, # rad
    'nu':  5.651523323887538 #rad
},
'date': 58487.59354167, #mjd
'ndot': 1.43e-05,
'ndotdot': 0.0,
'bstar': 1.8267e-05,
'revolutions': 14983,
'element_nb': 999,

'cospar_id': '1998-067A',
'norad_id': 25544
}

sv = orbits.StateVector([data['sv']['a'],
                         data['sv']['e'],
                         data['sv']['incl'],
                         data['sv']['raan'],
                         data['sv']['omega'],
                         data['sv']['nu']],
                         dates.date.Date(data['date']),
                         orbits.forms.KEPL,
                         frames.TEME)
orbit = sv.as_orbit(propagator="Sgp4")
orbit2 = orbit.copy(form="TLE")
orbit2.ndot = data['ndot']
orbit2.ndotdot = data['ndotdot']
orbit2.bstar =  data['bstar']
orbit2.revolutions = data['revolutions']
orbit2.element_nb = data['element_nb']

# optional:
orbit2.cospar_id = data['cospar_id']
orbit2.norad_id = data['norad_id']

tle = Tle.from_orbit(orbit2)
print(tle)

# Output:
# 1 25544U 98067A   19004.59354167  .00000715  00000-0  18267-4 0  9995
# 2 25544  51.6416  95.0104 0002419 236.2184 323.8248 15.53730729149833
coveralls commented 2 years ago

Coverage Status

Coverage increased (+0.002%) to 92.028% when pulling 148ae285ec3720f847955b785eb9cabc3c7729bd on kerel-fs:pr/fix_tle_gen into 1326a03ef2c918244078c48f8878705510a8eb1d on galactics:master.

galactics commented 2 years ago

Hi kerel-fs, and thank you for your pull request !

In essence, the problem you encountered is "custom attribute copying" for StateVector objects, that did not work as intended. I thought I coded those classes such that all attributes were passed to copies, but the example you gave proved something was clearly missing. This explains a few errors I keep getting from time to time.

So I fixed the underlying issue in commit a81c6a8, and now you should have no problem in your script.

Thank you for bringing this to my attention