Fix CAPE calculation
This commit is contained in:
parent
f2c28d75e4
commit
1f0842fc2a
1 changed files with 24 additions and 15 deletions
|
@ -197,6 +197,12 @@ def between(n, a, b):
|
||||||
return n > a and n < b
|
return n > a and n < b
|
||||||
|
|
||||||
class SoundingParameters():
|
class SoundingParameters():
|
||||||
|
def __init__(self):
|
||||||
|
self.lcl = None
|
||||||
|
self.lfc = None
|
||||||
|
self.el = None
|
||||||
|
self.cape = None
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def cape(temp_line: Series,
|
def cape(temp_line: Series,
|
||||||
moist_adiabat: Series,
|
moist_adiabat: Series,
|
||||||
|
@ -212,9 +218,6 @@ class SoundingParameters():
|
||||||
for pair in neighbors:
|
for pair in neighbors:
|
||||||
p_env, p_parcel = pair
|
p_env, p_parcel = pair
|
||||||
|
|
||||||
if not between(p_env, p_el, p_lfc):
|
|
||||||
continue
|
|
||||||
|
|
||||||
t_env = kelvin(temp_line[p_env])
|
t_env = kelvin(temp_line[p_env])
|
||||||
t_parcel = kelvin(moist_adiabat[p_parcel])
|
t_parcel = kelvin(moist_adiabat[p_parcel])
|
||||||
gph = pressure_height(p_env)
|
gph = pressure_height(p_env)
|
||||||
|
@ -222,14 +225,14 @@ class SoundingParameters():
|
||||||
if gph_last is not None:
|
if gph_last is not None:
|
||||||
gph_delta = gph - gph_last
|
gph_delta = gph - gph_last
|
||||||
|
|
||||||
|
if between(p_env, p_el, p_lfc):
|
||||||
cape += ((t_parcel - t_env) / t_env) * gph_delta
|
cape += ((t_parcel - t_env) / t_env) * gph_delta
|
||||||
|
|
||||||
gph_last = gph
|
gph_last = gph
|
||||||
|
|
||||||
return 9.8076 * cape
|
return 9.8076 * cape
|
||||||
|
|
||||||
@staticmethod
|
def load_sounding(self, sounding: Sounding):
|
||||||
def from_sounding(sounding: Sounding) -> Self:
|
|
||||||
temp_line = sounding.follow_temp()
|
temp_line = sounding.follow_temp()
|
||||||
dry_adiabat = follow_dry_adiabat(sounding.samples[0].temp,
|
dry_adiabat = follow_dry_adiabat(sounding.samples[0].temp,
|
||||||
sounding.samples[0].pressure)
|
sounding.samples[0].pressure)
|
||||||
|
@ -241,16 +244,22 @@ class SoundingParameters():
|
||||||
|
|
||||||
moist_adiabat = follow_moist_adiabat(*lcl)
|
moist_adiabat = follow_moist_adiabat(*lcl)
|
||||||
|
|
||||||
lfc = moist_adiabat.intersect(temp_line, SeriesIntersection.GREATER)
|
lfc = temp_line.intersect(moist_adiabat, SeriesIntersection.LESSER)
|
||||||
el = moist_adiabat.intersect(temp_line, SeriesIntersection.LESSER, lfc[1])
|
el = temp_line.intersect(moist_adiabat, SeriesIntersection.GREATER, lfc[1]-100)
|
||||||
|
|
||||||
|
self.lcl = lcl
|
||||||
|
self.lfc = lfc
|
||||||
|
self.el = el
|
||||||
|
self.cape = SoundingParameters.cape(temp_line, moist_adiabat, lfc, el)
|
||||||
|
|
||||||
|
self.temp_line = temp_line
|
||||||
|
self.dry_adiabat = dry_adiabat
|
||||||
|
self.saturated_mr_line = saturated_mr_line
|
||||||
|
self.moist_adiabat = moist_adiabat
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def from_sounding(sounding: Sounding) -> Self:
|
||||||
params = SoundingParameters()
|
params = SoundingParameters()
|
||||||
params.lcl = lcl
|
params.load_sounding(sounding)
|
||||||
params.lfc = lfc
|
|
||||||
params.el = el
|
|
||||||
params.cape = SoundingParameters.cape(temp_line,
|
|
||||||
moist_adiabat,
|
|
||||||
lfc,
|
|
||||||
el)
|
|
||||||
|
|
||||||
return params
|
return params
|
||||||
|
|
Loading…
Add table
Reference in a new issue