77import numpy as np
88
99from rocketpy .mathutils .function import Function
10+ from rocketpy .prints .flight_prints import _FlightPrints
11+ from rocketpy .plots .flight_plots import _FlightPlots
1012
1113
1214class RocketPyEncoder (json .JSONEncoder ):
@@ -75,6 +77,7 @@ class RocketPyDecoder(json.JSONDecoder):
7577 different types of objects from a JSON supported format."""
7678
7779 def __init__ (self , * args , ** kwargs ):
80+ self .resimulate = kwargs .pop ("resimulate" , False )
7881 super ().__init__ (object_hook = self .object_hook , * args , ** kwargs )
7982
8083 def object_hook (self , obj ):
@@ -84,7 +87,50 @@ def object_hook(self, obj):
8487 try :
8588 class_ = get_class_from_signature (signature )
8689
87- if hasattr (class_ , "from_dict" ):
90+ if class_ .__name__ == "Flight" and not self .resimulate :
91+ new_flight = class_ .__new__ (class_ )
92+ new_flight .prints = _FlightPrints (new_flight )
93+ new_flight .plots = _FlightPlots (new_flight )
94+ new_flight .rocket = obj ["rocket" ]
95+ new_flight .env = obj ["env" ]
96+ new_flight .rail_length = obj ["rail_length" ]
97+ new_flight .inclination = obj ["inclination" ]
98+ new_flight .heading = obj ["heading" ]
99+ new_flight .terminate_on_apogee = obj ["terminate_on_apogee" ]
100+ new_flight .max_time = obj ["max_time" ]
101+ new_flight .max_time_step = obj ["max_time_step" ]
102+ new_flight .min_time_step = obj ["min_time_step" ]
103+ new_flight .rtol = obj ["rtol" ]
104+ new_flight .atol = obj ["atol" ]
105+ new_flight .time_overshoot = obj ["time_overshoot" ]
106+ new_flight .name = obj ["name" ]
107+ new_flight .solution = obj ["solution" ]
108+ new_flight .out_of_rail_time = obj ["out_of_rail_time" ]
109+ new_flight .apogee_time = obj ["apogee_time" ]
110+ new_flight .apogee = obj ["apogee" ]
111+ new_flight .parachute_events = obj ["parachute_events" ]
112+ new_flight .impact_state = obj ["impact_state" ]
113+ new_flight .impact_velocity = obj ["impact_velocity" ]
114+ new_flight .x_impact = obj ["x_impact" ]
115+ new_flight .y_impact = obj ["y_impact" ]
116+ new_flight .t_final = obj ["t_final" ]
117+ new_flight .flight_phases = obj ["flight_phases" ]
118+ new_flight .ax = obj ["ax" ]
119+ new_flight .ay = obj ["ay" ]
120+ new_flight .az = obj ["az" ]
121+ new_flight .out_of_rail_time_index = obj ["out_of_rail_time_index" ]
122+ new_flight .function_evaluations = obj ["function_evaluations" ]
123+ new_flight .alpha1 = obj ["alpha1" ]
124+ new_flight .alpha2 = obj ["alpha2" ]
125+ new_flight .alpha3 = obj ["alpha3" ]
126+ new_flight .R1 = obj ["R1" ]
127+ new_flight .R2 = obj ["R2" ]
128+ new_flight .R3 = obj ["R3" ]
129+ new_flight .M1 = obj ["M1" ]
130+ new_flight .M2 = obj ["M2" ]
131+ new_flight .M3 = obj ["M3" ]
132+ return new_flight
133+ elif hasattr (class_ , "from_dict" ):
88134 return class_ .from_dict (obj )
89135 else :
90136 # Filter keyword arguments
@@ -118,7 +164,7 @@ def get_class_signature(obj):
118164 Signature of the class.
119165 """
120166 class_ = obj .__class__
121- name = getattr (class_ , ' __qualname__' , class_ .__name__ )
167+ name = getattr (class_ , " __qualname__" , class_ .__name__ )
122168
123169 return {"module" : class_ .__module__ , "name" : name }
124170
0 commit comments