PythonEventHandler problem

Hi, Orekit forum.
I think there’s a problem with EventHandler.
I compile using Python 3.7 with Pycharm, orekit version is 11.2.

Occurred error:

  File "C:\cb.py", line 84, in setup_timesampler
    self.event_handler
orekit.InvalidArgsError: (<class 'cb.TimeSampler'>, 'withHandler', <TimingEvent: {-76,733.9124456846; -64,040.5502612592; 3,273.3168213818}>)
Error: Not freed memory blocks: 8, total unfreed memory 0.010223 MB

Process finished with exit code 1

The relevant codes are as(timesampler and timingevent(PythonEventHandler)):

from org.orekit.propagation.events.handlers import PythonEventHandler

...(skip)...

class CelestialBody():

        self.event_handler = TimingEvent().of_(TimeSampler)
        self.time_sampler = None

        self.date_history = self.event_handler.date_history
        self.pos_history = self.event_handler.pos_history
        self.vel_history = self.event_handler.vel_history
        self.rot_history = self.event_handler.rot_history

    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)

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

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

    def init(self, initialstate, target):
        pass

    def eventOccurred(self, s, T, 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

If anyone knows about EventHandlers, please help.
I can provide you with more code if necessary.
Many thanks.

Sky

Hi Sky,

There are some examples of EventHandler in Python in the test suites, if you haven’t seen them please have a look at them, that may give you some examples. orekit_python_artifacts/test at version-11.3 · petrushy/orekit_python_artifacts · GitHub

It seems to fail on the TimeSampler initialization, this is your own class I think?

Regards