.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/plots/raster_declarative.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_plots_raster_declarative.py: Raster Plots using Declarative Syntax ===================================== The MetPy declarative syntax allows for a simplified interface to creating common meteorological analyses including surface observation plots. This example creates a temperature raster plot, though other potential raster plots include radar. .. GENERATED FROM PYTHON SOURCE LINES 12-19 .. code-block:: default import xarray as xr from metpy.cbook import get_test_data from metpy.plots import MapPanel, PanelContainer, RasterPlot from metpy.units import units .. GENERATED FROM PYTHON SOURCE LINES 20-21 Import the temperature data from the NARR file. .. GENERATED FROM PYTHON SOURCE LINES 21-23 .. code-block:: default narr_data = xr.open_dataset(get_test_data('narr_example.nc', as_file_obj=False)) .. GENERATED FROM PYTHON SOURCE LINES 24-25 Preview the data: .. GENERATED FROM PYTHON SOURCE LINES 25-27 .. code-block:: default narr_data .. raw:: html
<xarray.Dataset>
    Dimensions:              (time: 1, isobaric: 29, y: 118, x: 292)
    Coordinates:
      * time                 (time) datetime64[ns] 1987-04-04T18:00:00
      * isobaric             (isobaric) float64 1e+03 975.0 950.0 ... 125.0 100.0
      * y                    (y) float64 -3.087e+03 -3.054e+03 ... 678.9 711.4
      * x                    (x) float64 -3.977e+03 -3.945e+03 ... 5.47e+03
    Data variables:
        Temperature          (time, isobaric, y, x) float32 ...
        Lambert_Conformal    |S1 ...
        lat                  (y, x) float64 ...
        lon                  (y, x) float64 ...
        u_wind               (time, isobaric, y, x) float32 ...
        v_wind               (time, isobaric, y, x) float32 ...
        Geopotential_height  (time, isobaric, y, x) float32 ...
        Specific_humidity    (time, isobaric, y, x) float32 ...
    Attributes: (12/14)
        Conventions:              CF-1.0
        Originating_center:       US National Weather Service - NCEP(WMC) (7)
        Originating_subcenter:    The North American Regional Reanalysis (NARR) P...
        Generating_Model:         North American Regional Reanalysis (NARR)
        Product_Type:             Forecast/Uninitialized Analysis/Image Product
        title:                    US National Weather Service - NCEP(WMC) North A...
        ...                       ...
        history:                  Direct read of GRIB-1 into NetCDF-Java 4 API
        CF:feature_type:          GRID
        file_format:              GRIB-1
        location:                 /nomads3_data/raid2/noaaport/merged/narr/198704...
        _CoordinateModelRunDate:  1987-04-04T18:00:00Z
        History:                  Translated to CF-1.0 Conventions by Netcdf-Java...


.. GENERATED FROM PYTHON SOURCE LINES 28-30 Create the 'RasterPlot' object and provide it with the NARR data. Specify the level to be plotted, and use the Data variables column to specify the data field to be plotted. .. GENERATED FROM PYTHON SOURCE LINES 30-35 .. code-block:: default raster = RasterPlot() raster.data = narr_data raster.field = 'Temperature' raster.level = 700 * units.hPa .. GENERATED FROM PYTHON SOURCE LINES 36-37 Add the plot to a Map Panel and Panel Container. .. GENERATED FROM PYTHON SOURCE LINES 37-49 .. code-block:: default panel = MapPanel() panel.area = 'us' panel.projection = 'lcc' panel.layers = ['coastline'] panel.plots = [raster] pc = PanelContainer() pc.size = (8, 8) pc.panels = [panel] pc.draw() pc.show() .. image-sg:: /examples/plots/images/sphx_glr_raster_declarative_001.png :alt: Temperature@700 hectopascal :srcset: /examples/plots/images/sphx_glr_raster_declarative_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 0.770 seconds) .. _sphx_glr_download_examples_plots_raster_declarative.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: raster_declarative.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: raster_declarative.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_