.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/calculations/Equivalent_Potential_Temperature.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_Equivalent_Potential_Temperature.py: ================================ Equivalent Potential Temperature ================================ 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 equivalent potential temperature over the provided sounding data and plots the values up to 300-hPa. .. GENERATED FROM PYTHON SOURCE LINES 14-21 .. code-block:: Python import matplotlib.pyplot as plt import pandas as pd from metpy.calc import equivalent_potential_temperature from metpy.cbook import get_test_data from metpy.units import units .. GENERATED FROM PYTHON SOURCE LINES 22-24 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 24-32 .. 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 33-34 Drop any rows with all NaN values for T, Td, winds .. GENERATED FROM PYTHON SOURCE LINES 34-37 .. code-block:: Python df = df.dropna(subset=('temperature', 'dewpoint', 'direction', 'speed' ), how='all').reset_index(drop=True) .. GENERATED FROM PYTHON SOURCE LINES 38-39 Isolate pressure, temperature, dewpoint, and height and add units .. GENERATED FROM PYTHON SOURCE LINES 39-44 .. code-block:: Python p = df['pressure'].values * units.hPa T = df['temperature'].values * units.degC Td = df['dewpoint'].values * units.degC h = df['height'].values * units.meter .. GENERATED FROM PYTHON SOURCE LINES 45-46 Calculate the equivalent potential temperature for the whole sounding .. GENERATED FROM PYTHON SOURCE LINES 46-48 .. code-block:: Python theta_e = equivalent_potential_temperature(p, T, Td) .. GENERATED FROM PYTHON SOURCE LINES 49-50 Define a layer with pressure greater than 300 hPa .. GENERATED FROM PYTHON SOURCE LINES 50-52 .. code-block:: Python layer = p > 300 * units.hPa .. GENERATED FROM PYTHON SOURCE LINES 53-54 Use the layer defined above and plot the equivalent potential temperature .. GENERATED FROM PYTHON SOURCE LINES 54-58 .. code-block:: Python plt.figure(figsize=(8, 8)) plt.plot(theta_e[layer], h[layer]) plt.title('Equivalent Potential Temperature (Kelvin)') plt.show() .. image-sg:: /examples/calculations/images/sphx_glr_Equivalent_Potential_Temperature_001.png :alt: Equivalent Potential Temperature (Kelvin) :srcset: /examples/calculations/images/sphx_glr_Equivalent_Potential_Temperature_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.093 seconds) .. _sphx_glr_download_examples_calculations_Equivalent_Potential_Temperature.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: Equivalent_Potential_Temperature.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: Equivalent_Potential_Temperature.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_