Orekit Subclassing in Matlab

Hi all,

I feel I identified a huge stopper to continue using orekit in Matlab.
As we know, using it from Matlab relies on the wrapper accessing the compiled .jar.

Soon the necessity comes up to subclass, e.g. the “OrekitFixedStepHandler”.

For Pyhton there seems to appear a “PyhtonOrekitFixedStepHandler”, however for Matlab this seems not to.

So the question is: is this observation correct? It is not possible to subclass orekit classes in Matlab itself?

If yes, how dramatic do you see this. For me it appears to be a show stopper as soon as you want to use oerkit a bit more customized.

Cheers!

Hi,

You can write your custom classes in Java and pass the .jar as you said yourself to Matlab.

Cheers

Thanks. But for this I need to compile orekit in a Java IDE in order to create the .jar, correct?

You need to compile your Java code into a .jar, preferably using Maven. But you don’t have to package Orekit in your custom .jar, that way your custom.jar will be relatively small.

Thank you!
So simply asking for a concrete example:

In the “propagation tutorial/Intermediate states”:
https://www.orekit.org/site-orekit-tutorials-11.0/tutorials/propagation.html

it is required to have a custom “TutorialStepHandler” by implementing the “OrekitFixedStepHandler”.
How would I do this in Matlab?
Is this the case where I need to do it in Java, compile it to a .jar and then use in Matlab.
Or is there a way to do the implementation directly in Matlab?

private static class TutorialStepHandler implements OrekitFixedStepHandler {

    public void init(final SpacecraftState s0, final AbsoluteDate t, final double step) {
        System.out.println("          date                a           e" +
                           "           i         \u03c9          \u03a9" +
                           "          \u03bd");
    }

    public void handleStep(SpacecraftState currentState, boolean isLast) {
        KeplerianOrbit o = (KeplerianOrbit) OrbitType.KEPLERIAN.convertType(currentState.getOrbit());
        System.out.format(Locale.US, "%s %12.3f %10.8f %10.6f %10.6f %10.6f %10.6f%n",
                          currentState.getDate(),
                          o.getA(), o.getE(),
                          FastMath.toDegrees(o.getI()),
                          FastMath.toDegrees(o.getPerigeeArgument()),
                          FastMath.toDegrees(o.getRightAscensionOfAscendingNode()),
                          FastMath.toDegrees(o.getTrueAnomaly()));
        if (isLast) {
            System.out.println("this was the last step ");
            System.out.println();
        }
    }

}

Cheers

Yes if you need to process the intermediate states you have to implement the OrekitStepHandler or OrekitFixedStepHandler interface, but it’s not mandatory.

Yes this is the case where you have to compile the Java code and pass the .jar to Matlab (but maybe it is possible to implement interfaces directly in Matlab? I haven’t used Matlab for a long time).

Btw you are using an older version of the tutorials for Orekit 11.0. If you are starting a new project I recommend using the latest version based on Orekit 12.2: Orekit Tutorials – Propagation

Thanks! I got orekit running and compiling in a Java IDE.
The builder results in the orekit.jar which I then load and use from Matlab side.

How would I do it here very practically speaking:

I need to code a Java class which implements the OrekitFixedStepHandler, but where in the Java src would I put this piece of code, so later I have it packed and available in the .jar for Matlab?

Would it make sense to introduce another folder in the src/main/java/org/orekit e.g. “customs”, implement the “TutorialStepHandler” here and include it into the build to retrieve the .jar with it in the end to have it available on Matlab side?

(I hope it’s not too confusing^^)

Cheers, Alex

I would rather recommend to write your custom Java code in a separate repository. You don’t need to have it in the Orekit repo, you should just define the Orekit&Hipparchus dependencies in your Maven pom.xml file.

Ok, good I did it as you proposed. All good.

General Java ↔ Matlab question here:
Imagine I want the CustomStepHandler at every step, write data into a variable which I can access as well from Matlab side.

So e.g. the KeplerianElements of the current propagation step.

How do I do that? Would I need to define a additional property on Java side. Could I also call a Matlab function from Java side in case of the step?

Cheers, Alex

As you said yourself, you should write the data at every step into a public member variable (an array) of your Java step handler. After the propagation, you can then access this public variable from Matlab.

As to your last question, you cannot access a Matlab function from Java, only the other way round, you can only call Java code from Matlab.