.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/15_cbottle_generation.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_examples_15_cbottle_generation.py: CBottle Data Generation and Infilling ===================================== Climate in a Bottle (cBottle) inference workflows for global weather data synthesis. This example will demonstrate the cBottle diffusion model data source and infilling diagnostic model for generating global climate and weather data. Both the cBottle data source and infilling diagnostic use the same diffusion model but the sampling procedure is different enabling two unique modes of interaction. For more information on cBottle see: - https://arxiv.org/abs/2505.06474v1 In this example you will learn: - Generating synthetic climate data with cBottle data source - Instantiating cBottle infill diagnostic model - Creating a simple infilling inference workflow .. GENERATED FROM PYTHON SOURCE LINES 39-46 .. code-block:: Python # /// script # dependencies = [ # "earth2studio[cbottle] @ git+https://github.com/NVIDIA/earth2studio.git", # "cartopy", # ] # /// .. GENERATED FROM PYTHON SOURCE LINES 47-52 Set Up ------ For this example we will use the cBottle data source and infill diagnostic. Unlike other data sources the cBottle3D data source needs to be loaded similar to a prognostic or diagnostic model. .. GENERATED FROM PYTHON SOURCE LINES 54-59 Thus, we need the following: - Datasource: Generate data from the CBottle3D data api :py:class:`earth2studio.data.CBottle3D`. - Datasource: Pull data from the WeatherBench2 data api :py:class:`earth2studio.data.WB2ERA5`. - Diagnostic Model: Use the built in CBottle Infill Model :py:class:`earth2studio.models.dx.CBottleInfill`. .. GENERATED FROM PYTHON SOURCE LINES 61-83 .. code-block:: Python import os os.makedirs("outputs", exist_ok=True) from dotenv import load_dotenv load_dotenv() # TODO: make common example prep function import torch from earth2studio.data import WB2ERA5, CBottle3D from earth2studio.models.dx import CBottleInfill # Load the default model package which downloads the check point from NGC package = CBottle3D.load_default_package() cbottle_ds = CBottle3D.load_model(package, seed=0) # This is an AI data source, so also move it to device device = torch.device("cuda" if torch.cuda.is_available() else "cpu") cbottle_ds = cbottle_ds.to(device) # Create the ground truth data source era5_ds = WB2ERA5() .. rst-class:: sphx-glr-script-out .. code-block:: none Downloading training-state-000512000.checkpoint: 0%| | 0.00/568M [00:00 Size: 17MB array([[[[1.01743422e+05, 1.01743422e+05, 1.01743422e+05, ..., 1.01743422e+05, 1.01743422e+05, 1.01743422e+05], [1.01793445e+05, 1.01793289e+05, 1.01793289e+05, ..., 1.01794055e+05, 1.01793750e+05, 1.01793750e+05], [1.01839055e+05, 1.01838445e+05, 1.01838297e+05, ..., 1.01839969e+05, 1.01839508e+05, 1.01839203e+05], ..., [1.00018555e+05, 1.00018555e+05, 1.00018555e+05, ..., 1.00017945e+05, 1.00017945e+05, 1.00018250e+05], [9.98792891e+04, 9.98789844e+04, 9.98789844e+04, ..., 9.98786797e+04, 9.98789844e+04, 9.98789844e+04], [9.98712266e+04, 9.98712266e+04, 9.98712266e+04, ..., 9.98712266e+04, 9.98712266e+04, 9.98712266e+04]], [[1.33166103e+01, 1.33166103e+01, 1.33166103e+01, ..., 1.33166103e+01, 1.33166103e+01, 1.33166103e+01], [1.31231613e+01, 1.31231613e+01, 1.31231613e+01, ..., 1.31190758e+01, 1.31217995e+01, 1.31217995e+01], [1.28479767e+01, 1.28479767e+01, 1.28493385e+01, ..., 1.28357162e+01, 1.28384399e+01, 1.28425274e+01], ..., [2.75253296e-01, 2.75253296e-01, 2.75253296e-01, ..., 2.75253296e-01, 2.75253296e-01, 2.75253296e-01], [2.75253296e-01, 2.75253296e-01, 2.75253296e-01, ..., 2.75253296e-01, 2.75253296e-01, 2.75253296e-01], [2.73891449e-01, 2.73891449e-01, 2.73891449e-01, ..., 2.73891449e-01, 2.73891449e-01, 2.73891449e-01]]]]) Coordinates: * time (time) datetime64[ns] 8B 2022-09-05 * variable (variable) Size: 83MB array([[[[ 9.94979952e+04, 9.94979952e+04, 9.94979952e+04, ..., 9.94979952e+04, 9.94979952e+04, 9.94979952e+04], [ 9.95163836e+04, 9.95158991e+04, 9.95154146e+04, ..., 9.95178371e+04, 9.95173526e+04, 9.95168681e+04], [ 9.95347720e+04, 9.95338029e+04, 9.95328339e+04, ..., 9.95376790e+04, 9.95367100e+04, 9.95357410e+04], ..., [ 1.00292652e+05, 1.00292527e+05, 1.00292401e+05, ..., 1.00293029e+05, 1.00292903e+05, 1.00292778e+05], [ 1.00259271e+05, 1.00259208e+05, 1.00259146e+05, ..., 1.00259459e+05, 1.00259397e+05, 1.00259334e+05], [ 1.00225890e+05, 1.00225890e+05, 1.00225890e+05, ..., 1.00225890e+05, 1.00225890e+05, 1.00225890e+05]], [[ 8.41516213e+00, 8.41516213e+00, 8.41516213e+00, ..., 8.41516213e+00, 8.41516213e+00, 8.41516213e+00], [ 8.16163369e+00, 8.16432412e+00, 8.16701454e+00, ..., 8.15356243e+00, 8.15625285e+00, 8.15894327e+00], [ 7.90810525e+00, 7.91348610e+00, 7.91886694e+00, ..., 7.89196272e+00, 7.89734357e+00, 7.90272441e+00], ... [ 1.00297768e+05, 1.00297661e+05, 1.00297553e+05, ..., 1.00298091e+05, 1.00297983e+05, 1.00297876e+05], [ 1.00264442e+05, 1.00264388e+05, 1.00264334e+05, ..., 1.00264603e+05, 1.00264549e+05, 1.00264495e+05], [ 1.00231115e+05, 1.00231115e+05, 1.00231115e+05, ..., 1.00231115e+05, 1.00231115e+05, 1.00231115e+05]], [[ 8.44940207e+00, 8.44940207e+00, 8.44940207e+00, ..., 8.44940207e+00, 8.44940207e+00, 8.44940207e+00], [ 8.19866092e+00, 8.20134607e+00, 8.20403123e+00, ..., 8.19060545e+00, 8.19329060e+00, 8.19597576e+00], [ 7.94791976e+00, 7.95329007e+00, 7.95866038e+00, ..., 7.93180882e+00, 7.93717914e+00, 7.94254945e+00], ..., [-1.05174263e+00, -1.04816517e+00, -1.04458771e+00, ..., -1.06247502e+00, -1.05889756e+00, -1.05532010e+00], [-1.05885087e+00, -1.05706214e+00, -1.05527341e+00, ..., -1.06421706e+00, -1.06242833e+00, -1.06063960e+00], [-1.06595911e+00, -1.06595911e+00, -1.06595911e+00, ..., -1.06595911e+00, -1.06595911e+00, -1.06595911e+00]]]]) Coordinates: * time (time) datetime64[ns] 40B 2022-09-05 2022-09-05 ... 2022-09-05 * variable (variable) None: """Contour helper""" ax0.contourf( output_coords["lon"], output_coords["lat"], data.cpu(), vmin=vrange[0], vmax=vrange[1], transform=ccrs.PlateCarree(), levels=20, cmap=cmap, ) ax0.coastlines() ax0.gridlines() plot_contour(ax[0, 0], era5_data[0, 0, 0]) plot_contour(ax[0, 1], torch.mean(output_0[:, 0, var_idx], axis=0)) plot_contour(ax[0, 2], torch.mean(output_1[:, 0, var_idx], axis=0)) plot_contour( ax[1, 1], torch.std(output_0[:, 0, var_idx], axis=0), cmap="inferno", vrange=(0, 10) ) plot_contour( ax[1, 2], torch.std(output_1[:, 0, var_idx], axis=0), cmap="inferno", vrange=(0, 10) ) ax[0, 0].set_title("ERA5") ax[0, 1].set_title("3 Input Variables Mean") ax[0, 2].set_title("13 Input Variables Mean") ax[1, 1].set_title("3 Input Variables Std") ax[1, 2].set_title("13 Input Variables Std") plt.tight_layout() plt.savefig("outputs/15_tcwv_cbottle_infill.jpg") .. image-sg:: /examples/images/sphx_glr_15_cbottle_generation_002.png :alt: ERA5, 3 Input Variables Mean, 13 Input Variables Mean, 3 Input Variables Std, 13 Input Variables Std :srcset: /examples/images/sphx_glr_15_cbottle_generation_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none Fetching WB2 data: 0%| | 0/1 [00:00` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: 15_cbottle_generation.py <15_cbottle_generation.py>` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: 15_cbottle_generation.zip <15_cbottle_generation.zip>` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_