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,).
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:
SimulationVariableDict
->DependentVariableDictionary
result2dict
->create_simulation_variable_dictionary
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 theDependentVariableDictionary.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 aSingleDependentVariableSettings
object (or children instance), or the string ID of aSingleDependentVariableSettings
object. That is, the keys used by this method are the same we use to retrieve dependent variable histories in dictionary form from theDependentVariableDictionary
.See the example below as well.
where
(A, B)
is the shape of the dependent variable. The dependent variables arenp.squeeze
d 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:
DependentVariableDictionary.asarray
method to obtain NumPy arrays from dependent variable history dictionariesSingleArcSimulationResults.dependent_variable_history
tudatpy.util.result2array