Python binder event detection v.12

Since there have been significant improvements in handling events using the python wrappers with the new v.12, I thought I would share my updated version of the code

from org.orekit.bodies import GeodeticPoint
from org.orekit.bodies import OneAxisEllipsoid
from org.orekit.frames import FramesFactory
from org.orekit.frames import TopocentricFrame
from import ElevationDetector
from import EventsLogger
from org.orekit.utils import Constants as OrekitConstants
from org.orekit.utils import IERSConventions

def locate_event() :

    # Create earth
    earthFrame = FramesFactory.getITRF(IERSConventions.IERS_2010, True)
    earthBodyShape = OneAxisEllipsoid(OrekitConstants.WGS84_EARTH_EQUATORIAL_RADIUS, OrekitConstants.WGS84_EARTH_FLATTENING, earthFrame)
    # Creates the propagators
    orekitSat = # function to make orekit satellite
    station = GeodeticPoint(lat, lon, alt) 
    frame = TopocentricFrame(earthBodyShape, station, "name")

    passDetector = ElevationDetector(frame).withConstantElevation(threshold_elev)
    # Create events logger
    logger = EventsLogger()
    logPass = logger.monitorDetector(passDetector)
    # NOTE: Need to propagate to start time before can run event detector!
    # Otherwise risk bad pass data b/c of incorrect start times!
    # Propagates through until hit the stop time
    while sat.propagate(stop_time).getDate().isBefore(stop_time) :
    # Extracts events from the logger
    for i in range(0, logger.getLoggedEvents().size()) :
        # Get spacecraft state 
        s = logger.getLoggedEvents().get(i).getState()

@petrus.hyvonen I do have one question. Right now whether the satellite stops or continues to propagate when it encounters an event is automatically set by the EventDetector class used. It is not a big deal because all events are logged and you can simply continue to propagate the satellite until you hit your desired stop point, but Is there any way to set this condition manually in the python without resorting to a custom class such as was required in v.11? Thank you.

Hi there,

I believe you can do this:

stoppingDetector= passDetector.withHandler(StopOnEvent())

where StopOnEvent is to import from

This already existed in version 11 though


Hi @baubin ,

Nice you are sharing examples, and yes as @Serrof points out you can add an preset event handler (or ContinueOnEvent if you don’t want to stop).

If you want, you can also use propagate with (start_time, stop_time) and you can remove the first propagate (event detectors are not enabled before start time). With ContinueOnEvent you can then skip the .isBefore as well, just collecting the events to the logger.