Java AttributeError associated with Abstract Analytical Propagator

Hi, Orekit forum!

I’m a new user of the orekit, I don’t know much about the orekit. I’m here to ask for your help.
I don’t know the reason for the unknown orekit error, It’s maybe about Propagation.
I compile using Python 3.7 with Pycharm.

The portion of the code that causes the error and the package you imported are as:

package:

import math
import logging
import orekit
from org.orekit.propagation.events.handlers import RecordAndContinue
from org.orekit.propagation.events.handlers import PythonEventHandler
from org.orekit.propagation.events import DateDetector
from org.orekit.frames import FramesFactory
from org.orekit.time import AbsoluteDate
from org.orekit.time import TimeScalesFactory
from org.hipparchus.ode.events import Action

code:

    def propagate(self, start, end, steps, mode=1, factor=2):
        self.setup_timesampler(start, end, steps, mode, factor)

        if end is None:
            self.propagator.propagate(start)

        elif None not in (start, end):
            # TODO: check value of shift, technically 1s should be enough
            shifted_start = start.shiftedBy(-60.0)
            shifted_end = end.shiftedBy(60.0)

            self.propagator.propagate(shifted_start, shifted_end)

else:
            raise CelestialBodyError("Invalid arguments for propagation.")

for your information, setup_timesampler is as:

    def setup_timesampler(self, start, end, steps, mode=1, factor=2):
        """Create and attach TimeSampler to propagator."""
        self.time_sampler = TimeSampler(start, end, steps, mode, factor).withHandler(
            self.event_handler
        )
        self.propagator.addEventDetector(self.time_sampler)

The error is printed as:

  File "C:\space\cb.py", line 103, in propagate
    self.propagator.propagate(shifted_start, shifted_end)
orekit.JavaError: <super: <class 'JavaError'>, <JavaError object>>
    Java stacktrace:
java.lang.RuntimeException: AttributeError
	at org.orekit.propagation.events.handlers.PythonEventHandler.init(Native Method)
	at org.orekit.propagation.events.AbstractDetector.init(AbstractDetector.java:95)
	at org.orekit.propagation.events.EventState.init(EventState.java:141)
	at org.orekit.propagation.analytical.AbstractAnalyticalPropagator.propagate(AbstractAnalyticalPropagator.java:133)

I can provide you with more code if necessary. Please, would you mind help me?
Many thanks.

Sky

Hey there,

The problem seems to lie with your home made detector.
Could you provide us with its implementation?
What version of Orekit are you using? I would suggest using the latest i.e. 11.3.2.

Best,
Romain.

Thank you for answer @Serrof
My orekit version is 11.2.
The code for implementing time detector is as:

class TimeSampler(DateDetector):
    """TimeSampler implementation."""

    def __init__(self, start, end, steps, mode=1, factor=2):
        start = AbsoluteDate(2009,1,1,TimeScalesFactory.getUTC())
        duration = end.durationFrom(start)
        dtime = duration / (steps - 1)
        dtout = dtime
        self.times = []
        time = 0.0
        self.recorder = RecordAndContinue()

        if mode == 1:
            for _ in range(0, steps):
                self.times.append(start.shiftedBy(time))
                time += dtime

        elif mode == 2:
            halfdur = duration / 2.0

            for _ in range(0, steps):
                time2 = (halfdur + math.sinh(
                    (time - halfdur) * factor / halfdur
                    ) * halfdur / math.sinh(factor))
                self.times.append(start.shiftedBy(time2))
                time += dtime
            dtout = duration * math.sinh(factor / steps) / math.sinh(factor)

        DateDetector.__init__(self, dtout / 2.0, 1.0, self.times)

Many thanks for the reply!

I found a person who came to the same error than looking at the forum.
My symptoms are completely the same.

My EventHandler code:

class TimingEvent(PythonEventHandler):
    """TimingEvent handler."""

    def __init__(self):
        """Initialise a TimingEvent handler."""
        PythonEventHandler.__init__(self)
        self.date_history = []
        self.pos_history = []
        self.vel_history = []
        self.rot_history = []
        self.events = 0

    def eventOccurred(self, s, detector, increasing):
        """Handle occured event."""
        self.events += 1
        if self.events % 1 == 0:
            logger.debug(f"{s.getDate()} : event {self.events}")

        self.date_history.append(s.getDate())
        self.pos_history.append(s.getPVCoordinates().getPosition())
        self.vel_history.append(s.getPVCoordinates().getVelocity())
        self.rot_history.append(s.getAttitude().getRotation())
        return Action.CONTINUE

    def resetState(self, detector, oldState):
        """Reset TimingEvent handler to given state."""
        return oldState

I’d appreciate it if anyone could see and help me.
Many thanks.