InvalidArgError for 'org.orekit.models.earth.GeoMagneticField'

Hi. I have a basic CSV file that contains LLA information. For each LLA entry, I wish to generate the Magnetic Field Value using the WMM/IGRF model. As a result, I call the model in a for loop, but that throws an error.

When I call the GeoMagnetic field model independently using an example LLA value, it returns the Magnetic field Value.

Would appreciate the community’s help here as I am new to Orekit!

Here is a snippet of my code:

igrfyear = GeoMagneticField.getDecimalYear(1,4,2024)
model = GeoMagneticFieldFactory.getWMM(igrfyear)
for index,sample in tm.iterrows():
    lat_rad = angle.deg2rad(sample['gpsLatitude'])
    long_rad = angle.deg2rad(sample['gpsLongitude'])
    alt_m = sample['gpsAltitudeMeters']
    igrf = model.calculateField(lat_rad,long_rad,alt_m)

The error I get is:

---------------------------------------------------------------------------
InvalidArgsError                          Traceback (most recent call last)
~\AppData\Local\Temp\ipykernel_20616\3684579963.py in <module>
      5     long_rad = angle.deg2rad(sample['gpsLongitude'])
      6     alt_m = sample['gpsAltitudeMeters']
----> 7     igrf = model.calculateField(lat_rad,long_rad,alt_m)

InvalidArgsError: (<class 'org.orekit.models.earth.GeoMagneticField'>, 'calculateField', (0.5570752098432994, 0.5061478466338231, 420562.46875))

Hi,

This is a classic with the wrapper. It doesn’t accept Numpy or other non native types. So use cast them with float before calling the Orekit method.

Cheers,
Romain.

@Serrof Thanks a lot for the suggestion! It worked.

I get the output in this format. Is there a way to extract just the B value from this?

[<GeoMagneticElements: MagneticField[B={24,609.368; 1,823.541; 26,310.798},H=24,676.837,F=36,072.211,I=0.817,D=0.074]>,
 <GeoMagneticElements: MagneticField[B={20,323.846; -460.3; -15,743.268},H=20,329.057,F=25,712.274,I=-0.659,D=-0.023]>,
 <GeoMagneticElements: MagneticField[B={9,328.69; -4,635.985; -19,667.531},H=10,417.141,F=22,255.979,I=-1.084,D=-0.461]>,
 <GeoMagneticElements: MagneticField[B={14,791.528; 475.473; -35,518.432},H=14,799.168,F=38,478.233,I=-1.176,D=0.032]>,
 <GeoMagneticElements: MagneticField[B={11,610.018; 9,264.386; -42,494.396},H=14,853.329,F=45,015.498,I=-1.235,D=0.673]>,
 <GeoMagneticElements: MagneticField[B={25,253.302; 6,000.82; -19,002.44},H=25,956.485,F=32,168.802,I=-0.632,D=0.233]>,
 <GeoMagneticElements: MagneticField[B={23,660.695; 3,561.968; 15,343.971},H=23,927.308,F=28,424.524,I=0.57,D=0.149]>,
 <GeoMagneticElements: MagneticField[B={15,383.07; -86.636; 41,351.372},H=15,383.314,F=44,120.089,I=1.215,D=-0.006]>,
 <GeoMagneticElements: MagneticField[B={4,231.355; 2,109.51; 47,148.764},H=4,728.044,F=47,385.233,I=1.471,D=0.462]>,
 <GeoMagneticElements: MagneticField[B={20,071.875; 881.899; 32,772.104},H=20,091.24,F=38,440.457,I=1.021,D=0.044]>,
 <GeoMagneticElements: MagneticField[B={24,535.259; -1,384.35; -7,460.66},H=24,574.283,F=25,681.838,I=-0.295,D=-0.056]>,
 <GeoMagneticElements: MagneticField[B={8,786.729; -3,314.318; -18,804.404},H=9,391.022,F=21,018.966,I=-1.108,D=-0.361]>,
 <GeoMagneticElements: MagneticField[B={14,914.724; -933.144; -28,938.406},H=14,943.887,F=32,569.174,I=-1.094,D=-0.062]>,
 <GeoMagneticElements: MagneticField[B={4,005.422; 9,090.52; -48,567.859},H=9,933.829,F=49,573.359,I=-1.369,D=1.156]>,
 <GeoMagneticElements: MagneticField[B={22,048.313; 6,304.577; -33,761.226},H=22,931.982,F=40,812.941,I=-0.974,D=0.279]>,
 <GeoMagneticElements: MagneticField[B={27,612.993; 3,328.84; 3,167.667},H=27,812.92,F=27,992.725,I=0.113,D=0.12]>,
 <GeoMagneticElements: MagneticField[B={20,010.38; -1,918.389; 35,757.322},H=20,102.127,F=41,020.502,I=1.059,D=-0.096]>,
 <GeoMagneticElements: MagneticField[B={1,610.669; 954.718; 48,434.914},H=1,872.363,F=48,471.09,I=1.532,D=0.535]>,
 <GeoMagneticElements: MagneticField[B={15,488.365; -985.399; 38,084.132},H=15,519.68,F=41,124.95,I=1.184,D=-0.064]>,
 <GeoMagneticElements: MagneticField[B={25,707.54; -3,539.589; 5,352.021},H=25,950.073,F=26,496.234,I=0.203,D=-0.137]>,
 <GeoMagneticElements: MagneticField[B={12,137.92; -4,934.111; -15,915.424},H=13,102.463,F=20,614.928,I=-0.882,D=-0.386]>,
 <GeoMagneticElements: MagneticField[B={14,336.398; -130.231; -23,168.74},H=14,336.989,F=27,245.913,I=-1.017,D=-0.009]>,
 <GeoMagneticElements: MagneticField[B={-3,130.674; 8,515.431; -48,501.819},H=9,072.689,F=49,343.085,I=-1.386,D=1.923]>,
 <GeoMagneticElements: MagneticField[B={16,228.275; 4,710.4; -45,762.735},H=16,898.07,F=48,782.914,I=-1.217,D=0.282]>,
 <GeoMagneticElements: MagneticField[B={30,088.224; 1,960.095; -11,162.391},H=30,152.001,F=32,151.861,I=-0.355,D=0.065]>,

Hi @suraj101195 and welcome,

Here’s a link to the API of class GeoMagneticElements.
To get the total intensity in Teslas, use: getTotalIntensity().
To get the magnetic field vector in Teslas, use: getFieldVector()

Cheers,
Maxime

1 Like

@MaximeJ, Are you sure the values are outputted in Tesla? Looking at the values, it feels like they should be in nanoTeslas and not Teslas.

<Vector3D: {24,608.0284820637; 1,814.7226960906; 26,296.4574827308}>

Hi @suraj101195 ,
Values are in Teslas since Orekit 12.0. If you are using an earlier version, the values were in nanoTeslas.

Cheers,
Pascal

Got it. Thanks for all the help!