.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/correlated_examples/plot_1_meteorology.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_auto_examples_correlated_examples_plot_1_meteorology.py: Meteorological, 2D{1,1,2,1,1} dataset ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. GENERATED FROM PYTHON SOURCE LINES 6-18 The following dataset is obtained from `NOAA/NCEP Global Forecast System (GFS) Atmospheric Model `_ and subsequently converted to the CSD model file-format. The dataset consists of two spatial dimensions describing the geographical coordinates of the earth surface and five dependent variables with 1) surface temperature, 2) air temperature at 2 m, 3) relative humidity, 4) air pressure at sea level as the four `scalar` quantity_type dependent variables, and 5) wind velocity as the two-component `vector`, quantity_type dependent variable. Let's import the `csdmpy` module and load this dataset. .. GENERATED FROM PYTHON SOURCE LINES 18-24 .. code-block:: Python import csdmpy as cp domain = "https://www.ssnmr.org/sites/default/files/CSDM" filename = f"{domain}/correlatedDataset/forecast/NCEI.csdf" multi_dataset = cp.load(filename) .. GENERATED FROM PYTHON SOURCE LINES 26-28 The tuple of dimension and dependent variable objects from ``multi_dataset`` instance are .. GENERATED FROM PYTHON SOURCE LINES 28-31 .. code-block:: Python x = multi_dataset.dimensions y = multi_dataset.dependent_variables .. GENERATED FROM PYTHON SOURCE LINES 32-34 The dataset contains two dimension objects representing the `longitude` and `latitude` of the earth's surface. The labels along thee respective dimensions are .. GENERATED FROM PYTHON SOURCE LINES 34-36 .. code-block:: Python print(x[0].label) .. rst-class:: sphx-glr-script-out .. code-block:: none longitude .. GENERATED FROM PYTHON SOURCE LINES 37-39 .. code-block:: Python print(x[1].label) .. rst-class:: sphx-glr-script-out .. code-block:: none latitude .. GENERATED FROM PYTHON SOURCE LINES 40-43 There are a total of five dependent variables stored in this dataset. The first dependent variable is the surface air temperature. The data structure of this dependent variable is .. GENERATED FROM PYTHON SOURCE LINES 43-45 .. code-block:: Python print(y[0].data_structure) .. rst-class:: sphx-glr-script-out .. code-block:: none { "type": "internal", "description": "The label 'tmpsfc' is the standard attribute name for 'surface air temperature'.", "name": "Surface temperature", "unit": "K", "quantity_name": "temperature", "numeric_type": "float64", "quantity_type": "scalar", "component_labels": [ "tmpsfc - surface air temperature" ], "components": [ [ "292.8152160644531, 293.0152282714844, ..., 301.8152160644531, 303.8152160644531" ] ] } .. GENERATED FROM PYTHON SOURCE LINES 46-48 If you have followed all previous examples, the above data structure should be self-explanatory. .. GENERATED FROM PYTHON SOURCE LINES 50-52 We will use the following snippet to plot the dependent variables of scalar `quantity_type`. .. GENERATED FROM PYTHON SOURCE LINES 52-89 .. code-block:: Python import numpy as np import matplotlib.pyplot as plt from mpl_toolkits.axes_grid1 import make_axes_locatable def plot_scalar(yx): fig, ax = plt.subplots(1, 1, figsize=(6, 3)) # Set the extents of the image plot. extent = [ x[0].coordinates[0].value, x[0].coordinates[-1].value, x[1].coordinates[0].value, x[1].coordinates[-1].value, ] # Add the image plot. im = ax.imshow(yx.components[0], origin="lower", extent=extent, cmap="coolwarm") # Add a colorbar. divider = make_axes_locatable(ax) cax = divider.append_axes("right", size="5%", pad=0.05) cbar = fig.colorbar(im, cax) cbar.ax.set_ylabel(yx.axis_label[0]) # Set up the axes label and figure title. ax.set_xlabel(x[0].axis_label) ax.set_ylabel(x[1].axis_label) ax.set_title(yx.name) # Set up the grid lines. ax.grid(color="k", linestyle="--", linewidth=0.5) plt.tight_layout() plt.show() .. GENERATED FROM PYTHON SOURCE LINES 90-91 Now to plot the data from the dependent variable. .. GENERATED FROM PYTHON SOURCE LINES 91-93 .. code-block:: Python plot_scalar(y[0]) .. image-sg:: /auto_examples/correlated_examples/images/sphx_glr_plot_1_meteorology_001.png :alt: Surface temperature :srcset: /auto_examples/correlated_examples/images/sphx_glr_plot_1_meteorology_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 94-95 Similarly, other dependent variables with their respective plots are .. GENERATED FROM PYTHON SOURCE LINES 95-97 .. code-block:: Python print(y[1].name) .. rst-class:: sphx-glr-script-out .. code-block:: none Air temperature at 2m .. GENERATED FROM PYTHON SOURCE LINES 98-100 .. code-block:: Python plot_scalar(y[1]) .. image-sg:: /auto_examples/correlated_examples/images/sphx_glr_plot_1_meteorology_002.png :alt: Air temperature at 2m :srcset: /auto_examples/correlated_examples/images/sphx_glr_plot_1_meteorology_002.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 101-103 .. code-block:: Python print(y[3].name) .. rst-class:: sphx-glr-script-out .. code-block:: none Relative humidity .. GENERATED FROM PYTHON SOURCE LINES 104-106 .. code-block:: Python plot_scalar(y[3]) .. image-sg:: /auto_examples/correlated_examples/images/sphx_glr_plot_1_meteorology_003.png :alt: Relative humidity :srcset: /auto_examples/correlated_examples/images/sphx_glr_plot_1_meteorology_003.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 107-109 .. code-block:: Python print(y[4].name) .. rst-class:: sphx-glr-script-out .. code-block:: none Air pressure at sea level .. GENERATED FROM PYTHON SOURCE LINES 110-112 .. code-block:: Python plot_scalar(y[4]) .. image-sg:: /auto_examples/correlated_examples/images/sphx_glr_plot_1_meteorology_004.png :alt: Air pressure at sea level :srcset: /auto_examples/correlated_examples/images/sphx_glr_plot_1_meteorology_004.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 113-115 Notice, we skipped the dependent variable at index two. The reason is that this particular dependent variable is a vector dataset, .. GENERATED FROM PYTHON SOURCE LINES 115-117 .. code-block:: Python print(y[2].quantity_type) .. rst-class:: sphx-glr-script-out .. code-block:: none vector_2 .. GENERATED FROM PYTHON SOURCE LINES 118-120 .. code-block:: Python print(y[2].name) .. rst-class:: sphx-glr-script-out .. code-block:: none Wind velocity .. GENERATED FROM PYTHON SOURCE LINES 121-123 which represents the wind velocity, and requires a vector visualization routine. To visualize the vector data, we use the matplotlib quiver plot. .. GENERATED FROM PYTHON SOURCE LINES 123-158 .. code-block:: Python def plot_vector(yx): fig, ax = plt.subplots(1, 1, figsize=(6, 3)) magnitude = np.sqrt(yx.components[0] ** 2 + yx.components[1] ** 2) cf = ax.quiver( x[0].coordinates, x[1].coordinates, yx.components[0], yx.components[1], magnitude, pivot="middle", cmap="inferno", ) divider = make_axes_locatable(ax) cax = divider.append_axes("right", size="5%", pad=0.05) cbar = fig.colorbar(cf, cax) cbar.ax.set_ylabel(yx.name + " / " + str(yx.unit)) ax.set_xlim([x[0].coordinates[0].value, x[0].coordinates[-1].value]) ax.set_ylim([x[1].coordinates[0].value, x[1].coordinates[-1].value]) # Set axes labels and figure title. ax.set_xlabel(x[0].axis_label) ax.set_ylabel(x[1].axis_label) ax.set_title(yx.name) # Set grid lines. ax.grid(color="gray", linestyle="--", linewidth=0.5) plt.tight_layout() plt.show() .. GENERATED FROM PYTHON SOURCE LINES 159-160 .. code-block:: Python plot_vector(y[2]) .. image-sg:: /auto_examples/correlated_examples/images/sphx_glr_plot_1_meteorology_005.png :alt: Wind velocity :srcset: /auto_examples/correlated_examples/images/sphx_glr_plot_1_meteorology_005.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 2.026 seconds) .. _sphx_glr_download_auto_examples_correlated_examples_plot_1_meteorology.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_1_meteorology.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_1_meteorology.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_