__init__ method messing up with PythonBatchLSObserver

I am trying to setup a custom BatchSLObserver in Python, and trying to replicate the Orekit OD Tutorial.

If I setup a simple observer like this one, everything works fine :

class CustomObserver(PythonBatchLSObserver):
    def evaluationPerformed(self, itCounts, 
           evCounts, orbits, orbParams, propParams, 
           measParams, provider, lspEval):
        print(f"Iteration {itCounts}, Evaluation {evCounts}, Current solution {orbits[0]}")

But if i add an init class, it do not work anymore, but in a strange way :

class CustomObserver(PythonBatchLSObserver):
    def __init__(self):
        print('init')
    def evaluationPerformed(self, itCounts, 
           evCounts, orbits, orbParams, propParams, 
           measParams, provider, lspEval):
        print(f"Iteration {itCounts}, Evaluation {evCounts}, Current solution {orbits[0]}")

(this init method is very simple, but the goal would be to have the initial guess as input like in the tutorial)

The constructor is executed, but then nothing is displayed while the estimator runs, but without errors :thinking: I looked at this thread : Usage of the init() method - Orekit development - Orekit, but the init() method instead of _ _ init _ _ does not do the trick as it doesn’t seem to be called.

If someone has a hint to what I am missing/done wrong :pray:

Hi,

You are likely missing the super call to the default init of the subclassed type, see for example orekit_python_artifacts/test/PVMeasurementCreator.py at 7ee5d8bed451ad5515f6dcb5ab242c816427ad97 · petrushy/orekit_python_artifacts · GitHub

i.e. add

super().__init__()

in your init code

The JCC documentation states this as " When an init() is declared, super() must be called or else the Java wrapper class will not know about the Python instance it needs to invoke." Apache Lucene - Features

Regards
Petrus

2 Likes

Thanks, that was what was missing!