Chapter 3 Data profiling and assessment of data quality
Bee Observer is based on two sources of internal data: the continuous flow of sensor data from beehives which is stored in an influxdb database (InfluxData (3/3/2020)), and the beekeepers’ records of their irregular inspections, which are stored in a MySQL database. Beyond the internal data, there may be merit in combining this information with data from other sources, for example meteorological data or geospatial data on agricultural practices nearby. In the context of the project I am able to retrieve sensor data from the influxdb independently, but due to privacy concerns, access to the inspections database is restricted to the project team at the University of Bremen who regularly provide database dumps to Correlaid project members. Data can be retrieved and analyzed locally, but the university also provides a dedicated server for RStudio with 12 CPU cores and 48GB RAM. The analyses in this thesis cover data collected from 21 February 2019 to 30 September 2020, but given the huge volume of raw sensor data due to the high frequency some detailed analysis of raw sensor data may sometimes be limited to some shorter sample periods.
3.1 Sensor data
Since February 2019, monitored beehives are regularly storing data in an influxdb database system, a column-oriented system aimed at fast reading and writing of time series data. The data are organized in “series” or “measurements” tables for every string “tag” per beehive. The “field” variables only allow numerical or logical data. Besides requiring this structure, the system does not allow for further restrictions in the schema. As a consequence, the database will accept any numerical data for a given field. Data can be queried from the database using InfluxQL, a SQL-like query language which allows some basic aggregations and transformations, but for certain preprocessing required in the context of this project, such as conditional adjustments to fix erroneous sensor data or lags to model sequence classifiers, further processing in R is required.1
Every beehive transmits data on a number of variables, coming from three separate sensor units, as shown in figure 3.1 (taken from Senger et al. (2020)): first, there is one unit with six temperature sensors (“Ds18s20 1-Wire Parasite-Power Digital Thermometer” (5/9/2020)), measuring the temperature at five positions within the hive and once outside the hive. The second unit is a scale (“Single Point Load Cell H40a” (5/3/2020)), regularly measuring the weight of everything on it, i.e. the total of the hive, the bees, the pollen they foraged and honey they produced. Finally, there is another unit measuring humidity inside hive at the top, which also include another thermometer and a sensor for air pressure (“Bme280” (5/7/2020)). All sensors are connected to a small programmable development board (Pycom (28.09.2020)), from which the data are sent to the influxdb server. The sensors used in the kits were selected to be cheap2 and easy to install for beekeepers, so that the entry barrier to participate in the project is low, but this may come at the cost of accuracy, also common to sensor data in general.
Figure 3.1: Sensor set-up
For an overview of the main variables available see table 3.1. Every observation contains a timestamp and the unique key of the specific beehive. In total there are 15 numeric variables , but the data availability for those not listed in the table is too low for meaningful statistical analysis3. There is some variation in the decimal precision across sensor kits, as this is set at the calibration by the beekeeper, but the values stated are a valid minimum for most.
| variable.names | description | type | precision |
|---|---|---|---|
| time | timestamp of the observation in Universal Time Coordinated (UTC) | POSIX date-time | seconds |
| key | unique key of the beehive | string | - |
| weight_kg | total weight (= hive + bees + honey + food) | numeric | 0.001 kg |
| h | humidity at the top of the beehive | numeric | 0.01 % |
| p | air pressure at the top of the beehive | numeric | 1 hPa |
| t | temperature at the top of the beehive | numeric | 0.01 °C |
| t_i_1 … t_i_5 | temperature inside: sensors 1 and 5 on the outside, 3 in the center and 2 and 4 in between | numeric | 0.01 °C |
| t_o | temperature outside | numeric | 0.01 °C |
At the time of writing, the influx database has accumulated hundreds of millions of raw observations, coming from 129 different beehives. However, the dataset lacks in completeness: weight measurements are recorded in most observations, suggesting that the scale is sending data at shorter time intervals than the other sensors, or is less likely to fail than the other sensor components. Next in frequency are temperatures from the thermometers and since these are six individual sensors, data availability is varying across them considerably. The three variables coming from the humidity sensor (relative humidity, temperature and air pressure), by contrast, have roughly equal numbers of observations, see figure 3.2.
Figure 3.2: Number of non-missing observations in raw dataset
The number of observations on other variables is negligible. Sensors record data broadly every five seconds (the middle half of the intervals for all variables is at that value), but sometimes it takes less or more time between two valid observations of a variable, see figure A.1 in the appendix. One has to note, however, that the various sensors may record their observations at different times in a non-synchronized way, making multivariate analysis difficult: in only around 60% of observations do we have non-missing entries for all our main variables of interest4. To better enable multivariate methods, it may be useful to aggregate observations to a common and regular sampling rate. Cheng et al. (2018) established a framework for data quality assessment in IoT, which can also be applied in this case, also to guide the strategy for cleaning. It provides objective indicators describing the volume of data relative to the theoretically possible volume, the share of complete observations and the share of correct observations5.
The data quality indicators are based on a constant sampling rate and a common sampling period for all nodes of a sensor network. As the many sensor kits have been added to the Bee Observer project over time and since time intervals between observations are varying, these assumptions are quite strong in this case. By considering a short stable data sample, I lower the risk of including too many sensor kits with only partial data, and also save computing time6. As regards the sampling rate, it is actually preferable to reshape the dataset to a common sampling rate: one the one hand this will create regular time series which allows for various time series analysis methods, and second it will increase the share of usable observations. Figure 3.3 shows the data volume indicator, which is an average of the ratio of available observations to all possible observations in the common sampling period over all sensor kits: when aggregating the data to intervals of 5 seconds, which covered the majority of intervals of all variables of interest, data volume is at roughly 65%. When aggregating to lower frequency aggregates some gaps existing at higher frequencies are closed and the volume increases, reaching almost 75% at an interval of one minute and more than 80% at daily frequency.
Figure 3.3: Data volume indicator at various sampling rates
Aggregating the data to lower sampling rates will still not fix the issue of larger time gaps in the data: only a few beehives have transmitted data continuously over longer periods, and sensor outages over multiple days are not rare, see figure 3.4. For the application of many time series analysis methods, missing values are a problem and may have to be imputed.
Figure 3.4: Heatmap of data availability
Even when considering all hives together, the coverage of the period from March to May 2019 is low. Latest data until September 2020 show an increase in participation, nonetheless the problem of gaps in the data persisted, as can be seen in figure 3.5: while as of the second year of the project data availability is clearly trending upwards, the daily fluctuation in the number of sensor kits sending data suggests interruptions in transmission. Gaps can arise when a sensor itself or the Wi-Fi antenna fails, as the data are not stored in the sensor kit for a later attempt of retransmission. Even the maximum number of sensor kits sending data on a given day with around 50 is clearly below the total number of distinct sensor kits in the database of 129.
Figure 3.5: Data availability over time
The next indicator of data quality in sensor networks introduced by Cheng et al. (2018) is the data completeness indicator. This indicator is defined as the ratio of complete observations to the number of expected observations given the total sampling period and number of nodes in the network, in this case the sensor kits. I define a complete observation as one with non-missing values in the ten variables of interest. Figure 3.6 shows that at a sampling rate of 5 seconds the data set is around 40% complete, which can be increased to close to around 45% with a sampling rate of one observation per minute or lower. This low degree of completeness is due to a high share of beehives that do not have all sensors installed: out of 60 sensors transmitting data, only 36 send data on all variables of interest. Even at a low sampling rate such as daily, which is already not useful for a lot of real-time applications in beekeeping, less than half of observations are complete.
Figure 3.6: Data completeness at various sampling rates
The third data quality indicator by Cheng et al. (2018) that is relevant here relates to the correctness. The correctness indicator is defined as the ratio of observations for which the actual values deviate from the true value only by a small margin to all observations. As I do not have a way to know the true values of the physical phenomena measured in the beehives, I proxy the data correctness using the share of observations with values within the physical ranges as defined in the product specifications. Figure 3.7 shows that data correctness has a local peak at a sampling rate of 30 seconds at around 55% and goes down with lower sampling rates, again pointing at the issues of larger gaps in the data: as I aggregate to lower frequency intervals the share of correct values declines faster than overall observations. Even at daily frequency the ratio is not substantially higher at 57%.
Figure 3.7: Data correctness (proxied)
The low level of correctness is driven by the low completeness of the dataset: in order for an observation to be correct, all variables need to have non-missing values. Calculating the correctness indicator for the individual variables points at much higher rates (see figure A.2 in the appendix): even the variable with the lowest correctness (weight) has a share of valid values above 90%. The proxied correctness indicator has to be seen as an upper bound to actual data correctness, as the cheap sensors sometimes transmit data that is within the valid sensor ranges, but nonetheless not plausible. In particular, values are often persistent over longer periods of time. Given the high precision of the sensors and the continuous biological processes within the hive, changes of exactly zero are highly unlikely and probably represent sensor malfunctions. Within the beehives, the sensors can be exposed to extreme conditions for which they are not necessarily built: in case the beehive is not well-protected from direct sun, the sensors on the outside or at the top of the hive could easily overheat. Bees may build honeycombs around sensors with wax, which may block the functioning or also cause them to fail. Finally, exposure to organic acids during a treatment against Varroa mite may damage the sensors.
3.1.1 Single column analysis
3.1.1.1 Weight
The total weight of the beehive is by far the main indicator of success or failure for the beekeeper: during spring the beekeeper should observe an increase in weight when the bees are foraging pollen and nectar. With knowledge about the weight of the empty hive and the weight fluctuations during a day the beekeeper can also estimate the population of the colony or the current pollen inflow.
In the raw dataset the value distribution for the weight variable ranges from below negative 4 million on the bottom to more than 3 million. Given that there can be no negative weight, all negative values should be removed. Likewise, according to the product specifications, the measurement unit is kg and the weight sensor can only weigh up 300kg so values above 300 should also be removed. At the set-up, the beekeepers can calibrate the scale unit. In most cases, zero is set to the empty scale, but possibly some beekeepers may also set the zero value to the scale with the empty beehive on top7. Regarding upper limits of plausible weight values, one could further combine the data with information on the type of hive (see 3.3) and basic assumptions on the number and weight of bees in the colony.
The initial cleaning of implausible weight levels reduces the number of observations by more than 10%. Now the distribution shows 99% of the technically feasible values lie in a range between 0kg and around 70kg, with a longer tail reaching until (exactly) 300 kg.
As described earlier, there are considerable issues with sensor inaccuracy in the raw data, where sensors record extreme weight fluctuations by more than 10kg or even 20kg from one observation to the next, as seen in the thin grey lines of figure 3.8. From a logical point of view, in particular the temporary increases in weight appear questionable: the most likely possibility would be some wild animal climbing on the hive for some time, but this is unlikely to happen as often as indicated in the figure, thus pointing at erroneous measurements. To correct for possible mismeasurements, but also to create regular time series we can retrieve from the influxdb directly the median values for specified time-blocks, in the example shown we decided for five minutes. The solid red line in the same figure no longer shows that many extreme weight fluctuations. The remaining abrupt changes could all be explained by interactions of the beekeeper: temporary drops in weight would indicate a case when the beekeeper removes a number of frames from the hive to inspect the health of the colony, but otherwise does not interfere. A permanent abrupt increase in weight (typically by a few kg) would indicate an inspection with a feeding, while a permanent drop in weight would indicate the harvest of surplus honey.
Figure 3.8: Time series of weight for selected beehive at different sampling rates
Such a simple down-sampling to a lower frequency does, unfortunately, not always solve the problem: there remain implausible observations for other beehives, in particular abnormally high values. Looking closer at some of those cases, however, do not allow for a simple explanation: in cases when the scale jumps up, the observations following often indicate some fluctuation, often stronger than previously, see figure 3.9. Perhaps these are cases when an animal climbs onto the hive, but it could also indicate a temporary loss of calibration.
Figure 3.9: Anomalous weight observations
Also, the rate of change bringing the values to these new levels should be checked against the laws of physics: even during rather quick beekeeper inspections which should be the main cause of larger weight deviations, it will take the beekeeper some minutes to remove the frames from the hive and put them back in after inspection, as can be seen in figure A.3 in the appendix. Figure 3.10 illustrates that for most sensors, the weight measured changes from one observation to the next in a range between -10kg and +10kg per minute with the bulk of changes close to zero, while for a few sensors the range is much wider (from -10 tons to +10 tons per minute), indicating a general problem with the sensor.
Figure 3.10: Distribution of weight changes
Upon closer observation, two beehives appear to have their scales not correctly calibrated as they show massive daily fluctuations of up to 50kg which is clearly not possible (see figure A.4 in the appendix). Besides the impact of beekeeper inspections, the cleaned data indicate a reoccurring daily pattern during the foraging season: from sunset to sunrise the hive loses weight (~250 g) as the bees remain inside, but their bodies burn the consumed nutrients and foraged nectar and produced honey dries. Then at sunrise the weight drops to a daily minimum as the worker bees leave the hive to forage nectar and pollen and reaches a higher level again around sunset when all workers have returned. Depending on environmental conditions there may be a potential intermediate peak around noon, as can be seen in figure 3.11 for June 18th and 19th, 2019.
Figure 3.11: Daily seasonality in weight
This daily seasonal pattern is fairly strong: for most sensor kits with enough data the correlation between current weight and the weight one day before is strongly positive and - for most of those with at least 70 days of complete data - very close to 1. This is also true when considering shorter rolling windows, where the regularity is however interrupted whenever a beekeeper inspection is captured in the rolling window.
With the start of the winter the bees stop foraging and the weight fluctuation ends and becomes a continuous slow decline in weight until the temperatures rise again and bees can start their next cycle.
3.1.1.2 Temperature
Temperature is another important indicator for the well-being of a bee colony: for good breeding conditions, the temperature inside the hive close to the brood needs to be maintained around 34 °C. A consistently lower temperature may indicate that the colony is weakened and unable to maintain the microclimate necessary for breeding. A significantly higher temperature may indicate problems ventilating the hive, which may also lead to a colony collapse. Similar to the weight data, also the raw observations for the various temperature variables have wide distributions going far beyond the product specifications of the sensors (for the thermometer unit from -55°C to +125°C and for the humidity unit from -40°C to +85°C), in particular for those from the thermometer unit. After removing those implausible values, one can observe that while for all sensors there are values towards the limits of the technical sensor range, but that the bulk of observations is concentrated in a rather narrow range from around 0°C to +50°C inside and -10°C to +40°C outside, indicating that the values beyond these ranges are also more likely to be erroneous measurements. These, however, appear to occur quite often and over longer time periods, so that they may also be present when considering median values for five-minute blocks, see figure 3.12: over a course of four days the temperature readings of various thermometer units drop to levels close to 0°C and stay there for longer periods of time before returning back to normal. At a data precision of 0.01 °C, within a small space with thousands of living bees (or outside, subject to the elements), longer periods of exactly zero change is very unlikely and suggest an issue with the sensors. This phenomenon of values “frozen” for long appears to be linked to the five sensors of the temperature unit inside (t_i_1 – t_i_5). For a number of sensor kits a high share of observations show changes of zero, even at aggregations for a lower sampling rate, although this is not always at necessarily problematic levels. The temperature measurements from the humidity unit at the top of the hive as well as those from the outside sensor suffer less from this phenomenon, but nonetheless contain outliers. The temperature outliers for all sensors are often, but not always, located before or after a period without transmission.
Figure 3.12: Temperature time series for selected beehive
To monitor the health of the colony, in particular the health of the brood, it would be useful to obtain temperature measurements from close to the brood. The additional placement of cables in a hive, however, makes beekeeping more difficult. To interfere with beekeeping as little as possible, the designers of the system suggested to install the sensors in between the frames so that they can be removed without any issue (Hiverize (5/16/2020)). With this design based on the box rather than the bees, it is not possible to ensure to have a specific proximity to the brood. One would assume that the sensor in the middle, t_i_3, would be closest to the brood as one would expect the colony to maintain the brood at a maximum distance to the outside, to keep temperature at a sufficient level. This is, however, not the case for all hives and not for the whole time period as the distribution of brood cells within the hive may change over time, see figure 3.138.
Figure 3.13: Location of highest temperature for selected beehive
During the summer period, a stability in temperature around the optimum for brood development, as described in the literature (Zacepins et al. (2016)), can be observed for a lot of hives in this dataset, but this is not maintained over the winter. For the wider range of hives, all temperature data underlies considerable day-night fluctuations and a general seasonal pattern over the year.
3.1.1.3 Humidity
Humidity is another important parameter for the health of a bee colony, in particular for the development of the brood: Doull (1976) showed that there is an ideal range of relative humidity in the brood nest that allows larvae to develop well, while under too dry conditions the eggs may shrivel or if the bees do hatch, they may not be fully developed. More recent works using sensors (Human, Nicolson, and Dietemann (2006)) revealed distinct day and night patterns and somewhat different humidity levels at different locations inside the beehive. Researchers are still unclear as to whether humidity is actively regulated by the bees or passively as a side effect of thermoregulation: for example. when the nest temperature becomes too warm bees spread droplets of water on the comb and fan their wings to make the water evaporate and cool the temperature, this will at the same time raise humidity.
According to the product specifications, the sensor measures relative humidity, that is the saturation of air with water vapor relative to its maximum capacity at a given temperature, measured in percent. By definition, the values have to be within a range from 0% to 100%. The raw dataset does, however, contain both negative values as well as very large positive values, which need to be cleaned.
Humidity is also underlying a strong daily seasonality, during the foraging season humidity drops from sunrise onwards, becoming relatively dry as workers leave the hive, and increases again when they return: overnight the bees evaporate body heat and the foraged nectar, which to a large proportion is water, dries. In terms of data quality, long gaps in the data when no data (or at least no data within the sensor range) are transmitted are frequent across time and beehives, whereas the problem of frozen sensors, as illustrated earlier with temperature, does not occur so much. By contrast, besides the daily patterns, the relative humidity within the hive is very volatile, see figure 3.14, and much more so than for weight and temperature.
Figure 3.14: Daily seasonality and general volatility of relative humidity
With the start of the winter the daily fluctuation becomes less and the general level of relative humidity is higher, see figure 3.15. The positive correlation with the humidity level of the previous day is more stable than for weight, but somewhat lower.
Figure 3.15: Humidity fluctuation for a selected beehive with long history
3.1.1.4 Air pressure
So far there was no mentioning of the air pressure in previous work on precision beekeeping, but the humidity sensor unit does record this information, so discarding it may be premature: Air pressure is an environmental factor and could correlate with weather conditions, which ultimately would also affect bee behavior. According to the product specifications the sensor can measure air pressure in a range from 300 to 1100 hPa. As most beehives in the dataset are located in Germany, one could also generally exclude values that would imply the beehive is located higher than the Zugspitze, i.e. values below around 650 hPa. The remaining observations then stay in a quite narrow range. Over time there is cyclical variation in air pressure, which is more weekly rather than daily and in general not really predictable. Pressure values are very persistent, given the low precision of the sensor at 1 hPa, leading to step-like time series as shown in figure 3.16.
Figure 3.16: Air pressure over time for a selected bee hive
It appears unlikely that bee behavior is reflected in changes in air pressure as measured by the sensor given the difference in seasonality with the other variables, but the data on air pressure may still be useful as a more precise indicator for weather conditions than meteorological data that needs to be first retrieved from other sources and which will likely have a lower frequency.
3.1.2 Initial cleaning
In order to have good results in any analysis, the sensor data need to be cleaned from values that do not represent actual developments within the beehive, but rather sensor failures. At the same time, the cleaning should not be too computationally expensive so that the cleaning could also run online. As a first step we should remove observations clearly outside the sensor range and at the same time reduce volatility and improve completeness of the dataset by filtering and down-sampling to lower time intervals. This can already be implemented at the level of the influxdb database using continuous queries as shown in the code chunk below for the chosen interval of one minute using medians. The sampling rate of one minute is chosen to capture volatile developments such as swarms, which occur within only few minutes, as shown later.
CREATE CONTINUOUS QUERY "enforce_range_and_downsample_weight" ON "bee_data"
RESAMPLE EVERY 5m FOR 10m
BEGIN
SELECT median("weight_kg") AS "weight_kg" INTO "bee_data"."autogen"."downsampled_sensors"
FROM "sensors"
WHERE "weight_kg" >= 0 AND "weight_kg" <= 300
GROUP BY "key", time(1m)
ENDBased on the analysis in the previous sub-section, it appears to be a good idea to remove observations which show a faster rate of change than could be explained by natural changes in the bee hive, the environment or due to beekeeper interventions and thus indicate sensor failure. Further, observations representing zero change should be removed. While they occur quite often, and the observation levels of most of them are within plausible ranges, some form of interpolation method to more gradual changes may improve the predictive properties of models. The next code chunk shows an example of a simple R implementation on how to remove these types of observations using Tidyverse packages (Wickham et al. (2019)), which runs with a satisfactory performance on a local machine on a table of around 6 million observations with 10 columns at a 1-minute sampling rate: it is a simple loop that for each sensor-kit and variable computes the rate of change between two subsequent observations, filters out zero changes and extreme changes and repeats until there are no problematic changes left.
thresholds <- c(h = 10, weight_kg = 16, p = 2, t_o = 0.75, t = 6,
t_i_1 = 6, t_i_2 = 6, t_i_3 = 6, t_i_4 = 6, t_i_5 = 6)
clean_zero_and_extreme_change <- data_within_sensor_range %>%
group_by(key) %>%
group_modify(~ {
# FOR EACH VARIABLE FOR EACH SENSOR KIT
individual_dfs <- map(vars, function(variable) {
temp <- .x[, c("time", variable)] %>% rename(v = variable) %>%
# REMOVE MISSING VALUES AND COMPUTE GROWTH PER MINUTE RELATIVE TO PREVIOUS OBSERVATION
drop_na() %>%
mutate(derivative = (v - lag(v))/as.numeric(time - lag(time), units = "mins"))
# FILTER OUT ZERO CHANGES AND CHANGES BEYOND THE DEFINED THRESHOLD, RECOMPUTE CHANGES AND REPEAT UNTIL THERE ARE NO MORE EXTREME CHANGES
while(max(abs(temp$derivative), na.rm = T) > thresholds[variable]) {
temp <- temp %>% filter((abs(derivative) <= thresholds[variable] & derivative != 0) | is.na(derivative)) %>%
mutate(derivative = (v - lag(v))/as.numeric(time - lag(time), units = "mins"))
}
temp <- temp %>%
select(-derivative)
names(temp) <- c("time", variable)
return(temp)
})
# COMBINE VARIABLES TO ONE DATAFRAME
reduce(individual_dfs, full_join, by = c("time"))
})The thresholds selected for declaring changes as implausible is different across variables and are described in table 3.2. Given the extreme movements in weight - but partially also temperature - during beekeeper inspections, the thresholds for these variables need to be somewhat higher. The cleaning is thus only able to remove the most extreme implausible observations, as shown in the red lines in figure 3.17.
| variable.names | description | threshold.for.changes |
|---|---|---|
| weight_kg | total weight | 16 kg / minute |
| h | humidity at the top of the beehive | 10 % / minute |
| p | air pressure at the top of the beehive | 2 hPa / minute |
| t | temperature at the top of the beehive | 6°C / minute |
| t_i_1 … t_i_5 | temperature inside: sensors 1 and 5 on the outside, 3 in the center and 2 and 4 in between | 6°C / minute |
| t_o | temperature outside | 0.75°C / minute |
Figure 3.17: Effect of simple cleaning algorithm
While removing or correcting values may improve data quality, ideally sensor failures should not occur in the first place. To quickly react to wrong calibration or emerging defects of some sensors, monitoring tools for beekeepers as well as for the project team may help remedy these issues. A project team colleague has implemented an R script to identify longer sequences of missing values by sensor kit and variable which was already implemented in a dashboard solution for the project team, see figure 3.18. Simpler summaries on time elapsed between subsequent observations, or the number of observations outside the technical sensor range within a given time interval could also be implemented already at the level of the database using continuous queries and be visualized in near real-time.
Figure 3.18: Interactive visualization of missing values
By removing more observations, correctness may improve, but possibly at the cost of data volume and completeness. For certain lengths of data gaps, it may thus be useful to interpolate missing values based on available data for other variables. As a basis of understanding the relationships between the variables, the next section analyses the correlations between them.
3.1.3 Multi-column analysis
To analyze the relationship among the ten variables of interest, we restrict ourselves to a smaller subset of 34 bee hives which report observations on all variables of interest at multiple points in time, resulting in about 7.1 million observations since February 2019. After removing values outside the technically feasible ranges as well as steep changes and zero changes, we end up with slightly below 7 million observations containing information on at least one variable. As this step removed a lot of zero change values in between valid observations, it is useful to refill shorter gaps using simple interpolation techniques9. I do this with the using the imputeTS package (Moritz and Bartz-Beielstein (2017)). This brings the sample again closer to the original number of observations.
The data quality analysis at the beginning of this chapter already indicated that the data are very incomplete overall, but this is not just the case for bee hives with missing sensors and never report complete observations, but also for those that do have complete observations. Following the methodology of Kuhn and Johnson (2019), the so-called “upset plot” in figure 3.19 shows that after the interpolation of shorter gaps around one sixth of the observations are missing data from the temperature unit, whereas this is somewhat less of an issue for the scale and the humidity unit (bar chart panel on the left-hand side). Missingness tends to be clustered at the technical unit: in more than 600,000 observations all three variables from the humidity unit are missing and in around 300,000 cases the six sensors of the temperature unit did not report valid observations (tallest two bars on the top panel bar chart). In around 250,000 observations data from the scale are missing. Besides observations with no data at all (excluded from the chart), other combinations of missing variables or instances of only one variable missing are less frequent.
Figure 3.19: Upset plot of missingness after initial cleaning
Given the large issue of missingness from the temperature unit it would be useful to analyze whether missing values for temperature occur at specific values for the non-missing variables. Looking at the distribution of values for relative humidity and outside temperature between observations with the value for the central temperature sensor missing and those with data, there is a tendency for missingness to occur at lower outside temperatures and higher humidity (see figure A.6 and figure A.5 in the appendix). Looking at the last valid observations before a data gap compared with normal valid observations confirms this picture, see figure A.7 in the appendix. Thus, beekeepers as well as the project team should probably pay more attention on sensor maintenance during spring and autumn, when temperatures are lower, but inspections are still possible without endangering the bees too much.
As a next step we should analyze how the variables are related when not missing, as strong correlations may be useful for the imputation of missing values over longer periods. Given the higher volatility of the humidity data, we transform it to centered 5-minute moving averages. While the relationships differ somewhat between sensor kits, the general pattern seen everywhere is a positive correlation between the temperature sensors inside the hive, in particular of those next to each other. The temperature at the top of the hive is somewhat less positively correlated with the temperatures at the center, but more strongly with the outside temperature, see figure 3.20. Looking at all observations together, there is a clear negative correlation between humidity and temperature (in particular at the same sensor at the top of the hive), but this does not hold across all sensor kits, perhaps due to differences in the seasons covered.
Figure 3.20: Correlations among temperature variables
3.2 Inspections data
Further to installing the sensor kits, beekeepers participating in Bee Observer can log their inspections in a web application suitable to work on smartphones. Screenshots of all app menus can be found in the appendix (figure A.10). The information logged enters a MySQL database that is organized in rows per aspect of the inspection, instead of one row per inspection. This results in a somewhat odd mixed structure in which different data types are combined in one numeric column “value,” which, depending on the category ID, may represent either a Boolean value, a number, a qualitative value on an ordered Likert scale or the option selected from a dropdown list menu. The only mandatory variables that need to be provided is the date and time of the inspection, whether or not the colony was fed, a score on how gentle the bees react to the inspection, how much flight activity they show and how the hive was inspected (fully, i.e. by opening the box and removing frames, just by looking through the flight hole or something in between). All other fields are optional to not discourage beekeepers from participating in the project. For an overview of the schema see table 3.3.
| variable.name | description | type |
|---|---|---|
| inspection_id | unique identifier of the inspection | integer |
| created_at | date of submission | POSIX date-time |
| deleted_at | time of deletion, NULL otherwise | POSIX date-time |
| impression | overall impression (from the inspection in general) – three smileys | integer |
| attention | does the hive require attention? | Boolean |
| notes | textual notes on the inspection | string |
| reminder | textual notes to be sent along with the calendar reminder for the next inspection | text |
| category_id | identifier for the input field/variable | integer |
| value | value | numeric |
| category_input_id | identifier for the input type | integer |
| name | textual description of the category input ID | string |
| translation | textual description of the category ID – not unique! | string |
| hive_id | unique key of the hive – one hive can contain multiple sensor kits | integer |
| key | unique key of the sensor kit (as in sensor dataset) | string |
For the time period since February 2019 the database contains 18495 rows, but since some were test entries which were later deleted, this can be reduced to only 16239 data entries coming from 1099 inspections. However, a large number of records were prepared by beekeepers who do not have sensors installed in their hives or have not yet entered this information in the app. Excluding also those observations without a reference to a sensor key, the sample is further reduced to 6927 observations from 417 inspections.
Given that most fields are optional, there is considerable difference in the number of observations, see figure A.12 in the appendix. In around half of the inspections the beekeepers indicate whether the bees are foraging pollen, and whether frames have been added or removed. Data availability is also acceptable regarding the stocks of honey and pollen, the status of the brood and whether the colony is infested with Varroa mite. The most available data type is logical.
For the considered time period, the number of inspections per hive also varies considerably. More than half of all inspections were recorded for ten hives. For the hives with more than one logged inspection the interval between inspections is typically less than weekly, but for sometimes up to a month can pass until the next inspection.
Given the design of the mobile app, there is a logical functional dependence between related fields in most cases: for example, the beekeeper can only enter the number of frames that were added or removed during an inspection if he/she checked “Yes” in the parent box “Inserted/Removed Frames.” However, there are number of cases were the app allows for internally inconsistent responses, which should be corrected in a future version: for example, it is not physically possible to add or remove frames if the type of inspection was by only observing the flight entrance or just tilting the cover. Yet, two inspections can be found in the dataset where supposedly the cover was only tilted, but it was recorded that frames were added or removed.
The categories blocks “Swarming” and “Swarm prevention” are handled separately, which can lead to records where the destruction of queen cells as a swarm prevention method was recorded, but at the same time there was either no status reported on the building of queen cells or it was recorded as not occurring. In the current dataset this inconsistency can be observed in 30 cases.
Further, some fields are perhaps not clear to the beekeepers. The counters for adding or removing frames allow for negative numbers, thus the designers expected the users to record negative numbers for removed frames and positive numbers for added frames but this may not be how beekeepers have understood this. Currently the value distribution for the seven types of frames is rather balanced with values both on the positive and negative side, so from that point of view this appears fine. When combining sensor data from the scale with inspection data, however, there are cases of inspections with a reported net addition of frames in which the overall weight has dropped (see figure 44), which could indicate a wrong reporting10. In any case, the menu should be designed somewhat clearer, perhaps with an immediate response that a positive number is interpreted as an addition while a negative is a removal.
When using information from the inspection database as labels for classification models, one has to consider that there is some uncertainty surrounding the timestamp of the inspections. By default, the time recorded is the time when the inspection menu was opened, which should typically be after the inspection was completed. If the beekeeper choses to manipulate the date this may result in a timing closer to the change in weight, but in case the time is not remembered correctly, it may as well be recorded earlier than the change in weight. A mis-recording could potentially explain the position of the fourth inspection in figure 3.21. As most states of or events within the colony, however, likely take longer than just a few minutes, the information about the colony entered in the inspection log is probably valid for a longer time before (or around) the time of the inspection.
Figure 3.21: Time series of weight with inspections
For the available inconsistent records, the data can be corrected directly if applicable, or the beekeepers could be contacted by the Bee Observer project team to ask about the inspection.
As regards the time stamp, a method of anomaly detection might be well-placed to detect at least the strong movements in weight which are unlikely to be caused by the bees themselves.
3.3 Apiary and hive metadata as a means to integrate data from external sources
In order to record an inspection, beekeepers first need to create their apiary and its individual hives in the database. Only two variables are mandatory: the chosen name of the apiary and the type of hive. The optional variables at the apiary level relate to the geolocation, while at the hive level the beekeepers can specify the number of layers used in the hive for brood and honey and the number of frames per layer. Finally, specifics about the queen of the hive can be specified, such as the race, the birthdate and whether her wings have been clipped. The menus of the app are shown in figure A.9 in the appendix.
This metadata can provide useful information for the analysis of the sensor data. First of all, the mandatory information on the hive type can help in cleaning erroneous sensor data for weight more precisely. As the various hives are made from different materials are differently sized and may have their capacity used to different degrees, the lower threshold for the valid weight observations can vary significantly.
Second, with available geolocation data, one is able to calculate the position of the sun at a given time, and retrieve other external data that may be useful in explaining developments in a bee colony. As there have been increasing cases of colony theft across Germany (Meidel (9/4/2020)) the general terms of service of the Bee Observer project included a data protection clause limiting the use of geolocation data only at a lower precision. Specifically, we have coordinates rounded at one decimal, which amounts to an uncertainty of up to 11km. Within the inspections dataset there are currently 66 sensor kits at various locations in Germany (mostly the western Länder and Berlin) and the Netherlands, as shown in figure 3.22, and two in the USA.
Figure 3.22: Location of hives
3.3.1 Determining the sun level
The European Honey Bee has a diurnal cycle. Foraging worker bees cannot see well in the dark and research has also shown that they require a certain amount of rest (i.e. sleep) to function well during the day (Kaiser and Steiner-Kaiser (1983)). As a consequence, the activity within a hive will look different during day and night. Given the astrological cycle of the Earth around the sun, these daily cycles will change over the year, with days being longest and the sun’s position highest at the end of June at summer solstice. Afterwards the days become shorter and the sun’s position lower, reaching their trough at the end of December at winter solstice and so on. To get cleaner signals over the general trend of a colony it would be useful remove the changing daily seasonality from the trend. Time-series methods such as Seasonal and Trend decomposition using Loess (STL) (Cleveland et al. (1990)) are able to deal with slowly changing seasonal patterns, but require complete sequences of data, which is not always given in this case with sometimes long periods of sensor outages. Thus, it may be preferable to directly determine the cycles based on the position of the sun. The position of the sun can be calculated with a mathematical formula using the coordinates and the date-time information. The small uncertainty surrounding the exact location in this case should be negligible. The package suncalc (Thieurmel and Elmarhraoui (2019)) provides a simple R implementation for these computations. Figure 3.23 for a selected hive during June 2020 illustrates this daily cycle well: around sunrise, the worker bees leave the hive (which may result in further decrease in weight), but throughout the day bring nectar and pollen to the hive, leading to a peak in weight around sunset. Overnight the hive loses weight at a stable rate, as the stored honey dries and the bees’ bodies burn energy and evaporate humidity.
Figure 3.23: Sun position and weight for a selected hive during the foraging period
3.3.2 Meteorological data
Not only the day-night cycle can affect bee behavior, also meteorological phenomena can have an impact. While bees can still fly when it rains, flying during rain or even just mist is more difficult: water can accumulate on the bee’s body and thus increase its weight. Heavy raindrops can push a bee down and throw it off its course. Thus, during longer periods of rainfall bees typically do not go foraging and stay in the hive, as shown in figure 3.24, where a rainy week is interrupting a period of weight increase in the foraging season. The figure also shows one more potential issue of sensor quality: the sudden drop in weight around 1 May during the rainiest time could be a sign of a sensor malfunction due to the scale becoming wet or at least too damp. The only beekeeper inspection during the period shown was recorded at this beehive on 18 April, with a much lower weight fluctuation. The German Weather Service (DWD) provides regularly updated data on precipitation at various intervals from multiple weather stations throughout Germany, with the frequency going as high as per minute, reported from almost a thousand stations. Data on air temperature and the dew point are available at hourly frequency from around 500 stations. The datasets can be conveniently accessed from R using the rdwd package (Boessenkool (2020)). Due to the uncertainty surrounding the exact location of the hive, it may be useful to obtain data from multiple stations in the vicinity and combine them. Even in case the exact location was known, heavy rainfall at the nearest weather station may still be a very localized event that potentially would not affect the monitored colony at all.
Figure 3.24: Foraging behavior and precipitation
Joining the obscured hive locations with the location of the weather stations, one can see that within a radius of 20km around the hive there is at least one weather station for all hives in Germany. In case of precipitation data at one-minute frequency the majority of hives have two and more weather stations nearby (see figure A.13 in the appendix). Air pressure recorded by the sensor in the hive is typically lower during stronger rainfalls at a nearby station (see figure 3.25) and thus could be an indicator of rain, but a passing low-pressure area does not necessarily mean it indeed rained and if yes, at the same time. For the majority of hives with available location and pressure data, the correlation coefficient between pressure and cumulative daily rainfall ranges between -0.2 and -0.4 Thus, to control for the effect of rainfall on bee behavior in a model, using actual meteorological data should be preferable over just the pressure data from the sensor kits themselves.
Figure 3.25: Cumulative daily precipitation amounts and air pressure in the hive
Temperature data from an official source can also serve as a cross-check of the data quality for the outside temperature sensor. In figure 3.26, for example, one can observe a close co-movement between the sensor data and the measurements from surrounding weather stations until April 2020, when the sensor data significantly deviate upwards, likely due to sensor failure.
Figure 3.26: Outside temperature measured from sensor vs. official source
While at present, the DWD does not offer weather forecasts in an easily accessible format, this may be added in the future, allowing for potential use cases like suggestions for the ideal timing of inspections (before it rains).
3.3.3 Phenological data
Around 400 DWD weather stations also report on the stage of the lifecycle of various plants in the vicinity on a daily basis. Among these plants there are also eight11 which have been identified as useful for pollinators (“Pflanzen für Bestäuber” (n.d.)), as a source for pollen, nectar or both. Only for few plants the observers report both the beginning and end of the blossoming, while for most of the plants, only the start is recorded. Exploratory data analysis shows that one can indeed map the most productive time of the bee colony to the status of the environment. Assuming a consistent duration of the blossoming period of six weeks, figure 3.27 shows higher weight gains in periods when multiple plants are blossoming. Relevant seem to be in particular dandelion, sweet cherry, rapeseed and apple (starting to blossom around April to May).
Figure 3.27: Joining weight and phenological data
Knowledge about the state of the surrounding flora could be useful in focusing the models and detection algorithms to this crucial period and notify the beekeepers if there is no significant weight gain.
Influxdb is under continuous development: in the current beta branch, the system offers an alternative query language (flux) which already implements some of the described missing features, which would allow for a more streamlined data analysis pipeline going forward. However, some simple preprocessing such as filtering and down-sampling to a lower frequency can already be implemented using so-called “continuous queries” in the version currently available to the project.↩︎
At the time of writing the purchase price of all components together was just above 100 Euro.↩︎
The other variables include the calibration weight of the scale, however only with few observations, and the strength of the Wi-Fi signal.↩︎
This is a proxy, as influxQL does not allow for comparisons of numerical time series with NULL: in this column-oriented database system, if there is no value, there is no entry at all. The ratio is computed as the number of observations where the values of all our variables of interest are not equal to a specific value, divided by the number of observations for weight, the variable with the most observations.↩︎
The framework also contains indicators on the volatility and timeliness of the data However, as I have no physical access to any sensor kit, I cannot evaluate the timeliness of the data and thus focus in this section only on the first three indicators.↩︎
The month of July 2020 is chosen, as only six new sensor kits are added throughout the month, compared to more than a hundred existing ones.↩︎
This information is unfortunately not stored and is thus not available for a further cleaning to reduce the variable to pure developments in the weight of the bees and foraged food.↩︎
The temperature measured at the humidity sensor unit t, is excluded from this analysis: due to its position at the top of the hive it is more strongly correlated with the outside temperature and can thus easily reach high values during the summer, above those required in the brood nest.↩︎
Given the different volatility of the variables we chose different gaps: humidity 1 hour; temperatures 10 minutes; weight 5 minutes; pressure 4 hours. For this thesis a linear interpolation was chosen. The linear interpolation has the advantage that it can be implanted at the level influx of the influxdb and would not be able to create values outside the plausible sensor ranges again.↩︎
This is of course based on the simplified assumption that frames have the same weight when they are added to the hive as when they are removed and have the same weight across types of frames. Also, the changing of frames needs to be seen together with other beekeeping actions that influence weight, such as feeding and honey harvest.↩︎
Apple, sweet cherry, forsythia, dandelion, horse-chestnut, goat willow, corn and rapeseed.↩︎