Note
Go to the end to download the full example code.
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.CBottleTCGuidanceVisualizing 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
# /// script
# dependencies = [
# "earth2studio[cbottle] @ git+https://github.com/NVIDIA/earth2studio.git@0.16.0",
# "cartopy",
# ]
# ///
Set Up#
For this example we need the cBottle TC guidance diagnostic model. We load it twice:
Default (fast) path for standard guided sampling
Second-order-derivative path for odds-ratio computation
Thus, we need the following:
Diagnostic Model: Use the built in CBottle TC Guidance Model
earth2studio.models.dx.CBottleTCGuidance.
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)
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<02:53, 10.2MB/s]
Downloading training-state-002176000.checkpoint: 1%| | 20.0M/1.67G [00:01<01:23, 21.2MB/s]
Downloading training-state-002176000.checkpoint: 2%|▏ | 30.0M/1.67G [00:01<00:54, 32.2MB/s]
Downloading training-state-002176000.checkpoint: 2%|▏ | 40.0M/1.67G [00:01<00:40, 42.9MB/s]
Downloading training-state-002176000.checkpoint: 3%|▎ | 50.0M/1.67G [00:01<00:33, 52.4MB/s]
Downloading training-state-002176000.checkpoint: 4%|▎ | 60.0M/1.67G [00:01<00:28, 60.4MB/s]
Downloading training-state-002176000.checkpoint: 4%|▍ | 70.0M/1.67G [00:02<00:39, 43.3MB/s]
Downloading training-state-002176000.checkpoint: 5%|▍ | 80.0M/1.67G [00:02<00:33, 51.4MB/s]
Downloading training-state-002176000.checkpoint: 5%|▌ | 90.0M/1.67G [00:02<00:28, 58.7MB/s]
Downloading training-state-002176000.checkpoint: 6%|▌ | 100M/1.67G [00:02<00:25, 65.1MB/s]
Downloading training-state-002176000.checkpoint: 6%|▋ | 110M/1.67G [00:02<00:23, 70.2MB/s]
Downloading training-state-002176000.checkpoint: 7%|▋ | 120M/1.67G [00:02<00:22, 74.6MB/s]
Downloading training-state-002176000.checkpoint: 8%|▊ | 130M/1.67G [00:03<00:35, 46.1MB/s]
Downloading training-state-002176000.checkpoint: 8%|▊ | 140M/1.67G [00:03<00:30, 53.5MB/s]
Downloading training-state-002176000.checkpoint: 9%|▉ | 150M/1.67G [00:03<00:26, 60.5MB/s]
Downloading training-state-002176000.checkpoint: 9%|▉ | 160M/1.67G [00:03<00:31, 51.6MB/s]
Downloading training-state-002176000.checkpoint: 10%|▉ | 170M/1.67G [00:03<00:27, 58.7MB/s]
Downloading training-state-002176000.checkpoint: 11%|█ | 180M/1.67G [00:03<00:24, 64.2MB/s]
Downloading training-state-002176000.checkpoint: 11%|█ | 190M/1.67G [00:03<00:22, 70.2MB/s]
Downloading training-state-002176000.checkpoint: 12%|█▏ | 200M/1.67G [00:04<00:37, 41.7MB/s]
Downloading training-state-002176000.checkpoint: 12%|█▏ | 210M/1.67G [00:04<00:31, 49.3MB/s]
Downloading training-state-002176000.checkpoint: 13%|█▎ | 220M/1.67G [00:04<00:27, 56.4MB/s]
Downloading training-state-002176000.checkpoint: 13%|█▎ | 230M/1.67G [00:04<00:30, 50.3MB/s]
Downloading training-state-002176000.checkpoint: 14%|█▍ | 240M/1.67G [00:05<00:26, 57.4MB/s]
Downloading training-state-002176000.checkpoint: 15%|█▍ | 250M/1.67G [00:05<00:23, 63.8MB/s]
Downloading training-state-002176000.checkpoint: 15%|█▌ | 260M/1.67G [00:05<00:36, 41.3MB/s]
Downloading training-state-002176000.checkpoint: 16%|█▌ | 270M/1.67G [00:05<00:30, 48.9MB/s]
Downloading training-state-002176000.checkpoint: 16%|█▋ | 280M/1.67G [00:05<00:26, 56.2MB/s]
Downloading training-state-002176000.checkpoint: 17%|█▋ | 290M/1.67G [00:06<00:23, 62.7MB/s]
Downloading training-state-002176000.checkpoint: 18%|█▊ | 300M/1.67G [00:06<00:21, 68.3MB/s]
Downloading training-state-002176000.checkpoint: 18%|█▊ | 310M/1.67G [00:06<00:20, 72.7MB/s]
Downloading training-state-002176000.checkpoint: 19%|█▉ | 320M/1.67G [00:06<00:29, 49.9MB/s]
Downloading training-state-002176000.checkpoint: 19%|█▉ | 330M/1.67G [00:06<00:25, 56.5MB/s]
Downloading training-state-002176000.checkpoint: 20%|█▉ | 340M/1.67G [00:06<00:22, 63.3MB/s]
Downloading training-state-002176000.checkpoint: 21%|██ | 350M/1.67G [00:07<00:31, 44.8MB/s]
Downloading training-state-002176000.checkpoint: 21%|██ | 360M/1.67G [00:07<00:27, 52.2MB/s]
Downloading training-state-002176000.checkpoint: 22%|██▏ | 370M/1.67G [00:07<00:23, 59.2MB/s]
Downloading training-state-002176000.checkpoint: 22%|██▏ | 380M/1.67G [00:07<00:23, 58.5MB/s]
Downloading training-state-002176000.checkpoint: 23%|██▎ | 390M/1.67G [00:08<00:37, 36.6MB/s]
Downloading training-state-002176000.checkpoint: 23%|██▎ | 400M/1.67G [00:08<00:30, 44.3MB/s]
Downloading training-state-002176000.checkpoint: 24%|██▍ | 410M/1.67G [00:08<00:26, 51.8MB/s]
Downloading training-state-002176000.checkpoint: 25%|██▍ | 420M/1.67G [00:08<00:23, 56.5MB/s]
Downloading training-state-002176000.checkpoint: 25%|██▌ | 430M/1.67G [00:08<00:21, 63.0MB/s]
Downloading training-state-002176000.checkpoint: 26%|██▌ | 440M/1.67G [00:08<00:19, 68.4MB/s]
Downloading training-state-002176000.checkpoint: 26%|██▋ | 450M/1.67G [00:09<00:37, 34.7MB/s]
Downloading training-state-002176000.checkpoint: 27%|██▋ | 460M/1.67G [00:09<00:30, 42.3MB/s]
Downloading training-state-002176000.checkpoint: 28%|██▊ | 470M/1.67G [00:09<00:25, 49.8MB/s]
Downloading training-state-002176000.checkpoint: 28%|██▊ | 480M/1.67G [00:10<00:36, 34.7MB/s]
Downloading training-state-002176000.checkpoint: 29%|██▊ | 490M/1.67G [00:10<00:30, 42.0MB/s]
Downloading training-state-002176000.checkpoint: 29%|██▉ | 500M/1.67G [00:10<00:25, 50.0MB/s]
Downloading training-state-002176000.checkpoint: 30%|██▉ | 510M/1.67G [00:10<00:21, 57.2MB/s]
Downloading training-state-002176000.checkpoint: 30%|███ | 520M/1.67G [00:11<00:30, 40.2MB/s]
Downloading training-state-002176000.checkpoint: 31%|███ | 530M/1.67G [00:11<00:25, 47.9MB/s]
Downloading training-state-002176000.checkpoint: 32%|███▏ | 540M/1.67G [00:11<00:22, 55.2MB/s]
Downloading training-state-002176000.checkpoint: 32%|███▏ | 550M/1.67G [00:11<00:21, 56.1MB/s]
Downloading training-state-002176000.checkpoint: 33%|███▎ | 560M/1.67G [00:11<00:19, 62.8MB/s]
Downloading training-state-002176000.checkpoint: 33%|███▎ | 570M/1.67G [00:11<00:19, 61.1MB/s]
Downloading training-state-002176000.checkpoint: 34%|███▍ | 580M/1.67G [00:12<00:30, 38.1MB/s]
Downloading training-state-002176000.checkpoint: 35%|███▍ | 590M/1.67G [00:12<00:25, 45.5MB/s]
Downloading training-state-002176000.checkpoint: 35%|███▌ | 600M/1.67G [00:12<00:21, 53.2MB/s]
Downloading training-state-002176000.checkpoint: 36%|███▌ | 610M/1.67G [00:12<00:25, 45.5MB/s]
Downloading training-state-002176000.checkpoint: 36%|███▋ | 620M/1.67G [00:12<00:21, 53.0MB/s]
Downloading training-state-002176000.checkpoint: 37%|███▋ | 630M/1.67G [00:13<00:18, 59.8MB/s]
Downloading training-state-002176000.checkpoint: 38%|███▊ | 640M/1.67G [00:13<00:26, 41.9MB/s]
Downloading training-state-002176000.checkpoint: 38%|███▊ | 650M/1.67G [00:13<00:24, 44.6MB/s]
Downloading training-state-002176000.checkpoint: 39%|███▊ | 660M/1.67G [00:13<00:22, 48.9MB/s]
Downloading training-state-002176000.checkpoint: 39%|███▉ | 670M/1.67G [00:14<00:21, 50.2MB/s]
Downloading training-state-002176000.checkpoint: 40%|███▉ | 680M/1.67G [00:14<00:28, 37.9MB/s]
Downloading training-state-002176000.checkpoint: 40%|████ | 690M/1.67G [00:14<00:26, 40.0MB/s]
Downloading training-state-002176000.checkpoint: 41%|████ | 700M/1.67G [00:15<00:27, 38.9MB/s]
Downloading training-state-002176000.checkpoint: 42%|████▏ | 710M/1.67G [00:15<00:33, 31.5MB/s]
Downloading training-state-002176000.checkpoint: 42%|████▏ | 720M/1.67G [00:15<00:31, 32.4MB/s]
Downloading training-state-002176000.checkpoint: 43%|████▎ | 730M/1.67G [00:16<00:28, 35.8MB/s]
Downloading training-state-002176000.checkpoint: 43%|████▎ | 740M/1.67G [00:16<00:28, 35.9MB/s]
Downloading training-state-002176000.checkpoint: 44%|████▍ | 750M/1.67G [00:16<00:23, 42.6MB/s]
Downloading training-state-002176000.checkpoint: 45%|████▍ | 760M/1.67G [00:16<00:20, 48.6MB/s]
Downloading training-state-002176000.checkpoint: 45%|████▌ | 770M/1.67G [00:17<00:40, 24.1MB/s]
Downloading training-state-002176000.checkpoint: 46%|████▌ | 780M/1.67G [00:17<00:32, 29.8MB/s]
Downloading training-state-002176000.checkpoint: 46%|████▋ | 790M/1.67G [00:17<00:27, 34.6MB/s]
Downloading training-state-002176000.checkpoint: 47%|████▋ | 800M/1.67G [00:18<00:31, 29.8MB/s]
Downloading training-state-002176000.checkpoint: 48%|████▊ | 810M/1.67G [00:18<00:28, 33.4MB/s]
Downloading training-state-002176000.checkpoint: 48%|████▊ | 820M/1.67G [00:18<00:24, 37.7MB/s]
Downloading training-state-002176000.checkpoint: 49%|████▊ | 830M/1.67G [00:18<00:21, 43.2MB/s]
Downloading training-state-002176000.checkpoint: 49%|████▉ | 840M/1.67G [00:19<00:29, 31.2MB/s]
Downloading training-state-002176000.checkpoint: 50%|████▉ | 850M/1.67G [00:19<00:24, 36.4MB/s]
Downloading training-state-002176000.checkpoint: 50%|█████ | 860M/1.67G [00:19<00:21, 40.8MB/s]
Downloading training-state-002176000.checkpoint: 51%|█████ | 870M/1.67G [00:20<00:25, 34.8MB/s]
Downloading training-state-002176000.checkpoint: 52%|█████▏ | 880M/1.67G [00:20<00:22, 37.8MB/s]
Downloading training-state-002176000.checkpoint: 52%|█████▏ | 890M/1.67G [00:20<00:23, 36.8MB/s]
Downloading training-state-002176000.checkpoint: 53%|█████▎ | 900M/1.67G [00:21<00:30, 27.2MB/s]
Downloading training-state-002176000.checkpoint: 53%|█████▎ | 910M/1.67G [00:21<00:24, 34.3MB/s]
Downloading training-state-002176000.checkpoint: 54%|█████▍ | 920M/1.67G [00:21<00:19, 41.8MB/s]
Downloading training-state-002176000.checkpoint: 55%|█████▍ | 930M/1.67G [00:21<00:16, 49.4MB/s]
Downloading training-state-002176000.checkpoint: 55%|█████▌ | 940M/1.67G [00:21<00:14, 56.7MB/s]
Downloading training-state-002176000.checkpoint: 56%|█████▌ | 950M/1.67G [00:22<00:12, 63.2MB/s]
Downloading training-state-002176000.checkpoint: 56%|█████▋ | 960M/1.67G [00:22<00:15, 50.5MB/s]
Downloading training-state-002176000.checkpoint: 57%|█████▋ | 970M/1.67G [00:22<00:13, 57.7MB/s]
Downloading training-state-002176000.checkpoint: 57%|█████▋ | 980M/1.67G [00:22<00:11, 63.9MB/s]
Downloading training-state-002176000.checkpoint: 58%|█████▊ | 990M/1.67G [00:23<00:17, 42.8MB/s]
Downloading training-state-002176000.checkpoint: 59%|█████▊ | 0.98G/1.67G [00:23<00:14, 50.4MB/s]
Downloading training-state-002176000.checkpoint: 59%|█████▉ | 0.99G/1.67G [00:23<00:12, 57.4MB/s]
Downloading training-state-002176000.checkpoint: 60%|█████▉ | 1.00G/1.67G [00:23<00:11, 63.9MB/s]
Downloading training-state-002176000.checkpoint: 60%|██████ | 1.01G/1.67G [00:23<00:15, 45.8MB/s]
Downloading training-state-002176000.checkpoint: 61%|██████ | 1.02G/1.67G [00:23<00:13, 53.3MB/s]
Downloading training-state-002176000.checkpoint: 62%|██████▏ | 1.03G/1.67G [00:24<00:11, 60.1MB/s]
Downloading training-state-002176000.checkpoint: 62%|██████▏ | 1.04G/1.67G [00:24<00:10, 66.1MB/s]
Downloading training-state-002176000.checkpoint: 63%|██████▎ | 1.04G/1.67G [00:24<00:09, 71.2MB/s]
Downloading training-state-002176000.checkpoint: 63%|██████▎ | 1.05G/1.67G [00:24<00:08, 74.9MB/s]
Downloading training-state-002176000.checkpoint: 64%|██████▍ | 1.06G/1.67G [00:24<00:11, 55.4MB/s]
Downloading training-state-002176000.checkpoint: 65%|██████▍ | 1.07G/1.67G [00:24<00:10, 62.0MB/s]
Downloading training-state-002176000.checkpoint: 65%|██████▌ | 1.08G/1.67G [00:24<00:09, 67.6MB/s]
Downloading training-state-002176000.checkpoint: 66%|██████▌ | 1.09G/1.67G [00:25<00:11, 53.7MB/s]
Downloading training-state-002176000.checkpoint: 66%|██████▋ | 1.10G/1.67G [00:25<00:09, 60.5MB/s]
Downloading training-state-002176000.checkpoint: 67%|██████▋ | 1.11G/1.67G [00:25<00:08, 66.5MB/s]
Downloading training-state-002176000.checkpoint: 67%|██████▋ | 1.12G/1.67G [00:25<00:08, 70.4MB/s]
Downloading training-state-002176000.checkpoint: 68%|██████▊ | 1.13G/1.67G [00:26<00:12, 44.8MB/s]
Downloading training-state-002176000.checkpoint: 69%|██████▊ | 1.14G/1.67G [00:26<00:10, 52.3MB/s]
Downloading training-state-002176000.checkpoint: 69%|██████▉ | 1.15G/1.67G [00:26<00:09, 59.2MB/s]
Downloading training-state-002176000.checkpoint: 70%|██████▉ | 1.16G/1.67G [00:26<00:08, 65.2MB/s]
Downloading training-state-002176000.checkpoint: 70%|███████ | 1.17G/1.67G [00:26<00:07, 70.5MB/s]
Downloading training-state-002176000.checkpoint: 71%|███████ | 1.18G/1.67G [00:26<00:06, 74.6MB/s]
Downloading training-state-002176000.checkpoint: 72%|███████▏ | 1.19G/1.67G [00:27<00:11, 43.4MB/s]
Downloading training-state-002176000.checkpoint: 72%|███████▏ | 1.20G/1.67G [00:27<00:09, 51.0MB/s]
Downloading training-state-002176000.checkpoint: 73%|███████▎ | 1.21G/1.67G [00:27<00:08, 58.1MB/s]
Downloading training-state-002176000.checkpoint: 73%|███████▎ | 1.22G/1.67G [00:27<00:09, 48.1MB/s]
Downloading training-state-002176000.checkpoint: 74%|███████▍ | 1.23G/1.67G [00:27<00:08, 55.3MB/s]
Downloading training-state-002176000.checkpoint: 74%|███████▍ | 1.24G/1.67G [00:27<00:07, 61.8MB/s]
Downloading training-state-002176000.checkpoint: 75%|███████▌ | 1.25G/1.67G [00:28<00:10, 41.1MB/s]
Downloading training-state-002176000.checkpoint: 76%|███████▌ | 1.26G/1.67G [00:28<00:08, 48.7MB/s]
Downloading training-state-002176000.checkpoint: 76%|███████▌ | 1.27G/1.67G [00:28<00:07, 53.2MB/s]
Downloading training-state-002176000.checkpoint: 77%|███████▋ | 1.28G/1.67G [00:28<00:07, 53.4MB/s]
Downloading training-state-002176000.checkpoint: 78%|███████▊ | 1.30G/1.67G [00:29<00:05, 68.1MB/s]
Downloading training-state-002176000.checkpoint: 79%|███████▊ | 1.31G/1.67G [00:29<00:05, 71.9MB/s]
Downloading training-state-002176000.checkpoint: 79%|███████▉ | 1.32G/1.67G [00:29<00:06, 54.6MB/s]
Downloading training-state-002176000.checkpoint: 80%|███████▉ | 1.33G/1.67G [00:29<00:05, 60.5MB/s]
Downloading training-state-002176000.checkpoint: 80%|████████ | 1.34G/1.67G [00:29<00:05, 66.1MB/s]
Downloading training-state-002176000.checkpoint: 81%|████████ | 1.35G/1.67G [00:30<00:07, 47.1MB/s]
Downloading training-state-002176000.checkpoint: 82%|████████▏ | 1.36G/1.67G [00:30<00:06, 54.1MB/s]
Downloading training-state-002176000.checkpoint: 82%|████████▏ | 1.37G/1.67G [00:30<00:05, 60.7MB/s]
Downloading training-state-002176000.checkpoint: 83%|████████▎ | 1.38G/1.67G [00:30<00:06, 49.4MB/s]
Downloading training-state-002176000.checkpoint: 83%|████████▎ | 1.39G/1.67G [00:30<00:05, 56.7MB/s]
Downloading training-state-002176000.checkpoint: 84%|████████▍ | 1.40G/1.67G [00:30<00:04, 62.8MB/s]
Downloading training-state-002176000.checkpoint: 84%|████████▍ | 1.41G/1.67G [00:31<00:04, 68.6MB/s]
Downloading training-state-002176000.checkpoint: 85%|████████▌ | 1.42G/1.67G [00:31<00:03, 72.9MB/s]
Downloading training-state-002176000.checkpoint: 86%|████████▌ | 1.43G/1.67G [00:31<00:03, 76.4MB/s]
Downloading training-state-002176000.checkpoint: 86%|████████▌ | 1.44G/1.67G [00:31<00:03, 79.1MB/s]
Downloading training-state-002176000.checkpoint: 87%|████████▋ | 1.45G/1.67G [00:31<00:04, 55.9MB/s]
Downloading training-state-002176000.checkpoint: 87%|████████▋ | 1.46G/1.67G [00:31<00:04, 54.9MB/s]
Downloading training-state-002176000.checkpoint: 88%|████████▊ | 1.46G/1.67G [00:32<00:03, 55.7MB/s]
Downloading training-state-002176000.checkpoint: 89%|████████▊ | 1.47G/1.67G [00:32<00:06, 29.6MB/s]
Downloading training-state-002176000.checkpoint: 89%|████████▉ | 1.48G/1.67G [00:32<00:05, 36.8MB/s]
Downloading training-state-002176000.checkpoint: 90%|████████▉ | 1.49G/1.67G [00:33<00:04, 43.5MB/s]
Downloading training-state-002176000.checkpoint: 90%|█████████ | 1.50G/1.67G [00:33<00:05, 30.1MB/s]
Downloading training-state-002176000.checkpoint: 91%|█████████ | 1.51G/1.67G [00:33<00:04, 37.4MB/s]
Downloading training-state-002176000.checkpoint: 91%|█████████▏| 1.52G/1.67G [00:33<00:03, 45.0MB/s]
Downloading training-state-002176000.checkpoint: 92%|█████████▏| 1.53G/1.67G [00:34<00:03, 36.8MB/s]
Downloading training-state-002176000.checkpoint: 93%|█████████▎| 1.54G/1.67G [00:34<00:02, 43.9MB/s]
Downloading training-state-002176000.checkpoint: 93%|█████████▎| 1.55G/1.67G [00:34<00:02, 51.1MB/s]
Downloading training-state-002176000.checkpoint: 94%|█████████▍| 1.56G/1.67G [00:35<00:04, 25.9MB/s]
Downloading training-state-002176000.checkpoint: 94%|█████████▍| 1.57G/1.67G [00:35<00:03, 32.9MB/s]
Downloading training-state-002176000.checkpoint: 95%|█████████▌| 1.58G/1.67G [00:35<00:02, 40.3MB/s]
Downloading training-state-002176000.checkpoint: 96%|█████████▌| 1.59G/1.67G [00:35<00:01, 45.4MB/s]
Downloading training-state-002176000.checkpoint: 96%|█████████▌| 1.60G/1.67G [00:36<00:01, 51.1MB/s]
Downloading training-state-002176000.checkpoint: 97%|█████████▋| 1.61G/1.67G [00:36<00:01, 52.3MB/s]
Downloading training-state-002176000.checkpoint: 97%|█████████▋| 1.62G/1.67G [00:36<00:00, 52.5MB/s]
Downloading training-state-002176000.checkpoint: 98%|█████████▊| 1.63G/1.67G [00:37<00:01, 31.6MB/s]
Downloading training-state-002176000.checkpoint: 99%|█████████▊| 1.64G/1.67G [00:37<00:00, 35.1MB/s]
Downloading training-state-002176000.checkpoint: 99%|█████████▉| 1.65G/1.67G [00:37<00:00, 39.7MB/s]
Downloading training-state-002176000.checkpoint: 100%|█████████▉| 1.66G/1.67G [00:37<00:00, 35.2MB/s]
Downloading training-state-002176000.checkpoint: 100%|██████████| 1.67G/1.67G [00:37<00:00, 37.2MB/s]
Downloading training-state-002176000.checkpoint: 100%|██████████| 1.67G/1.67G [00:37<00:00, 47.1MB/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")

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)}")
calculate_odds_ratio[forward]: 0%| | 0/27 [00:00<?, ?it/s]
calculate_odds_ratio[forward]: 4%|▎ | 1/27 [00:01<00:26, 1.03s/it]
calculate_odds_ratio[forward]: 7%|▋ | 2/27 [00:02<00:25, 1.01s/it]
calculate_odds_ratio[forward]: 11%|█ | 3/27 [00:03<00:24, 1.00s/it]
calculate_odds_ratio[forward]: 15%|█▍ | 4/27 [00:03<00:22, 1.01it/s]
calculate_odds_ratio[forward]: 19%|█▊ | 5/27 [00:04<00:21, 1.01it/s]
calculate_odds_ratio[forward]: 22%|██▏ | 6/27 [00:05<00:20, 1.01it/s]
calculate_odds_ratio[forward]: 26%|██▌ | 7/27 [00:06<00:19, 1.01it/s]
calculate_odds_ratio[forward]: 30%|██▉ | 8/27 [00:07<00:18, 1.01it/s]
calculate_odds_ratio[forward]: 33%|███▎ | 9/27 [00:08<00:17, 1.01it/s]
calculate_odds_ratio[forward]: 37%|███▋ | 10/27 [00:09<00:16, 1.01it/s]
calculate_odds_ratio[forward]: 41%|████ | 11/27 [00:10<00:15, 1.01it/s]
calculate_odds_ratio[forward]: 44%|████▍ | 12/27 [00:12<00:17, 1.17s/it]
calculate_odds_ratio[forward]: 48%|████▊ | 13/27 [00:13<00:15, 1.12s/it]
calculate_odds_ratio[forward]: 52%|█████▏ | 14/27 [00:14<00:14, 1.08s/it]
calculate_odds_ratio[forward]: 56%|█████▌ | 15/27 [00:15<00:12, 1.06s/it]
calculate_odds_ratio[forward]: 59%|█████▉ | 16/27 [00:16<00:11, 1.04s/it]
calculate_odds_ratio[forward]: 63%|██████▎ | 17/27 [00:17<00:10, 1.02s/it]
calculate_odds_ratio[forward]: 67%|██████▋ | 18/27 [00:18<00:09, 1.01s/it]
calculate_odds_ratio[forward]: 70%|███████ | 19/27 [00:19<00:08, 1.01s/it]
calculate_odds_ratio[forward]: 74%|███████▍ | 20/27 [00:20<00:07, 1.00s/it]
calculate_odds_ratio[forward]: 78%|███████▊ | 21/27 [00:21<00:06, 1.00s/it]
calculate_odds_ratio[forward]: 81%|████████▏ | 22/27 [00:22<00:04, 1.00it/s]
calculate_odds_ratio[forward]: 85%|████████▌ | 23/27 [00:23<00:03, 1.00it/s]
calculate_odds_ratio[forward]: 89%|████████▉ | 24/27 [00:24<00:02, 1.00it/s]
calculate_odds_ratio[forward]: 93%|█████████▎| 25/27 [00:25<00:01, 1.00it/s]
calculate_odds_ratio[forward]: 96%|█████████▋| 26/27 [00:26<00:00, 1.00it/s]
calculate_odds_ratio[forward]: 100%|██████████| 27/27 [00:27<00:00, 1.00it/s]
calculate_odds_ratio[backward]: 0%| | 0/26 [00:00<?, ?it/s]
calculate_odds_ratio[backward]: 4%|▍ | 1/26 [00:05<02:09, 5.17s/it]
calculate_odds_ratio[backward]: 8%|▊ | 2/26 [00:10<02:01, 5.05s/it]
calculate_odds_ratio[backward]: 12%|█▏ | 3/26 [00:16<02:15, 5.88s/it]
calculate_odds_ratio[backward]: 15%|█▌ | 4/26 [00:23<02:17, 6.24s/it]
calculate_odds_ratio[backward]: 19%|█▉ | 5/26 [00:31<02:20, 6.67s/it]
calculate_odds_ratio[backward]: 23%|██▎ | 6/26 [00:38<02:14, 6.72s/it]
calculate_odds_ratio[backward]: 27%|██▋ | 7/26 [00:44<02:08, 6.75s/it]
calculate_odds_ratio[backward]: 31%|███ | 8/26 [00:51<02:02, 6.79s/it]
calculate_odds_ratio[backward]: 35%|███▍ | 9/26 [00:58<01:55, 6.81s/it]
calculate_odds_ratio[backward]: 38%|███▊ | 10/26 [01:05<01:49, 6.82s/it]
calculate_odds_ratio[backward]: 42%|████▏ | 11/26 [01:12<01:42, 6.83s/it]
calculate_odds_ratio[backward]: 46%|████▌ | 12/26 [01:19<01:35, 6.84s/it]
calculate_odds_ratio[backward]: 50%|█████ | 13/26 [01:26<01:28, 6.85s/it]
calculate_odds_ratio[backward]: 54%|█████▍ | 14/26 [01:32<01:22, 6.85s/it]
calculate_odds_ratio[backward]: 58%|█████▊ | 15/26 [01:39<01:15, 6.85s/it]
calculate_odds_ratio[backward]: 62%|██████▏ | 16/26 [01:46<01:08, 6.85s/it]
calculate_odds_ratio[backward]: 65%|██████▌ | 17/26 [01:53<01:01, 6.86s/it]
calculate_odds_ratio[backward]: 69%|██████▉ | 18/26 [02:00<00:54, 6.85s/it]
calculate_odds_ratio[backward]: 73%|███████▎ | 19/26 [02:07<00:47, 6.83s/it]
calculate_odds_ratio[backward]: 77%|███████▋ | 20/26 [02:13<00:41, 6.83s/it]
calculate_odds_ratio[backward]: 81%|████████ | 21/26 [02:20<00:34, 6.83s/it]
calculate_odds_ratio[backward]: 85%|████████▍ | 22/26 [02:28<00:28, 7.02s/it]
calculate_odds_ratio[backward]: 88%|████████▊ | 23/26 [02:35<00:20, 6.97s/it]
calculate_odds_ratio[backward]: 92%|█████████▏| 24/26 [02:41<00:13, 6.92s/it]
calculate_odds_ratio[backward]: 96%|█████████▌| 25/26 [02:48<00:06, 6.89s/it]
calculate_odds_ratio[backward]: 100%|██████████| 26/26 [02:53<00:00, 6.30s/it]
calculate_odds_ratio[backward_no_guidance]: 0%| | 0/26 [00:00<?, ?it/s]
calculate_odds_ratio[backward_no_guidance]: 4%|▍ | 1/26 [00:04<01:51, 4.46s/it]
calculate_odds_ratio[backward_no_guidance]: 8%|▊ | 2/26 [00:08<01:46, 4.44s/it]
calculate_odds_ratio[backward_no_guidance]: 12%|█▏ | 3/26 [00:13<01:42, 4.44s/it]
calculate_odds_ratio[backward_no_guidance]: 15%|█▌ | 4/26 [00:17<01:37, 4.44s/it]
calculate_odds_ratio[backward_no_guidance]: 19%|█▉ | 5/26 [00:22<01:33, 4.44s/it]
calculate_odds_ratio[backward_no_guidance]: 23%|██▎ | 6/26 [00:26<01:28, 4.43s/it]
calculate_odds_ratio[backward_no_guidance]: 27%|██▋ | 7/26 [00:31<01:24, 4.43s/it]
calculate_odds_ratio[backward_no_guidance]: 31%|███ | 8/26 [00:35<01:19, 4.43s/it]
calculate_odds_ratio[backward_no_guidance]: 35%|███▍ | 9/26 [00:39<01:15, 4.43s/it]
calculate_odds_ratio[backward_no_guidance]: 38%|███▊ | 10/26 [00:44<01:10, 4.43s/it]
calculate_odds_ratio[backward_no_guidance]: 42%|████▏ | 11/26 [00:48<01:06, 4.43s/it]
calculate_odds_ratio[backward_no_guidance]: 46%|████▌ | 12/26 [00:53<01:02, 4.43s/it]
calculate_odds_ratio[backward_no_guidance]: 50%|█████ | 13/26 [00:57<00:57, 4.44s/it]
calculate_odds_ratio[backward_no_guidance]: 54%|█████▍ | 14/26 [01:02<00:53, 4.43s/it]
calculate_odds_ratio[backward_no_guidance]: 58%|█████▊ | 15/26 [01:06<00:48, 4.44s/it]
calculate_odds_ratio[backward_no_guidance]: 62%|██████▏ | 16/26 [01:11<00:46, 4.62s/it]
calculate_odds_ratio[backward_no_guidance]: 65%|██████▌ | 17/26 [01:16<00:41, 4.57s/it]
calculate_odds_ratio[backward_no_guidance]: 69%|██████▉ | 18/26 [01:20<00:36, 4.53s/it]
calculate_odds_ratio[backward_no_guidance]: 73%|███████▎ | 19/26 [01:24<00:31, 4.50s/it]
calculate_odds_ratio[backward_no_guidance]: 77%|███████▋ | 20/26 [01:29<00:26, 4.49s/it]
calculate_odds_ratio[backward_no_guidance]: 81%|████████ | 21/26 [01:33<00:22, 4.47s/it]
calculate_odds_ratio[backward_no_guidance]: 85%|████████▍ | 22/26 [01:38<00:17, 4.47s/it]
calculate_odds_ratio[backward_no_guidance]: 88%|████████▊ | 23/26 [01:42<00:13, 4.46s/it]
calculate_odds_ratio[backward_no_guidance]: 92%|█████████▏| 24/26 [01:47<00:08, 4.46s/it]
calculate_odds_ratio[backward_no_guidance]: 96%|█████████▌| 25/26 [01:51<00:04, 4.45s/it]
calculate_odds_ratio[backward_no_guidance]: 100%|██████████| 26/26 [01:56<00:00, 4.45s/it]
Log odds ratio: 2.2465
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")

Total running time of the script: (6 minutes 28.506 seconds)