.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/calculations/Mountain_Problem.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_Mountain_Problem.py: ================ Mountain Problem ================ Use functions from `metpy.calc` to perform calculations for a rising and sinking parcel. The code below explores a common problem in meteorology where a parcel can be defined and lifted initiatlly dry adibatically until saturation is reached. It then ascends moist adiabatically to a desired level before descending back to the original level from which the parcel started. .. GENERATED FROM PYTHON SOURCE LINES 16-21 .. code-block:: Python import numpy as np from metpy.calc import dry_lapse, lcl, moist_lapse from metpy.units import units .. GENERATED FROM PYTHON SOURCE LINES 22-24 To set up the classic mountain problem, let's define that the parcel will start at 1000-hPa and ascend to 700-hPa with an initial temperature of 25 Celsius and a dewpoint of 10 Celsius .. GENERATED FROM PYTHON SOURCE LINES 24-29 .. code-block:: Python p = np.linspace(1000, 700, 301) * units.hPa T = 25 * units.degC Td = 10 * units.degC .. GENERATED FROM PYTHON SOURCE LINES 30-32 We first need to determine the maximum level of dry ascent. For this we can use the LCL function and retain the pressure level and temperature of the parcel at the LCL .. GENERATED FROM PYTHON SOURCE LINES 32-38 .. code-block:: Python lclp, lclt = lcl(p[0], T, Td) print('Initial dry ascent yields:') print(f' LCL Pressure: {lclp:.2f}') print(f' LCL Temperature: {lclt:.2f}') print() .. rst-class:: sphx-glr-script-out .. code-block:: none Initial dry ascent yields: LCL Pressure: 801.54 hectopascal LCL Temperature: 6.74 degree_Celsius .. GENERATED FROM PYTHON SOURCE LINES 39-43 Knowing that the calculation of the dry ascent is accomplished by the LCL calculation, we know how to begin our moist ascent. Begin by subsetting the pressure to begin at levels less than or equal to the LCL pressure and use the moist_lapse to find the temperature at the top of our ascent (700-hPa in our case) .. GENERATED FROM PYTHON SOURCE LINES 43-49 .. code-block:: Python moist_ascent_p = p[p <= lclp] moist_ascent_t = moist_lapse(moist_ascent_p, lclt) print('After moist ascent:') print(f' Temperature at top of ascent: {moist_ascent_t[-1]:.2f}') print() .. rst-class:: sphx-glr-script-out .. code-block:: none After moist ascent: Temperature at top of ascent: 0.82 degree_Celsius .. GENERATED FROM PYTHON SOURCE LINES 50-53 Now to come "down the mountain" our parcel will warm dry adiabatically, so we can use the dry_laspe function to descend from the lowest pressure (using [::-1] to reverse the order) and convert our solution to Celsius .. GENERATED FROM PYTHON SOURCE LINES 53-55 .. code-block:: Python dry_descent = dry_lapse(p[::-1], moist_ascent_t[-1]).to('degC') .. GENERATED FROM PYTHON SOURCE LINES 56-57 Pulling it all together .. GENERATED FROM PYTHON SOURCE LINES 57-62 .. code-block:: Python print(f'Starting Temperature: {T:.2f}') print(f'Starting Dewpoint: {Td:.2f}', end='\n\n') print(f'Final Temperature: {dry_descent[-1]:.2f}') print(f'Final Dewpoint: {moist_ascent_t[-1]:.2f}') .. rst-class:: sphx-glr-script-out .. code-block:: none Starting Temperature: 25.00 degree_Celsius Starting Dewpoint: 10.00 degree_Celsius Final Temperature: 30.21 degree_Celsius Final Dewpoint: 0.82 degree_Celsius .. GENERATED FROM PYTHON SOURCE LINES 63-66 So as we expect the parcel has warmed and dried out through the combined dry and moist ascent due to the release of latent heat and subsequent precipitating out of moisture from the parcel .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.006 seconds) .. _sphx_glr_download_examples_calculations_Mountain_Problem.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: Mountain_Problem.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: Mountain_Problem.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_