Skip to content

CBottle Tropical Cyclone Guidance

Guided tropical cyclone sampling with cBottle and odds-ratio diagnostics.

This example demonstrates the cBottle TC guidance model for generating synthetic tropical cyclone samples at user-specified locations and computing the log-odds ratio between the guided and unguided distributions. The odds ratio quantifies how much more likely a particular sample is under guidance compared to the base model.

For more information on cBottle see:

For more information on the odds ratio see:

In this example you will learn:

  • Running guided TC sampling with earth2studio.models.dx.CBottleTCGuidance
  • Visualizing a guided sample over a regional domain
  • Reloading the model with second-order derivative support for odds-ratio computation
  • Computing and interpreting the log-odds ratio of a guided sample

Set Up

For this example we need the cBottle TC guidance diagnostic model. We load it twice:

  1. Default (fast) path for standard guided sampling
  2. Second-order-derivative path for odds-ratio computation

Thus, we need the following:

import os

os.makedirs("outputs", exist_ok=True)
from dotenv import load_dotenv

load_dotenv()  # TODO: make common example prep function

from datetime import datetime

import numpy as np
import torch

from earth2studio.models.dx import CBottleTCGuidance

device = torch.device("cuda" if torch.cuda.is_available() else "cpu")

# Load the default model package which downloads the checkpoint from NGC
package = CBottleTCGuidance.load_default_package()

Guided TC Sampling (Fast Path)

The guidance tensor marks the location where we want TC activity. Here we place a single guidance point near Florida and request one timestamp during hurricane season. The fast model path (allow_second_order_derivatives=False) is optimized for standard guided inference.

lat = torch.tensor([27.0], device=device)  # Near Florida
lon = torch.tensor([-82.0], device=device)  # Converted internally to [0, 360)
times = [datetime(2005, 10, 11, 12)]

model = CBottleTCGuidance.load_model(package, seed=0).to(device)
# Create guidance tensor
guidance, coords = model.create_guidance_tensor(lat, lon, times)
guidance = guidance.to(device)
# Run guided sampling
guided_sample, guided_coords = model(guidance, coords)
Console output113 lines
Downloading training-state-002176000.checkpoint: 0%|          | 0.00/1.67G [00:00<?, ?B/s]
Downloading training-state-002176000.checkpoint: 1%|          | 10.0M/1.67G [00:01<03:19, 8.89MB/s]
Downloading training-state-002176000.checkpoint: 2%|โ–         | 30.0M/1.67G [00:01<01:02, 28.0MB/s]
Downloading training-state-002176000.checkpoint: 3%|โ–Ž         | 50.0M/1.67G [00:01<00:37, 45.8MB/s]
Downloading training-state-002176000.checkpoint: 4%|โ–Ž         | 60.0M/1.67G [00:01<00:32, 53.9MB/s]
Downloading training-state-002176000.checkpoint: 5%|โ–         | 80.0M/1.67G [00:01<00:24, 68.8MB/s]
Downloading training-state-002176000.checkpoint: 6%|โ–Œ         | 100M/1.67G [00:02<00:23, 70.7MB/s] 
Downloading training-state-002176000.checkpoint: 6%|โ–‹         | 110M/1.67G [00:02<00:22, 75.5MB/s]
Downloading training-state-002176000.checkpoint: 8%|โ–Š         | 130M/1.67G [00:02<00:19, 86.3MB/s]
Downloading training-state-002176000.checkpoint: 9%|โ–‰         | 150M/1.67G [00:02<00:17, 94.9MB/s]
Downloading training-state-002176000.checkpoint: 10%|โ–‰         | 170M/1.67G [00:02<00:16, 100MB/s]
Downloading training-state-002176000.checkpoint: 11%|โ–ˆ         | 190M/1.67G [00:02<00:15, 102MB/s]
Downloading training-state-002176000.checkpoint: 12%|โ–ˆโ–        | 210M/1.67G [00:03<00:18, 83.3MB/s]
Downloading training-state-002176000.checkpoint: 13%|โ–ˆโ–Ž        | 220M/1.67G [00:03<00:18, 83.6MB/s]
Downloading training-state-002176000.checkpoint: 14%|โ–ˆโ–        | 240M/1.67G [00:03<00:16, 91.3MB/s]
Downloading training-state-002176000.checkpoint: 15%|โ–ˆโ–Œ        | 260M/1.67G [00:04<00:20, 74.2MB/s]
Downloading training-state-002176000.checkpoint: 16%|โ–ˆโ–Œ        | 270M/1.67G [00:04<00:20, 75.2MB/s]
Downloading training-state-002176000.checkpoint: 16%|โ–ˆโ–‹        | 280M/1.67G [00:04<00:19, 74.7MB/s]
Downloading training-state-002176000.checkpoint: 18%|โ–ˆโ–Š        | 300M/1.67G [00:04<00:16, 86.7MB/s]
Downloading training-state-002176000.checkpoint: 18%|โ–ˆโ–Š        | 310M/1.67G [00:04<00:16, 89.7MB/s]
Downloading training-state-002176000.checkpoint: 19%|โ–ˆโ–‰        | 320M/1.67G [00:04<00:17, 84.9MB/s]
Downloading training-state-002176000.checkpoint: 19%|โ–ˆโ–‰        | 330M/1.67G [00:04<00:16, 88.9MB/s]
Downloading training-state-002176000.checkpoint: 21%|โ–ˆโ–ˆ        | 350M/1.67G [00:05<00:14, 97.4MB/s]
Downloading training-state-002176000.checkpoint: 21%|โ–ˆโ–ˆ        | 360M/1.67G [00:05<00:14, 96.8MB/s]
Downloading training-state-002176000.checkpoint: 22%|โ–ˆโ–ˆโ–       | 370M/1.67G [00:05<00:14, 98.0MB/s]
Downloading training-state-002176000.checkpoint: 22%|โ–ˆโ–ˆโ–       | 380M/1.67G [00:05<00:14, 98.5MB/s]
Downloading training-state-002176000.checkpoint: 23%|โ–ˆโ–ˆโ–Ž       | 400M/1.67G [00:05<00:14, 95.1MB/s]
Downloading training-state-002176000.checkpoint: 24%|โ–ˆโ–ˆโ–       | 410M/1.67G [00:05<00:16, 82.6MB/s]
Downloading training-state-002176000.checkpoint: 25%|โ–ˆโ–ˆโ–       | 420M/1.67G [00:05<00:17, 75.1MB/s]
Downloading training-state-002176000.checkpoint: 25%|โ–ˆโ–ˆโ–Œ       | 430M/1.67G [00:06<00:16, 79.9MB/s]
Downloading training-state-002176000.checkpoint: 26%|โ–ˆโ–ˆโ–Œ       | 440M/1.67G [00:06<00:15, 84.0MB/s]
Downloading training-state-002176000.checkpoint: 26%|โ–ˆโ–ˆโ–‹       | 450M/1.67G [00:06<00:16, 79.2MB/s]
Downloading training-state-002176000.checkpoint: 27%|โ–ˆโ–ˆโ–‹       | 460M/1.67G [00:06<00:16, 78.2MB/s]
Downloading training-state-002176000.checkpoint: 28%|โ–ˆโ–ˆโ–Š       | 470M/1.67G [00:06<00:15, 82.5MB/s]
Downloading training-state-002176000.checkpoint: 29%|โ–ˆโ–ˆโ–Š       | 490M/1.67G [00:06<00:13, 94.5MB/s]
Downloading training-state-002176000.checkpoint: 30%|โ–ˆโ–ˆโ–‰       | 510M/1.67G [00:06<00:12, 101MB/s] 
Downloading training-state-002176000.checkpoint: 31%|โ–ˆโ–ˆโ–ˆ       | 530M/1.67G [00:07<00:11, 103MB/s]
Downloading training-state-002176000.checkpoint: 32%|โ–ˆโ–ˆโ–ˆโ–      | 540M/1.67G [00:07<00:11, 102MB/s]
Downloading training-state-002176000.checkpoint: 33%|โ–ˆโ–ˆโ–ˆโ–Ž      | 560M/1.67G [00:07<00:11, 105MB/s]
Downloading training-state-002176000.checkpoint: 34%|โ–ˆโ–ˆโ–ˆโ–      | 580M/1.67G [00:07<00:10, 108MB/s]
Downloading training-state-002176000.checkpoint: 35%|โ–ˆโ–ˆโ–ˆโ–Œ      | 600M/1.67G [00:07<00:10, 108MB/s]
Downloading training-state-002176000.checkpoint: 36%|โ–ˆโ–ˆโ–ˆโ–‹      | 620M/1.67G [00:07<00:10, 110MB/s]
Downloading training-state-002176000.checkpoint: 38%|โ–ˆโ–ˆโ–ˆโ–Š      | 640M/1.67G [00:08<00:10, 112MB/s]
Downloading training-state-002176000.checkpoint: 39%|โ–ˆโ–ˆโ–ˆโ–Š      | 660M/1.67G [00:08<00:09, 114MB/s]
Downloading training-state-002176000.checkpoint: 40%|โ–ˆโ–ˆโ–ˆโ–‰      | 680M/1.67G [00:08<00:09, 114MB/s]
Downloading training-state-002176000.checkpoint: 41%|โ–ˆโ–ˆโ–ˆโ–ˆ      | 700M/1.67G [00:08<00:09, 114MB/s]
Downloading training-state-002176000.checkpoint: 42%|โ–ˆโ–ˆโ–ˆโ–ˆโ–     | 720M/1.67G [00:08<00:09, 114MB/s]
Downloading training-state-002176000.checkpoint: 43%|โ–ˆโ–ˆโ–ˆโ–ˆโ–Ž     | 740M/1.67G [00:09<00:09, 112MB/s]
Downloading training-state-002176000.checkpoint: 45%|โ–ˆโ–ˆโ–ˆโ–ˆโ–     | 760M/1.67G [00:09<00:08, 114MB/s]
Downloading training-state-002176000.checkpoint: 46%|โ–ˆโ–ˆโ–ˆโ–ˆโ–Œ     | 780M/1.67G [00:09<00:09, 104MB/s]
Downloading training-state-002176000.checkpoint: 47%|โ–ˆโ–ˆโ–ˆโ–ˆโ–‹     | 800M/1.67G [00:09<00:09, 99.4MB/s]
Downloading training-state-002176000.checkpoint: 48%|โ–ˆโ–ˆโ–ˆโ–ˆโ–Š     | 820M/1.67G [00:09<00:08, 104MB/s] 
Downloading training-state-002176000.checkpoint: 49%|โ–ˆโ–ˆโ–ˆโ–ˆโ–‰     | 840M/1.67G [00:10<00:09, 98.0MB/s]
Downloading training-state-002176000.checkpoint: 50%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ     | 860M/1.67G [00:10<00:08, 102MB/s] 
Downloading training-state-002176000.checkpoint: 52%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–    | 880M/1.67G [00:10<00:08, 105MB/s]
Downloading training-state-002176000.checkpoint: 53%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–Ž    | 900M/1.67G [00:10<00:08, 104MB/s]
Downloading training-state-002176000.checkpoint: 54%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–    | 920M/1.67G [00:10<00:07, 104MB/s]
Downloading training-state-002176000.checkpoint: 55%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–Œ    | 940M/1.67G [00:11<00:07, 108MB/s]
Downloading training-state-002176000.checkpoint: 56%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–‹    | 960M/1.67G [00:11<00:07, 105MB/s]
Downloading training-state-002176000.checkpoint: 57%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–‹    | 980M/1.67G [00:11<00:08, 90.9MB/s]
Downloading training-state-002176000.checkpoint: 58%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–Š    | 990M/1.67G [00:11<00:08, 91.4MB/s]
Downloading training-state-002176000.checkpoint: 59%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–Š    | 0.98G/1.67G [00:11<00:08, 91.7MB/s]
Downloading training-state-002176000.checkpoint: 59%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–‰    | 0.99G/1.67G [00:11<00:08, 90.1MB/s]
Downloading training-state-002176000.checkpoint: 60%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–‰    | 1.00G/1.67G [00:12<00:08, 87.7MB/s]
Downloading training-state-002176000.checkpoint: 60%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ    | 1.01G/1.67G [00:12<00:09, 73.5MB/s]
Downloading training-state-002176000.checkpoint: 61%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ    | 1.02G/1.67G [00:12<00:09, 77.1MB/s]
Downloading training-state-002176000.checkpoint: 62%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–   | 1.03G/1.67G [00:12<00:08, 76.9MB/s]
Downloading training-state-002176000.checkpoint: 62%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–   | 1.04G/1.67G [00:12<00:08, 79.4MB/s]
Downloading training-state-002176000.checkpoint: 63%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–Ž   | 1.04G/1.67G [00:12<00:07, 83.8MB/s]
Downloading training-state-002176000.checkpoint: 63%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–Ž   | 1.05G/1.67G [00:12<00:07, 87.0MB/s]
Downloading training-state-002176000.checkpoint: 64%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–   | 1.06G/1.67G [00:13<00:09, 66.5MB/s]
Downloading training-state-002176000.checkpoint: 65%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–   | 1.07G/1.67G [00:13<00:08, 74.1MB/s]
Downloading training-state-002176000.checkpoint: 65%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–Œ   | 1.08G/1.67G [00:13<00:07, 78.2MB/s]
Downloading training-state-002176000.checkpoint: 66%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–Œ   | 1.09G/1.67G [00:13<00:07, 81.9MB/s]
Downloading training-state-002176000.checkpoint: 66%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–‹   | 1.10G/1.67G [00:13<00:07, 81.0MB/s]
Downloading training-state-002176000.checkpoint: 67%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–‹   | 1.11G/1.67G [00:13<00:07, 81.5MB/s]
Downloading training-state-002176000.checkpoint: 67%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–‹   | 1.12G/1.67G [00:13<00:07, 80.5MB/s]
Downloading training-state-002176000.checkpoint: 68%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–Š   | 1.13G/1.67G [00:14<00:09, 62.1MB/s]
Downloading training-state-002176000.checkpoint: 69%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–Š   | 1.14G/1.67G [00:14<00:08, 68.0MB/s]
Downloading training-state-002176000.checkpoint: 69%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–‰   | 1.15G/1.67G [00:14<00:07, 74.8MB/s]
Downloading training-state-002176000.checkpoint: 70%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–‰   | 1.16G/1.67G [00:14<00:07, 70.4MB/s]
Downloading training-state-002176000.checkpoint: 70%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ   | 1.17G/1.67G [00:14<00:07, 73.7MB/s]
Downloading training-state-002176000.checkpoint: 71%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ   | 1.18G/1.67G [00:14<00:07, 72.4MB/s]
Downloading training-state-002176000.checkpoint: 72%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–  | 1.19G/1.67G [00:15<00:07, 63.9MB/s]
Downloading training-state-002176000.checkpoint: 72%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–  | 1.20G/1.67G [00:15<00:07, 68.8MB/s]
Downloading training-state-002176000.checkpoint: 73%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–Ž  | 1.21G/1.67G [00:15<00:06, 75.4MB/s]
Downloading training-state-002176000.checkpoint: 74%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–  | 1.23G/1.67G [00:15<00:05, 88.2MB/s]
Downloading training-state-002176000.checkpoint: 74%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–  | 1.24G/1.67G [00:15<00:04, 91.6MB/s]
Downloading training-state-002176000.checkpoint: 75%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–Œ  | 1.25G/1.67G [00:15<00:05, 80.2MB/s]
Downloading training-state-002176000.checkpoint: 76%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–Œ  | 1.26G/1.67G [00:15<00:05, 84.6MB/s]
Downloading training-state-002176000.checkpoint: 77%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–‹  | 1.28G/1.67G [00:16<00:04, 97.3MB/s]
Downloading training-state-002176000.checkpoint: 78%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–Š  | 1.30G/1.67G [00:16<00:03, 108MB/s] 
Downloading training-state-002176000.checkpoint: 79%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–‰  | 1.32G/1.67G [00:16<00:04, 88.8MB/s]
Downloading training-state-002176000.checkpoint: 80%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ  | 1.34G/1.67G [00:16<00:03, 99.3MB/s]
Downloading training-state-002176000.checkpoint: 82%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ– | 1.36G/1.67G [00:16<00:03, 105MB/s] 
Downloading training-state-002176000.checkpoint: 83%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–Ž | 1.38G/1.67G [00:17<00:03, 95.5MB/s]
Downloading training-state-002176000.checkpoint: 84%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ– | 1.40G/1.67G [00:17<00:02, 99.3MB/s]
Downloading training-state-002176000.checkpoint: 85%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–Œ | 1.42G/1.67G [00:17<00:02, 106MB/s] 
Downloading training-state-002176000.checkpoint: 86%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–Œ | 1.44G/1.67G [00:17<00:02, 112MB/s]
Downloading training-state-002176000.checkpoint: 87%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–‹ | 1.46G/1.67G [00:17<00:02, 105MB/s]
Downloading training-state-002176000.checkpoint: 89%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–Š | 1.47G/1.67G [00:18<00:02, 96.6MB/s]
Downloading training-state-002176000.checkpoint: 89%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–‰ | 1.48G/1.67G [00:18<00:02, 93.1MB/s]
Downloading training-state-002176000.checkpoint: 90%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ | 1.50G/1.67G [00:18<00:02, 67.5MB/s]
Downloading training-state-002176000.checkpoint: 91%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–| 1.52G/1.67G [00:18<00:01, 78.8MB/s]
Downloading training-state-002176000.checkpoint: 93%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–Ž| 1.54G/1.67G [00:19<00:01, 86.4MB/s]
Downloading training-state-002176000.checkpoint: 94%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–| 1.56G/1.67G [00:19<00:01, 89.2MB/s]
Downloading training-state-002176000.checkpoint: 95%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–Œ| 1.58G/1.67G [00:19<00:00, 93.4MB/s]
Downloading training-state-002176000.checkpoint: 96%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–Œ| 1.60G/1.67G [00:19<00:00, 102MB/s] 
Downloading training-state-002176000.checkpoint: 97%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–‹| 1.62G/1.67G [00:20<00:00, 83.2MB/s]
Downloading training-state-002176000.checkpoint: 98%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–Š| 1.63G/1.67G [00:20<00:00, 77.4MB/s]
Downloading training-state-002176000.checkpoint: 99%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–‰| 1.65G/1.67G [00:20<00:00, 74.9MB/s]
Downloading training-state-002176000.checkpoint: 100%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ| 1.67G/1.67G [00:20<00:00, 84.2MB/s]
Downloading training-state-002176000.checkpoint: 100%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ| 1.67G/1.67G [00:20<00:00, 86.7MB/s]

Post Processing Guided Sample

Plot the 10-metre zonal wind (u10m) over a Caribbean domain to visualize the generated tropical cyclone structure.

import cartopy.crs as ccrs
import matplotlib.pyplot as plt

plt.close("all")

variables = guided_coords["variable"]
u_var = "u10m"
u_idx = int(np.where(variables == u_var)[0][0])

# guided_sample dims: [time, lead_time, variable, lat, lon]
u = guided_sample[0, 0, u_idx].detach().cpu().numpy()
lat_coords = guided_coords["lat"]
lon_coords = guided_coords["lon"]

# Caribbean box in 0-360 longitude convention
lon_min, lon_max = 260.0, 300.0  # 100W to 60W
lat_min, lat_max = 15.0, 40.0  # 15N to 40N
lon_mask = (lon_coords >= lon_min) & (lon_coords <= lon_max)
lat_mask = (lat_coords >= lat_min) & (lat_coords <= lat_max)

u_carib = u[np.ix_(lat_mask, lon_mask)]
lat_carib = lat_coords[lat_mask]
lon_carib = lon_coords[lon_mask]
# Convert to -180..180 for plotting
lon_carib_deg = ((lon_carib + 180.0) % 360.0) - 180.0

fig, ax = plt.subplots(subplot_kw={"projection": ccrs.PlateCarree()}, figsize=(8, 4.5))
pcm = ax.pcolormesh(
    lon_carib_deg,
    lat_carib,
    u_carib,
    shading="auto",
    cmap="RdBu_r",
    vmin=-30,
    vmax=30,
    transform=ccrs.PlateCarree(),
)
ax.set_extent([-100.0, -60.0, lat_min, lat_max], crs=ccrs.PlateCarree())
ax.coastlines(resolution="110m", linewidth=0.8)
ax.gridlines(draw_labels=True, linewidth=0.5, alpha=0.5, linestyle="--")
plt.colorbar(pcm, ax=ax, label=f"{u_var} (m/s)", pad=0.08, shrink=0.92)
ax.set_title("Guided TC Sample: 10m Zonal Wind")
plt.tight_layout()
plt.savefig("outputs/05_cbottle_tc_guided_sample.jpg")

Output from CBottle Tropical Cyclone Guidance

Computing the Odds Ratio

The odds ratio requires computing Hutchinson divergence terms that need second-order derivatives through the model. We reload with allow_second_order_derivatives=True for odds ratio calculations.

Note: sampler_steps is also reduced in this section to speed up runtime. Use the default sampler settings for improved quality and more stable odds-ratio values.

model = CBottleTCGuidance.load_model(
    package,
    seed=0,
    sampler_steps=2,
    allow_second_order_derivatives=True,
).to(device)

log_odds_ratio, forward_latents, latent_coords = model.calculate_odds_ratio(
    guidance,
    coords,
)

print(f"Log odds ratio: {log_odds_ratio:.4f}")
print(f"Forward latents shape: {tuple(forward_latents.shape)}")
Console output89 lines
calculate_odds_ratio[forward]:   0%|          | 0/27 [00:00<?, ?it/s]
calculate_odds_ratio[forward]:   4%|โ–Ž         | 1/27 [00:00<00:25,  1.02it/s]
calculate_odds_ratio[forward]:   7%|โ–‹         | 2/27 [00:01<00:23,  1.06it/s]
calculate_odds_ratio[forward]:  11%|โ–ˆ         | 3/27 [00:02<00:22,  1.07it/s]
calculate_odds_ratio[forward]:  15%|โ–ˆโ–        | 4/27 [00:03<00:21,  1.08it/s]
calculate_odds_ratio[forward]:  19%|โ–ˆโ–Š        | 5/27 [00:04<00:20,  1.08it/s]
calculate_odds_ratio[forward]:  22%|โ–ˆโ–ˆโ–       | 6/27 [00:05<00:19,  1.08it/s]
calculate_odds_ratio[forward]:  26%|โ–ˆโ–ˆโ–Œ       | 7/27 [00:06<00:18,  1.08it/s]
calculate_odds_ratio[forward]:  30%|โ–ˆโ–ˆโ–‰       | 8/27 [00:07<00:17,  1.09it/s]
calculate_odds_ratio[forward]:  33%|โ–ˆโ–ˆโ–ˆโ–Ž      | 9/27 [00:08<00:16,  1.09it/s]
calculate_odds_ratio[forward]:  37%|โ–ˆโ–ˆโ–ˆโ–‹      | 10/27 [00:09<00:15,  1.09it/s]
calculate_odds_ratio[forward]:  41%|โ–ˆโ–ˆโ–ˆโ–ˆ      | 11/27 [00:10<00:16,  1.05s/it]
calculate_odds_ratio[forward]:  44%|โ–ˆโ–ˆโ–ˆโ–ˆโ–     | 12/27 [00:11<00:15,  1.01s/it]
calculate_odds_ratio[forward]:  48%|โ–ˆโ–ˆโ–ˆโ–ˆโ–Š     | 13/27 [00:12<00:13,  1.02it/s]
calculate_odds_ratio[forward]:  52%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–    | 14/27 [00:13<00:12,  1.05it/s]
calculate_odds_ratio[forward]:  56%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–Œ    | 15/27 [00:14<00:11,  1.07it/s]
calculate_odds_ratio[forward]:  59%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–‰    | 16/27 [00:15<00:10,  1.08it/s]
calculate_odds_ratio[forward]:  63%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–Ž   | 17/27 [00:15<00:09,  1.10it/s]
calculate_odds_ratio[forward]:  67%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–‹   | 18/27 [00:16<00:08,  1.10it/s]
calculate_odds_ratio[forward]:  70%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ   | 19/27 [00:17<00:07,  1.11it/s]
calculate_odds_ratio[forward]:  74%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–  | 20/27 [00:18<00:06,  1.11it/s]
calculate_odds_ratio[forward]:  78%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–Š  | 21/27 [00:19<00:05,  1.11it/s]
calculate_odds_ratio[forward]:  81%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ– | 22/27 [00:20<00:04,  1.09it/s]
calculate_odds_ratio[forward]:  85%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–Œ | 23/27 [00:21<00:03,  1.11it/s]
calculate_odds_ratio[forward]:  89%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–‰ | 24/27 [00:22<00:02,  1.10it/s]
calculate_odds_ratio[forward]:  93%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–Ž| 25/27 [00:23<00:01,  1.11it/s]
calculate_odds_ratio[forward]:  96%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–‹| 26/27 [00:24<00:00,  1.11it/s]
calculate_odds_ratio[forward]: 100%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ| 27/27 [00:25<00:00,  1.09it/s]


calculate_odds_ratio[backward]:   0%|          | 0/26 [00:00<?, ?it/s]
calculate_odds_ratio[backward]:   4%|โ–         | 1/26 [00:04<01:55,  4.61s/it]
calculate_odds_ratio[backward]:   8%|โ–Š         | 2/26 [00:09<01:54,  4.75s/it]
calculate_odds_ratio[backward]:  12%|โ–ˆโ–        | 3/26 [00:15<02:04,  5.43s/it]
calculate_odds_ratio[backward]:  15%|โ–ˆโ–Œ        | 4/26 [00:21<02:05,  5.71s/it]
calculate_odds_ratio[backward]:  19%|โ–ˆโ–‰        | 5/26 [00:27<02:02,  5.85s/it]
calculate_odds_ratio[backward]:  23%|โ–ˆโ–ˆโ–Ž       | 6/26 [00:34<01:58,  5.93s/it]
calculate_odds_ratio[backward]:  27%|โ–ˆโ–ˆโ–‹       | 7/26 [00:40<01:53,  6.00s/it]
calculate_odds_ratio[backward]:  31%|โ–ˆโ–ˆโ–ˆ       | 8/26 [00:46<01:48,  6.04s/it]
calculate_odds_ratio[backward]:  35%|โ–ˆโ–ˆโ–ˆโ–      | 9/26 [00:52<01:43,  6.07s/it]
calculate_odds_ratio[backward]:  38%|โ–ˆโ–ˆโ–ˆโ–Š      | 10/26 [00:58<01:37,  6.08s/it]
calculate_odds_ratio[backward]:  42%|โ–ˆโ–ˆโ–ˆโ–ˆโ–     | 11/26 [01:04<01:31,  6.10s/it]
calculate_odds_ratio[backward]:  46%|โ–ˆโ–ˆโ–ˆโ–ˆโ–Œ     | 12/26 [01:10<01:25,  6.11s/it]
calculate_odds_ratio[backward]:  50%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ     | 13/26 [01:16<01:19,  6.10s/it]
calculate_odds_ratio[backward]:  54%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–    | 14/26 [01:23<01:14,  6.25s/it]
calculate_odds_ratio[backward]:  58%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–Š    | 15/26 [01:29<01:08,  6.22s/it]
calculate_odds_ratio[backward]:  62%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–   | 16/26 [01:35<01:01,  6.19s/it]
calculate_odds_ratio[backward]:  65%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–Œ   | 17/26 [01:41<00:55,  6.18s/it]
calculate_odds_ratio[backward]:  69%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–‰   | 18/26 [01:48<00:49,  6.17s/it]
calculate_odds_ratio[backward]:  73%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–Ž  | 19/26 [01:54<00:43,  6.15s/it]
calculate_odds_ratio[backward]:  77%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–‹  | 20/26 [02:00<00:36,  6.15s/it]
calculate_odds_ratio[backward]:  81%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ  | 21/26 [02:06<00:30,  6.15s/it]
calculate_odds_ratio[backward]:  85%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ– | 22/26 [02:12<00:24,  6.15s/it]
calculate_odds_ratio[backward]:  88%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–Š | 23/26 [02:18<00:18,  6.14s/it]
calculate_odds_ratio[backward]:  92%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–| 24/26 [02:24<00:12,  6.14s/it]
calculate_odds_ratio[backward]:  96%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–Œ| 25/26 [02:30<00:06,  6.12s/it]
calculate_odds_ratio[backward]: 100%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ| 26/26 [02:35<00:00,  5.60s/it]


calculate_odds_ratio[backward_no_guidance]:   0%|          | 0/26 [00:00<?, ?it/s]
calculate_odds_ratio[backward_no_guidance]:   4%|โ–         | 1/26 [00:03<01:38,  3.93s/it]
calculate_odds_ratio[backward_no_guidance]:   8%|โ–Š         | 2/26 [00:08<01:40,  4.21s/it]
calculate_odds_ratio[backward_no_guidance]:  12%|โ–ˆโ–        | 3/26 [00:12<01:34,  4.09s/it]
calculate_odds_ratio[backward_no_guidance]:  15%|โ–ˆโ–Œ        | 4/26 [00:16<01:28,  4.03s/it]
calculate_odds_ratio[backward_no_guidance]:  19%|โ–ˆโ–‰        | 5/26 [00:20<01:24,  4.00s/it]
calculate_odds_ratio[backward_no_guidance]:  23%|โ–ˆโ–ˆโ–Ž       | 6/26 [00:24<01:19,  3.99s/it]
calculate_odds_ratio[backward_no_guidance]:  27%|โ–ˆโ–ˆโ–‹       | 7/26 [00:28<01:15,  3.98s/it]
calculate_odds_ratio[backward_no_guidance]:  31%|โ–ˆโ–ˆโ–ˆ       | 8/26 [00:32<01:11,  3.97s/it]
calculate_odds_ratio[backward_no_guidance]:  35%|โ–ˆโ–ˆโ–ˆโ–      | 9/26 [00:35<01:07,  3.97s/it]
calculate_odds_ratio[backward_no_guidance]:  38%|โ–ˆโ–ˆโ–ˆโ–Š      | 10/26 [00:39<01:03,  3.97s/it]
calculate_odds_ratio[backward_no_guidance]:  42%|โ–ˆโ–ˆโ–ˆโ–ˆโ–     | 11/26 [00:43<00:59,  3.96s/it]
calculate_odds_ratio[backward_no_guidance]:  46%|โ–ˆโ–ˆโ–ˆโ–ˆโ–Œ     | 12/26 [00:47<00:55,  3.96s/it]
calculate_odds_ratio[backward_no_guidance]:  50%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ     | 13/26 [00:51<00:51,  3.96s/it]
calculate_odds_ratio[backward_no_guidance]:  54%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–    | 14/26 [00:55<00:47,  3.96s/it]
calculate_odds_ratio[backward_no_guidance]:  58%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–Š    | 15/26 [00:59<00:43,  3.95s/it]
calculate_odds_ratio[backward_no_guidance]:  62%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–   | 16/26 [01:04<00:40,  4.08s/it]
calculate_odds_ratio[backward_no_guidance]:  65%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–Œ   | 17/26 [01:08<00:36,  4.04s/it]
calculate_odds_ratio[backward_no_guidance]:  69%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–‰   | 18/26 [01:12<00:32,  4.02s/it]
calculate_odds_ratio[backward_no_guidance]:  73%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–Ž  | 19/26 [01:15<00:27,  4.00s/it]
calculate_odds_ratio[backward_no_guidance]:  77%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–‹  | 20/26 [01:19<00:23,  3.99s/it]
calculate_odds_ratio[backward_no_guidance]:  81%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ  | 21/26 [01:23<00:19,  3.98s/it]
calculate_odds_ratio[backward_no_guidance]:  85%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ– | 22/26 [01:27<00:15,  3.97s/it]
calculate_odds_ratio[backward_no_guidance]:  88%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–Š | 23/26 [01:31<00:11,  3.97s/it]
calculate_odds_ratio[backward_no_guidance]:  92%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–| 24/26 [01:35<00:07,  3.97s/it]
calculate_odds_ratio[backward_no_guidance]:  96%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–Œ| 25/26 [01:39<00:03,  3.96s/it]
calculate_odds_ratio[backward_no_guidance]: 100%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ| 26/26 [01:43<00:00,  3.96s/it]

Log odds ratio: 1.5916
Forward latents shape: (1, 45, 721, 1440)

Post Processing Forward Latents

The forward_latents tensor is returned on the same grid as the model output (lat-lon when lat_lon=True). We visualize a single channel (u10m) over the same Caribbean domain. This shows the latent-space representation that the odds-ratio computation operates on.

plt.close("all")

# Identify the u10m channel in output variable ordering
latent_variables = latent_coords["variable"]
u_latent_idx = int(np.where(latent_variables == u_var)[0][0])
latent_u = forward_latents[0, u_latent_idx].detach().cpu().numpy()

latent_u_carib = latent_u[np.ix_(lat_mask, lon_mask)]

fig, ax = plt.subplots(subplot_kw={"projection": ccrs.PlateCarree()}, figsize=(8, 4.5))
pcm = ax.pcolormesh(
    lon_carib_deg,
    lat_carib,
    latent_u_carib,
    shading="auto",
    cmap="viridis",
    transform=ccrs.PlateCarree(),
)
ax.set_extent([-100.0, -60.0, lat_min, lat_max], crs=ccrs.PlateCarree())
ax.coastlines(resolution="110m", linewidth=0.8)
ax.gridlines(draw_labels=True, linewidth=0.5, alpha=0.5, linestyle="--")
plt.colorbar(pcm, ax=ax, label=f"Forward Latent ({u_var})", pad=0.08, shrink=0.92)
ax.set_title(f"Forward Latents: {u_var} Channel")
plt.tight_layout()
plt.savefig("outputs/05_cbottle_tc_forward_latents.jpg")

Output from CBottle Tropical Cyclone Guidance


Execution profile

Runtime telemetry

Total runtime5m 53s

Execution environment

CPUAMD EPYC 9554 64-Core Processor
GPUNVIDIA H100 NVL ยท 93.6 GiB
System RAM58.4 GiB
PlatformLinux 6.8.0-137-generic
Python3.13.13
GPU driver / CUDADriver 595.84 ยท CUDA support 13.2