From 46f067311b513c8302587adcfffe0b96e17ddc21 Mon Sep 17 00:00:00 2001 From: wroberts <wroberts4@wisc.edu> Date: Wed, 4 Sep 2019 12:37:06 -0500 Subject: [PATCH] Make timestamp index when creating dataframe and add more documentation --- aosstower/level_00/influxdb.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/aosstower/level_00/influxdb.py b/aosstower/level_00/influxdb.py index d29faa4..4dee9a4 100644 --- a/aosstower/level_00/influxdb.py +++ b/aosstower/level_00/influxdb.py @@ -78,7 +78,13 @@ class Updater(object): if self.data.get(key) is None: self.data[key] = np.array([]) self.data[key] = np.append(self.data[key][time_mask], record[key]) - # Gets the seconds from the start of the current year. This makes any interval chronologically consistent. + # Gets the seconds from the start of the current year. This makes any interval equal to or smaller than a + # year an absolute interval (ie if the submit interval was 5 minutes, then data is submitted at 5, 10, 15, + # etc). For example: if "reference" used the start of the current minute and we wanted to submit anything in + # longer intervals than a minute, then the times that data is submitted would not be consistent. i.e. if the + # current minute was 13 and the submit interval was 5 minutes, then data would be submitted at 18, 23, 28, + # etc. If data collection went down and the next recorded current minute was 14, then data would be submitted + # at 19, 24, 29, etc (inconsistent). reference = pd.datetime(record['timestamp'].year, 1, 1) progress = (record['timestamp'] - reference).total_seconds() % self.submit_interval # If data hits or will pass over a submit_interval interval, return data. @@ -86,8 +92,8 @@ class Updater(object): return self._calculate_averages() def _calculate_averages(self): - frame = pd.DataFrame(self.data) - frame.set_index('timestamp', inplace=True) + index = self.data.pop('timestamp') + frame = pd.DataFrame(self.data, index=index) frame.mask(frame == -99999., inplace=True) # Add wind direction components so we can average wind direction properly. frame['wind_east'], frame['wind_north'], _ = calc.wind_vector_components(frame['wind_speed'], -- GitLab