MagneticFieldDetector usage

Hello everyone,
i am trying to implement the MagneticFieldDetector in Python to detect when the propagated satellite pass in the South Atlantic Anomaly.
Python give me an error: “org.orekit.errors.OrekitException: ^IGRF.COF$ inesistente nel classpath”
P.S. I have downloaded the IGRF.COF file from https://www.ngdc.noaa.gov/IAGA/vmod/igrf.html
Here is my code:

""" #  INITIAL PARAMETERS  # """
utc = TimeScalesFactory.getUTC()

earth = OneAxisEllipsoid(
    Constants.WGS84_EARTH_EQUATORIAL_RADIUS,
    Constants.WGS84_EARTH_FLATTENING,
    FramesFactory.getITRF(IERSConventions.IERS_2010, True))

duration = 1*24*3600.0 # seconds
step   = 10.0 #second

startTime = AbsoluteDate(2020, 7, 1, 00, 0, 01.000, utc)
endTime = startTime.shiftedBy(duration)

# Time array in orekit AbsoluteDate format
t = [startTime.shiftedBy(float(dt)) \
        for dt in np.arange(0, duration, step)]

""" # Keplerian Orbit  # """
i =  97.7         # inclination
omega = 90.0     # perigee argument
raan = 130.0  # RAAN
lv = 45.0    # True anomaly
sma = 6992944.41046
ecc = 0.00014597

initialOrbit = KeplerianOrbit(
    sma, ecc,
    radians(i), radians(omega),
    radians(raan), radians(lv),PositionAngle.TRUE,
    FramesFactory.getEME2000(), startTime, Constants.WGS84_EARTH_MU)

propagator = KeplerianPropagator(initialOrbit)

""" #  MAGNETIC FIELD  # """
magnetic_model = GeoMagneticFieldFactory.FieldModel.IGRF

""" #   SET AN EVENT DETECTOR  # """
magnetic_detector = MagneticFieldDetector(60.0, 0.1, 32000.0E-9, magnetic_model, earth, True).withHandler(ContinueOnEvent())

""" #  SET AN EVENT LOGGER  # """
EventLogger = EventsLogger() #Build an empty logger for events detectors. 
logged_detector = EventLogger.monitorDetector(magnetic_detector)

""" # PROPAGATE THE EVENTS LOGGER # """
propagator.addEventDetector(logged_detector)

""" #  GET THE EVENTS  # """
state = propagator.propagate(startTime, endTime)
start_time = None

results = pd.DataFrame()
events = EventLogger.getLoggedEvents()
print(events.size())

for event in events :
    if not event.isIncreasing(): #g is changing the sign
        start_time = event.getState().getDate()
        start_PVCoordinates = event.getState().getPVCoordinates(FramesFactory.getEME2000())
        start_Coordinate= start_PVCoordinates.getPosition() #ho un vettore 3-D , ma cosa mi da? e come posso avere le coordinate long/lat
       
    elif start_time:
        stop_time = event.getState().getDate()
        stop_PVCoordinates = event.getState().getPVCoordinates(FramesFactory.getEME2000())
        results = results.append({"Duration (s)": stop_time.durationFrom(start_time),
                                        "Start Time (UTC)": absolutedate_to_datetime(start_time),
                                        "Stop Time (UTC)": absolutedate_to_datetime(stop_time)},                                 
                                        ignore_index=True)
        #contacts.to_csv('Accesses', sep='\t', index=True)
        start_time = None

print(results)

Can someone help me? … please :slight_smile:

Hi @rekoraffa
The magnetic field data file is not found, 2 possible causes:
1 - the expected file should be named IGRF.COF, did you rename the file retrieved from the NOAA site correctly?
2 - the file must be added to the data used by Orekit, either in the orekit-data.zip archive, if you use the default setup (setup_orekit_curdir()), or in the orekit-data directory, if you use a dedicated setup (setup_orekit_curdir(orekit-data))