Python TransformProviderUtils bug?


I’m getting a java NullPointerException trying to use the TransformProviderUtils to reverse a TransformProvider defined in python.

Using orekit 11.2, installed from conda-forge on the following script:

import orekit

from org.hipparchus.geometry.euclidean.threed import Rotation, Vector3D
from org.orekit.frames import Transform, StaticTransform, TransformProviderUtils, PythonTransformProvider
from org.orekit.time import AbsoluteDate

vm = orekit.initVM()

class FixedTransformProvider(PythonTransformProvider):
    def __init__(self, tx:Vector3D=None, r:Rotation=None):
        self.__tx = tx
        self.__r = r
    def getTransform(self, date:AbsoluteDate) -> Transform:
        # translation is unspecified
        if self.__tx is None:
            # if both are none, identity transform
            if self.__r is None:
                return Transform.IDENTITY
            # if only rotation
                return StaticTransform.of(date, self.__r)
        # translation is specified
            # both translation and rotation are specified
            if not self.__r is None:
                return StaticTransform.of(date, self.__tx, self.__r)
            # only translation
                return StaticTransform.of(date, self.__tx)
    def getTransform_F(self, date):

t1 = FixedTransformProvider(tx=Vector3D.PLUS_I)
t2 = TransformProviderUtils.getReversedProvider(t1)


I get the following error:

orekit.JavaError: <super: <class 'JavaError'>, <JavaError object>>
    Java stacktrace:
        at org.orekit.frames.TransformProviderUtils$2.getTransform(

I’m thinking there’s something obvious I’m missing, perhaps someone could point it out?



I think it is that you are missing a call to super in init

think it would become

super( FixedTransformProvider, self).__init__(self) 


ahh yes, thank you very much @petrus.hyvonen

However, I think there’s something else going on now. I see 2 different problems, though i’m not familiar enough with the python bindings to know if they’re related:

problem #1: TypeError when my TransformProvider returns a StaticTransform. Fixing the FixedTransformProvider constructor as suggested, then executing the code yields this error:

orekit.JavaError: <super: <class 'JavaError'>, <JavaError object>>
    Java stacktrace:
java.lang.RuntimeException: type error
        at org.orekit.frames.PythonTransformProvider.getTransform(Native Method)
        at org.orekit.frames.TransformProviderUtils$2.getTransform(

This problem goes away when remove StaticTransform and instead directly create instances of Transform.

However, returning instances of Transform brings us to problem number 2:

Problem #2: AttributeError: 'Transform' object has no attribute 'transformPosition

this line:

print(Transform(AbsoluteDate.ARBITRARY_EPOCH, Vector3D.PLUS_I).transformPosition(Vector3D.PLUS_J))

gives me this error:

print(Transform(AbsoluteDate.ARBITRARY_EPOCH, Vector3D.PLUS_I).transformPosition(Vector3D.PLUS_J))
AttributeError: 'Transform' object has no attribute 'transformPosition'

but, switching to use StaticTransform directly, works just fine:

print(StaticTransform.of(AbsoluteDate.ARBITRARY_EPOCH, Vector3D.PLUS_I).transformPosition(Vector3D.PLUS_J))

prints as expected

{1; 1; 0}

Hi @greyskyy,

A cast is required for Transform as StaticTransform to use the method transformPosition.

Please see

thanks! I’m not sure how I missed that in the forums. appreciate the link.