tudat-team / tudatpy

A Python platform to perform astrodynamics and space research.
https://tudat-space.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
29 stars 29 forks source link

Dependent variable dictionary - definitive and inside hybrid kernel #120

Closed alopezrivera closed 10 months ago

alopezrivera commented 10 months ago

Pull request building on https://github.com/tudat-team/tudatpy/pull/115 (which can be closed upon merging this one).

Improvements

Naming

Changed to indicate what the class and function do as of today:

NumPy array conversion

New method DependentVariableDictionary.asarray implemented, allowing users to easily retrieve the time history of each dependent variable as a NumPy array. Paired with the DependentVariableDictionary.time_history attribute this streamlines away the data juggling that was required before to plot dependent variables.

The new method works like this: dep_vars_dict.asarray(<key>), where <key> can be either a SingleDependentVariableSettings object (or children instance), or the string ID of a SingleDependentVariableSettings object. That is, the keys used by this method are the same we use to retrieve dependent variable histories in dictionary form from the DependentVariableDictionary.

See the example below as well.

# Create semantic dependent variable history
dep_vars_dict = create_dependent_variable_dictionary(dynamics_simulator)

# Retrieve dependent variable history as NumPy array of shape (n, A, B)
a_scalar_dependent_variable = dep_vars_dict.asarray(dependent_variables_to_save[0])

# Plot
plt.plot(
    dep_vars_dict.time_history,
    a_scalar_dependent_variable
)

where (A, B) is the shape of the dependent variable. The dependent variables are np.squeezed to remove singleton/trivial dimensions, so in the case of a scalar variable (n, A, B) shape would simply become (n,).

Testing (dependent_variable_dict (tudat-team/tudatpy#115))

Test added to the tudatpy tests which tests:

DominicDirkx commented 10 months ago

Code merged into develop