How to pass Correct Input Parameters to DTM2000 implementation

Hi all,

I am trying to write a function that will query the DTM2000 density model given a position (ECI) and a time.

def query_dtm2000(position, datetime):
    absolute_date = datetime_to_absolutedate(datetime)
    frame = FramesFactory.getEME2000()
    wgs84Ellipsoid = ReferenceEllipsoid.getWgs84(FramesFactory.getITRF(IERSConventions.IERS_2010, True))
    
    sun = CelestialBodyFactory.getSun()
    utc = TimeScalesFactory.getUTC()
    atmosphere = DTM2000(PythonDTM2000InputParameters(), sun, wgs84Ellipsoid)
    
    position_vector = Vector3D(float(position[0]), float(position[1]), float(position[2]))
    density = atmosphere.getDensity(absolute_date, position_vector, frame)
    return density

At the moment I get the following error and I am not really sure what to make of it

  File "query_models.py", line 24, in append_dtm2000_density
    dens = query_dtm2000(r, date_val)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "orekit_tools.py", line 73, in query_dtm2000
    density = atmosphere.getDensity(absolute_date, position_vector, frame)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
orekit.JavaError: <super: <class 'JavaError'>, <JavaError object>>
    Java stacktrace:
java.lang.RuntimeException: AttributeError
        at org.orekit.models.earth.atmosphere.PythonDTM2000InputParameters.getMaxDate(Native Method)
        at org.orekit.models.earth.atmosphere.DTM2000.getDensity(DTM2000.java:331)

It seems like the getMaxDate() function is not correctly returning the date ?

I had this working fine when I was using the CSSI data provider as such:

cssi_sw_data = CssiSpaceWeatherData(CssiSpaceWeatherData.DEFAULT_SUPPORTED_NAMES)
atmosphere = DTM2000(cssi_sw_data, sun, wgs84Ellipsoid)

But I wanted to make sure the correct data provider is being used (since the Kp index is supposed to be shifted by 3-hours in time).

Does anyone have insights into what might be causing this issue or suggestions on how to resolve it?

Any help much appreciated :smiley: :folded_hands:

Hi,

AttributeError is usually solved by “casting”, something like:

Atmosphere.cast_(atmosphere).getDensity(...)

Cheers,
Romain.

Hi @Serrof :smile:

Thanks for your help!

I have tried both

atmosphere = DTM2000(PythonDTM2000InputParameters(), sun, wgs84Ellipsoid)
density = DTM2000.cast_(atmosphere).getDensity(absolute_date, position_vector, frame)

and

atmosphere = DTM2000(PythonDTM2000InputParameters(), sun, wgs84Ellipsoid)
density = Atmosphere.cast_(atmosphere).getDensity(absolute_date, position_vector, frame)

But I keep getting the same error.

I feel like the JCC binding is detecting that PythonDTM2000InputParameters defines these methods and therefore uses them instead of delegating to the native Java implementations. I’m not sure what to do about this. I tried also a fresh environment with just orekit installed and updated to the latest version but the same thing occurs.

Alternatively, I will just have to write my own InputParameters provider in python, but this seems like a shame (and a pain :face_with_tongue:).

Thanks again for you help :slight_smile:

Wait but the Python[...] classes are abstract and must be implemented. Basically they replace the Java interfaces which you cannot directly extend in Python.

So if you want to use built-in Orekit stuff, it’s either CssiSpaceWeatherData or MarshallSolarActivityFutureEstimation

1 Like

Ah yes so I was initially trying to use the non-Python[...] class DTM2000Inputs referenced here. I switched to the Python[...] one thinking that this might be the required fix.

But so you are saying only msafe and cssi are available in Python to drive the models? If so, I will write my own parameters provider and share it here in due course :slight_smile:

Thanks again for you help @Serrof !

P.S. It might be helpful to add a note in the documentation clarifying that certain models need to be run with the model inputs provided in a specific way—using msafe/cssi as they are may lead to “incorrect” model outputs.

Hello again,

I think I misunderstood a couple of things so maybe my questions weren’t making much sense… Apologies

To clarify, I have been running, prior to this, DTM2000 driven using CssiSpaceWeatherData. This should work since it is an implementing class of DTM2000InputParameters. And the model runs but the Kp delay is not correctly applied.

As per the documentation, getThreeHourlyKP, should be doing this:

Get the value of the 3 hours geomagnetic index. With a delay of 3 hours at pole to 6 hours at equator using: delay=6-abs(lat)*0.033 (lat in deg.)

However having compared my model output to a reference version, I can see that the Kp is not being shifted by 3 hours (see below):

Correct reference version

Current DTM2000 driven by CssiSpaceWeatherData

Apologies if I’m being a bit slow here… And thanks again for your help! :slight_smile: