Better utilize Sounding.hodograph_samples()

This commit is contained in:
XANTRONIX 2025-03-30 14:19:12 -04:00
parent 90187f9f4b
commit 66e49a2b24
2 changed files with 12 additions and 10 deletions

View file

@ -168,20 +168,13 @@ class Hodograph():
return (0.4, 0.4, 1.0)
def each_significant_sample(self, sounding: Sounding):
for sample in sounding.hodograph_samples():
if sample.wind_speed is None or sample.wind_dir is None:
continue
yield sample
def find_extents(self, sounding: Sounding):
min_x, min_y = None, None
max_x, max_y = None, None
first = True
for sample in self.each_significant_sample(sounding):
for sample in sounding.hodograph_samples():
sx, sy = self.sample_to_screen(knots(sample.wind_speed),
sample.wind_dir)
@ -225,7 +218,7 @@ class Hodograph():
min_x, min_y = self.extents['min']
max_x, max_y = self.extents['max']
for sample in self.each_significant_sample(sounding):
for sample in sounding.hodograph_samples():
color = self.color(sample.height)
if color is None:

View file

@ -286,7 +286,16 @@ class Sounding(DatabaseTable):
return wind_speed_dir(shear_u / levels, shear_v / levels)
def hodograph_samples(self) -> list[SoundingSample]:
samples = filter(lambda s: s.height is not None, self.samples)
def test(s: SoundingSample):
if s.height is None:
return False
if s.wind_speed is None or s.wind_dir is None:
return False
return True
samples = filter(test, self.samples)
return sorted(samples, key=lambda s: s.height)