[Python] Write AEM files with OREKIT

Discussão em 'Python' iniciado por Stack, Julho 17, 2025.

  1. Stack

    Stack Membro Participativo

    I am new to orekit and without a lot of knowledge about space physics. I am using orekit jpype to create an AEM file. No matter what I try, I get errors of the same format, something like:

    in write_aem
    writer.writeMessage(kvn_gen, aem)
    org.orekit.errors.OrekitException: org.orekit.errors.OrekitException: frame EME2000 is not valid in this CCSDS file context


    Also tried other frames.

    My code is this:

    def write_aem(attitudes_sequence: AttitudesSequence, states: list, filename: str, switch_date: AbsoluteDate):
    start_time = states[0].getDate()
    stop_time = states[-1].getDate()

    # Header
    header = AdmHeader()
    header.setOriginator("SAFRAN SCSA")
    header.setCreationDate(start_time) # Use start time as creation date

    # Determine switch date from the attitude sequence and split states into two segments

    states_segment_1 = [s for s in states if s.getDate().compareTo(switch_date) <= 0]
    states_segment_2 = [s for s in states if s.getDate().compareTo(switch_date) > 0]

    segments = ArrayList()
    for segment_states in [states_segment_1, states_segment_2]:
    if not segment_states:
    continue # Skip empty segments

    start_time = segment_states[0].getDate()
    stop_time = segment_states[-1].getDate()

    metadata = AemMetadata(1)
    metadata.setObjectName("Satellite_name")
    metadata.setObjectID("Sat_ID")
    metadata.setCenter(BodyFacade("EARTH", CelestialBodyFactory.getEarth()))
    metadata.setTimeSystem(TimeSystem.UTC)
    metadata.setStartTime(start_time)
    metadata.setStopTime(stop_time)
    # TODO: Check this! which one is A and which is B???
    metadata.getEndpoints().setFrameA(FrameFacade.map(states[0].getFrame()))
    metadata.getEndpoints().setFrameB(FrameFacade.map(FramesFactory.getEME2000()))

    aem_data = AemData()
    for state in segment_states:
    attitude = state.getAttitude()
    timestamped = TimeStampedAngularCoordinates(
    attitude.getDate(), attitude.getRotation(), attitude.getSpin(), attitude.getRotationAcceleration()
    )
    aem_data.addData(timestamped)

    segments.add(AemSegment(metadata, aem_data))

    # Create AEM file object
    aem = Aem(header, segments, IERSConventions.IERS_2010, DataContext.getDefault())

    # Writer
    writer = WriterBuilder().buildAemWriter()
    with open(filename, "w") as fp:
    buffer = StringBuilder()
    kvn_gen = KvnGenerator(buffer, AemWriter.KVN_PADDING_WIDTH, String("AEM file"), Constants.JULIAN_DAY, 60)
    writer.writeMessage(kvn_gen, aem)
    fp.write(str(buffer.toString()))


    I of course want to choose the correct frames, but in a first moment, already creating the file would be great.

    In here, example 4.3.1 they use 'SC_BODY', I tried creating this, but setFrameB only accepts FrameFacade input, and I have no idea how to create SC_BODY as it is not in the FramesFactory.

    Why am I having this problem? And how can I solve it?

    Continue reading...

Compartilhe esta Página