Some work on units
authorAlexander Vasarab <alexander@wylark.com>
Wed, 1 Jul 2020 00:56:08 +0000 (17:56 -0700)
committerAlexander Vasarab <alexander@wylark.com>
Wed, 1 Jul 2020 00:56:08 +0000 (17:56 -0700)
- If units are specified as metric, then make sure InfoEx sees the right
  unit as well
- Override units for NRCS to imperial, for now

infoex-autowx.py

index 78279f2672cdf0d1f0d2eec5d961a906836fb545..78c4d49be685bd86719fa0ccbc7651b681c8bbf3 100755 (executable)
@@ -112,6 +112,11 @@ try:
                     'PREC'  # PRECIPITATION ACCUMULATION (in)
                     ]
 
+        # XXX: For NRCS, we're manually overriding units for now! Once
+        #      unit conversion is supported for NRCS, REMOVE THIS!
+        if 'units' not in data:
+            data['units'] = 'imperial'
+
     if data['provider'] == 'mesowest':
         data['source'] = 'https://api.synopticdata.com/v2/stations/timeseries'
         data['station_id'] = config['station']['station_id']
@@ -208,6 +213,20 @@ elif data['provider'] == 'mesowest':
     iemap['wind_direction'] = 'windDirectionNum'
     iemap['wind_gust'] = 'windGustSpeedNum'
 
+# override units if user selected metric
+#
+# NOTE: to update this, use the fmap<->final_data mapping laid out above
+#
+# NOTE: this only 'works' with MesoWest for now, as the MesoWest API
+#       itself handles the unit conversion; in the future, we will also
+#       support NRCS unit conversion, but this must be done by this
+#       program.
+if data['units'] == 'metric':
+    final_data[fmap['tempPresUnit']] = 'C'
+    final_data[fmap['hsUnit']] = 'm'
+    final_data[fmap['windSpeedUnit']] = 'm/s'
+    final_data[fmap['windGustSpeedNumUnit']] = 'm/s'
+
 # floor time to nearest hour
 dt = datetime.datetime.now()
 end_date = dt - datetime.timedelta(minutes=dt.minute % 60,