diff weather_server/types.py @ 41:4af79d69b12e v0.2.0

Use units better suited for science.
author Paul Fisher <paul@pfish.zone>
date Tue, 01 Apr 2025 16:04:52 -0400
parents b77c8e7d2742
children 10bde12a9163
line wrap: on
line diff
--- a/weather_server/types.py	Tue Apr 01 15:54:42 2025 -0400
+++ b/weather_server/types.py	Tue Apr 01 16:04:52 2025 -0400
@@ -13,6 +13,10 @@
     return c * 9 / 5 + 32
 
 
+def c_to_k(c: float) -> float:
+    return c + 273.15
+
+
 # Values from Sontag1990 via Wikipedia:
 # https://en.wikipedia.org/wiki/Dew_point
 _MAGNUS_B = 17.62
@@ -41,6 +45,10 @@
     @property
     def temp_f(self) -> float:
         return c_to_f(self.temp_c)
+    
+    @property
+    def temp_k(self) -> float:
+        return c_to_k(self.temp_k)
 
     @property
     def dew_point_c(self) -> float:
@@ -50,6 +58,10 @@
     @property
     def dew_point_f(self) -> float:
         return c_to_f(self.dew_point_c)
+    
+    @property
+    def dew_point_k(self) -> float:
+        return c_to_k(self.dew_point_c)
 
     @classmethod
     def from_dict(cls: t.Type[T], d: t.Dict[str, t.Any]) -> T: