tudat-team / tudat-space

An introduction and guide to tudat-space.
https://tudat-space.readthedocs.io
14 stars 17 forks source link

DCM matrix builter #65

Closed gregoriomarchesini closed 2 years ago

gregoriomarchesini commented 2 years ago

Hi

I have written two simple functions that could be useful in the future if you want to add them. I hope they can be of any help and let me know if you want me to modify them

import numpy as np

def split_history(state_history:dict,n_bodies:int):

    """
    Parameters
    -----------

    state_history        (dict ) :  dictionary containing the state_history
                                    of N propagated bodies.
                                    The dictionary is defined as a standard 
                                    state_history following the TUdat convention. 

                                    the keys of the dictionary are the time stamps 
                                    corresponding to each state and the argument is 
                                    the state of the body at the given time stamp

    n_bodies            (int)     : number of propagated bodies

    Returns
    -----------

    state_hostory_book (list)   : list of state_history dictionaries for each propagated body.
                                  The order of the list is given directly by the order 
                                  in which the bodies are propagated.

    Description
    -----------
    Creates a list of state histories based on the unified state_history
    from the propagation of n_bodies 

    """

    state_history_book = []
    time               = [key for key in state_history.keys() ]
    n_variables        = len(state_history[time[0]])
    step               = int(n_variables/n_bodies)

    for n in range(n_bodies) :
        current_history = dict()

        for t in time:
           current_history[t]= state_history[t][step*n:step*n+step]

        state_history_book.append(current_history)

    return state_history_book

def vector2matrix(flat_matrix:np.ndarray) :

    """
    Parameters
    -----------

    flat_matrix     (np.ndarray ) : vector containing a flatttened rotation matrix 
                                    following the TuDat standards
                                    a rotation matrix is returned as a nine-entry 
                                    vector in the dependent variable output, where entry
                                    (i,j) of the matrix is stored in entry (3i+j)  of the vector
                                    with i,j = 0,1,2

    Returns
    -----------

    rotation_matrix      (np.ndarray)     : returns (3x3) Rotation matrix 
                                            (orthogonal matrix)

    Descriptiom
    -----------

    Retruns rotation matrix from its flattened vectorial version.
    Check for details :
    https://tudatpy.readthedocs.io/en/latest/dependent_variable.html#tudatpy.numerical_simulation.propagation_setup.dependent_variable.inertial_to_body_fixed_rotation_frame

    """

    rotations_matrix = np.empty((3,3))

    for i in range(3) :
        for j in range(3) :
           rotations_matrix[i,j]=flat_matrix[3*i+j]

    return rotations_matrix
DominicDirkx commented 2 years ago

Hi Greg, this looks useful :) Thanks!

@Marchesini010126 If we were to add this now, we would copy paste this into he code and push it. If you formulate it as a pull request, your name would also show up in the tudat git commit history. In case you would want that, for us it makes little difference (I think)

@gaffarelj Could you add these to a future tudatpy update?

gaffarelj commented 2 years ago

Hi all :)

I can take care of adding these functions to tudatpy, yes. Looking through them, I will then put them inside the tudatpy.util module.

@Marchesini010126 tell me if you want to take care of it trough a push request, otherwise I will make it myself, and mention your username in the commit message.

gregoriomarchesini commented 2 years ago

Hi

You can definitely go ahead. It is fine for me even if I don’t make the push my self Happy to help you !

Gregorio Marchesini

Personal Email @.***

Academic Email @.***

On 5 Apr 2022, at 14:22, Jérémie Gaffarel @.***> wrote:

Hi all :)

I can take care of adding these functions to tudatpy, yes. Looking through them, I will then put them inside the tudatpy.util module.

@Marchesini010126 https://github.com/Marchesini010126 tell me if you want to take care of it trough a push request, otherwise I will make it myself, and mention your username in the commit message.

— Reply to this email directly, view it on GitHub https://github.com/tudat-team/tudat-space/issues/65#issuecomment-1088637261, or unsubscribe https://github.com/notifications/unsubscribe-auth/AQ76ADGGG6WW3PG5BYCZMTTVDQV7DANCNFSM5SSF5JRA. You are receiving this because you were mentioned.

gaffarelj commented 2 years ago

Hi @Marchesini010126!

Small update: I think that there is an incorrect assumption with your split_history function. It looks like you assume your state to be [translational body A, mass body A, translational body B, mass body B], where it is in fact [translational body A, translational body B, mass body A, mass body B] (as an example). So your function, as it is, would work fine if you propagate only translational dynamics, but not if you propagate any other state type (like mass, rotational, etc).

I am making the appropriate changes to your function (and tudatpy) so that this functionality can still be implemented, but that will take just a little bit longer (though it's well underway already).

gregoriomarchesini commented 2 years ago

Hey

Yes you are right I mainly work with translational dynamics and this is the reason why I had made this assumption.

Really grateful I watched this issue and let me know if you need anything! Great catch

Have a nice day Gregorio Marchesini

Personal Email @.***

Academic Email @.***

On 8 Apr 2022, at 16:43, Jérémie Gaffarel @.***> wrote:

Hi @Marchesini010126 https://github.com/Marchesini010126!

Small update: I think that there is an incorrect assumption with your split_history function. It looks like you assume your state to be [translational body A, mass body A, translational body B, mass body B], where it is in fact [translational body A, translational body B, mass body A, mass body B] (as an example). So your function, as it is, would work fine if you propagate only translational dynamics, but not if you propagate any other state type (like mass, rotational, etc).

I am making the appropriate changes to your function (and tudatpy) so that this functionality can still be implemented, but that will take just a little bit longer (though it's well underway already).

— Reply to this email directly, view it on GitHub https://github.com/tudat-team/tudat-space/issues/65#issuecomment-1092937238, or unsubscribe https://github.com/notifications/unsubscribe-auth/AQ76ADF4TOT76JKJHVZBJFDVEBA25ANCNFSM5SSF5JRA. You are receiving this because you were mentioned.

gaffarelj commented 2 years ago

I implemented both of these functions and made this pull request accordingly. @DominicDirkx can you review it?

Thanks again for these additions @Marchesini010126 :)

gaffarelj commented 2 years ago

These new features have been merged with tudatpy/develop with commit c56ab7f. They will be included in the next conda release of tudatpy, and in the online documentation as soon as possible (there is a little fix needed for the docs to be updatable again).

gaffarelj commented 2 years ago

Just to confirm, the new API docs (that are now building again) contain the two new features mentioned in this issue: