.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/03_ensemble_workflow.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_03_ensemble_workflow.py: Running Ensemble Inference ========================== Simple ensemble inference workflow. This example will demonstrate how to run a simple inference workflow to generate a ensemble forecast using one of the built in models of Earth-2 Inference Studio. In this example you will learn: - How to instantiate a built in prognostic model - Creating a data source and IO object - Select a perturbation method - Running a simple built in workflow for ensembling - Post-processing results .. GENERATED FROM PYTHON SOURCE LINES 38-43 Set Up ------ All workflows inside Earth2Studio require constructed components to be handed to them. In this example, we will use the built in ensemble workflow :py:meth:`earth2studio.run.ensemble`. .. GENERATED FROM PYTHON SOURCE LINES 45-49 .. literalinclude:: ../../earth2studio/run.py :language: python :start-after: # sphinx - ensemble start :end-before: # sphinx - ensemble end .. GENERATED FROM PYTHON SOURCE LINES 51-57 We need the following: - Prognostic Model: Use the built in FourCastNet model :py:class:`earth2studio.models.px.FCN`. - perturbation_method: Use the Spherical Gaussian Method :py:class:`earth2studio.perturbation.SphericalGaussian`. - Datasource: Pull data from the GFS data api :py:class:`earth2studio.data.GFS`. - IO Backend: Save the outputs into a Zarr store :py:class:`earth2studio.io.ZarrBackend`. .. GENERATED FROM PYTHON SOURCE LINES 59-92 .. 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 numpy as np from earth2studio.data import GFS from earth2studio.io import ZarrBackend from earth2studio.models.px import FCN from earth2studio.perturbation import SphericalGaussian from earth2studio.run import ensemble # Load the default model package which downloads the check point from NGC package = FCN.load_default_package() model = FCN.load_model(package) # Instantiate the pertubation method sg = SphericalGaussian(noise_amplitude=0.15) # Create the data source data = GFS() # Create the IO handler, store in memory chunks = {"ensemble": 1, "time": 1, "lead_time": 1} io = ZarrBackend( file_name="outputs/03_ensemble_sg.zarr", chunks=chunks, backend_kwargs={"overwrite": True}, ) .. rst-class:: sphx-glr-script-out .. code-block:: none /usr/lib/python3.12/tarfile.py:2254: DeprecationWarning: Python 3.14 will, by default, filter extracted tar archives and reject files or modify their metadata. Use the filter argument to control this behavior. warnings.warn( .. GENERATED FROM PYTHON SOURCE LINES 93-102 Execute the Workflow -------------------- With all components initialized, running the workflow is a single line of Python code. Workflow will return the provided IO object back to the user, which can be used to then post process. Some have additional APIs that can be handy for post-processing or saving to file. Check the API docs for more information. For the forecast we will predict for 10 steps (for FCN, this is 60 hours) with 8 ensemble members which will be ran in 2 batches with batch size 4. .. GENERATED FROM PYTHON SOURCE LINES 104-120 .. code-block:: Python nsteps = 10 nensemble = 8 batch_size = 2 io = ensemble( ["2024-01-01"], nsteps, nensemble, model, data, io, sg, batch_size=batch_size, output_coords={"variable": np.array(["t2m", "tcwv"])}, ) .. rst-class:: sphx-glr-script-out .. code-block:: none 2025-03-27 07:56:48.297 | INFO | earth2studio.run:ensemble:315 - Running ensemble inference! 2025-03-27 07:56:48.297 | INFO | earth2studio.run:ensemble:323 - Inference device: cuda /home/jenkins/agent/workspace/Studio-Build-Docs/repo/earth2studio/utils/time.py:38: DeprecationWarning: datetime.datetime.utcfromtimestamp() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.fromtimestamp(timestamp, datetime.UTC). time = [datetime.utcfromtimestamp((date - _unix) / _ds) for date in time] 2025-03-27 07:56:48.332 | DEBUG | earth2studio.data.gfs:_fetch_gfs_dataarray:214 - Fetching GFS index file: 2024-01-01 00:00:00 lead 0:00:00 Fetching GFS for 2024-01-01 00:00:00: 0%| | 0/26 [00:00` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: 03_ensemble_workflow.py <03_ensemble_workflow.py>` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: 03_ensemble_workflow.zip <03_ensemble_workflow.zip>` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_