---
jupytext:
  text_representation:
    extension: .md
    format_name: myst
    format_version: 0.12
    jupytext_version: 1.7.1
kernelspec:
  display_name: Python 3
  language: python
  name: python3
platform: HALO
flight_id: HALO-20240822a
takeoff: "2024-08-22 11:10:00Z"
landing: "2024-08-22 20:00:00Z"
departure_airport: GVAC
arrival_airport: GVAC
crew:
  - name: Florian Ewald
    job: PI
  - name: Silke Groß
    job: WALES
  - name: Clara Bayley
    job: HAMP
  - name: Nina Robbins
    job: Dropsondes
  - name: Sophie Rosenburg
    job: Smart/VELOX
  - name: Veronika Pörtge
    job: SpecMACS
  - name: Brett McKim
    job: Scientist
  - name: Georgios Dekoutsidis
    job: Ground contact
categories: [ec_under, ec_track, c_north, c_mid, c_south, c_atr]
orphan: true
---

{logo}`PERCUSION`

# Flight plan - {front}`flight_id`

```{badges}
```

## Crew

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

```{crew}
```

## Flight plan

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

from orcestra.flightplan import sal, bco, LatLon, IntoCircle, path_preview, plot_cwv, find_ec_lon, mindelo
import orcestra.sat
from datetime import datetime
import intake
import easygems.healpix as egh

cat = intake.open_catalog("https://tcodata.mpimet.mpg.de/internal.yaml")

# Define dates for forecast initialization and flight

issued_time = datetime(2024, 8, 19, 0, 0, 0)
issued_time_str = issued_time.strftime('%Y-%m-%d')

flight_time = datetime(2024, 8, 22, 11, 10, 0)
flight_time_str = flight_time.strftime('%Y-%m-%d')
flight_index = f"HALO-{flight_time.strftime('%Y%m%d')}a"

print("Initalization date of IFS forecast: " + issued_time_str + "\nFlight date: " + flight_time_str + "\nFlight index: " + flight_index)

# Load ec satellite track for
track = orcestra.sat.SattrackLoader("EARTHCARE", "2024-08-22", kind="PRE").get_track_for_day(flight_time_str)
track = track.sel(time=slice(flight_time_str + " 06:00", None))
ec_lons, ec_lats = track.lon.values, track.lat.values

radius = 133e3

lat_edge_south = 6.0
lat_edge_north = 13.3
lat_edge_center = 9.5

airport = sal

lat_north = 17.0 # 10th percentile     #???
lat_south = 6.0 # 5th percentile - 1°  #???

lat_north_ec = 17.0
lat_meet_ec = 15.75
lat_south_ec = 14.5

lat_atr_south_ec = 13.89083333
lat_atr_circle_ec = 14.18
lat_atr_north_ec = 14.77972222

lat_atr_circle_east = 16.064
lon_atr_circle_east = -21.889

# Setting lat/lon coordinates

# Points where we get on ec track?
north_ec = LatLon(lat_north, find_ec_lon(lat_north, ec_lons, ec_lats), "north")
south_ec = LatLon(lat_south, find_ec_lon(lat_south, ec_lons, ec_lats), "south")

# Points where to meet atr and earthcare
north_ec_atr = LatLon(lat_north_ec, find_ec_lon(lat_north_ec, ec_lons, ec_lats), "north_ec")
meet_ec_atr = LatLon(lat_meet_ec, find_ec_lon(lat_meet_ec, ec_lons, ec_lats), "meet_ec")
south_ec_atr = LatLon(lat_south_ec, find_ec_lon(lat_south_ec, ec_lons, ec_lats), "south_ec")

# Intersection of ITCZ edges with ec track
circle_north = LatLon(lat_edge_north, find_ec_lon(lat_edge_north, ec_lons, ec_lats), "circle_north")

circle_center = LatLon(lat_edge_center, find_ec_lon(lat_edge_center, ec_lons, ec_lats), "circle_center")

circle_south = LatLon(lat_edge_south, find_ec_lon(lat_edge_south, ec_lons, ec_lats), "circle_south")

circle_atr_ec = LatLon(lat_atr_circle_ec, find_ec_lon(lat_atr_circle_ec, ec_lons, ec_lats),'circle_atr_ec')

circle_atr_east = LatLon(lat_atr_circle_east, lon_atr_circle_east,'circle_atr_east')


leg_south = [
     airport,
     north_ec,
     circle_north,
     circle_center,
]

leg_circles = [
     IntoCircle(circle_south, radius, 360),
     IntoCircle(circle_center, radius, 360),
     north_ec,
     IntoCircle(circle_atr_ec, 60e3, 360),
     IntoCircle(circle_north, radius, 360),
]
    
leg_home = [
     mindelo,
     IntoCircle(circle_atr_east, 60e3, 360),
     airport,
]

path = leg_south + leg_circles + leg_home 

cat = intake.open_catalog("https://tcodata.mpimet.mpg.de/internal.yaml")
ds = cat.HIFS(datetime=issued_time).to_dask().pipe(egh.attach_coords)
cwv_flight_time = ds["tcwv"].sel(time=flight_time, method = "nearest")

ax = path_preview(path)
plot_cwv(cwv_flight_time)



```

```{code-cell} python3
:tags: [hide-input]
import pandas as pd
from dataclasses import asdict

pd.DataFrame.from_records(map(asdict, [
     north_ec_atr,
     north_ec,
     meet_ec_atr,
     south_ec_atr,
     circle_north,
     circle_center,
     circle_south,
     south_ec,
     mindelo])).set_index("label")
```

```{code-cell} python3
:tags: [hide-input]
from orcestra.flightplan import export_flightplan

export_flightplan("HALO-20240822a", path)
```
