-
-
Notifications
You must be signed in to change notification settings - Fork 259
ENH: Environment object from EnvironmentAnalysis #813
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 7 commits
56dadb4
ab7fa13
bb1d1ad
02f98c0
1534924
56986ea
e6cdf8f
2ca3d86
7cd78b4
2425f29
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
| ): | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you change the name from
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( | ||
| self.converted_elevation, self.unit_system["length"], "m" | ||
| ) | ||
| altitude_si = convert_units(self.altitude_list, self.unit_system["length"], "m") | ||
| # Recalculating pressure profile using numpy.percentile | ||
| pressures = [ | ||
| 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( | ||
| pressure_profile, self.unit_system["pressure"], "Pa" | ||
| ) | ||
| temperature_si = convert_units( | ||
| self.average_temperature_profile, self.unit_system["temperature"], "K" | ||
| ) | ||
| wind_velocity_x_si = convert_units( | ||
| self.average_wind_velocity_x_profile, self.unit_system["wind_speed"], "m/s" | ||
| ) | ||
| wind_velocity_y_si = convert_units( | ||
| self.average_wind_velocity_y_profile, self.unit_system["wind_speed"], "m/s" | ||
| ) | ||
| env = Environment( | ||
| gravity, | ||
| date, | ||
| self.latitude, | ||
| self.longitude, | ||
| elevation_si, | ||
| datum, | ||
| self.preferred_timezone, | ||
| max_expected_height, | ||
| ) | ||
| env.set_atmospheric_model( | ||
| 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 | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ | |
|
|
||
| import matplotlib as plt | ||
| import pytest | ||
| from rocketpy import Environment | ||
|
|
||
| plt.rcParams.update({"figure.max_open_warning": 0}) | ||
|
|
||
|
|
@@ -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) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ArthurJWH this still needs the name change |
||
Uh oh!
There was an error while loading. Please reload this page.