Custom handler Java runtime exception

Hi all, I would like to implement a custom handler to get sun vector position relative to spacecraft frame. Looking in some examples I am implementing it as shown in the code below.

class SunvectorPosHandler(PythonOrekitFixedStepHandler):
    def __init__(self, angle):
            # set up Earth model
   = OneAxisEllipsoid(Constants.WGS84_EARTH_EQUATORIAL_RADIUS,
                                         FramesFactory.getITRF(IERSConventions.IERS_2010, False))
            self.sun = CelestialBodyFactory.getSun()
            self.sunRadius = Constants.SUN_RADIUS

            self.dates = []
            self.sunXs = []
            self.sunYs = []
            self.sunZs = []
            # Initialize the superclass as well
            super(CorridorHandler, self).__init__()
    def init(self, s0:SpacecraftState, t:AbsoluteDate, step: float):
        # needs to be stated to fulfill the interface specification
    def handleStep(self, currentState: SpacecraftState):
        inertToSpacecraft = currentState.toTransform()
        date    = currentState.getDate()
        sunInert = self.sun.getPVCoordinates(date, currentState.getFrame()).getPosition()
        #sunSat = inertToSpacecraft.transformPosition(sunInert)
        #sunX = sunSat.getX() / sunSat.getNorm()
        #sunY = sunSat.getY() / sunSat.getNorm()
        #sunZ = sunSat.getZ() / sunSat.getNorm()
    def finish(self, finalState: SpacecraftState):

handler = CorridorHandler(ANGULAR_OFFSET)
Propagator.cast_(propagator).setStepHandler(STEP, handler)

start = epochDate
propagator.propagate(start, start.shiftedBy(DURATION))

It throws the following:

JavaError Traceback (most recent call last) Cell In[9], [line 2]
start = epochDate 
---->propagator.propagate(start, start.shiftedBy(DURATION)) JavaError: <super: <class 

'JavaError'>, <JavaError object>> Java stacktrace: java.lang.RuntimeException: AttributeError 
at org.orekit.propagation.sampling.PythonOrekitFixedStepHandler.handleStep(Native Method)
at org.orekit.propagation.sampling.OrekitStepNormalizer.handleStep(
at org.orekit.propagation.sampling.StepHandlerMultiplexer.handleStep(
at org.orekit.propagation.analytical.AbstractAnalyticalPropagator.acceptStep(
at org.orekit.propagation.analytical.AbstractAnalyticalPropagator.propagate(

If I comment the line
sunInert = self.sun.getPVCoordinates(date, currentState.getFrame()).getPosition()

Then it runs ok.

Could anyone please guide me on what could be happening here?
Thank you

Hi, see:

Hi Petrus, thank you very much! That worked for that line. Now, when I uncomment the following line

sunSat = inertToSpacecraft.transformPosition(sunInert)

Now the same error. I didn’t get well the explanation in the link you shared:

I think this is true in general with the Python wrapper when you want to use a method from an interface implemented by a class: the class must be explicitely casted to the interface.

How is this applied to this new line?
And sorry for this newbie questions, I’m not a great python coder neither, but learning.

Thank you!


Think you need to cast as StaticTransform.


Hi Serrof,

Yes, I get more or less the idea, but can’t figure exactly the implementation for the line

sunSat = inertToSpacecraft.transformPosition(sunInert)

Sorry :pray:
And thanks in advance if you guide me more on this.

Ok, I get it. I must modify the line from:

sunSat = inertToSpacecraft.transformPosition(sunInert)


sunSat = StaticTransform.cast_(currentState.toTransform()).transformPosition(sunInert)

Thanks for you guidance.