Skip to content

Commit 0c4b26b

Browse files
Merge branch 'dev/adds-coverage-configuration-file' of https://github.com/RocketPy-Team/RocketPy into dev/adds-coverage-configuration-file
2 parents 3a3a311 + 191650f commit 0c4b26b

File tree

7 files changed

+301
-224
lines changed

7 files changed

+301
-224
lines changed

rocketpy/environment/environment.py

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,7 @@ def get_elevation_from_topographic_profile(self, lat, lon):
652652
653653
Returns
654654
-------
655-
elevation : float
655+
elevation : float | int
656656
Elevation provided by the topographic data, in meters.
657657
"""
658658
if self.topographic_profile_activated == False:
@@ -3335,6 +3335,29 @@ def export_environment(self, filename="environment"):
33353335
atmospheric_model_file = ""
33363336
atmospheric_model_dict = ""
33373337

3338+
try:
3339+
height = self.height
3340+
atmospheric_model_pressure_profile = ma.getdata(
3341+
self.pressure.get_source()(height)
3342+
).tolist()
3343+
atmospheric_model_wind_velocity_x_profile = ma.getdata(
3344+
self.wind_velocity_x.get_source()(height)
3345+
).tolist()
3346+
atmospheric_model_wind_velocity_y_profile = ma.getdata(
3347+
self.wind_velocity_y.get_source()(height)
3348+
).tolist()
3349+
3350+
except AttributeError:
3351+
atmospheric_model_pressure_profile = (
3352+
"Height Above Sea Level (m) was not provided"
3353+
)
3354+
atmospheric_model_wind_velocity_x_profile = (
3355+
"Height Above Sea Level (m) was not provided"
3356+
)
3357+
atmospheric_model_wind_velocity_y_profile = (
3358+
"Height Above Sea Level (m) was not provided"
3359+
)
3360+
33383361
self.export_env_dictionary = {
33393362
"gravity": self.gravity(self.elevation),
33403363
"date": [
@@ -3352,18 +3375,12 @@ def export_environment(self, filename="environment"):
33523375
"atmospheric_model_type": self.atmospheric_model_type,
33533376
"atmospheric_model_file": atmospheric_model_file,
33543377
"atmospheric_model_dict": atmospheric_model_dict,
3355-
"atmospheric_model_pressure_profile": ma.getdata(
3356-
self.pressure.get_source()
3357-
).tolist(),
3378+
"atmospheric_model_pressure_profile": atmospheric_model_pressure_profile,
33583379
"atmospheric_model_temperature_profile": ma.getdata(
33593380
self.temperature.get_source()
33603381
).tolist(),
3361-
"atmospheric_model_wind_velocity_x_profile": ma.getdata(
3362-
self.wind_velocity_x.get_source()
3363-
).tolist(),
3364-
"atmospheric_model_wind_velocity_y_profile": ma.getdata(
3365-
self.wind_velocity_y.get_source()
3366-
).tolist(),
3382+
"atmospheric_model_wind_velocity_x_profile": atmospheric_model_wind_velocity_x_profile,
3383+
"atmospheric_model_wind_velocity_y_profile": atmospheric_model_wind_velocity_y_profile,
33673384
}
33683385

33693386
f = open(filename + ".json", "w")
@@ -3696,7 +3713,7 @@ def decimal_degrees_to_arc_seconds(angle):
36963713
-------
36973714
degrees : float
36983715
The degrees.
3699-
arc_minutes : float
3716+
arc_minutes : int
37003717
The arc minutes. 1 arc-minute = (1/60)*degree
37013718
arc_seconds : float
37023719
The arc Seconds. 1 arc-second = (1/3600)*degree

tests/fixtures/environment/environment_fixtures.py

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,57 @@
1-
import datetime
1+
from datetime import datetime, timedelta
22

33
import pytest
4-
54
from rocketpy import Environment, EnvironmentAnalysis
65

76

87
@pytest.fixture
9-
def example_env():
10-
"""Create a simple object of the Environment class to be used in the tests.
11-
This allows to avoid repeating the same code in all tests. The environment
12-
set here is the simplest possible, with no parameters set.
8+
def example_plain_env():
9+
"""Simple object of the Environment class to be used in the tests.
1310
1411
Returns
1512
-------
1613
rocketpy.Environment
17-
The simplest object of the Environment class
1814
"""
1915
return Environment()
2016

2117

2218
@pytest.fixture
23-
def example_env_robust():
24-
"""Create an object of the Environment class to be used in the tests. This
25-
allows to avoid repeating the same code in all tests. The environment set
26-
here is a bit more complex than the one in the example_env fixture. This
27-
time the latitude, longitude and elevation are set, as well as the datum and
28-
the date. The location refers to the Spaceport America Cup launch site,
29-
while the date is set to tomorrow at noon.
19+
def example_date_naive():
20+
"""Naive tomorrow date
21+
22+
Returns
23+
-------
24+
datetime.datetime
25+
"""
26+
return datetime.now() + timedelta(days=1)
27+
28+
29+
@pytest.fixture
30+
def example_spaceport_env(example_date_naive):
31+
"""Environment class with location set to Spaceport America Cup launch site
3032
3133
Returns
3234
-------
3335
rocketpy.Environment
34-
An object of the Environment class
3536
"""
36-
env = Environment(
37+
spaceport_env = Environment(
3738
latitude=32.990254,
3839
longitude=-106.974998,
3940
elevation=1400,
4041
datum="WGS84",
4142
)
42-
tomorrow = datetime.date.today() + datetime.timedelta(days=1)
43-
env.set_date((tomorrow.year, tomorrow.month, tomorrow.day, 12))
44-
return env
43+
spaceport_env.set_date(example_date_naive)
44+
spaceport_env.height = 1425
45+
return spaceport_env
4546

4647

4748
@pytest.fixture
4849
def env_analysis():
49-
"""Create a simple object of the Environment Analysis class to be used in
50-
the tests. This allows to avoid repeating the same code in all tests.
50+
"""Environment Analysis class with hardcoded parameters
5151
5252
Returns
5353
-------
5454
EnvironmentAnalysis
55-
A simple object of the Environment Analysis class
5655
"""
5756
env_analysis = EnvironmentAnalysis(
5857
start_date=datetime.datetime(2019, 10, 23),

tests/fixtures/flight/flight_fixtures.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55

66
@pytest.fixture
7-
def flight_calisto(calisto, example_env): # old name: flight
7+
def flight_calisto(calisto, example_plain_env): # old name: flight
88
"""A rocketpy.Flight object of the Calisto rocket. This uses the calisto
99
without the aerodynamic surfaces and parachutes. The environment is the
1010
simplest possible, with no parameters set.
@@ -13,7 +13,7 @@ def flight_calisto(calisto, example_env): # old name: flight
1313
----------
1414
calisto : rocketpy.Rocket
1515
An object of the Rocket class. This is a pytest fixture too.
16-
example_env : rocketpy.Environment
16+
example_plain_env : rocketpy.Environment
1717
An object of the Environment class. This is a pytest fixture too.
1818
1919
Returns
@@ -23,7 +23,7 @@ def flight_calisto(calisto, example_env): # old name: flight
2323
conditions.
2424
"""
2525
return Flight(
26-
environment=example_env,
26+
environment=example_plain_env,
2727
rocket=calisto,
2828
rail_length=5.2,
2929
inclination=85,
@@ -33,7 +33,7 @@ def flight_calisto(calisto, example_env): # old name: flight
3333

3434

3535
@pytest.fixture
36-
def flight_calisto_nose_to_tail(calisto_nose_to_tail, example_env):
36+
def flight_calisto_nose_to_tail(calisto_nose_to_tail, example_plain_env):
3737
"""A rocketpy.Flight object of the Calisto rocket. This uses the calisto
3838
with "nose_to_tail" coordinate system orientation, just as described in the
3939
calisto_nose_to_tail fixture.
@@ -42,7 +42,7 @@ def flight_calisto_nose_to_tail(calisto_nose_to_tail, example_env):
4242
----------
4343
calisto_nose_to_tail : rocketpy.Rocket
4444
An object of the Rocket class. This is a pytest fixture too.
45-
example_env : rocketpy.Environment
45+
example_plain_env : rocketpy.Environment
4646
An object of the Environment class. This is a pytest fixture too.
4747
4848
Returns
@@ -52,7 +52,7 @@ def flight_calisto_nose_to_tail(calisto_nose_to_tail, example_env):
5252
"nose_to_tail".
5353
"""
5454
return Flight(
55-
environment=example_env,
55+
environment=example_plain_env,
5656
rocket=calisto_nose_to_tail,
5757
rail_length=5.2,
5858
inclination=85,
@@ -62,7 +62,7 @@ def flight_calisto_nose_to_tail(calisto_nose_to_tail, example_env):
6262

6363

6464
@pytest.fixture
65-
def flight_calisto_robust(calisto_robust, example_env_robust):
65+
def flight_calisto_robust(calisto_robust, example_spaceport_env):
6666
"""A rocketpy.Flight object of the Calisto rocket. This uses the calisto
6767
with the aerodynamic surfaces and parachutes. The environment is a bit more
6868
complex than the one in the flight_calisto fixture. This time the latitude,
@@ -74,7 +74,7 @@ def flight_calisto_robust(calisto_robust, example_env_robust):
7474
----------
7575
calisto_robust : rocketpy.Rocket
7676
An object of the Rocket class. This is a pytest fixture too.
77-
example_env_robust : rocketpy.Environment
77+
example_spaceport_env : rocketpy.Environment
7878
An object of the Environment class. This is a pytest fixture too.
7979
8080
Returns
@@ -84,7 +84,7 @@ def flight_calisto_robust(calisto_robust, example_env_robust):
8484
condition.
8585
"""
8686
return Flight(
87-
environment=example_env_robust,
87+
environment=example_spaceport_env,
8888
rocket=calisto_robust,
8989
rail_length=5.2,
9090
inclination=85,
@@ -94,7 +94,7 @@ def flight_calisto_robust(calisto_robust, example_env_robust):
9494

9595

9696
@pytest.fixture
97-
def flight_calisto_custom_wind(calisto_robust, example_env_robust):
97+
def flight_calisto_custom_wind(calisto_robust, example_spaceport_env):
9898
"""A rocketpy.Flight object of the Calisto rocket. This uses the calisto
9999
with the aerodynamic surfaces and parachutes. The environment is a bit more
100100
complex than the one in the flight_calisto_robust fixture. Now the wind is
@@ -104,15 +104,15 @@ def flight_calisto_custom_wind(calisto_robust, example_env_robust):
104104
----------
105105
calisto_robust : rocketpy.Rocket
106106
An object of the Rocket class. This is a pytest fixture too.
107-
example_env_robust : rocketpy.Environment
107+
example_spaceport_env : rocketpy.Environment
108108
An object of the Environment class. This is a pytest fixture too.
109109
110110
Returns
111111
-------
112112
rocketpy.Flight
113113
114114
"""
115-
env = example_env_robust
115+
env = example_spaceport_env
116116
env.set_atmospheric_model(
117117
type="custom_atmosphere",
118118
temperature=300,
@@ -130,7 +130,7 @@ def flight_calisto_custom_wind(calisto_robust, example_env_robust):
130130

131131

132132
@pytest.fixture
133-
def flight_calisto_air_brakes(calisto_air_brakes_clamp_on, example_env):
133+
def flight_calisto_air_brakes(calisto_air_brakes_clamp_on, example_plain_env):
134134
"""A rocketpy.Flight object of the Calisto rocket. This uses the calisto
135135
with the aerodynamic surfaces and air brakes. The environment is the
136136
simplest possible, with no parameters set. The air brakes are set to clamp
@@ -140,7 +140,7 @@ def flight_calisto_air_brakes(calisto_air_brakes_clamp_on, example_env):
140140
----------
141141
calisto_air_brakes_clamp_on : rocketpy.Rocket
142142
An object of the Rocket class.
143-
example_env : rocketpy.Environment
143+
example_plain_env : rocketpy.Environment
144144
An object of the Environment class.
145145
146146
Returns
@@ -151,7 +151,7 @@ def flight_calisto_air_brakes(calisto_air_brakes_clamp_on, example_env):
151151
"""
152152
return Flight(
153153
rocket=calisto_air_brakes_clamp_on,
154-
environment=example_env,
154+
environment=example_plain_env,
155155
rail_length=5.2,
156156
inclination=85,
157157
heading=0,

0 commit comments

Comments
 (0)