Access airport data#

The pycontrails.core.airports module provides access to global airport data and helper functions for working with airport data.

Airport data is loaded at runtime from Our Airports from a fork of the ourairports-data repository.

[1]:
from pycontrails.core import airports

Download global airport database#

The global_airport_database method downloads and caches airport data.

[2]:
db = airports.global_airport_database()
db.head()
[2]:
type name latitude longitude elevation_ft iso_country iso_region municipality scheduled_service icao_code iata_code elevation_m
0 small_airport Rothera Point Airport -67.566941 -68.126993 0.0 AQ AQ-U-A Rothera Point no AAXX NaN 0.0000
1 small_airport Angeles City Flying Club 15.254326 120.677772 100.0 PH PH-U-A MG no ACFC AFC 30.4800
2 small_airport Afutara Aerodrome -9.191389 160.948611 23.0 SB SB-ML Bila yes AGAF AFT 7.0104
3 small_airport Ulawa Airport -9.860544 161.979547 40.0 SB SB-MK Arona no AGAR RNA 12.1920
4 small_airport Uru Harbour Airport -8.873330 161.011002 0.0 SB SB-ML Atoifi yes AGAT ATD 0.0000

You can override the cache location by passing in a pycontrails CacheStore to the cachestore argument:

[3]:
from pycontrails import DiskCacheStore
[4]:
cache = DiskCacheStore(cache_dir="data/airports")
db = airports.global_airport_database(cachestore=cache)
db.head()
[4]:
type name latitude longitude elevation_ft iso_country iso_region municipality scheduled_service icao_code iata_code elevation_m
0 small_airport Rothera Point Airport -67.566941 -68.126993 0.0 AQ AQ-U-A Rothera Point no AAXX NaN 0.0000
1 small_airport Angeles City Flying Club 15.254326 120.677772 100.0 PH PH-U-A MG no ACFC AFC 30.4800
2 small_airport Afutara Aerodrome -9.191389 160.948611 23.0 SB SB-ML Bila yes AGAF AFT 7.0104
3 small_airport Ulawa Airport -9.860544 161.979547 40.0 SB SB-MK Arona no AGAR RNA 12.1920
4 small_airport Uru Harbour Airport -8.873330 161.011002 0.0 SB SB-ML Atoifi yes AGAT ATD 0.0000

You can force an update of the cached airports by passing in update_cache=True:

[5]:
# redownloads airport database
db = airports.global_airport_database(update_cache=True)

Find nearest airport#

Find the nearest airport to waypoint location

[6]:
# a point in the Massachusetts bay close to BOS
longitude = -70.842554
latitude = 42.387466
altitude = 1000

# open the airport database
db = airports.global_airport_database()

# returns the icao code of the closest airport
airports.find_nearest_airport(db, longitude, latitude, altitude)
[6]:
'KBOS'

The function returns None if no airport is found within the default bounding box (2°)

[7]:
# Somewhere in the atlantic
longitude = -50
latitude = 35
altitude = 1000

airports.find_nearest_airport(db, longitude, latitude, altitude)

Pass in the bbox parameter (in units of °) to increase the search distance

[8]:
airports.find_nearest_airport(db, longitude, latitude, altitude, bbox=20)
[8]:
'CYYT'

Find distance to airports#

Calculate the haversine distance (in m) to all input airports

[9]:
db = airports.global_airport_database()

# select BOS and JFK
subset = db[db["iata_code"].isin(["BOS", "JFK"])]

# Find distance to a point in the massachusetts bay close to BOS
longitude = -70.842554
latitude = 42.387466
altitude = 500

airports.distance_to_airports(subset, longitude, latitude, altitude)
[9]:
array([ 13616.14944594, 312341.96236736])