Add python post-processing scripts to Orekit tutorials

In the Orekit tutorials, there are some examples that could really benefit from having simple python post-processing scripts, mainly to display interactive plots with plotly or matplotlib.

The examples remain written in Java, but for plotting it seems that python is a lot easier to handle than Java. It also avoids adding Java plotting libraries as extra dependencies for the tutorials.

The tutorial I’m working on currently is about generating porkchop plots and estimating an optimal two-impulse transfer between two orbits (in terms of overall delta-V). It comes directly from some work I had to do last year.
It currently generates a CSV file with all the delta-V values as a function of departure date and transfer time. But an image is always more telling that a thousand words. And providing a means to generate these images would be nice.

I would like to propose to regroup all the python post-processing scripts in the folder “orekit-tutorials/src/main/python”.

Another idea would be to include some post-processing python code in the markdown version of the tutorial, and let the interested users copy-paste that code into their own python script. It seems more cumbersome to me, especially for long-winded python codes, where the purpose is just to plot stuff and not explain how to plot it.

What do you think about this idea ?

2 Likes

It seems a good idea to me.
I am really a big fan of gnuplot, but if you prefer python, it’s fine.

Hi Jerome,

The python jpype wrapper has an example section that is rather sparse. If your tutorial is very graphically oriented, why not contributed it there? Since the jpype syntax is almost identical to the java one, people would still be able to pick up snippets for their own use.

Cheers,
Romain.

Hi, there are much more elaborate examples at GitHub - petrushy/orekit_jpype_examples (should probably be moved to the orekit gitlab) and one example with a project with mixed “user-side” java and python code at GitHub - petrushy/jpype_java_extension_example

But I guess @JTabeaud initial question is more on running some scripts automated in the documentation generation?

Hello,

I think it was just providing a plotting script for a starter. But you’re right, running some scripts automated in the document generation would be very nice.

Do you think that moving them to where @JTabeaud wants to put Python files “orekit-tutorials/src/main/python” would be a good option ?
That way we could have tutorials for both languages in a single repo. The only issue would be that sometimes the two versions will be different (between a Java release and a Python release)

Hi everyone,

My initial idea was to provide mostly plotting examples to post-process the existing tutorials’ text and file outputs, whether they are written in Java or python. They do not need to be automatically called by the pipeline or the java examples, but it would provide a good basis for the users to plot and make sense of the data they generate using Orekit. In the markdown versions of the tutorials, the post-processing scripts can be mentioned and the resulting plots can be directly included (as PNGs) to illustrate better what the tutorial is teaching.

The tutorial I’m working on is currently written in Java, as the classes supporting it were initially all in Java and it was the most logical approach to keep everything in the same language. I could of course translate it to python using the jpype wrapper and seemlessly integrate the plots in the tutorial itself. But it is not particularily heavily graphically oriented per se.

I am not really familiar with gnuplot and I don’t really have any experience with it. I do prefer python for all the flexibility it offers with all the packages available online (matplotlib, plotly, cairo, 3d graphics libraries, etc). It allows to do virtually anything we could possibly want to do, and it is very likely that the people looking at the Orekit tutorials know something about python.

I was also wondering if it would not make more sense to merge all the tutorials (java and jpype) in orekit-tutorials, so that anyone who wants to learn about Orekit just has to download the one and only orekit-tutorials repo and then looks either into the java/ folder or in the python/ folder, depending on their needs.

There is also another idea that sprouted after talking with @MaximeJ about the maintenance of the tutorials, especially when the interfaces change from one major version of Orekit to the next. It currently requires people to manually update all the tutorials, both in raw code but also in the markdown version, along with all the code snippets whithin it.
I wrote a little python utility script to automatically extract code snippets from any code source file to insert it in a markdown (or latex, or HTML, or anything text-based, really). With that tool, only the source file is modified to fit the changes in API, and the markdown files are processed automatically to include the up-to-date code. That tool would be best called automatically when “mvn site” is called, as a pre-processing step.
This little script, along with a working example, is viewable on my self-hosted repository.

Cheers

I remember that some time ago, I did add a GroundTrack tutorial that generates 2D or 3D plots using gnuplot. I used it to generate some images for ISAE-Sup’Aéro students.

Just a side note, @luc. I had tried to do the same thing that you did with gnuplot but with Python.
This means wrapping the call to a Python plot function in a ProcessBuilder Java object.
But I remember I had problems with loading the proper Python environment from within Java and I wasn’t able to load libraries like numpy or plotly.
But by that time I used Anaconda which I tend to avoid now. So maybe it would work better. I’ll have to give it another try when I have time.

Hi Maxime, yes now with jpype version it should be possible to use pip install and most toolchains. If you can, try uv as package manager, very smooth imho.

1 Like