Merge branch 'snotel-hn24'
authorAlexander Vasarab <alexander@wylark.com>
Thu, 3 Mar 2022 23:02:19 +0000 (15:02 -0800)
committerAlexander Vasarab <alexander@wylark.com>
Thu, 3 Mar 2022 23:02:19 +0000 (15:02 -0800)
README.md
infoex-autowx.py

index d9aec9d7790472538b36167134786e93966af05b..cde6bd150500e68106ff163d866f1c7dcafe7071 100644 (file)
--- a/README.md
+++ b/README.md
@@ -85,8 +85,8 @@ options.
 `units = # either english or metric -- only applies when type is mesowest #`  
 `tz = # any entry from the Olson tz database e.g. America/Denver #`  
 `path = # the filesystem path to the Python program -- only applies when type is python #`  
-`wind_mode = # normal or average #`  
-`hn24 = # yes or no #`  
+`wind_mode = # normal or average -- only applies when type is mesowest #`  
+`hn24 = # true or false -- only applies when type is mesowest #`  
 
 `[infoex]`  
 `host = # InfoEx FTP host address #`  
@@ -331,6 +331,10 @@ windGustSpeedNum
 Version history
 ---------------
 
+- 3.4.0 (Mar 2022)
+
+  Implement HN24 for NRCS SNOTEL stations.
+
 - 3.3.1 (Jan 2022)
 
   Fix bug in which HN24 values under certain circumstances could be
index f05939412945b367b39167c53e5c4572793862eb..05e1d4661bc08fc01343c52a6aa31c1ab0581a91 100755 (executable)
@@ -430,6 +430,10 @@ def setup_infoex_counterparts_mapping(provider):
         iemap['WDIR'] = 'windDirectionNum'
         # unsupported by NRCS:
         # windGustSpeedNum
+
+        # NOTE: this doesn't exist in NRCS SNOTEL, we create it in this
+        #       program, so add it to the map here
+        iemap['hn24'] = 'hn24Auto'
     elif provider == 'mesowest':
         iemap['precip_accum'] = 'precipitationGauge'
         iemap['air_temp'] = 'tempPres'
@@ -499,6 +503,43 @@ def get_nrcs_data(begin, end, station):
         else:
             remote_data[element_cd] = None
 
+
+        # calc hn24, if applicable
+        hn24 = None
+
+        if station['hn24']:
+            hn24_values = []
+
+            if element_cd == "SNWD":
+                for idx, _ in enumerate(values):
+                    val = values[idx]
+                    if val is None:
+                        continue
+                    hn24_values.append(val['value'])
+
+                if len(hn24_values) > 0:
+                    # 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
+                    # settlement; if it's not, then we have HN24
+                    hn24 = hn24_values[0] - hn24_values[len(hn24_values)-1]
+
+                    if hn24 < 0.0:
+                        hn24 = abs(hn24)
+                    else:
+                        # this case represents HS settlement
+                        hn24 = 0.0
+
+            # finally, if user wants hn24 and it's set to None at this
+            # point, then force it to 0.0
+            if hn24 is None:
+                hn24 = 0.0
+
+        if hn24 is not None:
+            remote_data['hn24'] = hn24
+
     return remote_data
 
 def get_mesowest_data(begin, end, station):
@@ -630,18 +671,22 @@ def get_mesowest_data(begin, end, station):
         # 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)
+        # if the result is positive, then we have settlement; if it's not,
+        # then we have HN24
         hn24 = hn24_values[0] - hn24_values[len(hn24_values)-1]
 
         if hn24 < 0.0:
+            hn24 = abs(hn24)
+        else:
             # this case represents HS settlement
-            #
-            # TODO: determine if InfoEx supports auto-stations reporting
-            #       HS settlement values
             hn24 = 0.0
 
+
+    # finally, if user wants hn24 and it's set to None at this
+    # point, then force it to 0.0
+    if station['hn24'] and hn24 is None:
+        hn24 = 0.0
+
     if len(wind_speed_values) > 0:
         wind_speed_avg = sum(wind_speed_values) / len(wind_speed_values)