Trajectory optimization with 4d wind field¶
In [1]:
import warnings
import openap
from fastmeteo.source import ArcoEra5
import numpy as np
import opentop
import pandas as pd
warnings.filterwarnings("ignore")
/home/junzi/arc/code/1-public/opentop/.venv/lib/python3.13/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html from .autonotebook import tqdm as notebook_tqdm
airports and aircraft¶
In [2]:
actype = "A320"
origin = "EHAM"
destination = "LGAV"
m0 = 0.85
o = openap.nav.airport(origin)
d = openap.nav.airport(destination)
latmin = min(o["lat"], d["lat"]) - 2
latmax = max(o["lat"], d["lat"]) + 2
lonmin = min(o["lon"], d["lon"]) - 2
lonmax = max(o["lon"], d["lon"]) + 2
wind data¶
We will use fastmeteo to get the wind field data
In [3]:
latitudes = np.linspace(latmin, latmax, 20)
longitudes = np.linspace(lonmin, lonmax, 20)
altitudes = np.linspace(1000, 45000, 30)
timestamps = pd.date_range("2021-05-01 08:00:00", "2021-05-01 15:00:00", freq="1H")
latitudes, longitudes, altitudes, times = np.meshgrid(
latitudes, longitudes, altitudes, timestamps
)
grid = pd.DataFrame().assign(
latitude=latitudes.flatten(),
longitude=longitudes.flatten(),
altitude=altitudes.flatten(),
timestamp=times.flatten(),
)
fmg = ArcoEra5(local_store="/tmp/era5-zarr")
wind = fmg.interpolate(grid)
In [4]:
wind.head()
Out[4]:
| latitude | longitude | altitude | timestamp | u_component_of_wind | v_component_of_wind | temperature | specific_humidity | |
|---|---|---|---|---|---|---|---|---|
| 0 | 35.92351 | 2.7463 | 1000.0 | 2021-05-01 08:00:00 | 2.661991 | -0.268154 | 287.403711 | 0.007505 |
| 1 | 35.92351 | 2.7463 | 1000.0 | 2021-05-01 09:00:00 | 2.610644 | 0.375756 | 288.403974 | 0.006770 |
| 2 | 35.92351 | 2.7463 | 1000.0 | 2021-05-01 10:00:00 | 3.806019 | 0.308188 | 289.144602 | 0.006112 |
| 3 | 35.92351 | 2.7463 | 1000.0 | 2021-05-01 11:00:00 | 3.865913 | -0.590817 | 290.408729 | 0.005582 |
| 4 | 35.92351 | 2.7463 | 1000.0 | 2021-05-01 12:00:00 | 4.224835 | -1.288763 | 291.952265 | 0.005171 |
Optimize¶
reformat the wind dataframe columns before using it in the optimization
In [5]:
wind = (
wind.rename(columns={"u_component_of_wind": "u", "v_component_of_wind": "v"})
.assign(ts=lambda x: (x.timestamp - x.timestamp.iloc[0]).dt.total_seconds())
.eval("h=altitude * 0.3048")
)
optimizer = opentop.CompleteFlight(actype, origin, destination, m0)
optimizer.enable_wind(wind)
flight = optimizer.trajectory(objective="fuel")
In [6]:
opentop.vis.trajectory(flight)
Out[6]:
<module 'matplotlib.pyplot' from '/home/junzi/arc/code/1-public/opentop/.venv/lib/python3.13/site-packages/matplotlib/pyplot.py'>