Skip to content

Commit a9ec005

Browse files
authored
Merge branch 'develop' into mnt/export-non-apogee-flights
2 parents b11ad3c + 8797068 commit a9ec005

File tree

5 files changed

+213
-105
lines changed

5 files changed

+213
-105
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ Attention: The newest changes should be on top -->
4545
### Changed
4646

4747
- MNT: allow for exporting of non apogee flights. [#863](https://github.com/RocketPy-Team/RocketPy/pull/863)
48+
- TST: remove remaining files after test session. [#862](https://github.com/RocketPy-Team/RocketPy/pull/862)
4849
- MNT: bumps min python version to 3.10 [#857](https://github.com/RocketPy-Team/RocketPy/pull/857)
4950
- DOC: Update docs dependencies and sub dependencies [#851](https://github.com/RocketPy-Team/RocketPy/pull/851)
5051
- MNT: extract flight data exporters [#845](https://github.com/RocketPy-Team/RocketPy/pull/845)
@@ -53,6 +54,7 @@ Attention: The newest changes should be on top -->
5354

5455
### Fixed
5556

57+
- BUG: correct encoding for trapezoidal sweep length and angle. [#861](https://github.com/RocketPy-Team/RocketPy/pull/861)
5658
- BUG: Fix no time initialization when passing initial_solution as array to Flight object [#844](https://github.com/RocketPy-Team/RocketPy/pull/844)
5759

5860

rocketpy/rocket/aero_surface/fins/trapezoidal_fins.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,6 @@ def __init__(
176176
sweep_length = np.tan(sweep_angle * np.pi / 180) * span
177177
elif sweep_length is None:
178178
sweep_length = root_chord - tip_chord
179-
else:
180-
# Sweep length is given
181-
pass
182179

183180
self._tip_chord = tip_chord
184181
self._sweep_length = sweep_length
@@ -351,12 +348,12 @@ def all_info(self):
351348
def to_dict(self, **kwargs):
352349
data = super().to_dict(**kwargs)
353350
data["tip_chord"] = self.tip_chord
351+
data["sweep_length"] = self.sweep_length
352+
data["sweep_angle"] = self.sweep_angle
354353

355354
if kwargs.get("include_outputs", False):
356355
data.update(
357356
{
358-
"sweep_length": self.sweep_length,
359-
"sweep_angle": self.sweep_angle,
360357
"shape_vec": self.shape_vec,
361358
"Af": self.Af,
362359
"AR": self.AR,
@@ -382,4 +379,5 @@ def from_dict(cls, data):
382379
cant_angle=data["cant_angle"],
383380
airfoil=data["airfoil"],
384381
name=data["name"],
382+
sweep_length=data.get("sweep_length"),
385383
)

tests/fixtures/surfaces/surface_fixtures.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,50 @@ def calisto_trapezoidal_fins():
6969
)
7070

7171

72+
@pytest.fixture
73+
def calisto_trapezoidal_fins_custom_sweep_length():
74+
"""The trapezoidal fins of the Calisto rocket with
75+
a custom sweep length.
76+
77+
Returns
78+
-------
79+
rocketpy.TrapezoidalFins
80+
The trapezoidal fins of the Calisto rocket.
81+
"""
82+
return TrapezoidalFins(
83+
n=4,
84+
span=0.100,
85+
root_chord=0.120,
86+
tip_chord=0.040,
87+
rocket_radius=0.0635,
88+
name="calisto_trapezoidal_fins_custom_sweep_length",
89+
cant_angle=0,
90+
sweep_length=0.1,
91+
)
92+
93+
94+
@pytest.fixture
95+
def calisto_trapezoidal_fins_custom_sweep_angle():
96+
"""The trapezoidal fins of the Calisto rocket with
97+
a custom sweep angle.
98+
99+
Returns
100+
-------
101+
rocketpy.TrapezoidalFins
102+
The trapezoidal fins of the Calisto rocket.
103+
"""
104+
return TrapezoidalFins(
105+
n=4,
106+
span=0.100,
107+
root_chord=0.120,
108+
tip_chord=0.040,
109+
rocket_radius=0.0635,
110+
name="calisto_trapezoidal_fins_custom_sweep_angle",
111+
cant_angle=0,
112+
sweep_angle=30,
113+
)
114+
115+
72116
@pytest.fixture
73117
def calisto_free_form_fins():
74118
"""The free form fins of the Calisto rocket.

tests/integration/simulation/test_monte_carlo.py

Lines changed: 129 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,18 @@
99
plt.rcParams.update({"figure.max_open_warning": 0})
1010

1111

12+
def _post_test_file_cleanup():
13+
"""Clean monte carlo files after test session if they exist."""
14+
if os.path.exists("monte_carlo_class_example.kml"):
15+
os.remove("monte_carlo_class_example.kml")
16+
if os.path.exists("monte_carlo_test.errors.txt"):
17+
os.remove("monte_carlo_test.errors.txt")
18+
if os.path.exists("monte_carlo_test.inputs.txt"):
19+
os.remove("monte_carlo_test.inputs.txt")
20+
if os.path.exists("monte_carlo_test.outputs.txt"):
21+
os.remove("monte_carlo_test.outputs.txt")
22+
23+
1224
@pytest.mark.slow
1325
@pytest.mark.parametrize("parallel", [False, True])
1426
def test_monte_carlo_simulate(monte_carlo_calisto, parallel):
@@ -19,27 +31,29 @@ def test_monte_carlo_simulate(monte_carlo_calisto, parallel):
1931
monte_carlo_calisto : MonteCarlo
2032
The MonteCarlo object, this is a pytest fixture.
2133
"""
22-
# NOTE: this is really slow, it runs 10 flight simulations
23-
monte_carlo_calisto.simulate(
24-
number_of_simulations=10, append=False, parallel=parallel
25-
)
26-
27-
assert monte_carlo_calisto.num_of_loaded_sims == 10
28-
assert monte_carlo_calisto.number_of_simulations == 10
29-
assert str(monte_carlo_calisto.filename.name) == "monte_carlo_test"
30-
assert str(monte_carlo_calisto.error_file.name) == "monte_carlo_test.errors.txt"
31-
assert str(monte_carlo_calisto.output_file.name) == "monte_carlo_test.outputs.txt"
32-
assert np.isclose(
33-
monte_carlo_calisto.processed_results["apogee"][0], 4711, rtol=0.2
34-
)
35-
assert np.isclose(
36-
monte_carlo_calisto.processed_results["impact_velocity"][0],
37-
-5.234,
38-
rtol=0.2,
39-
)
40-
os.remove("monte_carlo_test.errors.txt")
41-
os.remove("monte_carlo_test.outputs.txt")
42-
os.remove("monte_carlo_test.inputs.txt")
34+
try:
35+
# NOTE: this is really slow, it runs 10 flight simulations
36+
monte_carlo_calisto.simulate(
37+
number_of_simulations=10, append=False, parallel=parallel
38+
)
39+
40+
assert monte_carlo_calisto.num_of_loaded_sims == 10
41+
assert monte_carlo_calisto.number_of_simulations == 10
42+
assert str(monte_carlo_calisto.filename.name) == "monte_carlo_test"
43+
assert str(monte_carlo_calisto.error_file.name) == "monte_carlo_test.errors.txt"
44+
assert (
45+
str(monte_carlo_calisto.output_file.name) == "monte_carlo_test.outputs.txt"
46+
)
47+
assert np.isclose(
48+
monte_carlo_calisto.processed_results["apogee"][0], 4711, rtol=0.2
49+
)
50+
assert np.isclose(
51+
monte_carlo_calisto.processed_results["impact_velocity"][0],
52+
-5.234,
53+
rtol=0.2,
54+
)
55+
finally:
56+
_post_test_file_cleanup()
4357

4458

4559
def test_monte_carlo_set_inputs_log(monte_carlo_calisto):
@@ -50,14 +64,17 @@ def test_monte_carlo_set_inputs_log(monte_carlo_calisto):
5064
monte_carlo_calisto : MonteCarlo
5165
The MonteCarlo object, this is a pytest fixture.
5266
"""
53-
monte_carlo_calisto.input_file = "tests/fixtures/monte_carlo/example.inputs.txt"
54-
monte_carlo_calisto.set_inputs_log()
55-
assert len(monte_carlo_calisto.inputs_log) == 100
56-
assert all(isinstance(item, dict) for item in monte_carlo_calisto.inputs_log)
57-
assert all(
58-
"gravity" in item and "elevation" in item
59-
for item in monte_carlo_calisto.inputs_log
60-
)
67+
try:
68+
monte_carlo_calisto.input_file = "tests/fixtures/monte_carlo/example.inputs.txt"
69+
monte_carlo_calisto.set_inputs_log()
70+
assert len(monte_carlo_calisto.inputs_log) == 100
71+
assert all(isinstance(item, dict) for item in monte_carlo_calisto.inputs_log)
72+
assert all(
73+
"gravity" in item and "elevation" in item
74+
for item in monte_carlo_calisto.inputs_log
75+
)
76+
finally:
77+
_post_test_file_cleanup()
6178

6279

6380
def test_monte_carlo_set_outputs_log(monte_carlo_calisto):
@@ -68,14 +85,19 @@ def test_monte_carlo_set_outputs_log(monte_carlo_calisto):
6885
monte_carlo_calisto : MonteCarlo
6986
The MonteCarlo object, this is a pytest fixture.
7087
"""
71-
monte_carlo_calisto.output_file = "tests/fixtures/monte_carlo/example.outputs.txt"
72-
monte_carlo_calisto.set_outputs_log()
73-
assert len(monte_carlo_calisto.outputs_log) == 100
74-
assert all(isinstance(item, dict) for item in monte_carlo_calisto.outputs_log)
75-
assert all(
76-
"apogee" in item and "impact_velocity" in item
77-
for item in monte_carlo_calisto.outputs_log
78-
)
88+
try:
89+
monte_carlo_calisto.output_file = (
90+
"tests/fixtures/monte_carlo/example.outputs.txt"
91+
)
92+
monte_carlo_calisto.set_outputs_log()
93+
assert len(monte_carlo_calisto.outputs_log) == 100
94+
assert all(isinstance(item, dict) for item in monte_carlo_calisto.outputs_log)
95+
assert all(
96+
"apogee" in item and "impact_velocity" in item
97+
for item in monte_carlo_calisto.outputs_log
98+
)
99+
finally:
100+
_post_test_file_cleanup()
79101

80102

81103
# def test_monte_carlo_set_errors_log(monte_carlo_calisto):
@@ -86,22 +108,30 @@ def test_monte_carlo_set_outputs_log(monte_carlo_calisto):
86108

87109
def test_monte_carlo_prints(monte_carlo_calisto):
88110
"""Tests the prints methods of the MonteCarlo class."""
89-
monte_carlo_calisto.info()
90-
monte_carlo_calisto.compare_info(monte_carlo_calisto)
111+
try:
112+
monte_carlo_calisto.info()
113+
monte_carlo_calisto.compare_info(monte_carlo_calisto)
114+
finally:
115+
_post_test_file_cleanup()
91116

92117

93118
@patch("matplotlib.pyplot.show") # pylint: disable=unused-argument
94119
def test_monte_carlo_plots(mock_show, monte_carlo_calisto_pre_loaded):
95120
"""Tests the plots methods of the MonteCarlo class."""
96-
assert monte_carlo_calisto_pre_loaded.all_info() is None
97-
assert (
98-
monte_carlo_calisto_pre_loaded.compare_plots(monte_carlo_calisto_pre_loaded)
99-
is None
100-
)
101-
assert (
102-
monte_carlo_calisto_pre_loaded.compare_ellipses(monte_carlo_calisto_pre_loaded)
103-
is None
104-
)
121+
try:
122+
assert monte_carlo_calisto_pre_loaded.all_info() is None
123+
assert (
124+
monte_carlo_calisto_pre_loaded.compare_plots(monte_carlo_calisto_pre_loaded)
125+
is None
126+
)
127+
assert (
128+
monte_carlo_calisto_pre_loaded.compare_ellipses(
129+
monte_carlo_calisto_pre_loaded
130+
)
131+
is None
132+
)
133+
finally:
134+
_post_test_file_cleanup()
105135

106136

107137
def test_monte_carlo_export_ellipses_to_kml(monte_carlo_calisto_pre_loaded):
@@ -112,17 +142,18 @@ def test_monte_carlo_export_ellipses_to_kml(monte_carlo_calisto_pre_loaded):
112142
monte_carlo_calisto_pre_loaded : MonteCarlo
113143
The MonteCarlo object, this is a pytest fixture.
114144
"""
115-
assert (
116-
monte_carlo_calisto_pre_loaded.export_ellipses_to_kml(
117-
filename="monte_carlo_class_example.kml",
118-
origin_lat=32.990254,
119-
origin_lon=-106.974998,
120-
type="all",
145+
try:
146+
assert (
147+
monte_carlo_calisto_pre_loaded.export_ellipses_to_kml(
148+
filename="monte_carlo_class_example.kml",
149+
origin_lat=32.990254,
150+
origin_lon=-106.974998,
151+
type="all",
152+
)
153+
is None
121154
)
122-
is None
123-
)
124-
125-
os.remove("monte_carlo_class_example.kml")
155+
finally:
156+
_post_test_file_cleanup()
126157

127158

128159
@pytest.mark.slow
@@ -134,47 +165,45 @@ def test_monte_carlo_callback(monte_carlo_calisto):
134165
monte_carlo_calisto : MonteCarlo
135166
The MonteCarlo object, this is a pytest fixture.
136167
"""
137-
138-
# define valid data collector
139-
valid_data_collector = {
140-
"name": lambda flight: flight.name,
141-
"density_t0": lambda flight: flight.env.density(0),
142-
}
143-
144-
monte_carlo_calisto.data_collector = valid_data_collector
145-
# NOTE: this is really slow, it runs 10 flight simulations
146-
monte_carlo_calisto.simulate(number_of_simulations=10, append=False)
147-
148-
# tests if print works when we have None in summary
149-
monte_carlo_calisto.info()
150-
151-
## tests if an error is raised for invalid data_collector definitions
152-
# invalid type
153-
def invalid_data_collector(flight):
154-
return flight.name
155-
156-
with pytest.raises(ValueError):
157-
monte_carlo_calisto._check_data_collector(invalid_data_collector)
158-
159-
# invalid key overwrite
160-
invalid_data_collector = {"apogee": lambda flight: flight.apogee}
161-
with pytest.raises(ValueError):
162-
monte_carlo_calisto._check_data_collector(invalid_data_collector)
163-
164-
# invalid callback definition
165-
invalid_data_collector = {"name": "Calisto"} # callbacks must be callables!
166-
with pytest.raises(ValueError):
167-
monte_carlo_calisto._check_data_collector(invalid_data_collector)
168-
169-
# invalid logic (division by zero)
170-
invalid_data_collector = {
171-
"density_t0": lambda flight: flight.env.density(0) / "0",
172-
}
173-
monte_carlo_calisto.data_collector = invalid_data_collector
174-
# NOTE: this is really slow, it runs 10 flight simulations
175-
with pytest.raises(ValueError):
168+
try:
169+
# define valid data collector
170+
valid_data_collector = {
171+
"name": lambda flight: flight.name,
172+
"density_t0": lambda flight: flight.env.density(0),
173+
}
174+
175+
monte_carlo_calisto.data_collector = valid_data_collector
176+
# NOTE: this is really slow, it runs 10 flight simulations
176177
monte_carlo_calisto.simulate(number_of_simulations=10, append=False)
177178

178-
os.remove("monte_carlo_test.errors.txt")
179-
os.remove("monte_carlo_test.outputs.txt")
180-
os.remove("monte_carlo_test.inputs.txt")
179+
# tests if print works when we have None in summary
180+
monte_carlo_calisto.info()
181+
182+
## tests if an error is raised for invalid data_collector definitions
183+
# invalid type
184+
def invalid_data_collector(flight):
185+
return flight.name
186+
187+
with pytest.raises(ValueError):
188+
monte_carlo_calisto._check_data_collector(invalid_data_collector)
189+
190+
# invalid key overwrite
191+
invalid_data_collector = {"apogee": lambda flight: flight.apogee}
192+
with pytest.raises(ValueError):
193+
monte_carlo_calisto._check_data_collector(invalid_data_collector)
194+
195+
# invalid callback definition
196+
invalid_data_collector = {"name": "Calisto"} # callbacks must be callables!
197+
with pytest.raises(ValueError):
198+
monte_carlo_calisto._check_data_collector(invalid_data_collector)
199+
200+
# invalid logic (division by zero)
201+
invalid_data_collector = {
202+
"density_t0": lambda flight: flight.env.density(0) / "0",
203+
}
204+
monte_carlo_calisto.data_collector = invalid_data_collector
205+
# NOTE: this is really slow, it runs 10 flight simulations
206+
with pytest.raises(ValueError):
207+
monte_carlo_calisto.simulate(number_of_simulations=10, append=False)
208+
finally:
209+
_post_test_file_cleanup()

0 commit comments

Comments
 (0)