|
5 | 5 | __license__ = "MIT" |
6 | 6 |
|
7 | 7 | import bisect |
| 8 | +import datetime |
8 | 9 | import json |
9 | 10 | import warnings |
10 | 11 | from collections import defaultdict |
|
23 | 24 | from scipy import stats |
24 | 25 | from timezonefinder import TimezoneFinder |
25 | 26 | from windrose import WindroseAxes |
| 27 | +from rocketpy.Environment import Environment |
26 | 28 |
|
27 | 29 | from rocketpy.Function import Function |
28 | 30 | from rocketpy.units import convert_units |
@@ -105,6 +107,8 @@ def __init__( |
105 | 107 | pressureLevelDataFile=None, |
106 | 108 | timezone=None, |
107 | 109 | unit_system="metric", |
| 110 | + forecast_date=None, |
| 111 | + forecast_args=None, |
108 | 112 | maxExpectedAltitude=None, |
109 | 113 | ): |
110 | 114 | """Constructor for the EnvironmentAnalysis class. |
@@ -140,6 +144,12 @@ def __init__( |
140 | 144 | unit_system : str, optional |
141 | 145 | Unit system to be used when displaying results. |
142 | 146 | 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. |
143 | 153 | maxExpectedAltitude : float, optional |
144 | 154 | Maximum expected altitude for your analysis. This is used to calculate |
145 | 155 | plot limits from pressure level data profiles. If None is set, the |
@@ -202,6 +212,30 @@ def __init__( |
202 | 212 | # Run calculations |
203 | 213 | self.process_data() |
204 | 214 |
|
| 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 | + |
205 | 239 | def __bilinear_interpolation(self, x, y, x1, x2, y1, y2, z11, z12, z21, z22): |
206 | 240 | """ |
207 | 241 | Bilinear interpolation. |
@@ -2624,6 +2658,15 @@ def plot_wind_profile_over_average_day(self, clear_range_limits=False): |
2624 | 2658 | x_max = current_x_max if current_x_max > x_max else x_max |
2625 | 2659 | y_max = current_y_max if current_y_max > y_max else y_max |
2626 | 2660 | 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 | + |
2627 | 2670 | ax.label_outer() |
2628 | 2671 | ax.grid() |
2629 | 2672 | # Set x and y limits for the last axis. Since axes are shared, set to all |
|
0 commit comments