.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/calculations/Bulk_Shear.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_calculations_Bulk_Shear.py: ========== Bulk Shear ========== Use functions from `metpy.calc` as well as pint's unit support to perform calculations. The code below uses example data from our test suite to calculate the bulk shear over the lowest three kilometers for the provided sounding data. .. GENERATED FROM PYTHON SOURCE LINES 14-20 .. code-block:: Python import pandas as pd from metpy.calc import bulk_shear, wind_components from metpy.cbook import get_test_data from metpy.units import units .. GENERATED FROM PYTHON SOURCE LINES 21-23 Upper air data can be obtained using the siphon package, but for this example we will use some of MetPy's sample data. .. GENERATED FROM PYTHON SOURCE LINES 23-31 .. code-block:: Python # Set column names col_names = ['pressure', 'height', 'temperature', 'dewpoint', 'direction', 'speed'] # Read in test data using col_names df = pd.read_fwf(get_test_data('jan20_sounding.txt', as_file_obj=False), skiprows=5, usecols=[0, 1, 2, 3, 6, 7], names=col_names) .. GENERATED FROM PYTHON SOURCE LINES 32-33 Drop any rows with all NaN values for T, Td, winds .. GENERATED FROM PYTHON SOURCE LINES 33-36 .. code-block:: Python df = df.dropna(subset=('temperature', 'dewpoint', 'direction', 'speed'), how='all').reset_index(drop=True) .. GENERATED FROM PYTHON SOURCE LINES 37-38 Isolate pressure, wind direction, wid speed, and height and add units .. GENERATED FROM PYTHON SOURCE LINES 38-43 .. code-block:: Python p = df['pressure'].values * units.hPa wdir = df['direction'].values * units.degree sped = df['speed'].values * units.knot height = df['height'].values * units.meter .. GENERATED FROM PYTHON SOURCE LINES 44-45 Calculate the u and v-components of the wind .. GENERATED FROM PYTHON SOURCE LINES 45-47 .. code-block:: Python u, v = wind_components(sped, wdir) .. GENERATED FROM PYTHON SOURCE LINES 48-49 Compute the bulk shear for the lowest three km .. GENERATED FROM PYTHON SOURCE LINES 49-50 .. code-block:: Python print(bulk_shear(p, u, v, height, depth=3 * units.km, bottom=height[0])) .. rst-class:: sphx-glr-script-out .. code-block:: none (, ) .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.010 seconds) .. _sphx_glr_download_examples_calculations_Bulk_Shear.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: Bulk_Shear.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: Bulk_Shear.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_