.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/02_diagnostic_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_02_diagnostic_workflow.py: Running Diagnostic Inference ============================ Basic prognostic + diagnostic inference workflow. This example will demonstrate how to run a deterministic inference workflow that couples a prognostic model with a diagnostic model. This diagnostic model will predict a new atmospheric quantity from the predicted fields of the prognostic. In this example you will learn: - How to instantiate a prognostic model - How to instantiate a diagnostic model - Creating a data source and IO object - Running the built in diagnostic workflow - Post-processing results .. GENERATED FROM PYTHON SOURCE LINES 38-42 Set Up ------ For this example, the built in diagnostic workflow :py:meth:`earth2studio.run.diagnostic` will be used. .. GENERATED FROM PYTHON SOURCE LINES 44-48 .. literalinclude:: ../../earth2studio/run.py :language: python :start-after: # sphinx - diagnostic start :end-before: # sphinx - diagnostic end .. GENERATED FROM PYTHON SOURCE LINES 51-57 Thus, we need the following: - Prognostic Model: Use the built in FourCastNet Model :py:class:`earth2studio.models.px.FCN`. - Diagnostic Model: Use the built in precipitation AFNO model :py:class:`earth2studio.models.dx.PrecipitationAFNO`. - 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-84 .. 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 earth2studio.data import GFS from earth2studio.io import ZarrBackend from earth2studio.models.dx import PrecipitationAFNO from earth2studio.models.px import FCN # Load the default model package which downloads the check point from NGC package = FCN.load_default_package() prognostic_model = FCN.load_model(package) package = PrecipitationAFNO.load_default_package() diagnostic_model = PrecipitationAFNO.load_model(package) # Create the data source data = GFS() # Create the IO handler, store in memory io = ZarrBackend() .. rst-class:: sphx-glr-script-out .. code-block:: none /localhome/user/miniconda3/envs/e2studio/lib/python3.10/site-packages/modulus/models/module.py:360: FutureWarning: You are using `torch.load` with `weights_only=False` (the current default value), which uses the default pickle module implicitly. It is possible to construct malicious pickle data which will execute arbitrary code during unpickling (See https://github.com/pytorch/pytorch/blob/main/SECURITY.md#untrusted-models for more details). In a future release, the default value for `weights_only` will be flipped to `True`. This limits the functions that could be executed during unpickling. Arbitrary objects will no longer be allowed to be loaded via this mode unless they are explicitly allowlisted by the user via `torch.serialization.add_safe_globals`. We recommend you start setting `weights_only=True` for any use case where you don't have full control of the loaded file. Please open an issue on GitHub for any issues related to this experimental feature. model_dict = torch.load( .. GENERATED FROM PYTHON SOURCE LINES 85-91 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. .. GENERATED FROM PYTHON SOURCE LINES 93-102 .. code-block:: Python import earth2studio.run as run nsteps = 8 io = run.diagnostic( ["2021-06-01"], nsteps, prognostic_model, diagnostic_model, data, io ) print(io.root.tree()) .. rst-class:: sphx-glr-script-out .. code-block:: none 2024-09-20 15:59:00.610 | INFO | earth2studio.run:diagnostic:179 - Running diagnostic workflow! 2024-09-20 15:59:00.611 | INFO | earth2studio.run:diagnostic:186 - Inference device: cuda 2024-09-20 15:59:00.668 | DEBUG | earth2studio.data.gfs:_fetch_gfs_dataarray:178 - Fetching GFS index file: 2021-06-01 00:00:00 lead 0:00:00 Fetching GFS for 2021-06-01 00:00:00: 0%| | 0/26 [00:00` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: 02_diagnostic_workflow.py <02_diagnostic_workflow.py>` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: 02_diagnostic_workflow.zip <02_diagnostic_workflow.zip>` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_