---
arrival_airport: TBPB
categories: [ec_under, ec_track, c_north, c_mid, c_south]
crew:
- job: PI
  name: Bjorn Stevens
- job: WALES
  name: Georgios Dekoutsidis
- job: HAMP
  name: Clara Bayley
- job: Dropsondes
  name: "Helene Gl\xF6ckner"
- job: Smart/VELOX
  name: "Michael Sch\xE4fer"
- job: SpecMACS
  name: Anja Stallmach
- job: Flight Documentation
  name: Daniel Rowe
- job: Ground contact
  name: Chavez Pope
departure_airport: TBPB
flight_id: HALO-20240907a
jupytext:
  text_representation:
    extension: .md
    format_name: myst
kernelspec:
  display_name: Python 3 (ipykernel)
  language: python
  name: python3
landing: '2024-09-07 20:17:02Z'
orphan: true
platform: HALO
takeoff: '2024-09-07 12:51:06Z'
---

{logo}`PERCUSION`

# Flight plan - {front}`flight_id`

```{badges}
```

## Crew

The flight is planned to take off at {front}`takeoff`.

```{crew}
```

## Flight plan

```{code-cell} ipython3
:tags: [hide-input]

from dataclasses import asdict
from datetime import datetime
import orcestra.sat
from orcestra.flightplan import bco, sal, mindelo, point_on_track, LatLon, IntoCircle, FlightPlan

# Some fixed coordinates

lon_min, lon_max, lat_min, lat_max = -65, -5, -5, 25

airport = bco

radius = 72e3*1.852

# Define dates for flight

flight_time   = datetime(2024, 9, 7, 12, 0, 0)
flight_index = f"HALO-{flight_time.strftime('%Y%m%d')}a"

# Load satellite tracks 

ec_fcst_time  = "2024-09-06"
ec_track = orcestra.sat.SattrackLoader("EARTHCARE", ec_fcst_time, kind="PRE",roi="BARBADOS") \
    .get_track_for_day(f"{flight_time:%Y-%m-%d}")\
    .sel(time=slice(f"{flight_time:%Y-%m-%d} 14:00", None))

# Create elements of track

c_south  = point_on_track(ec_track,lat=  7.00).assign(label = "c_south")
c_mid    = point_on_track(ec_track,lat= 10.25).assign(label = "c_mid")
c_north  = point_on_track(ec_track,lat= 13.50).assign(label = "c_north")

c_wait   = c_south.towards(c_mid,distance=radius*0.75).assign(label = "c_wait")
join     = c_south.towards(c_mid,distance=radius).assign(label = "join")
c_out    = c_north.towards(c_mid,distance=radius).assign(label = "c_out")
ec_north = point_on_track(ec_track,lat= 15.00).assign(label = "ec_north") 
xlat     = c_south.towards(c_mid,distance=-radius).lat
ec_south = point_on_track(ec_track,lat=  xlat).assign(label = "ec_south")
ec_mid   = ec_north.towards(ec_south).assign(label = "ec_mid")
ec_turn  = ec_mid.towards(ec_south,fraction=2/3.).assign(label = "ec_turn")

xlat     = c_mid.towards(c_north,fraction=1/6).lat
ec_under = point_on_track(ec_track, lat=xlat, with_time=True).assign(label = "ec_under", note = "meet EarthCARE")

# Additional Waypoints

extra_waypoints = []

# Define Flight Paths

waypoints = [
    airport.assign(fl=0),
    join.assign(fl=410),
    IntoCircle(c_wait.assign(fl=410), radius/4,  360),   
    IntoCircle(c_south.assign(fl=410), radius,360),   
    join.assign(fl=410),
    IntoCircle(c_mid.assign(fl=430), radius, -360,enter=-90), 
    c_mid.assign(fl=450),
    ec_under.assign(fl=450),
    c_out.assign(fl=450),
    IntoCircle(c_north.assign(fl=450), radius, -360), 
    airport.assign(fl=0),
]

# Crew

crew = {
    'Mission PI': 'Bjorn Stevens',
    'DropSondes': 'Helene Glöckner',
    'HAMP': 'Clara Bayley',
    'SMART/VELOX': 'Michael Schäfer',
    'SpecMACS': 'Anja Stallmach',
    'WALES' : 'Georgios Dekoutsidis',
    'Flight Documentation': 'Daniel Rowe',
    'Ground Support': 'Chavez Pope'
}

# Plan

plan = FlightPlan(waypoints, flight_index, extra_waypoints=extra_waypoints, crew=crew)
print(f"Flight index: {plan.flight_id}")
print(f"Take-off: {plan.takeoff_time:%H:%M %Z}\nLanding:  {plan.landing_time:%H:%M %Z}\n")
```

```{code-cell} ipython3
:tags: [hide-input]

import matplotlib.pyplot as plt
import cartopy.crs as ccrs
import easygems.healpix as egh
import intake
from orcestra.flightplan import plot_cwv, plot_path

forecast_overlay = True

plt.figure(figsize = (14, 8))
ax = plt.axes(projection=ccrs.PlateCarree())
ax.set_extent([lon_min, lon_max, lat_min, lat_max], crs=ccrs.PlateCarree())
ax.coastlines(alpha=1.0)
ax.gridlines(draw_labels=True, dms=True, x_inline=False, y_inline=False, alpha = 0.25)

if (forecast_overlay):
    ifs_fcst_time = datetime(2024, 9, 4, 0, 0, 0)
    ds = intake.open_catalog("https://tcodata.mpimet.mpg.de/internal.yaml").HIFS(datetime = ifs_fcst_time).to_dask().pipe(egh.attach_coords)
    cwv_flight_time = ds["tcwv"].sel(time=flight_time, method = "nearest")
    plot_cwv(cwv_flight_time, levels = [50.0, 60.0], ax=ax)
    plt.title(f"{flight_time}\n(CWV forecast issued on {ifs_fcst_time})")

plt.plot(ec_track.lon, ec_track.lat, c='k', ls='dotted')
plot_path(plan, ax, color="C1")

if (False):
    natal   = LatLon(-5.795,-35.209439, label = "natal")
    airways = [natal,sal]
    plot_path(airways, ax, color="purple")
```

```{code-cell} ipython3
:tags: [hide-input]

from orcestra.flightplan import vertical_preview

vertical_preview(waypoints)
```

```{code-cell} ipython3
:tags: [hide-input]

plan.show_details()
plan.export()
```

```{code-cell} ipython3

```
