Skip to content

Commit e8da19e

Browse files
Merge remote-tracking branch 'RocketPy-Team/enh/env_analysis_euroc' into enh/env_analysis_wind_direction
2 parents 9516619 + df7f927 commit e8da19e

File tree

2 files changed

+49921
-60833
lines changed

2 files changed

+49921
-60833
lines changed

docs/notebooks/environment_analysis_EuroC_example.ipynb

Lines changed: 49878 additions & 60833 deletions
Large diffs are not rendered by default.

rocketpy/EnvironmentAnalysis.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
__license__ = "MIT"
66

77
import bisect
8+
import datetime
89
import json
910
import warnings
1011
from collections import defaultdict
@@ -23,6 +24,7 @@
2324
from scipy import stats
2425
from timezonefinder import TimezoneFinder
2526
from windrose import WindroseAxes
27+
from rocketpy.Environment import Environment
2628

2729
from rocketpy.Function import Function
2830
from rocketpy.units import convert_units
@@ -105,6 +107,8 @@ def __init__(
105107
pressureLevelDataFile=None,
106108
timezone=None,
107109
unit_system="metric",
110+
forecast_date=None,
111+
forecast_args=None,
108112
maxExpectedAltitude=None,
109113
):
110114
"""Constructor for the EnvironmentAnalysis class.
@@ -140,6 +144,12 @@ def __init__(
140144
unit_system : str, optional
141145
Unit system to be used when displaying results.
142146
Options are: SI, metric, imperial. Default is metric.
147+
forecast_date : datetime.date, optional
148+
Date for the forecast models. It will be requested the environment forecast
149+
for multiple hours within that specified date.
150+
forecast_args : dictionary, optional
151+
Arguments for setting the forecast on the Environment class. With this argument
152+
it is possible to change the forecast model being used.
143153
maxExpectedAltitude : float, optional
144154
Maximum expected altitude for your analysis. This is used to calculate
145155
plot limits from pressure level data profiles. If None is set, the
@@ -202,6 +212,30 @@ def __init__(
202212
# Run calculations
203213
self.process_data()
204214

215+
# Processing forecast
216+
self.forecast = None
217+
if forecast_date:
218+
self.forecast = {}
219+
hours = list(self.pressureLevelDataDict.values())[0].keys()
220+
for hour in hours:
221+
hour_datetime = datetime.datetime(
222+
year=forecast_date.year,
223+
month=forecast_date.month,
224+
day=forecast_date.day,
225+
hour=int(hour),
226+
)
227+
228+
Env = Environment(
229+
railLength=5,
230+
date=hour_datetime,
231+
latitude=self.latitude,
232+
longitude=self.longitude,
233+
elevation=self.elevation,
234+
)
235+
forecast_args = forecast_args or {"type": "Forecast", "file": "GFS"}
236+
Env.setAtmosphericModel(**forecast_args)
237+
self.forecast[hour] = Env
238+
205239
def __bilinear_interpolation(self, x, y, x1, x2, y1, y2, z11, z12, z21, z22):
206240
"""
207241
Bilinear interpolation.
@@ -2624,6 +2658,15 @@ def plot_wind_profile_over_average_day(self, clear_range_limits=False):
26242658
x_max = current_x_max if current_x_max > x_max else x_max
26252659
y_max = current_y_max if current_y_max > y_max else y_max
26262660
y_min = current_y_min if current_y_min < y_min else y_min
2661+
2662+
if self.forecast:
2663+
forecast = self.forecast
2664+
y = self.average_wind_profile_at_given_hour[hour][1]
2665+
x = forecast[hour].windSpeed.getValue(y) * convert_units(
2666+
1, "m/s", self.unit_system["wind_speed"]
2667+
)
2668+
ax.plot(x, y, "b--")
2669+
26272670
ax.label_outer()
26282671
ax.grid()
26292672
# Set x and y limits for the last axis. Since axes are shared, set to all

0 commit comments

Comments
 (0)