<jupyter_start><jupyter_text>MetPy Declarative - 300 hPa===========================By: <NAME>This example uses the declarative syntax available through the MetPypackage to allow a more convenient method for creating simple maps ofatmospheric data. The key thing the declarative language does is toreduce the number of packages that users will need to know in detail andinstead allow them to set key parameters to get the map they desire. Onekey element is the use of xarray as the data object, which allowscoordinate information to be associated with atmospheric variables.<jupyter_code>from datetime import datetime

import metpy.calc as mpcalc
from metpy.plots.declarative import *
from metpy.units import units
import xarray as xr<jupyter_output><empty_output><jupyter_text>Open dataset using xarray module and subset global GFS to be over theCONUS.<jupyter_code>ds = xr.open_dataset('https://thredds.ucar.edu/thredds/dodsC/casestudies'
                     '/python-gallery/GFS_20101026_1200.nc').sel(
    lon=slice(360-150, 360-50, 2), lat=slice(65, 20, 2))<jupyter_output><empty_output><jupyter_text>Calculate Variable and Add to Dataset-------------------------------------Here it is demonstrated how you can calculate a new variable and add itto the xarray dataset (ds) so that it can be plotted with thedeclarative syntax. The key to adding a variable to an xarray datasetfor use in the declarative syntax is the need to add a ``grid_mapping``and ``units`` attribute.<jupyter_code># Calculate New Variables and place into Xarray Dataset
uwnd = ds['u-component_of_wind_isobaric']
vwnd = ds['v-component_of_wind_isobaric']

# Compute wind speed using MetPy
wspd = mpcalc.wind_speed(uwnd, vwnd)

# Place wind speed (wspd) into xarray dataset and attach needed attributes
ds['wind_speed'] = wspd<jupyter_output><empty_output><jupyter_text>Declarative Plot----------------The following settings create a single panel map plot of 300 hPageopotential heights, wind speed, and wind barbs.<jupyter_code># Countour Plot of Geopotential Heights
contour = ContourPlot()
contour.data = ds
contour.time = datetime(2010, 10, 31, 12)
contour.field = 'Geopotential_height_isobaric'
contour.level = 300 * units.hPa
contour.linecolor = 'black'
contour.linestyle = '-'
contour.linewidth = 2
contour.clabels = True
contour.contours = list(range(0, 20000, 120))

# Colorfilled Plot of Wind Speed
cfill = FilledContourPlot()
cfill.data = ds
cfill.field = 'wind_speed'
cfill.level = 300 * units.hPa
cfill.colormap = 'BuPu'
cfill.contours = list(range(50, 171, 20))
cfill.colorbar = 'vertical'
cfill.plot_units = 'kt'

# Plot wind barbs
barb = BarbPlot()
barb.data = ds
barb.level = 300 * units.hPa
barb.field = ['u-component_of_wind_isobaric', 'v-component_of_wind_isobaric']
barb.skip = (3, 3)
barb.color = 'black'
barb.barblength = 6.5
barb.earth_relative = False
barb.plot_units = 'kt'

# Panel for plot with Map features
panel = MapPanel()
panel.layout = (1, 1, 1)
panel.area = (-124, -72, 20, 53)
panel.projection = 'lcc'
panel.layers = ['coastline', 'borders', 'states', 'land']
panel.plots = [cfill, contour, barb]

# Bringing it all together
pc = PanelContainer()
pc.size = (15, 9)
pc.panels = [panel]

pc.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11777434312210201, 'fraction_numerical': 0.027820710973724884, 'mean_word_length': 4.86231884057971, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 18, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '262929', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 1148, 'n_tokens_neox': 1037, 'n_words': 342, 'path': 'pages/gallery/Declarative_300hPa.ipynb', 'repo_name': 'rrbuchholz/python-training', 'size': '3243'}