{ "cells": [ { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "# Fleet Computation\n", "\n", "The `/trajectory` endpoints in [Contrails API](https://api.contrails.org) were designed to evaluate a scientific model over a single flight. Here, a **flight** is a sequence of discrete temporal spatial points defining the 1-dimensional path of a flight.\n", "\n", "A common use-case evaluates a scientific model over a collection flights (hereby dubbed a **fleet**). This can be achieved through this API by simply sequentially calling an endpoint for each flight in the fleet. In most cases, this sequential computation is *not* optimal.\n", "\n", "Many computations in the backend can be performed substantially faster if run in tandem rather than sequentially over distinct flights. To this end, Contrails API supports **fleet computation**. A sequence of flights can be concatenated into a single POST request body for ingestion by the API. An additional `flight_id` field is required to decompose the fleet object into individual flights. In general, this mode of computation will be nearly as fast as if calling the API with a single flight trajectory.\n", "\n", "This notebook demonstrate best practices for fleet computation in Contrails API." ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import os\n", "import matplotlib.colors as mcolors # pip install matplotlib\n", "import pandas as pd # pip install pandas\n", "import requests # pip install requests" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "# Define credentials\n", "URL = \"https://api.contrails.org\"\n", "API_KEY = os.environ[\"CONTRAILS_API_KEY\"] # put in your API key here\n", "HEADERS = {\"x-api-key\": API_KEY}" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "## Create a fleet\n", "\n", "Here, we load a sample fleet of pre-cleaned flight trajectories from 2023-02-10. This sample is [available for download](../_static/fleet_sample.csv) as a CSV file." ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " | flight_id | \n", "engine_uid | \n", "aircraft_type | \n", "longitude | \n", "latitude | \n", "altitude | \n", "time | \n", "
---|---|---|---|---|---|---|---|
0 | \n", "b5ad83811c43ba5ad584eda8c4b6d836 | \n", "01P10IA020 | \n", "A319 | \n", "-74.178192 | \n", "40.684994 | \n", "12.0 | \n", "2023-02-10T19:48:40Z | \n", "
1 | \n", "b5ad83811c43ba5ad584eda8c4b6d836 | \n", "01P10IA020 | \n", "A319 | \n", "-74.177826 | \n", "40.685491 | \n", "12.0 | \n", "2023-02-10T19:49:00Z | \n", "
2 | \n", "b5ad83811c43ba5ad584eda8c4b6d836 | \n", "01P10IA020 | \n", "A319 | \n", "-74.177460 | \n", "40.685989 | \n", "12.0 | \n", "2023-02-10T19:49:20Z | \n", "
3 | \n", "b5ad83811c43ba5ad584eda8c4b6d836 | \n", "01P10IA020 | \n", "A319 | \n", "-74.177424 | \n", "40.686048 | \n", "12.0 | \n", "2023-02-10T19:49:40Z | \n", "
4 | \n", "b5ad83811c43ba5ad584eda8c4b6d836 | \n", "01P10IA020 | \n", "A319 | \n", "-74.177387 | \n", "40.686107 | \n", "12.0 | \n", "2023-02-10T19:50:00Z | \n", "