{ "cells": [ { "cell_type": "markdown", "id": "06eecdd2-f107-4ae7-bb8d-39bb6c6ed6a0", "metadata": {}, "source": [ "# ADS-B API\n", "\n", "The [Contrails API](https://api.contrails.org) enables authorized users to access a common ADS-B dataset for contrails research. \n", "\n", "The underlying ADS-B data is provided by [Spire Aviation](https://aviation-docs.spire.com/).\n", "\n", "E-mail [api@contrails.org](mailto:api@contrails.org?subject=Common%20ADS-B%20Access) with subject **Common ADS-B Access** to learn more about how your organization can participate in this program." ] }, { "cell_type": "code", "execution_count": 1, "id": "25cdb008-d720-4614-9dcf-d1785e40349d", "metadata": {}, "outputs": [], "source": [ "import os" ] }, { "cell_type": "code", "execution_count": 2, "id": "d5aaa134-eed6-40e6-83e1-e968c4750da3", "metadata": {}, "outputs": [], "source": [ "# Load API key\n", "# (contact api@contrails.org if you need an API key)\n", "URL = \"https://api.contrails.org\"\n", "API_KEY = os.environ[\"CONTRAILS_API_KEY\"]\n", "HEADERS = {\"x-api-key\": API_KEY}" ] }, { "cell_type": "markdown", "id": "8fe4646c-0521-4c64-94ab-2cc4def86532", "metadata": {}, "source": [ "## Telemetry\n", "\n", "**GET [/v1/adsb/telemetry](https://api.contrails.org/openapi#/ADS-B/get_telemetry_v1_adsb_telemetry_get)**\n", "\n", "> Note this endpoint can take up to 30 seconds to return depending on bandwidth\n", "\n", "This endpoint returns 1 hour range of all global ADS-B telemetry data as an [Apache Parquet](https://parquet.apache.org/) file.\n", "\n", "Input date must be an ISO 8601 datetime string (UTC) with hourly resolution, e.g. `\"2025-01-06T00\"`. \n", "Any minute or second resolution is ignored.\n", "\n", "See the [ADS-B schema](https://apidocs.contrails.org/_static/adsb-schema.json) for the description of each data key in the Parquet file." ] }, { "cell_type": "code", "execution_count": 3, "id": "bb7d9661-2e40-407e-95f8-6cffb3dfd0c1", "metadata": {}, "outputs": [], "source": [ "import requests # pip install requests\n", "import matplotlib.pyplot as plt # pip install matplotlib\n", "import pandas as pd # pip install pandas" ] }, { "cell_type": "markdown", "id": "02244627-ddb4-4503-9ffe-31c0ef0190e4", "metadata": {}, "source": [ "### Get data for a single hour" ] }, { "cell_type": "code", "execution_count": 4, "id": "71be1e61-0ff6-46cd-81f5-9952910ebcc8", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "HTTP Response Code: 200 OK\n", "\n" ] } ], "source": [ "params = {\n", " \"date\": \"2025-01-24T02\" # ISO 8601 (UTC)\n", "}\n", "\n", "r = requests.get(f\"{URL}/v1/adsb/telemetry\", params=params, headers=HEADERS)\n", "print(f\"HTTP Response Code: {r.status_code} {r.reason}\\n\")\n", "\n", "# write out response content as parquet file\n", "with open(f\"{params['date']}.pq\", \"wb\") as f:\n", " f.write(r.content)" ] }, { "cell_type": "code", "execution_count": 5, "id": "58f47a94-4a68-48ee-83b5-64a421501900", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Number of unique flights: 17103\n", "Number of unique waypoints: 1093322\n" ] }, { "data": { "text/html": [ "
\n", " | timestamp | \n", "latitude | \n", "longitude | \n", "collection_type | \n", "altitude_baro | \n", "icao_address | \n", "flight_id | \n", "callsign | \n", "tail_number | \n", "flight_number | \n", "aircraft_type_icao | \n", "airline_iata | \n", "departure_airport_icao | \n", "departure_scheduled_time | \n", "arrival_airport_icao | \n", "arrival_scheduled_time | \n", "
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | \n", "2025-01-24 02:59:59 | \n", "37.882629 | \n", "-80.429001 | \n", "terrestrial | \n", "31000 | \n", "A91986 | \n", "93a5cd24-1e7b-4dca-a07d-ad391a2e8237 | \n", "PDT5701 | \n", "N686AE | \n", "AA5701 | \n", "E145 | \n", "PT | \n", "KCLT | \n", "2025-01-24 01:53:00 | \n", "KERI | \n", "2025-01-24 03:48:00 | \n", "
1 | \n", "2025-01-24 02:59:59 | \n", "36.193588 | \n", "-112.395912 | \n", "terrestrial | \n", "35000 | \n", "AB415E | \n", "d1dfe570-9e39-4323-a6cf-f4cf602b4149 | \n", "SCX618 | \n", "N824SY | \n", "SY618 | \n", "B738 | \n", "SY | \n", "KPSP | \n", "2025-01-24 02:24:00 | \n", "KMSP | \n", "2025-01-24 05:41:00 | \n", "
2 | \n", "2025-01-24 02:59:59 | \n", "-44.230362 | \n", "171.841019 | \n", "terrestrial | \n", "33950 | \n", "C81D8E | \n", "12d6d993-c01e-4553-80e1-944a34119f69 | \n", "ANZ689 | \n", "ZK-OAB | \n", "NZ689 | \n", "A320 | \n", "NZ | \n", "NZWN | \n", "2025-01-24 02:05:00 | \n", "NZDN | \n", "2025-01-24 03:25:00 | \n", "
3 | \n", "2025-01-24 02:59:59 | \n", "43.008354 | \n", "26.135494 | \n", "terrestrial | \n", "38000 | \n", "4B187F | \n", "0e7d48c3-a4e2-4489-aaa3-4c9b9bea05c2 | \n", "SWR155 | \n", "HB-JHF | \n", "LX155 | \n", "A333 | \n", "LX | \n", "VABB | \n", "2025-01-23 19:50:00 | \n", "LSZH | \n", "2025-01-24 05:10:00 | \n", "
4 | \n", "2025-01-24 02:59:59 | \n", "28.975525 | \n", "-109.411362 | \n", "terrestrial | \n", "37000 | \n", "0D09D5 | \n", "b4050af1-1fc8-4997-ac5a-1d46b690c869 | \n", "VOI1743 | \n", "XA-VLU | \n", "Y41743 | \n", "A321 | \n", "Y4 | \n", "KLAS | \n", "2025-01-24 01:31:00 | \n", "MMGL | \n", "2025-01-24 04:43:00 | \n", "