Skip to content
Snippets Groups Projects
Verified Commit c749cc63 authored by David Hoese's avatar David Hoese
Browse files

Add initial basic tests of influxdb tools

parent fd17fdca
No related branches found
No related tags found
No related merge requests found
from datetime import datetime
from metobscommon import influxdb
def test_frame_records_single_dict():
now = datetime(2023, 1, 1, 12, 0, 0)
timestamp = 1672574400000000000 # now in nanoseconds from epoch
data_dict = {
"air_temp": 20.0,
"wind_speed": 15.0,
"timestamp": now,
}
lines = list(influxdb.frame_records(
data_dict,
measurement_name="test",
site="aoss",
inst="tower",
))
assert len(lines) == 1
assert lines[0] == f"test,inst=tower,site=aoss air_temp=20.0,wind_speed=15.0 {timestamp}"
def test_frame_records_single_dict_with_winds():
now = datetime(2023, 1, 1, 12, 0, 0)
timestamp = 1672574400000000000 # now in nanoseconds from epoch
data_dict = {
"air_temp": 20.0,
"wind_speed": 15.0,
"wind_dir": 0.0,
"timestamp": now,
}
lines = list(influxdb.frame_records(
data_dict,
measurement_name="test",
site="aoss",
inst="tower",
))
assert len(lines) == 1
assert lines[0] == f"test,inst=tower,site=aoss air_temp=20.0,wind_speed=15.0,wind_east=0.0,wind_north=15.0 {timestamp}"
......@@ -126,10 +126,9 @@ def dir2txt(val):
def wind_vector_components(windspd, winddir):
"""Decompose scalar or list/array polar wind direction and speed data
into the horizontal and vertical vector components and speed vector.
"""Decompose polar wind direction and speed into the horizontal and vertical vector components and speed vector.
Inputs can be scalar or arrays.
Inputs can be scalar or arrays. Wind direction of 0 is north.
"""
dir_rad = np.deg2rad(winddir)
spd_arr = np.array(windspd)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment