Trouble with TLE generation using Python wrapper

I am attempting to generate a TLE set using the Python wrapper, and am not understanding why I see "TypeError: descriptor 'generate' for 'FixedPointTleGenerationAlgorithm' objects doesn't apply to a > 'SpacecraftState' object" My code:

import orekit
from orekit.pyhelpers import setup_orekit_curdir
vm = orekit.initVM()
setup_orekit_curdir()
from org.hipparchus.geometry.euclidean.threed import Vector3D
position = Vector3D(4692152.0, 4227918.0,-2746672.0)
velocity = Vector3D(2956.0, 1225.0, 6902.0)
from org.orekit import frames
frame_eme2000 = frames.FramesFactory.getEME2000()
from org.orekit import time
epoch = time.AbsoluteDate(2024, 7, 4, 4, 55, 38.0, time.TimeScalesFactory.getUTC())
from org.orekit import utils
absPVcoordinates = utils.AbsolutePVCoordinates(frame_eme2000, epoch, position, velocity)
from org.orekit import propagation
spacecraftState = propagation.SpacecraftState(absPVcoordinates)
tle_template = propagation.analytical.tle.TLE(
        "1 99219U          24186.17291666  .00000000  00000-0  50000-4 0    01",
        "2 99219  97.4000  39.2969 0001454   0.0000 144.8600 15.21937999    02")
from org.orekit.propagation.analytical.tle.generation import FixedPointTleGenerationAlgorithm
tle = FixedPointTleGenerationAlgorithm.generate(spacecraftState, tle_template)

Hi @jfitz2521,

The problem is that you are building the SpacecraftState with an AbsolutePVCoordinates, you need to use a CartesianOrbit to build the SpacecraftState for the algorithm to work.

1 Like

@pascal.parraud thanks for the quick response. I have adjusted my code to use a CartesianOrbit when constructing my SpacecraftState object, but still get the same TypeError: descriptor 'generate' for 'FixedPointTleGenerationAlgorithm' objects doesn't apply to a 'SpacecraftState' object complaint from Python. My second attempt:

import orekit
from orekit.pyhelpers import setup_orekit_curdir
from org.hipparchus.geometry.euclidean.threed import Vector3D
from org.orekit import time, utils, frames, orbits, propagation
from org.orekit.propagation.analytical import tle

vm = orekit.initVM()
setup_orekit_curdir()

position = Vector3D(4692152.0, 4227918.0,-2746672.0)
velocity = Vector3D(2956.0, 1225.0, 6902.0)
pvaCoordinates = utils.PVCoordinates(position, velocity)
date = time.AbsoluteDate(2024, 7, 4, 4, 55, 38.0,
        time.TimeScalesFactory.getUTC())
orbit = orbits.CartesianOrbit(pvaCoordinates,
        frames.FramesFactory.getEME2000(),
        date,
        utils.Constants.WGS84_EARTH_MU)
spacecraftState = propagation.SpacecraftState(orbit)
tle_template = tle.TLE(
    "1 99219U          24186.17291666  .00000000  00000-0  50000-4 0    01",
    "2 99219  97.4000  39.2969 0001454   0.0000 144.8600 15.21937999    02")
tle = tle.generation.FixedPointTleGenerationAlgorithm.generate(
        spacecraftState, tle_template)

Hello @jfitz2521,

I think that you need to instantiate your FixedPointTleGenerationAlgorithm before calling the generate method.

You can also use the static method available in the TLE class (documentation here):

TLE.stateToTLE​(SpacecraftState state, TLE templateTLE, TleGenerationAlgorithm generationAlgorithm)

Hope this helps !

Cheers,
Vincent

1 Like

Ahh, of course I need to instantiate the algorithm object! Now the error message makes perfect sense to me. Both my original attempt and your static method suggestion generate TLE sets that look just fine. For completeness demonstrating both techniques I ended up with:

import orekit
from orekit.pyhelpers import setup_orekit_curdir
from org.hipparchus.geometry.euclidean.threed import Vector3D
from org.orekit import time, utils, frames, orbits, propagation
from org.orekit.propagation.analytical import tle

vm = orekit.initVM()
setup_orekit_curdir()

position = Vector3D(4692152.0, 4227918.0,-2746672.0)
velocity = Vector3D(2956.0, 1225.0, 6902.0)
pvaCoordinates = utils.PVCoordinates(position, velocity)
date = time.AbsoluteDate(2024, 7, 4, 4, 55, 38.0,
        time.TimeScalesFactory.getUTC())
orbit = orbits.CartesianOrbit(pvaCoordinates,
        frames.FramesFactory.getEME2000(),
        date,
        utils.Constants.WGS84_EARTH_MU)

spacecraftState = propagation.SpacecraftState(orbit)
tle_template = tle.TLE(
    "1 99219U          24186.17291666  .00000000  00000-0  50000-4 0    01",
    "2 99219  97.4000  39.2969 0001454   0.0000 144.8600 15.21937999    02")

fptga = tle.generation.FixedPointTleGenerationAlgorithm()
tle = fptga.generate(spacecraftState, tle_template)
print(tle)

tle = tle.stateToTLE(spacecraftState, tle_template, fptga)
print(tle)

2 Likes

Glad it worked :wink: !

Thank you for providing a complete example, this will most probably be useful to other users :smiley: !

Cheers,
Vincent

1 Like