diff --git a/metobscommon/tests/test_influxdb.py b/metobscommon/tests/test_influxdb.py new file mode 100644 index 0000000000000000000000000000000000000000..e963ffbc5b94b1ad60037e778aed990118ef100c --- /dev/null +++ b/metobscommon/tests/test_influxdb.py @@ -0,0 +1,39 @@ +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}" diff --git a/metobscommon/util/calc.py b/metobscommon/util/calc.py index 153038a0eb16aa6a6d8605abb867c4ef405a1b56..ee08c9f51c38ff5a87e9ef8b6fd0bd98ac36bcec 100644 --- a/metobscommon/util/calc.py +++ b/metobscommon/util/calc.py @@ -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)