Skip to content
Merged
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Attention: The newest changes should be on top -->
- ENH: Create a rocketpy file to store flight simulations [#800](https://github.com/RocketPy-Team/RocketPy/pull/800)
- ENH: Support for the RSE file format has been added to the library [#798](https://github.com/RocketPy-Team/RocketPy/pull/798)
- ENH: Introduce Net Thrust with pressure corrections [#789](https://github.com/RocketPy-Team/RocketPy/pull/789)
- ENH: Environment object from EnvironmentAnalysis [#813](https://github.com/RocketPy-Team/RocketPy/pull/813)

### Changed

Expand Down
76 changes: 76 additions & 0 deletions rocketpy/environment/environment_analysis.py
Comment thread
Gui-FernandesBR marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -2885,3 +2885,79 @@
file.write(encoded_class)
file.close()
print("Your Environment Analysis file was saved, check it out: " + filename)

def get_environment_object(
self, gravity=None, date=None, datum="SIRGAS2000", max_expected_height=80000.0
):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you change the name from get_ to create_?

get implies that you are just accessing an attribute or something of the sort, create would make more sense here.

After this change we can merge

"""Creates an Environment object with the data from the Environment Analysis instance.
It uses the average values from the data.

Parameters
----------
gravity : int, float, callable, string, array, optional
Surface gravitational acceleration. Positive values point the
acceleration down. If None, the Somigliana formula is used.
See :meth:`Environment.set_gravity_model` for more information.
date : list or tuple, optional
List or tuple of length 4, stating (year, month, day, hour) in the
time zone used in the Environment Analysis instance.
Alternatively, can be a ``datetime`` object specifying launch
date and time. The dates are stored as follows:

- :attr:`Environment.local_date`: Local time of launch in
the time zone specified in the Environment Analysis instance.

- :attr:`Environment.datetime_date`: UTC time of launch.

Default is None.
See :meth:`Environment.set_date` for more information.
datum : string, optional
The desired reference ellipsoidal model, the following options are
available: "SAD69", "WGS84", "NAD83", and "SIRGAS2000". The default
is "SIRGAS2000".
max_expected_height : float, optional
Maximum altitude in meters to keep weather data. The altitude must
be above sea level (ASL). Especially useful for visualization. Can
be altered as desired by running ``max_expected_height = number``.
"""
elevation_si = convert_units(

Check warning on line 2923 in rocketpy/environment/environment_analysis.py

View check run for this annotation

Codecov / codecov/patch

rocketpy/environment/environment_analysis.py#L2923

Added line #L2923 was not covered by tests
self.converted_elevation, self.unit_system["length"], "m"
)
altitude_si = convert_units(self.altitude_list, self.unit_system["length"], "m")

Check warning on line 2926 in rocketpy/environment/environment_analysis.py

View check run for this annotation

Codecov / codecov/patch

rocketpy/environment/environment_analysis.py#L2926

Added line #L2926 was not covered by tests
# Recalculating pressure profile using numpy.percentile
pressures = [

Check warning on line 2928 in rocketpy/environment/environment_analysis.py

View check run for this annotation

Codecov / codecov/patch

rocketpy/environment/environment_analysis.py#L2928

Added line #L2928 was not covered by tests
day_dict[hour]["pressure"](self.altitude_list)
for day_dict in self.converted_pressure_level_data.values()
for hour in day_dict.keys()
]
pressure_profile = np.percentile(pressures, 50, axis=0)
pressure_si = convert_units(

Check warning on line 2934 in rocketpy/environment/environment_analysis.py

View check run for this annotation

Codecov / codecov/patch

rocketpy/environment/environment_analysis.py#L2933-L2934

Added lines #L2933 - L2934 were not covered by tests
pressure_profile, self.unit_system["pressure"], "Pa"
)
temperature_si = convert_units(

Check warning on line 2937 in rocketpy/environment/environment_analysis.py

View check run for this annotation

Codecov / codecov/patch

rocketpy/environment/environment_analysis.py#L2937

Added line #L2937 was not covered by tests
self.average_temperature_profile, self.unit_system["temperature"], "K"
)
wind_velocity_x_si = convert_units(

Check warning on line 2940 in rocketpy/environment/environment_analysis.py

View check run for this annotation

Codecov / codecov/patch

rocketpy/environment/environment_analysis.py#L2940

Added line #L2940 was not covered by tests
self.average_wind_velocity_x_profile, self.unit_system["wind_speed"], "m/s"
)
wind_velocity_y_si = convert_units(

Check warning on line 2943 in rocketpy/environment/environment_analysis.py

View check run for this annotation

Codecov / codecov/patch

rocketpy/environment/environment_analysis.py#L2943

Added line #L2943 was not covered by tests
self.average_wind_velocity_y_profile, self.unit_system["wind_speed"], "m/s"
)
env = Environment(

Check warning on line 2946 in rocketpy/environment/environment_analysis.py

View check run for this annotation

Codecov / codecov/patch

rocketpy/environment/environment_analysis.py#L2946

Added line #L2946 was not covered by tests
gravity,
date,
self.latitude,
self.longitude,
elevation_si,
datum,
self.preferred_timezone,
max_expected_height,
)
env.set_atmospheric_model(

Check warning on line 2956 in rocketpy/environment/environment_analysis.py

View check run for this annotation

Codecov / codecov/patch

rocketpy/environment/environment_analysis.py#L2956

Added line #L2956 was not covered by tests
type="custom_atmosphere",
pressure=list(zip(altitude_si, pressure_si)),
temperature=list(zip(altitude_si, temperature_si)),
wind_u=list(zip(altitude_si, wind_velocity_x_si)),
wind_v=list(zip(altitude_si, wind_velocity_y_si)),
)
return env

Check warning on line 2963 in rocketpy/environment/environment_analysis.py

View check run for this annotation

Codecov / codecov/patch

rocketpy/environment/environment_analysis.py#L2963

Added line #L2963 was not covered by tests
7 changes: 7 additions & 0 deletions tests/integration/test_environment_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import matplotlib as plt
import pytest
from rocketpy import Environment

plt.rcParams.update({"figure.max_open_warning": 0})

Expand Down Expand Up @@ -55,3 +56,9 @@ def test_exports(mock_show, env_analysis): # pylint: disable=unused-argument
os.remove("env_analysis_dict")
os.remove("wind_rose.gif")
os.remove("export_env_analysis.json")


@pytest.mark.slow
@patch("matplotlib.pyplot.show")
def test_get_environment_object(mock_show, env_analysis): # pylint: disable=unused-argument
assert isinstance(env_analysis.get_environment_object(), Environment)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ArthurJWH this still needs the name change