.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/13_cyclone_tracking.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_13_cyclone_tracking.py: Tropical Cyclone Tracking ========================= Tropical cyclone tracking with tracker diagnostic models. This example will demonstrate how to use the tropical cyclone (TC) tracker diagnostic models for creating TC paths. The diagnostics used here can be combined with other AI weather models and ensemble methods to create complex inference workflow that enable downstream analysis. In this example you will learn: - How to instantiate a TC tracker diagnostic - How to apply the TC tracker to data - How to couple the TC tracker to a prognostic model - Post-processing results .. GENERATED FROM PYTHON SOURCE LINES 37-44 .. code-block:: Python # /// script # dependencies = [ # "earth2studio[cyclone,sfno] @ git+https://github.com/NVIDIA/earth2studio.git", # "cartopy", # ] # /// .. GENERATED FROM PYTHON SOURCE LINES 45-58 Set Up ------ This example will look at tracking cyclones during August 2009, a moment in time when multiple tropical cyclones where impacting East Asia. Earth2Studio provides multiple variations of TC trackers such as :py:class:`earth2studio.models.dx.TCTrackerVitart` and :py:class:`earth2studio.models.dx.TCTrackerWuDuan`. The difference being the underlying algorithm used to identify the center. This example needs the following: - Diagostic Model: Use the TC tracker :py:class:`earth2studio.models.dx.TCTrackerWuDuan`. - Datasource: Pull data from the WB2 ERA5 data api :py:class:`earth2studio.data.WB2ERA5`. - Prognostic Model: Use the built in FourCastNet Model :py:class:`earth2studio.models.px.FCN`. .. GENERATED FROM PYTHON SOURCE LINES 60-89 .. code-block:: Python 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, timedelta import torch from earth2studio.data import ARCO from earth2studio.models.dx import TCTrackerWuDuan from earth2studio.models.px import SFNO from earth2studio.utils.time import to_time_array # Create tropical cyclone tracker tracker = TCTrackerWuDuan() # Load the default model package which downloads the check point from NGC package = SFNO.load_default_package() prognostic = SFNO.load_model(package) # Create the data source data = ARCO() nsteps = 16 # Number of steps to run the tracker for into future start_time = datetime(2009, 8, 5) # Start date for inference .. GENERATED FROM PYTHON SOURCE LINES 90-98 Tracking Analysis Data ---------------------- Before coupling the TC tracker with a prognostic model, we will first apply it to analysis data. We can fetch a small time range from the data source and provide it to our model. For the forecast we will predict for two days (these will get executed as a batch) for 20 forecast steps which is 5 days. .. GENERATED FROM PYTHON SOURCE LINES 100-117 .. code-block:: Python from earth2studio.data import fetch_data, prep_data_array device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu") tracker = tracker.to(device) # Land fall occured August 25th 2017 times = [start_time + timedelta(hours=6 * i) for i in range(nsteps + 1)] for step, time in enumerate(times): da = data(time, tracker.input_coords()["variable"]) x, coords = prep_data_array(da, device=device) output, output_coords = tracker(x, coords) print(f"Step {step}: ARCO tracks output shape {output.shape}") era5_tracks = output.cpu() torch.save(era5_tracks, "outputs/13_era5_paths.pt") .. rst-class:: sphx-glr-script-out .. code-block:: none 2025-12-15 01:27:14.419 | DEBUG | earth2studio.data.arco:_async_init:125 - Using Multi-Storage Client for ARCO data access Fetching ARCO data: 0%| | 0/5 [00:00 2: color = era5_cmap(path / era5_paths.shape[1]) ax.plot( lons[mask], lats[mask], color=color, linestyle="-.", marker="x", label="ERA5" if path == 0 else "", transform=ccrs.PlateCarree(), ) for path in range(sfno_paths.shape[1]): # Get lat/lon coordinates, filtering out nans lats = sfno_paths[0, path, :, 0] lons = sfno_paths[0, path, :, 1] mask = ~np.isnan(lats) & ~np.isnan(lons) if mask.any() and len(lons[mask]) > 2: color = sfno_cmap(path / sfno_paths.shape[1]) ax.plot( lons[mask], lats[mask], color=color, linestyle="-", label="SFNO" if path == 0 else "", transform=ccrs.PlateCarree(), ) era5_patch = mpatches.Rectangle( (0, 0), 1, 1, fc=era5_cmap(0.3), alpha=0.9, label="ERA5" ) sfno_patch = mpatches.Rectangle( (0, 0), 1, 1, fc=sfno_cmap(0.3), alpha=0.9, label="SFNO" ) ax.legend(handles=[era5_patch, sfno_patch], loc="upper right", title="Cyclone Tracks") plt.title( f'Tropical Cyclone Tracks\n{start_time.strftime("%Y-%m-%d")} to {end_time.strftime("%Y-%m-%d")}' ) plt.savefig(f"outputs/13_{start_time}_cyclone_tracks.jpg", bbox_inches="tight", dpi=300) .. image-sg:: /examples/images/sphx_glr_13_cyclone_tracking_001.png :alt: Tropical Cyclone Tracks 2009-08-05 to 2009-08-09 :srcset: /examples/images/sphx_glr_13_cyclone_tracking_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 259-265 In addition to filtering out the NaN values, users may want to apply other post processing steps on the paths which may be enforcing path lengths are above a certain threshold or other geography based filters. No cyclone tracker is perfect, we encourage users to experiment and tune the tracker as needed. .. rst-class:: sphx-glr-timing **Total running time of the script:** (1 minutes 23.603 seconds) .. _sphx_glr_download_examples_13_cyclone_tracking.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: 13_cyclone_tracking.ipynb <13_cyclone_tracking.ipynb>` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: 13_cyclone_tracking.py <13_cyclone_tracking.py>` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: 13_cyclone_tracking.zip <13_cyclone_tracking.zip>` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_