From ebae24b38ecd65f5c07f8b6f063c091212ecab5d Mon Sep 17 00:00:00 2001 From: XANTRONIX Industrial Date: Sat, 8 Mar 2025 22:39:41 -0500 Subject: [PATCH] Implement finding equilibrium level Other changes: * Rework Series.intersect() to return a tuple containing temperature, pressure * Rework other methods returning Series to return a tuple containing temperature, pressure --- lib/xmet/series.py | 4 ++-- lib/xmet/sounding.py | 21 ++++++++++++++++++--- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/lib/xmet/series.py b/lib/xmet/series.py index d7b15d2..2835594 100644 --- a/lib/xmet/series.py +++ b/lib/xmet/series.py @@ -7,7 +7,7 @@ class Series(dict): def __init__(self): super().__init__() - def intersect(self, series: Self): + def intersect(self, series: Self) -> tuple[float]: pairs = nearest(sorted(self.keys(), reverse=True), sorted(series.keys(), reverse=True)) @@ -19,6 +19,6 @@ class Series(dict): sign = cmp(v1, v2) if sign == 0 or (sign_last is not None and sign_last != sign): - return pair[0] + return v1, pair[0] sign_last = sign diff --git a/lib/xmet/sounding.py b/lib/xmet/sounding.py index 44fdb7f..22d373f 100644 --- a/lib/xmet/sounding.py +++ b/lib/xmet/sounding.py @@ -185,7 +185,7 @@ class Sounding(DatabaseTable): return series - def find_lfc(self, temp: float, pressure: float) -> float: + def find_lfc(self, temp: float, pressure: float) -> tuple[float]: moist_adiabat = follow_moist_adiabat(temp, pressure) temp_line = self.follow_temp() @@ -196,7 +196,20 @@ class Sounding(DatabaseTable): v1, v2 = moist_adiabat[pair[0]], temp_line[pair[1]] if v1 > v2: - return pair[0] + return v1, pair[0] + + def find_el(self, temp: float, pressure: float) -> tuple[float]: + moist_adiabat = follow_moist_adiabat(temp, pressure) + temp_line = self.follow_temp() + + pairs = nearest(sorted(moist_adiabat.keys(), reverse=True), + sorted(temp_line.keys(), reverse=True)) + + for pair in pairs: + v1, v2 = moist_adiabat[pair[0]], temp_line[pair[1]] + + if v1 < v2: + return v1, pair[0] def derive_parameters(self) -> SoundingParameters: dry_adiabat = follow_dry_adiabat(self.samples[0].temp, @@ -206,10 +219,12 @@ class Sounding(DatabaseTable): self.samples[0].pressure) lcl = dry_adiabat.intersect(saturated_mr_line) - lfc = self.find_lfc(dry_adiabat[lcl], lcl) + lfc = self.find_lfc(lcl[0], lcl[1]) + el = self.find_el(lfc[0], lfc[1]) params = SoundingParameters() params.lcl = lcl params.lfc = lfc + params.el = el return params