Skip to content

Commit

Permalink
Merge branch 'develop' into enh/class_dispersion
Browse files Browse the repository at this point in the history
  • Loading branch information
Gui-FernandesBR authored Mar 13, 2024
2 parents 0d783df + 6096bfd commit cc02d06
Show file tree
Hide file tree
Showing 7 changed files with 301 additions and 224 deletions.
39 changes: 28 additions & 11 deletions rocketpy/environment/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,7 @@ def get_elevation_from_topographic_profile(self, lat, lon):
Returns
-------
elevation : float
elevation : float | int
Elevation provided by the topographic data, in meters.
"""
if self.topographic_profile_activated == False:
Expand Down Expand Up @@ -3335,6 +3335,29 @@ def export_environment(self, filename="environment"):
atmospheric_model_file = ""
atmospheric_model_dict = ""

try:
height = self.height
atmospheric_model_pressure_profile = ma.getdata(
self.pressure.get_source()(height)
).tolist()
atmospheric_model_wind_velocity_x_profile = ma.getdata(
self.wind_velocity_x.get_source()(height)
).tolist()
atmospheric_model_wind_velocity_y_profile = ma.getdata(
self.wind_velocity_y.get_source()(height)
).tolist()

except AttributeError:
atmospheric_model_pressure_profile = (
"Height Above Sea Level (m) was not provided"
)
atmospheric_model_wind_velocity_x_profile = (
"Height Above Sea Level (m) was not provided"
)
atmospheric_model_wind_velocity_y_profile = (
"Height Above Sea Level (m) was not provided"
)

self.export_env_dictionary = {
"gravity": self.gravity(self.elevation),
"date": [
Expand All @@ -3352,18 +3375,12 @@ def export_environment(self, filename="environment"):
"atmospheric_model_type": self.atmospheric_model_type,
"atmospheric_model_file": atmospheric_model_file,
"atmospheric_model_dict": atmospheric_model_dict,
"atmospheric_model_pressure_profile": ma.getdata(
self.pressure.get_source()
).tolist(),
"atmospheric_model_pressure_profile": atmospheric_model_pressure_profile,
"atmospheric_model_temperature_profile": ma.getdata(
self.temperature.get_source()
).tolist(),
"atmospheric_model_wind_velocity_x_profile": ma.getdata(
self.wind_velocity_x.get_source()
).tolist(),
"atmospheric_model_wind_velocity_y_profile": ma.getdata(
self.wind_velocity_y.get_source()
).tolist(),
"atmospheric_model_wind_velocity_x_profile": atmospheric_model_wind_velocity_x_profile,
"atmospheric_model_wind_velocity_y_profile": atmospheric_model_wind_velocity_y_profile,
}

f = open(filename + ".json", "w")
Expand Down Expand Up @@ -3696,7 +3713,7 @@ def decimal_degrees_to_arc_seconds(angle):
-------
degrees : float
The degrees.
arc_minutes : float
arc_minutes : int
The arc minutes. 1 arc-minute = (1/60)*degree
arc_seconds : float
The arc Seconds. 1 arc-second = (1/3600)*degree
Expand Down
43 changes: 21 additions & 22 deletions tests/fixtures/environment/environment_fixtures.py
Original file line number Diff line number Diff line change
@@ -1,58 +1,57 @@
import datetime
from datetime import datetime, timedelta

import pytest

from rocketpy import Environment, EnvironmentAnalysis


@pytest.fixture
def example_env():
"""Create a simple object of the Environment class to be used in the tests.
This allows to avoid repeating the same code in all tests. The environment
set here is the simplest possible, with no parameters set.
def example_plain_env():
"""Simple object of the Environment class to be used in the tests.
Returns
-------
rocketpy.Environment
The simplest object of the Environment class
"""
return Environment()


@pytest.fixture
def example_env_robust():
"""Create an object of the Environment class to be used in the tests. This
allows to avoid repeating the same code in all tests. The environment set
here is a bit more complex than the one in the example_env fixture. This
time the latitude, longitude and elevation are set, as well as the datum and
the date. The location refers to the Spaceport America Cup launch site,
while the date is set to tomorrow at noon.
def example_date_naive():
"""Naive tomorrow date
Returns
-------
datetime.datetime
"""
return datetime.now() + timedelta(days=1)


@pytest.fixture
def example_spaceport_env(example_date_naive):
"""Environment class with location set to Spaceport America Cup launch site
Returns
-------
rocketpy.Environment
An object of the Environment class
"""
env = Environment(
spaceport_env = Environment(
latitude=32.990254,
longitude=-106.974998,
elevation=1400,
datum="WGS84",
)
tomorrow = datetime.date.today() + datetime.timedelta(days=1)
env.set_date((tomorrow.year, tomorrow.month, tomorrow.day, 12))
return env
spaceport_env.set_date(example_date_naive)
spaceport_env.height = 1425
return spaceport_env


@pytest.fixture
def env_analysis():
"""Create a simple object of the Environment Analysis class to be used in
the tests. This allows to avoid repeating the same code in all tests.
"""Environment Analysis class with hardcoded parameters
Returns
-------
EnvironmentAnalysis
A simple object of the Environment Analysis class
"""
env_analysis = EnvironmentAnalysis(
start_date=datetime.datetime(2019, 10, 23),
Expand Down
30 changes: 15 additions & 15 deletions tests/fixtures/flight/flight_fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@


@pytest.fixture
def flight_calisto(calisto, example_env): # old name: flight
def flight_calisto(calisto, example_plain_env): # old name: flight
"""A rocketpy.Flight object of the Calisto rocket. This uses the calisto
without the aerodynamic surfaces and parachutes. The environment is the
simplest possible, with no parameters set.
Expand All @@ -13,7 +13,7 @@ def flight_calisto(calisto, example_env): # old name: flight
----------
calisto : rocketpy.Rocket
An object of the Rocket class. This is a pytest fixture too.
example_env : rocketpy.Environment
example_plain_env : rocketpy.Environment
An object of the Environment class. This is a pytest fixture too.
Returns
Expand All @@ -23,7 +23,7 @@ def flight_calisto(calisto, example_env): # old name: flight
conditions.
"""
return Flight(
environment=example_env,
environment=example_plain_env,
rocket=calisto,
rail_length=5.2,
inclination=85,
Expand All @@ -33,7 +33,7 @@ def flight_calisto(calisto, example_env): # old name: flight


@pytest.fixture
def flight_calisto_nose_to_tail(calisto_nose_to_tail, example_env):
def flight_calisto_nose_to_tail(calisto_nose_to_tail, example_plain_env):
"""A rocketpy.Flight object of the Calisto rocket. This uses the calisto
with "nose_to_tail" coordinate system orientation, just as described in the
calisto_nose_to_tail fixture.
Expand All @@ -42,7 +42,7 @@ def flight_calisto_nose_to_tail(calisto_nose_to_tail, example_env):
----------
calisto_nose_to_tail : rocketpy.Rocket
An object of the Rocket class. This is a pytest fixture too.
example_env : rocketpy.Environment
example_plain_env : rocketpy.Environment
An object of the Environment class. This is a pytest fixture too.
Returns
Expand All @@ -52,7 +52,7 @@ def flight_calisto_nose_to_tail(calisto_nose_to_tail, example_env):
"nose_to_tail".
"""
return Flight(
environment=example_env,
environment=example_plain_env,
rocket=calisto_nose_to_tail,
rail_length=5.2,
inclination=85,
Expand All @@ -62,7 +62,7 @@ def flight_calisto_nose_to_tail(calisto_nose_to_tail, example_env):


@pytest.fixture
def flight_calisto_robust(calisto_robust, example_env_robust):
def flight_calisto_robust(calisto_robust, example_spaceport_env):
"""A rocketpy.Flight object of the Calisto rocket. This uses the calisto
with the aerodynamic surfaces and parachutes. The environment is a bit more
complex than the one in the flight_calisto fixture. This time the latitude,
Expand All @@ -74,7 +74,7 @@ def flight_calisto_robust(calisto_robust, example_env_robust):
----------
calisto_robust : rocketpy.Rocket
An object of the Rocket class. This is a pytest fixture too.
example_env_robust : rocketpy.Environment
example_spaceport_env : rocketpy.Environment
An object of the Environment class. This is a pytest fixture too.
Returns
Expand All @@ -84,7 +84,7 @@ def flight_calisto_robust(calisto_robust, example_env_robust):
condition.
"""
return Flight(
environment=example_env_robust,
environment=example_spaceport_env,
rocket=calisto_robust,
rail_length=5.2,
inclination=85,
Expand All @@ -94,7 +94,7 @@ def flight_calisto_robust(calisto_robust, example_env_robust):


@pytest.fixture
def flight_calisto_custom_wind(calisto_robust, example_env_robust):
def flight_calisto_custom_wind(calisto_robust, example_spaceport_env):
"""A rocketpy.Flight object of the Calisto rocket. This uses the calisto
with the aerodynamic surfaces and parachutes. The environment is a bit more
complex than the one in the flight_calisto_robust fixture. Now the wind is
Expand All @@ -104,15 +104,15 @@ def flight_calisto_custom_wind(calisto_robust, example_env_robust):
----------
calisto_robust : rocketpy.Rocket
An object of the Rocket class. This is a pytest fixture too.
example_env_robust : rocketpy.Environment
example_spaceport_env : rocketpy.Environment
An object of the Environment class. This is a pytest fixture too.
Returns
-------
rocketpy.Flight
"""
env = example_env_robust
env = example_spaceport_env
env.set_atmospheric_model(
type="custom_atmosphere",
temperature=300,
Expand All @@ -130,7 +130,7 @@ def flight_calisto_custom_wind(calisto_robust, example_env_robust):


@pytest.fixture
def flight_calisto_air_brakes(calisto_air_brakes_clamp_on, example_env):
def flight_calisto_air_brakes(calisto_air_brakes_clamp_on, example_plain_env):
"""A rocketpy.Flight object of the Calisto rocket. This uses the calisto
with the aerodynamic surfaces and air brakes. The environment is the
simplest possible, with no parameters set. The air brakes are set to clamp
Expand All @@ -140,7 +140,7 @@ def flight_calisto_air_brakes(calisto_air_brakes_clamp_on, example_env):
----------
calisto_air_brakes_clamp_on : rocketpy.Rocket
An object of the Rocket class.
example_env : rocketpy.Environment
example_plain_env : rocketpy.Environment
An object of the Environment class.
Returns
Expand All @@ -151,7 +151,7 @@ def flight_calisto_air_brakes(calisto_air_brakes_clamp_on, example_env):
"""
return Flight(
rocket=calisto_air_brakes_clamp_on,
environment=example_env,
environment=example_plain_env,
rail_length=5.2,
inclination=85,
heading=0,
Expand Down
Loading

0 comments on commit cc02d06

Please sign in to comment.