Add OreCzml to orekit-jpype

Hello,
I am new to orekit python wrapper. I’d like to know how to integrate the new OreCzml to orekit-jpype (Files · master · Orekit / OreCZML · GitLab).

How can I achieve this ?

2 goals :

  • a python env to run python projects with orekit & oreczml
  • a python env as language server for vscode with orekit & oreczml
    … both running as docker

For now, it works but with a stock conda prepared environnement and the “old” wrapper… without oreczml.

Thanks !

Hi @Koxx3 ,

This is indeed an interesting area, I have done some initial work on it but it is still quite rough. The cesiumjs widgets that are currently available for jupyterlab is quite limited and basic.

Check my branch at Files · oreczml_example · Orekit / orekit_jpype · GitLab
In the examples there is a notebook which shows an orbit as a widget, based on oreczml.

1 Like

oh !!! nice ! thank you.
I’ll have a look :wink:

working good !

import os
import jdk4py
#######################################################################
# USE IN ALL SCRIPT - Ensure print statements are flushed immediately
import functools
print = functools.partial(print, flush=True)
#######################################################################


import orekit_jpype
libjvm_path = os.path.join(jdk4py.JAVA_HOME, "lib", "server", "libjvm.so")
print(f"libjvm_path: {libjvm_path}")
orekit_jpype.initVM(jvmpath=libjvm_path)

from orekit_jpype.pyhelpers import setup_orekit_curdir
setup_orekit_curdir("/app/orekit-data.zip")
print("setup_orekit_curdir : ok")

from org.orekit.time import AbsoluteDate, TimeScalesFactory
from org.orekit.orbits import KeplerianOrbit, PositionAngleType
from org.orekit.frames import FramesFactory
from org.orekit.utils import Constants, IERSConventions
from org.orekit.bodies import OneAxisEllipsoid
from org.orekit.propagation.analytical import KeplerianPropagator
from org.orekit.propagation.numerical import NumericalPropagator
from org.orekit.propagation import SpacecraftState
from org.orekit.forces.gravity.potential import GravityFieldFactory
from org.orekit.forces.gravity import HolmesFeatherstoneAttractionModel
from org.orekit.forces import ForceModel
from org.hipparchus.ode.nonstiff import DormandPrince853Integrator
from org.hipparchus.util import FastMath
from java.awt import Color
from org.orekit.czml.file import CzmlFile, CzmlFileBuilder
from org.orekit.czml.object.primary import Satellite, GroundTrack, Header
from org.orekit.czml.object.secondary import Clock
from org.orekit.orbits import OrbitType

# Paths
root = "."
pathToJSFolder = root + "/Javascript/public/"
output = root + "/czml.json"
print("output : ", output)

def list_files(directory='.'):
    print(f"Listing files in directory: {directory}\n")
    for dirpath, dirnames, filenames in os.walk(directory):
        # Compute the relative path from the starting directory
        rel_dir = os.path.relpath(dirpath, directory)
        # Handle the case when rel_dir is '.'
        rel_dir_display = '' if rel_dir == '.' else f"{rel_dir}/"
        for filename in filenames:
            print(f"- {rel_dir_display}{filename}")


list_files()

 # Creation of the clock
UTC = TimeScalesFactory.getUTC()
durationOfSimulation = 10 * 3600  # in seconds
stepBetweenEachInstant = 60.0  # in seconds
startDate = AbsoluteDate(2024, 3, 15, 0, 0, 0.0, UTC)
finalDate = startDate.shiftedBy(durationOfSimulation)
clock = Clock(startDate, finalDate, UTC, stepBetweenEachInstant)


print("clock : ", clock)

header = Header("Visualisation of a ground track of a satellite", clock, pathToJSFolder)

# Build of an MEO orbit
EME2000 = FramesFactory.getEME2000()
initialOrbit = KeplerianOrbit(10878000, 0, FastMath.toRadians(20), 0,
                              FastMath.toRadians(0), FastMath.toRadians(0), PositionAngleType.MEAN, EME2000, startDate,
                              Constants.WGS84_EARTH_MU)

initialState = SpacecraftState(initialOrbit)

positionTolerance = 10.0
minStep = 0.001
maxStep = 1000
provider = GravityFieldFactory.getNormalizedProvider(10, 10)
holmesFeatherstone = HolmesFeatherstoneAttractionModel(EME2000, provider)

tolerances = NumericalPropagator.tolerances(positionTolerance, initialOrbit, OrbitType.CARTESIAN)
integrator = DormandPrince853Integrator(minStep, maxStep, tolerances[0], tolerances[1])

propagator = NumericalPropagator(integrator)
propagator.setOrbitType(OrbitType.CARTESIAN)
propagator.addForceModel(holmesFeatherstone)
propagator.setInitialState(initialState)

generator = propagator.getEphemerisGenerator()
propagator.propagate(startDate, finalDate)
boundedPropagator = generator.getGeneratedEphemeris()

# Creation of the satellite
# satellite = Satellite.builder(boundedPropagator, header).withModelPath("demo/orekit/cmzl/satellite.png").build()
satellite = Satellite.builder(boundedPropagator, header).build()

# Creation of the model of the earth
IERS = IERSConventions.IERS_2010
ITRF = FramesFactory.getITRF(IERS, True)
earth = OneAxisEllipsoid(Constants.WGS84_EARTH_EQUATORIAL_RADIUS,
                         Constants.WGS84_EARTH_FLATTENING, ITRF)


# Build of the ground track
groundTrack = GroundTrack.builder(satellite, earth, header).withColor(Color(255, 10, 20)).build()

# Creation of the file
mfile = CzmlFile.builder().withHeader(header).withSatellite(satellite).withGroundTrack(groundTrack).build()

mfile.write(output)

# with open(output, 'r') as file:
#     # load as text file
#     data = file.read()
#     print("data = ", data)

print("done")

tomorrow, I’ll check it stubs for pyright/pylance are implemented to ease the coding pain :wink:

5 Likes

Wow super nice !

Thank you @petrus.hyvonen for guiding him to use OreCzml in python !

I will use this topic as a reference for people who want to use OreCzml in python.

1 Like