Skip to content

Commit e49e6ca

Browse files
committed
ENH: add from_dict to new classes
1 parent a5249e6 commit e49e6ca

File tree

9 files changed

+67
-42
lines changed

9 files changed

+67
-42
lines changed

rocketpy/rocket/aero_surface/fins/_elliptical_mixin.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,3 +131,21 @@ def info(self):
131131
def all_info(self):
132132
self.prints.all()
133133
self.plots.all()
134+
135+
def to_dict(self, include_outputs=False):
136+
data = super().to_dict(include_outputs)
137+
if include_outputs:
138+
data.update(
139+
{
140+
"Af": self.Af,
141+
"AR": self.AR,
142+
"gamma_c": self.gamma_c,
143+
"Yma": self.Yma,
144+
"roll_geometrical_constant": self.roll_geometrical_constant,
145+
"tau": self.tau,
146+
"lift_interference_factor": self.lift_interference_factor,
147+
"roll_damping_interference_factor": self.roll_damping_interference_factor,
148+
"roll_forcing_interference_factor": self.roll_forcing_interference_factor,
149+
}
150+
)
151+
return data

rocketpy/rocket/aero_surface/fins/_free_form_mixin.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -219,17 +219,6 @@ def to_dict(self, include_outputs=False):
219219
)
220220
return data
221221

222-
@classmethod
223-
def from_dict(cls, data):
224-
return cls(
225-
data["n"],
226-
data["shape_points"],
227-
data["rocket_radius"],
228-
data["cant_angle"],
229-
data["airfoil"],
230-
data["name"],
231-
)
232-
233222
def info(self):
234223
self.prints.geometry()
235224
self.prints.lift()

rocketpy/rocket/aero_surface/fins/_trapezoidal_mixin.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -178,15 +178,3 @@ def to_dict(self, include_outputs=False):
178178
)
179179
return data
180180

181-
@classmethod
182-
def from_dict(cls, data):
183-
return cls(
184-
n=data["n"],
185-
root_chord=data["root_chord"],
186-
tip_chord=data["tip_chord"],
187-
span=data["span"],
188-
rocket_radius=data["rocket_radius"],
189-
cant_angle=data["cant_angle"],
190-
airfoil=data["airfoil"],
191-
name=data["name"],
192-
)

rocketpy/rocket/aero_surface/fins/elliptical_fin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ def to_dict(self, include_outputs=False):
202202
@classmethod
203203
def from_dict(cls, data):
204204
return cls(
205-
n=data["n"],
205+
angular_position=data["angular_position"],
206206
root_chord=data["root_chord"],
207207
span=data["span"],
208208
rocket_radius=data["rocket_radius"],

rocketpy/rocket/aero_surface/fins/elliptical_fins.py

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -184,24 +184,6 @@ def evaluate_center_of_pressure(self):
184184
self.cpz = cpz
185185
self.cp = (self.cpx, self.cpy, self.cpz)
186186

187-
def to_dict(self, include_outputs=False):
188-
data = super().to_dict(include_outputs)
189-
if include_outputs:
190-
data.update(
191-
{
192-
"Af": self.Af,
193-
"AR": self.AR,
194-
"gamma_c": self.gamma_c,
195-
"Yma": self.Yma,
196-
"roll_geometrical_constant": self.roll_geometrical_constant,
197-
"tau": self.tau,
198-
"lift_interference_factor": self.lift_interference_factor,
199-
"roll_damping_interference_factor": self.roll_damping_interference_factor,
200-
"roll_forcing_interference_factor": self.roll_forcing_interference_factor,
201-
}
202-
)
203-
return data
204-
205187
@classmethod
206188
def from_dict(cls, data):
207189
return cls(

rocketpy/rocket/aero_surface/fins/free_form_fin.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,3 +168,14 @@ def evaluate_center_of_pressure(self):
168168
self.cpy = self.Yma
169169
self.cpz = cpz
170170
self.cp = (self.cpx, self.cpy, self.cpz)
171+
172+
@classmethod
173+
def from_dict(cls, data):
174+
return cls(
175+
angular_position=data["angular_position"],
176+
shape_points=data["shape_points"],
177+
rocket_radius=data["rocket_radius"],
178+
cant_angle=data["cant_angle"],
179+
airfoil=data["airfoil"],
180+
name=data["name"],
181+
)

rocketpy/rocket/aero_surface/fins/free_form_fins.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,3 +167,14 @@ def evaluate_center_of_pressure(self):
167167
self.cpy = 0
168168
self.cpz = cpz
169169
self.cp = (self.cpx, self.cpy, self.cpz)
170+
171+
@classmethod
172+
def from_dict(cls, data):
173+
return cls(
174+
n=data["n"],
175+
shape_points=data["shape_points"],
176+
rocket_radius=data["rocket_radius"],
177+
cant_angle=data["cant_angle"],
178+
airfoil=data["airfoil"],
179+
name=data["name"],
180+
)

rocketpy/rocket/aero_surface/fins/trapezoidal_fin.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,3 +182,16 @@ def evaluate_center_of_pressure(self):
182182
self.cpy = self.Yma
183183
self.cpz = cpz
184184
self.cp = (self.cpx, self.cpy, self.cpz)
185+
186+
@classmethod
187+
def from_dict(cls, data):
188+
return cls(
189+
angular_position=data["angular_position"],
190+
root_chord=data["root_chord"],
191+
tip_chord=data["tip_chord"],
192+
span=data["span"],
193+
rocket_radius=data["rocket_radius"],
194+
cant_angle=data["cant_angle"],
195+
airfoil=data["airfoil"],
196+
name=data["name"],
197+
)

rocketpy/rocket/aero_surface/fins/trapezoidal_fins.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,3 +193,16 @@ def evaluate_center_of_pressure(self):
193193
self.cpy = 0
194194
self.cpz = cpz
195195
self.cp = (self.cpx, self.cpy, self.cpz)
196+
197+
@classmethod
198+
def from_dict(cls, data):
199+
return cls(
200+
n=data["n"],
201+
root_chord=data["root_chord"],
202+
tip_chord=data["tip_chord"],
203+
span=data["span"],
204+
rocket_radius=data["rocket_radius"],
205+
cant_angle=data["cant_angle"],
206+
airfoil=data["airfoil"],
207+
name=data["name"],
208+
)

0 commit comments

Comments
 (0)