Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vantage windchill #550

Merged
merged 5 commits into from
Feb 29, 2024
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 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,19 @@ 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...
BrianJKoopman marked this conversation as resolved.
Show resolved Hide resolved

Temp: Temperature in Fahrenheit
wind: Speed in miles per hour
"""

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 +332,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