Fix bug possible erroneous HN24 values bug
authorAlexander Vasarab <alexander@wylark.com>
Fri, 21 Jan 2022 02:13:19 +0000 (18:13 -0800)
committerAlexander Vasarab <alexander@wylark.com>
Fri, 21 Jan 2022 02:13:19 +0000 (18:13 -0800)
In certain cases, HN24 can be reported erroneously. What triggers this
is e.g. a storm which deposits 5cm of low-density snow which quickly
settles. During such a storm, the HS over a 24-hour period may go from
e.g. 100cm to 105cm then back to 100cm.

The root cause was taking the difference between the highest HS value
reported over a 24-hour period and subtracting the lowest value. But
when HS fluctuates throughout a storm due to rapid settlement and/or
wind, this calculation does not provide correct data.

Additionally, this bugfix opens the door to reporting HS settlement to
InfoEx should InfoEx support that data via autostations.

infoex-autowx.py

index 87c9c4a33cc1fe568ec098e4277f6011bf11bd14..ab39f87d2008e8ae835d5710b7cfc3e420a71f65 100755 (executable)
@@ -627,7 +627,20 @@ def get_mesowest_data(begin, end, station):
             remote_data[element_cd] = None
 
     if len(hn24_values) > 0:
             remote_data[element_cd] = None
 
     if len(hn24_values) > 0:
-        hn24 = max(hn24_values) - min(hn24_values)
+        # instead of taking MAX - MIN, we want the first value (most
+        # distant) - the last value (most recent)
+        #
+        # if the result is positive, then we have HN24; if it's not,
+        # then we have settlement
+        #hn24 = max(hn24_values) - min(hn24_values)
+        hn24 = hn24_values[0] - hn24_values[len(hn24_values)-1]
+
+        if hn24 < 0.0:
+            # this case represents HS settlement
+            #
+            # TODO: determine if InfoEx supports auto-stations reporting
+            #       HS settlement values
+            hn24 = 0.0
 
     if len(wind_speed_values) > 0:
         wind_speed_avg = sum(wind_speed_values) / len(wind_speed_values) 
 
     if len(wind_speed_values) > 0:
         wind_speed_avg = sum(wind_speed_values) / len(wind_speed_values)