如要執行這個入門版 Colab 並查看預測結果,請使用 Public_Contrails_API_Tester 筆記本。
擷取預測網格
如要透過 Python 存取預報格線 API,請按照下列步驟操作:
import io
import requests
import xarray as xr
API_KEY = "AIza...(replace with your API key)"
params = {"time": "2025-05-15T20:00:00Z"}
response = requests.get(
url="https://contrails.googleapis.com/v2/grids",
params=params,
headers={"x-goog-api-key": API_KEY},
)
response.raise_for_status()
dataset = xr.load_dataset(io.BytesIO(response.content))
擷取預測區域
如要使用 Python 存取預報區域 API,請按照下列步驟操作:
import requests
import geopandas as gpd
API_KEY = "AIza...(replace with your API key)"
params = {"time": "2025-05-15T20:00:00Z"}
response = requests.get(
url="https://contrails.googleapis.com/v2/regions",
params=params,
headers={"x-goog-api-key": API_KEY},
)
response.raise_for_status()
geodataframe = gpd.GeoDataFrame.from_features(response.json())