77import numpy as np
88
99from rocketpy .mathutils .function import Function
10- from rocketpy .prints .flight_prints import _FlightPrints
1110from rocketpy .plots .flight_plots import _FlightPlots
11+ from rocketpy .prints .flight_prints import _FlightPrints
1212
1313
1414class RocketPyEncoder (json .JSONEncoder ):
@@ -91,50 +91,7 @@ def object_hook(self, obj):
9191 new_flight = class_ .__new__ (class_ )
9292 new_flight .prints = _FlightPrints (new_flight )
9393 new_flight .plots = _FlightPlots (new_flight )
94- attributes = (
95- "rocket" ,
96- "env" ,
97- "rail_length" ,
98- "inclination" ,
99- "heading" ,
100- "initial_solution" ,
101- "terminate_on_apogee" ,
102- "max_time" ,
103- "max_time_step" ,
104- "min_time_step" ,
105- "rtol" ,
106- "atol" ,
107- "time_overshoot" ,
108- "name" ,
109- "solution" ,
110- "out_of_rail_time" ,
111- "apogee_time" ,
112- "apogee" ,
113- "parachute_events" ,
114- "impact_state" ,
115- "impact_velocity" ,
116- "x_impact" ,
117- "y_impact" ,
118- "t_final" ,
119- "flight_phases" ,
120- "ax" ,
121- "ay" ,
122- "az" ,
123- "out_of_rail_time_index" ,
124- "function_evaluations" ,
125- "alpha1" ,
126- "alpha2" ,
127- "alpha3" ,
128- "R1" ,
129- "R2" ,
130- "R3" ,
131- "M1" ,
132- "M2" ,
133- "M3" ,
134- )
135- for attribute in attributes :
136- setattr (new_flight , attribute , obj [attribute ])
137- new_flight .t_initial = new_flight .initial_solution [0 ]
94+ set_minimal_flight_attributes (new_flight , obj )
13895 return new_flight
13996 elif hasattr (class_ , "from_dict" ):
14097 return class_ .from_dict (obj )
@@ -153,6 +110,63 @@ def object_hook(self, obj):
153110 return obj
154111
155112
113+ def set_minimal_flight_attributes (flight , obj ):
114+ attributes = (
115+ "rocket" ,
116+ "env" ,
117+ "rail_length" ,
118+ "inclination" ,
119+ "heading" ,
120+ "initial_solution" ,
121+ "terminate_on_apogee" ,
122+ "max_time" ,
123+ "max_time_step" ,
124+ "min_time_step" ,
125+ "rtol" ,
126+ "atol" ,
127+ "time_overshoot" ,
128+ "name" ,
129+ "solution" ,
130+ "out_of_rail_time" ,
131+ "apogee_time" ,
132+ "apogee" ,
133+ "parachute_events" ,
134+ "impact_state" ,
135+ "impact_velocity" ,
136+ "x_impact" ,
137+ "y_impact" ,
138+ "t_final" ,
139+ "flight_phases" ,
140+ "ax" ,
141+ "ay" ,
142+ "az" ,
143+ "out_of_rail_time_index" ,
144+ "function_evaluations" ,
145+ "speed" ,
146+ "alpha1" ,
147+ "alpha2" ,
148+ "alpha3" ,
149+ "R1" ,
150+ "R2" ,
151+ "R3" ,
152+ "M1" ,
153+ "M2" ,
154+ "M3" ,
155+ "net_thrust" ,
156+ )
157+
158+ for attribute in attributes :
159+ try :
160+ setattr (flight , attribute , obj [attribute ])
161+ except KeyError :
162+ # Manual resolution of new attributes
163+ if attribute == "net_thrust" :
164+ flight .net_thrust = obj ["rocket" ].motor .thrust
165+ flight .net_thrust .set_discrete_based_on_model (flight .speed )
166+
167+ flight .t_initial = flight .initial_solution [0 ]
168+
169+
156170def get_class_signature (obj ):
157171 """Returns the signature of a class so it can be identified on
158172 decoding. The signature is a dictionary with the module and
0 commit comments