From 7af2b763b955e68ef76b93ba2259f83529cf55db Mon Sep 17 00:00:00 2001 From: Aki Date: Sun, 2 Apr 2023 23:46:40 +0200 Subject: Connected processing all the way to storage --- waterspout_radar/_radar.py | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) (limited to 'waterspout_radar/_radar.py') diff --git a/waterspout_radar/_radar.py b/waterspout_radar/_radar.py index 345bbd6..c8cca1f 100644 --- a/waterspout_radar/_radar.py +++ b/waterspout_radar/_radar.py @@ -23,6 +23,31 @@ class Prediction: low_clouds: float swi: float + def json(self): + return { + "time": self.time.isoformat(), + "latitude": self.latitude, + "longitude": self.longitude, + "dt": self.temperature_difference.m_as("kelvin"), + "ccd": self.convective_cloud_depth.m_as("foot"), + "wind": self.wind.m_as("knot"), + "clouds": self.low_clouds, + "swi": self.swi, + } + + @classmethod + def from_json(cls, json): + return cls( + datetime.datetime.fromisoformat(json["time"]), + json["latitude"], + json["longitude"], + json["dt"] * metunits.units.kelvin, + json["ccd"] * metunits.units.foot, + json["wind"] * metunits.units.knot, + json["clouds"], + json["swi"]) + + def calculate(config) -> typing.List[Prediction]: units = metunits.units @@ -45,12 +70,13 @@ def calculate(config) -> typing.List[Prediction]: pressure, _ = calc.el(cast["pressure"], cast["temp"], cast["dewpoint"]) el = calc.pressure_to_height_std(pressure) ccd = (el - lcl).to(units.ft) - clouds = cast["lclouds"].magnitude / 100 + clouds = cast["lclouds"][0].magnitude / 100 try: swi = szilagyi.calculate_swi(dt, ccd) except ValueError: swi = -10 - yield Prediction(cast.timestamp, latitude, longitude, dt, ccd, 0, clouds, swi) + wind = 0.0 * units.kts + yield Prediction(cast.timestamp, latitude, longitude, dt, ccd, wind, clouds, swi) predictions = [] locator = geocoders.Nominatim(user_agent="waterspout-radar") -- cgit v1.1