Getting Access to Event Handler Data

LookAngleGenerator.java (14.5 KB)

I am trying to get the rise/set times out of the EventHandler using the EventLogger but am obviously am not doing something in the correct way. I want to grab these times in order to generate the look angles for use in an OD routine. Any assistance will be appreciated.

Hi Stephen,

Here are some remarks I can make on your code:

In the section

        // Add event to be detected
        numProp.addEventDetector(sta1Vis);
        numProp.addEventDetector(sta2Vis);
        numProp.addEventDetector(sta3Vis);
        numProp.addEventDetector(sta4Vis);

        numProp.addEventDetector(logger.monitorDetector(sta1Vis));
        numProp.addEventDetector(logger.monitorDetector(sta2Vis));
        numProp.addEventDetector(logger.monitorDetector(sta3Vis));
        numProp.addEventDetector(logger.monitorDetector(sta4Vis));

The first four lines should be removed as the detectors should be added only wrapped in the logger, not directly. When the detectors are added both directly and wrapped, they are triggered twice.

In the section

        List<EventsLogger.LoggedEvent> allEvents = logger.getLoggedEvents();    
        SpacecraftState finalState = numProp.propagate(new AbsoluteDate(initialDate, 12000.0));

The two statements should be interchanged so the events are collected from the logger after the propagation has been performed. With lines in their current order, the events list is empty because nothing has been computed yet.

In the section

        for (extrapDateP = initialDate; extrapDateP.compareTo(finalDateP) <= 0; extrapDateP = extrapDateP.shiftedBy(stepT)) {
                SpacecraftState extrapState = numProp.propagate(extrapDateP);
                ...
        }

It would be better to use a first a single propagation from initialDate to finalDateP using ephemeris generation mode, and then a second propagation using the generated ephemeris in master mode with an OrekitFixedStepHandler with a step size set to stepT. The current loop that uses several one minute propagations in the numerical propagator reset the generated ephemeris each time a propagation is run. This implies that at the end of the loop, the generated ephemeris only covers the last one minute time span corresponding to the last iteration of the loop.

Luc,
Thank you very much for your helpful comments. Making the changes you suggested I get the following when I run the code:
System.out.println(" allEvents " + allEvents.size() );
System.out.println(" allEvents " + allEvents.get(0) );

allEvents 15
allEvents org.orekit.propagation.events.EventsLogger$LoggedEvent@6a2bcfcb

How do I convert the last line into rise/set times to use for computing my azimuth, elevation and range values?
(I appreciate your patience as I am an astrodynamicist who is working to learn Java.)
When I try:
String str1 = allEvents.get(0).toString();
System.out.println(" str1 " + str1);
I get the same representation:
str1 org.orekit.propagation.events.EventsLogger$LoggedEvent@6a2bcfcb

Thanks for the comments on the propagation. I now understand why the visibility were triggering again during my propagation loop.

The allEvents.get(0) will return a EventsLogger.LoggedEvent object which is a small container holding three properties:

  • the detector that was triggered
  • the Spacecraft state at the event occurrence
  • the increasing boolean describing the event slope direction

If I understand your needs, you want to compute the azimuth/elevation at event occurrence (which can be used to check elevation is zero since there is no refraction model used here). Here is how you get them:

  for (EventsLogger.LoggedEvent logged : allEvents) {
    ElevationDetector detector = (ElevationDetector) logged.getEventDetector();
    TopocentricFrame station = detector.getTopocentricFrame();
    SpacecraftState state = logged.getState();
    double azimuth = station.getAzimuth(state.getPVCoordinates().getPosition(),
                                        state.getFrame(),
                                        state.getDate());
    double elevation = station.getElevation(state.getPVCoordinates().getPosition(),
                                        state.getFrame(),
                                        state.getDate());
    System.out.println(station.getName() + " " +
                       (logged.isIncreasing() ? "raising" : "setting") + " " +
                       state.getDate() + " " +
                       FastMath.toDegrees(azimuth) + " " +
                       FastMath.toDegrees(elevation));
  }

Note that if you want to improve accuracy, you can set up a refraction model in the elevation detector and in the print loop above fix the geometric elevation by adding the following line just before the print:

   elevation += refractionModel.getRefraction(trueElevation);

Thanks again for you help. That is exactly what I am looking for.