Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3DView support #80

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from
Draft

3DView support #80

wants to merge 10 commits into from

Conversation

jeandet
Copy link
Member

@jeandet jeandet commented Dec 20, 2022

No description provided.

@jeandet jeandet added the enhancement New feature or request label Dec 20, 2022
@jeandet jeandet added this to the v1.1.0 milestone Dec 20, 2022
# -*- coding: utf-8 -*-

"""Tests for `cdpp_3dview` package."""
import os

Check notice

Code scanning / CodeQL

Unused import Note

Import of 'os' is not used.

from ddt import data, ddt, unpack

import speasy as spz

Check notice

Code scanning / CodeQL

Unused import Note

Import of 'spz' is not used.
from ddt import data, ddt, unpack

import speasy as spz
from speasy.inventories import flat_inventories

Check notice

Code scanning / CodeQL

Unused import Note

Import of 'flat_inventories' is not used.
speasy/webservices/cdpp_3dview/ws.py Fixed Show fixed Hide fixed
@jeandet jeandet force-pushed the 3DView branch 2 times, most recently from e4c54ab to 335aecb Compare December 23, 2022 09:06
@jeandet jeandet modified the milestones: v1.1.0, 1.2.0 May 1, 2023
Signed-off-by: Alexis Jeandet <alexis.jeandet@member.fsf.org>
Signed-off-by: Alexis Jeandet <alexis.jeandet@member.fsf.org>
Signed-off-by: Alexis Jeandet <alexis.jeandet@member.fsf.org>
Signed-off-by: Alexis Jeandet <alexis.jeandet@member.fsf.org>
Signed-off-by: Alexis Jeandet <alexis.jeandet@member.fsf.org>
Signed-off-by: Alexis Jeandet <alexis.jeandet@member.fsf.org>
Signed-off-by: Alexis Jeandet <alexis.jeandet@member.fsf.org>
@jeandet
Copy link
Member Author

jeandet commented May 10, 2023

@vgenot I've added some ssc comparisons here, does the absolute and relative errors thresholds look OK to you? Not sure why MMS1 fails this test in GSM.

@jeandet
Copy link
Member Author

jeandet commented May 11, 2023

Here are two plots for MMS1 in GSE and GSM:
MMS1_GSE
MMS1_GSM

GSE seems pretty OK to me with < 10 km accuracy, while trajectories in GSM coordinates system seems to have a bigger error (up to 200 km). I guess this comes from differences in magnetic pole position determination since Z is the most affected axis and Y a bit less (X being really accurate).

@jeandet
Copy link
Member Author

jeandet commented May 11, 2023

just for the record the script used to produce plots (using speasy private API):

from datetime import timedelta

import numpy as np
import matplotlib.pyplot as plt

import speasy as spz
from speasy.webservices.cdpp_3dview.ws import _WS_impl

_ws = _WS_impl()

def find_body(name: str):
    bodies = _ws.get_spacecraft_list()
    for body in bodies:
        if body.name == name or body.name.lower() == name.lower():
            return body
    return None


def find_frame(name: str):
    frames = _ws.get_frame_list()
    for frame in frames:
        if frame.name == name or frame.name.lower() == name.lower():
            return frame
    return None



def compare_ssc_trajectory(ssc_index, coordinate_system, cdpp_coordinate_system=None):
    cdpp_coordinate_system = cdpp_coordinate_system or coordinate_system
    start_time = spz.core.make_utc_datetime("2021-01-01")
    stop_time = spz.core.make_utc_datetime("2021-01-05")
    ssc_data = spz.get_data(ssc_index, start_time, stop_time,
                            coordinate_system=coordinate_system)
    ssc_data = ssc_data.to_dataframe()

    cdpp_3DView_data = _ws.get_orbit_data(body=find_body(ssc_index.Id),
                                          start_time=start_time,
                                          stop_time=stop_time,
                                          frame=find_frame(coordinate_system),
                                          time_vector=list(
                                              map(spz.core.make_utc_datetime, ssc_data.index.to_pydatetime())))


    cdpp_3DView_data = cdpp_3DView_data.to_dataframe()

    ssc_data.columns = cdpp_3DView_data.columns
    abs_error = abs(ssc_data - cdpp_3DView_data)
    percent_error = 100 * abs((ssc_data - cdpp_3DView_data) / ssc_data)
    
    fig, axs = plt.subplots(3, 1, sharex=True)
    axs[0].set_title(f"{ssc_index.Id} Trajectories from SSCWeb and 3DView in {coordinate_system} frame")
    axs[0].plot(ssc_data, label=ssc_data.columns)
    axs[0].plot(cdpp_3DView_data, label=cdpp_3DView_data.columns)
    axs[0].set_ylabel('Spacecraft position (km)')
    axs[0].legend()
    
    axs[1].set_title(f"Relative error of 3DView trajectory vs SSC")
    axs[1].plot(percent_error, label=percent_error.columns)
    axs[1].set_ylabel('Error (%)')
    axs[1].set_ylim(0, 10)
    axs[1].legend()
    
    axs[2].set_title(f"Absolute error of 3DView trajectory vs SSC")
    axs[2].plot(abs_error, label=abs_error.columns)
    axs[2].set_ylabel('Error (km)')
    axs[2].legend()
    
    plt.show()


compare_ssc_trajectory(spz.inventories.tree.ssc.Trajectories.mms1, "GSM")
compare_ssc_trajectory(spz.inventories.tree.ssc.Trajectories.mms1, "GSE")

Signed-off-by: Alexis Jeandet <alexis.jeandet@member.fsf.org>
Signed-off-by: Alexis Jeandet <alexis.jeandet@member.fsf.org>
Signed-off-by: Alexis Jeandet <alexis.jeandet@member.fsf.org>
@jeandet jeandet added the New WS label Jul 10, 2023
@jeandet jeandet modified the milestones: 1.2.0, 1.3.0 Oct 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request New WS
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant