Point Queries

Single Point & Init Time

Check the weather for Zurich.

query = {
    "models": ["ept2"],
    "geo": {
        "type": "point",
        "value": [47.3784, 8.5387],  # [longitude, latitude] - Zurich
        "method": "nearest",
    },
    "variables": [
        "air_temperature_at_height_level_2m",
        "wind_speed_at_height_level_100m",
    ],
    "init_time": "latest",
    "prediction_timedelta": {"start": 0, "end": 72},  # 0-72 hours ahead
}

# Estimate cost before executing
cost_response = requests.post(cost_url, headers=headers, json=query)
cost_response.raise_for_status()
cost_info = cost_response.json()
print(f"Estimated cost: {cost_info['total_credits_needed']:.4f} credits")
print(f"Rows to return: {cost_info['total_rows_returned']}")
print(f"Rows to access: {cost_info['total_rows_accessed']}")

response = requests.post(url, headers=headers, json=query)
response.raise_for_status()

data = response.json()
df = pd.DataFrame(data)
print(f"✅ Retrieved {len(df)} rows")
print(df.head())

Multiple Points, Single Init Time

Get the latest forecast for three points of interest.

points = [
    [47.3784, 8.5387],  # Zurich
    [46.2044, 6.1432],  # Geneva
    [45.4642, 9.1900],  # Milan
]

query = {
    "models": ["ept2"],
    "geo": {
        "type": "point",
        "value": points,
        "method": "bilinear",  # Use bilinear interpolation
    },
    "variables": [
        "air_temperature_at_height_level_2m",
        "air_pressure_at_mean_sea_level",
    ],
    "init_time": "latest",
    "prediction_timedelta": [
        0,
        1,
        2,
        3,
        24,
        48,
        72,
    ],  # Specific timesteps: 0, 1h, 2h, 3h
}

# Estimate cost before executing
cost_response = requests.post(cost_url, headers=headers, json=query)
cost_response.raise_for_status()
cost_info = cost_response.json()
print(f"Estimated cost: {cost_info['total_credits_needed']:.4f} credits")
print(f"Rows to return: {cost_info['total_rows_returned']}")
print(f"Rows to access: {cost_info['total_rows_accessed']}")

response = requests.post(url, headers=headers, json=query)
response.raise_for_status()

data = response.json()
df = pd.DataFrame(data)
print(f"✅ Retrieved {len(df)} rows")
print(df.head(12))

Multiple Models & Points

Request data for mulitple models and locations to compare them.

 query = {
    "models": ["ept2", "aifs"],  # Multiple models
    "geo": {
        "type": "point",
        "value": [
            [47.3784, 8.5387],  # Zurich
            [46.9479, 7.4474],  # Bern
        ],
        "method": "nearest",
    },
    "variables": [
        "air_temperature_at_height_level_2m",
        "wind_speed_at_height_level_10m",
    ],
    "init_time": "latest",
    "prediction_timedelta": {"start": 0, "end": 4},  # 0-4 hours
    "order_by": ["model", "latitude", "longitude", "prediction_timedelta"],
}

# Estimate cost before executing
cost_response = requests.post(cost_url, headers=headers, json=query)
cost_response.raise_for_status()
cost_info = cost_response.json()
print(f"Estimated cost: {cost_info['total_credits_needed']:.4f} credits")
print(f"Rows to return: {cost_info['total_rows_returned']}")
print(f"Rows to access: {cost_info['total_rows_accessed']}")

response = requests.post(url, headers=headers, json=query)
response.raise_for_status()

data = response.json()
df = pd.DataFrame(data)
print(f"✅ Retrieved {len(df)} rows")
print(df.head(10))

# Show comparison between models
if len(df) > 0:
    print("\nModel comparison at first timestep:")
    print(
        df[df["prediction_timedelta"] == df["prediction_timedelta"].min()][
            ["model", "latitude", "longitude", "air_temperature_at_height_level_2m"]
        ]
    )

Historical Data for Single Point

Query two months of 3-day forecasts for Zurich

# Query forecasts from March to April 2025
start_time = datetime(2025, 3, 1, 0, 0, 0)
end_time = datetime(2025, 4, 30, 23, 59, 59)

query = {
    "models": ["ept2"],
    "geo": {
        "type": "point",
        "value": [47.3784, 8.5387],  # Zurich
        "method": "nearest",
    },
    "variables": [
        "air_temperature_at_height_level_2m",
        "precipitation_amount_sum_1h",
    ],
    "init_time": {
        "start": start_time.strftime("%Y-%m-%dT%H:%M:%S"),
        "end": end_time.strftime("%Y-%m-%dT%H:%M:%S"),
    },
    "prediction_timedelta": {"start": 0, "end": 72},
    "order_by": ["init_time", "prediction_timedelta"],
}

# Estimate cost before executing
cost_response = requests.post(cost_url, headers=headers, json=query)
cost_response.raise_for_status()
cost_info = cost_response.json()
print(f"Estimated cost: {cost_info['total_credits_needed']:.4f} credits")
print(f"Rows to return: {cost_info['total_rows_returned']}")
print(f"Rows to access: {cost_info['total_rows_accessed']}")

response = requests.post(url, headers=headers, json=query)
response.raise_for_status()

data = response.json()
df = pd.DataFrame(data)
print(f"✅ Retrieved {len(df)} rows")
print(df.head(10))

if len(df) > 0:
    print(f"\nInit times range: {df['init_time'].min()} to {df['init_time'].max()}")

Last updated