.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/plots/upperair_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_upperair_declarative.py: =========================================== Upper Air Analysis using Declarative Syntax =========================================== The MetPy declarative syntax allows for a simplified interface to creating common meteorological analyses including upper air observation plots. .. GENERATED FROM PYTHON SOURCE LINES 14-22 .. code-block:: default from datetime import datetime import pandas as pd from metpy.cbook import get_test_data import metpy.plots as mpplots from metpy.units import units .. GENERATED FROM PYTHON SOURCE LINES 23-28 **Getting the data** In this example, data is originally from the Iowa State Upper-air archive (https://mesonet.agron.iastate.edu/archive/raob/) available through a Siphon method. The data are pre-processed to attach latitude/longitude locations for each RAOB site. .. GENERATED FROM PYTHON SOURCE LINES 28-38 .. code-block:: default data = pd.read_csv(get_test_data('UPA_obs.csv', as_file_obj=False)) # In a real-world case, you could obtain and preprocess the data with code such as # from siphon.simplewebservice.iastate import IAStateUpperAir # from metpy.io import add_station_lat_lon # data = IAStateUpperAir().request_all_data(datetime(2021, 8, 25, 12)) # data = add_station_lat_lon(data) .. GENERATED FROM PYTHON SOURCE LINES 39-42 **Plotting the data** Use the declarative plotting interface to create a CONUS upper-air map for 500 hPa .. GENERATED FROM PYTHON SOURCE LINES 42-69 .. code-block:: default # Plotting the Observations obs = mpplots.PlotObs() obs.data = data obs.time = datetime(1993, 3, 14, 0) obs.level = 500 * units.hPa obs.fields = ['temperature', 'dewpoint', 'height'] obs.locations = ['NW', 'SW', 'NE'] obs.formats = [None, None, lambda v: format(v, '.0f')[:3]] obs.vector_field = ('u_wind', 'v_wind') obs.reduce_points = 0 # Add map features for the particular panel panel = mpplots.MapPanel() panel.layout = (1, 1, 1) panel.area = (-124, -72, 20, 53) panel.projection = 'lcc' panel.layers = ['coastline', 'borders', 'states', 'land', 'ocean'] panel.plots = [obs] # Collecting panels for complete figure pc = mpplots.PanelContainer() pc.size = (15, 10) pc.panels = [panel] # Showing the results pc.show() .. image-sg:: /examples/plots/images/sphx_glr_upperair_declarative_001.png :alt: temperature and dewpoint and height@500 hectopascal :srcset: /examples/plots/images/sphx_glr_upperair_declarative_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 1.111 seconds) .. _sphx_glr_download_examples_plots_upperair_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: upperair_declarative.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: upperair_declarative.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_