.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/01_deterministic_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_01_deterministic_workflow.py: Running Deterministic Inference =============================== Basic deterministic inference workflow. This example will demonstrate how to run a simple inference workflow to generate a basic determinstic 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 - Running a simple built in workflow - Post-processing results .. GENERATED FROM PYTHON SOURCE LINES 37-42 Set Up ------ All workflows inside Earth2Studio require constructed components to be handed to them. In this example, let's take a look at the most basic: :py:meth:`earth2studio.run.deterministic`. .. GENERATED FROM PYTHON SOURCE LINES 44-48 .. literalinclude:: ../../earth2studio/run.py :language: python :start-after: # sphinx - deterministic start :end-before: # sphinx - deterministic end .. GENERATED FROM PYTHON SOURCE LINES 50-55 Thus, we need the following: - Prognostic Model: Use the built in FourCastNet Model :py:class:`earth2studio.models.px.FCN`. - Datasource: Pull data from the GFS data api :py:class:`earth2studio.data.GFS`. - IO Backend: Let's save the outputs into a Zarr store :py:class:`earth2studio.io.ZarrBackend`. .. GENERATED FROM PYTHON SOURCE LINES 57-78 .. 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.px import FCN # Load the default model package which downloads the check point from NGC package = FCN.load_default_package() model = FCN.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 79-88 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 two days (these will get executed as a batch) for 20 forecast steps which is 5 days. .. GENERATED FROM PYTHON SOURCE LINES 90-97 .. code-block:: Python import earth2studio.run as run nsteps = 20 io = run.deterministic(["2024-01-01"], nsteps, model, data, io) print(io.root.tree()) .. rst-class:: sphx-glr-script-out .. code-block:: none 2024-09-20 15:57:56.966 | INFO | earth2studio.run:deterministic:75 - Running simple workflow! 2024-09-20 15:57:57.059 | INFO | earth2studio.run:deterministic:82 - Inference device: cuda 2024-09-20 15:57:57.229 | DEBUG | earth2studio.data.gfs:_fetch_gfs_dataarray:178 - 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 type is zero. setattr(self, word, getattr(machar, word).flat[0]) /localhome/user/miniconda3/envs/e2studio/lib/python3.10/site-packages/numpy/core/getlimits.py:89: UserWarning: The value of the smallest subnormal for type is zero. return self._float_to_str(self.smallest_subnormal) Fetching GFS for 2024-01-01 00:00:00: 4%|▍ | 1/26 [00:00<00:14, 1.69it/s] 2024-09-20 15:57:58.785 | DEBUG | earth2studio.data.gfs:_fetch_gfs_dataarray:226 - Fetching GFS grib file for variable: v10m at 2024-01-01 00:00:00_0 Fetching GFS for 2024-01-01 00:00:00: 4%|▍ | 1/26 [00:00<00:14, 1.69it/s] 2024-09-20 15:57:58.810 | DEBUG | earth2studio.data.gfs:_fetch_gfs_dataarray:226 - Fetching GFS grib file for variable: t2m at 2024-01-01 00:00:00_0 Fetching GFS for 2024-01-01 00:00:00: 4%|▍ | 1/26 [00:00<00:14, 1.69it/s] 2024-09-20 15:57:58.835 | DEBUG | earth2studio.data.gfs:_fetch_gfs_dataarray:226 - Fetching GFS grib file for variable: sp at 2024-01-01 00:00:00_0 Fetching GFS for 2024-01-01 00:00:00: 4%|▍ | 1/26 [00:00<00:14, 1.69it/s] 2024-09-20 15:57:58.859 | DEBUG | earth2studio.data.gfs:_fetch_gfs_dataarray:226 - Fetching GFS grib file for variable: msl at 2024-01-01 00:00:00_0 Fetching GFS for 2024-01-01 00:00:00: 4%|▍ | 1/26 [00:00<00:14, 1.69it/s] 2024-09-20 15:57:58.880 | DEBUG | earth2studio.data.gfs:_fetch_gfs_dataarray:226 - Fetching GFS grib file for variable: t850 at 2024-01-01 00:00:00_0 Fetching GFS for 2024-01-01 00:00:00: 4%|▍ | 1/26 [00:00<00:14, 1.69it/s] Fetching GFS for 2024-01-01 00:00:00: 23%|██▎ | 6/26 [00:00<00:01, 10.82it/s] 2024-09-20 15:57:58.898 | DEBUG | earth2studio.data.gfs:_fetch_gfs_dataarray:226 - Fetching GFS grib file for variable: u1000 at 2024-01-01 00:00:00_0 Fetching GFS for 2024-01-01 00:00:00: 23%|██▎ | 6/26 [00:00<00:01, 10.82it/s] 2024-09-20 15:57:58.917 | DEBUG | earth2studio.data.gfs:_fetch_gfs_dataarray:226 - Fetching GFS grib file for variable: v1000 at 2024-01-01 00:00:00_0 Fetching GFS for 2024-01-01 00:00:00: 23%|██▎ | 6/26 [00:00<00:01, 10.82it/s] 2024-09-20 15:57:58.935 | DEBUG | earth2studio.data.gfs:_fetch_gfs_dataarray:226 - Fetching GFS grib file for variable: z1000 at 2024-01-01 00:00:00_0 Fetching GFS for 2024-01-01 00:00:00: 23%|██▎ | 6/26 [00:00<00:01, 10.82it/s] 2024-09-20 15:57:58.954 | DEBUG | earth2studio.data.gfs:_fetch_gfs_dataarray:226 - Fetching GFS grib file for variable: u850 at 2024-01-01 00:00:00_0 Fetching GFS for 2024-01-01 00:00:00: 23%|██▎ | 6/26 [00:00<00:01, 10.82it/s] 2024-09-20 15:57:58.972 | DEBUG | earth2studio.data.gfs:_fetch_gfs_dataarray:226 - Fetching GFS grib file for variable: v850 at 2024-01-01 00:00:00_0 Fetching GFS for 2024-01-01 00:00:00: 23%|██▎ | 6/26 [00:00<00:01, 10.82it/s] 2024-09-20 15:57:58.990 | DEBUG | earth2studio.data.gfs:_fetch_gfs_dataarray:226 - Fetching GFS grib file for variable: z850 at 2024-01-01 00:00:00_0 Fetching GFS for 2024-01-01 00:00:00: 23%|██▎ | 6/26 [00:00<00:01, 10.82it/s] Fetching GFS for 2024-01-01 00:00:00: 46%|████▌ | 12/26 [00:00<00:00, 20.85it/s] 2024-09-20 15:57:59.009 | DEBUG | earth2studio.data.gfs:_fetch_gfs_dataarray:226 - Fetching GFS grib file for variable: u500 at 2024-01-01 00:00:00_0 Fetching GFS for 2024-01-01 00:00:00: 46%|████▌ | 12/26 [00:00<00:00, 20.85it/s] 2024-09-20 15:57:59.027 | DEBUG | earth2studio.data.gfs:_fetch_gfs_dataarray:226 - Fetching GFS grib file for variable: v500 at 2024-01-01 00:00:00_0 Fetching GFS for 2024-01-01 00:00:00: 46%|████▌ | 12/26 [00:00<00:00, 20.85it/s] 2024-09-20 15:57:59.045 | DEBUG | earth2studio.data.gfs:_fetch_gfs_dataarray:226 - Fetching GFS grib file for variable: z500 at 2024-01-01 00:00:00_0 Fetching GFS for 2024-01-01 00:00:00: 46%|████▌ | 12/26 [00:00<00:00, 20.85it/s] 2024-09-20 15:57:59.063 | DEBUG | earth2studio.data.gfs:_fetch_gfs_dataarray:226 - Fetching GFS grib file for variable: t500 at 2024-01-01 00:00:00_0 Fetching GFS for 2024-01-01 00:00:00: 46%|████▌ | 12/26 [00:00<00:00, 20.85it/s] 2024-09-20 15:57:59.081 | DEBUG | earth2studio.data.gfs:_fetch_gfs_dataarray:226 - Fetching GFS grib file for variable: z50 at 2024-01-01 00:00:00_0 Fetching GFS for 2024-01-01 00:00:00: 46%|████▌ | 12/26 [00:00<00:00, 20.85it/s] 2024-09-20 15:57:59.099 | DEBUG | earth2studio.data.gfs:_fetch_gfs_dataarray:226 - Fetching GFS grib file for variable: r500 at 2024-01-01 00:00:00_0 Fetching GFS for 2024-01-01 00:00:00: 46%|████▌ | 12/26 [00:00<00:00, 20.85it/s] Fetching GFS for 2024-01-01 00:00:00: 69%|██████▉ | 18/26 [00:00<00:00, 29.27it/s] 2024-09-20 15:57:59.117 | DEBUG | earth2studio.data.gfs:_fetch_gfs_dataarray:226 - Fetching GFS grib file for variable: r850 at 2024-01-01 00:00:00_0 Fetching GFS for 2024-01-01 00:00:00: 69%|██████▉ | 18/26 [00:00<00:00, 29.27it/s] 2024-09-20 15:57:59.135 | DEBUG | earth2studio.data.gfs:_fetch_gfs_dataarray:226 - Fetching GFS grib file for variable: tcwv at 2024-01-01 00:00:00_0 Fetching GFS for 2024-01-01 00:00:00: 69%|██████▉ | 18/26 [00:00<00:00, 29.27it/s] 2024-09-20 15:57:59.154 | DEBUG | earth2studio.data.gfs:_fetch_gfs_dataarray:226 - Fetching GFS grib file for variable: u100m at 2024-01-01 00:00:00_0 Fetching GFS for 2024-01-01 00:00:00: 69%|██████▉ | 18/26 [00:00<00:00, 29.27it/s] 2024-09-20 15:57:59.172 | DEBUG | earth2studio.data.gfs:_fetch_gfs_dataarray:226 - Fetching GFS grib file for variable: v100m at 2024-01-01 00:00:00_0 Fetching GFS for 2024-01-01 00:00:00: 69%|██████▉ | 18/26 [00:00<00:00, 29.27it/s] 2024-09-20 15:57:59.190 | DEBUG | earth2studio.data.gfs:_fetch_gfs_dataarray:226 - Fetching GFS grib file for variable: u250 at 2024-01-01 00:00:00_0 Fetching GFS for 2024-01-01 00:00:00: 69%|██████▉ | 18/26 [00:00<00:00, 29.27it/s] 2024-09-20 15:57:59.208 | DEBUG | earth2studio.data.gfs:_fetch_gfs_dataarray:226 - Fetching GFS grib file for variable: v250 at 2024-01-01 00:00:00_0 Fetching GFS for 2024-01-01 00:00:00: 69%|██████▉ | 18/26 [00:01<00:00, 29.27it/s] Fetching GFS for 2024-01-01 00:00:00: 92%|█████████▏| 24/26 [00:01<00:00, 35.91it/s] 2024-09-20 15:57:59.227 | DEBUG | earth2studio.data.gfs:_fetch_gfs_dataarray:226 - Fetching GFS grib file for variable: z250 at 2024-01-01 00:00:00_0 Fetching GFS for 2024-01-01 00:00:00: 92%|█████████▏| 24/26 [00:01<00:00, 35.91it/s] 2024-09-20 15:57:59.245 | DEBUG | earth2studio.data.gfs:_fetch_gfs_dataarray:226 - Fetching GFS grib file for variable: t250 at 2024-01-01 00:00:00_0 Fetching GFS for 2024-01-01 00:00:00: 92%|█████████▏| 24/26 [00:01<00:00, 35.91it/s] Fetching GFS for 2024-01-01 00:00:00: 100%|██████████| 26/26 [00:01<00:00, 24.31it/s] 2024-09-20 15:57:59.343 | SUCCESS | earth2studio.run:deterministic:95 - Fetched data from GFS 2024-09-20 15:57:59.354 | INFO | earth2studio.run:deterministic:125 - Inference starting! Running inference: 0%| | 0/21 [00:00 type is zero. setattr(self, word, getattr(machar, word).flat[0]) /localhome/user/miniconda3/envs/e2studio/lib/python3.10/site-packages/numpy/core/getlimits.py:89: UserWarning: The value of the smallest subnormal for type is zero. return self._float_to_str(self.smallest_subnormal) .. rst-class:: sphx-glr-timing **Total running time of the script:** (1 minutes 0.035 seconds) **Estimated memory usage:** 2273 MB .. _sphx_glr_download_examples_01_deterministic_workflow.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: 01_deterministic_workflow.ipynb <01_deterministic_workflow.ipynb>` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: 01_deterministic_workflow.py <01_deterministic_workflow.py>` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: 01_deterministic_workflow.zip <01_deterministic_workflow.zip>` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_