From c749cc63c96bbb5f81a93872d3f00632b1ecc731 Mon Sep 17 00:00:00 2001 From: David Hoese <david.hoese@ssec.wisc.edu> Date: Tue, 7 Mar 2023 21:32:43 -0600 Subject: [PATCH] Add initial basic tests of influxdb tools --- metobscommon/tests/test_influxdb.py | 39 +++++++++++++++++++++++++++++ metobscommon/util/calc.py | 5 ++-- 2 files changed, 41 insertions(+), 3 deletions(-) create mode 100644 metobscommon/tests/test_influxdb.py diff --git a/metobscommon/tests/test_influxdb.py b/metobscommon/tests/test_influxdb.py new file mode 100644 index 0000000..e963ffb --- /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 153038a..ee08c9f 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) -- GitLab