Translating from python to java


I’ve been successfully running numerical orbit propagation using Orekit when using the python wrapper. I now need to convert this to java for the next step of my project but and running into issues.

I want to set up the propagator and given the same initial orbit propagate to successive time intervals. Using the code below:

	PVCoordinates[] pv_coord = new PVCoordinates[duration];	
	PVCoordinates tmp;
	for (int i = 0; i<duration; i++) {
			tmp = propagator_num.propagate(epochs[i]).getPVCoordinates();
			pv_coord[i] = tmp;

This works fine for i=0 but fails when i=1 trowing a “java.lang.NullPointerException” error. Is it necessary to create a new propagator for each instance of propagation? Thanks

A much better way to extract all coordinates is to run one propagation only from start to end and to use a step handler to pick up the coordinates on the fly.

If your epochs are separated by a fixed time step, this can be done as follows:

        final double timeStep = ...;
        final List<TimeStampedPVCoordinates> pv = new ArrayList<>();
        propagator.getMultiplexer().add(timeStep, s -> pv.add(s.getPVCoordinates()));

If your epochs are irregular, this is more involved. You should first create a step handler
to pick up the data at the dates you want:

    public PickupHandler implements OrekitStepHandler {

        private final List<TimeStampedPVCoordinates> pv;
        private final AbsoluteDate[] epochs;
        private int next;

        public PickupHandler(AbsoluteDate[] epochs) {
          this.pv     = new ArrayList<>();
          this.epochs = epochs.clone();
   = 0;

        void init(SpacecraftState s0, AbsoluteDate t) {
          while (next < epochs.length - 1 && epochs[next + 1].isBefore(s0)) {

        void handleStep(OrekitStepInterpolator interpolator) {
          while (next < epochs.length &&
                 epochs[next].isAfterOrEqualTo(interpolator.getPreviousState()) &&
                 epochs[next].isBefore(interpolator.getCurrentState()) {
            // the next epoch belongs to the range covered by the current step

        List<TimeStampedPVCoordinates> getPV() {
          return pv;

Then you use this step handler in the single propagation:

        final PickupHandler handler = new PickupHandler(epochs);
        final List<TimeStampedPVCoordinates> pv = handler.getPV();

Using one propagation only should be way faster than looping by yourself.

Thank you, I didn’t realise it was possible to extract intermediate steps from a single propagation.

I’m new to java and haven’t come across the “->” operator before can I ask what it does here? Thank you again.

It is a λ function, i.e. an anonymous function that is built and encapsulated on the fly to create an implementation of some interface (here OrekitFixedStepHandler) by implementing the only method in the interface that does not have a default implementation (here handleStep). The left part of the ‘->’ notation (here s) is the argument, and as OrekitFixedStepHandler.handleStep expects a SpacecraftState, it will be a SpacecraftState. The right part af the ‘->’ notation is the body of the function, which here is a single statement.

Also beware that in the two cases (regular or irregular epochs), we used two close be slightly different features.
In the first case, regular steps, we called the method add(timeStep, fixedHandler) from the step handler multiplexer. This method fixes the time step for calling the handler to the value specified by the first argument, and the fixed handler is called directly with a SpacecraftState at the correct time.
In the second case, irregular steps, we called the method add(variableStepHandler) from the step handler multiplexer. This method just follows the propagator decision about steps sizes and calls the handler giving it an interpolator that is valid throughout the step. The job to extract the SpacecraftState from the interpolator at any desired intermediate time is the responsibility of the handler in this case. If the propagator is an analytical propagator, the step size will be the full propagation, so the handler will be called once with a long range interpolator (backed by the analytical model). If the propagator is a numerical or semi-analytical model, the step size will depend on the underlying ODE integrator, and in most cases people use variable step size integrators like Dormand-Prince 8(5, 3), so the step size will vary throughout propagation.