Skip to content

Commit

Permalink
Add windchill calculation to Vantage agent (#550)
Browse files Browse the repository at this point in the history
* Added wind chill temperature to acquisition data

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Limit wind chill calc upper range

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Brian Koopman <[email protected]>
  • Loading branch information
3 people authored and d-hoshino2626 committed Apr 12, 2024
1 parent b3dcc2b commit b811836
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions socs/agents/vantagepro2/drivers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import struct
import time

import numpy as np
from serial import Serial

# some commands require a CRC code (cyclic redundancy check) -
Expand Down Expand Up @@ -58,6 +59,22 @@ def F_to_C(temp):
return (temp - 32) * (5 / 9)


def wind_chill(temp, wind):
"""Function to calculate wind chill temperature. Only valid if temp < 50F.
Taken from https://www.calculator.net/wind-chill-calculator.html
If temp > 50F, need to use heat index instead...
Temp: Temperature in Fahrenheit
wind: Speed in miles per hour
"""
# Calculation not valid above 50 F
if temp > 50:
return temp

chill = 35.75 + 0.6215 * temp - 35.75 * np.power(wind, 0.16) + 0.4275 * temp * np.power(wind, 0.16)
return chill


class VantagePro2:
"""Allows communication to Vantage Pro 2 Weather Monitor Module.
Contains commands to be issued and member variables that store
Expand Down Expand Up @@ -318,6 +335,11 @@ def receive_data(self):
loop_data['time_sunrise'] = byte_data[75]
loop_data['time_sunset'] = byte_data[76]

# Add wind chill temperature to observation data
temp = byte_data[9] / 10.0
wind_speed = byte_data[10]
loop_data['wind_chill_temp'] = F_to_C(wind_chill(temp, wind_speed))

# Correct UV Index by a factor of 10 and fix overflow
uvi = loop_data['UV']
if uvi < 0:
Expand Down

0 comments on commit b811836

Please sign in to comment.