Compute the LCL from actual temperature in lfc/el used by cape_cin#4067
Open
gaoflow wants to merge 2 commits into
Open
Compute the LCL from actual temperature in lfc/el used by cape_cin#4067gaoflow wants to merge 2 commits into
gaoflow wants to merge 2 commits into
Conversation
…ta#3857) cape_cin replaces the environmental and parcel temperature profiles with virtual temperatures before calling lfc and el. Those functions then recomputed the LCL from the virtual temperatures, treating virtual temperature as actual temperature. Because virtual temperature exceeds temperature, the LCL came out at too low a pressure (too high an altitude), which biased the LFC and EL upward (they are floored at the LCL). Add optional lcl_pressure (and, for lfc, lcl_temperature) keywords to lfc and el so the caller can supply an LCL computed from the actual temperatures. cape_cin already computes the LCL from the actual temperatures before the virtual-temperature substitution, so it now passes that LCL through. Direct callers are unaffected: when the keywords are omitted the LCL is computed as before. Add a regression test and update the expected CAPE in test_cape_cin_value_error, whose LFC is floored at the LCL and so increases now that the correct LCL is used.
The lfc/el LCL fix changes the surface-based and most-unstable CAPE for the sounding used in these docstring examples (their LFC is floored at the LCL, which now sits at the correct, higher pressure), so refresh the expected doctest output. Verified with the repo's own doctest command (python -m pytest --doctest-modules -k 'not test' src): 89 passed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes #3857.
cape_cinapplies the virtual temperature correction by replacing the environmentaland parcel temperature profiles with their virtual temperatures before calling
lfcand
el:lfcandelthen recompute the LCL from those arrays —lfcfromparcel_temperature_profile[0],elfromtemperature[0]— i.e. they treat thevirtual temperature as if it were the actual temperature. Because virtual temperature
is always ≥ temperature, the LCL comes out at too low a pressure (too high an
altitude). Since the LFC and EL are floored at the LCL, both get biased upward; the
effect is strongest on the LFC, exactly as described in the issue.
Fix
Give
lfcandeloptionallcl_pressure(and, forlfc,lcl_temperature)keywords so the caller can supply an LCL computed from the actual temperatures. When
the keywords are omitted the LCL is computed from the inputs exactly as before, so
direct callers and the public API are unchanged.
cape_cinalready computes the LCL from the actual temperatures (for itsbelow_lclmixing-ratio logic) before the virtual-temperature substitution, so it simply passes
that LCL through to
lfc/el.Effect
For a sounding whose LFC is floored at the LCL, the actual-temperature LCL sits about
30–45 hPa higher in pressure than the virtual one, so the LFC (and the CAPE integration
that starts there) is corrected accordingly. For example, on the profile in
test_cape_cin_value_errorthe surface-based CAPE goes from the previously-reported2161.9 J/kg to 2206.7 J/kg once the LFC is floored at the correct LCL.
Tests
test_lfc_el_lcl_from_actual_temperature: reconstructs the virtual-temperatureprofiles
cape_cinbuilds and shows that, without the override,lfcfloors at thespuriously-low virtual LCL, while supplying the actual-temperature LCL floors it at
the correct LCL (and that
elhonors the keyword).test_cape_cin_value_error(whose LFC is floored at theLCL) with a comment explaining the change.
The full
tests/calc/test_thermo.pysuite passes (228 tests);ruffis clean.