knitr::opts_chunk$set(fig.width = 6, fig.height = 4)

You can install the 'bcgroundwater' R 📦 package directly from GitHub. To do so, you will need the remotes package:

install.packages("remotes")

Next, install the bcgroundwater package using remotes::install_github():

library("remotes")
install_github("bcgov/bcgroundwater")

Then load the package:

library(bcgroundwater)

Get Your Data

First, decide which groundwater observation well is your well of interest from the British Columbia Provinicial Groundwater Observation Well Monitoring Network interactive map tool. Here we will work with data from Groundwater Observation Well #309.

Download data on the well of interest—this may take a few moments.

If you are interested in daily averages, specify which = "daily":

daily_data <- get_gwl(wells = 309, which = "daily")
head(daily_data)

If you are interested only in recent hourly data—within the last two years— specify which = "recent":

recent_data <- get_gwl(wells = 309, which = "recent")
head(recent_data)

Otherwise, by default which = "all" which downloads all hourly data for that well:

data <- get_gwl(wells = 309)
head(data)

The Provincial Groundwater Observation Well Network - Groundwater Levels Data is programatically sourced from the B.C. Data Catalogue, distributed under the Open Government Licence - British Columbia.

Summarise & Visualise Your Data

Next, you can calculate the median monthly values:

monthly_data <- monthly_values(data)
head(monthly_data)

You can plot the seasonal patterns in the water levels of the well with gwl_monthly_plot(). This displays the mean deviation from the yearly average, as well as the range of variation:

monthlyplot <- gwl_monthly_plot(monthly_data, last12 = TRUE)
plot(monthlyplot)

To perform the trend analysis, you will need to generate a full regular time series with no gaps in the dates. make_well_ts() does this for you, removing consecutive missing values near the beginning or the end of the time series—due to the strong influence of these regions on trend analysis—and interpolating the remaining missing values:

full_monthly_data <- make_well_ts(monthly_data)
head(full_monthly_data)

Ten years is often considered the minimum time series length for meaningful long-term trend analysis, and it is useful to also consider an acceptable allowable "maximum" amount of missing (interpolated) data. You can use the dplyr package to generate some summary information about the well dataset to help you decide if it is approrpiate to conduct a trend analysis:

library(dplyr)

time_series_attr <- full_monthly_data %>%
  group_by(Well_Num) %>%
  summarise(dataStart = as.Date(min(Date)), 
            dataEnd = as.Date(max(Date)), 
            dataYears = as.numeric(dataEnd - dataStart) / 365, 
            nObs = n(), 
            nMissing = length(med_GWL[nReadings == 0]), 
            percent_missing = round(nMissing/nObs*100, 1)) %>% 
  select(Well_Num, dataYears, nMissing, percent_missing) 
time_series_attr

Groundwater Observation Well #309 has over 28 years of consecutive water level data with minimal missing data (2%), ideal for long-term trend analysis.

For trend analysis over a long time series, it is often beneficial to test for trends with yearly averages, otherwise serial autocorrelation can be a problem (even with pre-whitening). These can be calculated using the dplyr package:

library(dplyr)

annual_data <- full_monthly_data %>%
  select(-yearmonth) %>%
  group_by(EMS_ID, Well_Num, Year) %>%
  summarize(nReadings = n(),
            mean_GWL = mean(med_GWL),
            SD = sd(med_GWL),
            med_GWL = median(med_GWL),
            q95_GWL = quantile(med_GWL, 0.95),
            n_months = n()) %>% 
  filter(n_months == 12)
head(annual_data)

Analyse & Visualise Your Data

You can now calculate the long-term trend:

trends <- gwl_zyp_test(annual_data, byID = "Well_Num", col = "mean_GWL")
trends

We we will use the results from the yuepilon method, and categorize the observed long-term trend using the combined statistical & environmental significance criteria developed for the Environmental Reporting BC indicator on trends in groundwater levels: Stable, Increasing, Moderate Rate of Decline or Large Rate of Decline:

result <-  trends %>% 
  filter(test_type == "yuepilon") %>%
  mutate(trend_category = case_when(trend >= 0.1 & sig < 0.05 ~ "Large Rate of Decline",
                           trend >= 0.03 & trend < 0.1 & sig < 0.05 ~ "Moderate Rate of Decline",
                           trend <= -0.03 & sig < 0.05 ~ "Increasing",
                           TRUE ~ "Stable")) 
result

Finally, you can plot the time series and the significant trend lines, optionally showing any interpolated values. Showing the overlaid trend line when the trend category is stable is also optional:

trend_plot <- gwl_area_plot(full_monthly_data, trend = result$trend,
                          intercept = result$intercept, sig = result$sig, 
                          trend_category = result$trend_category,
                          mkperiod = "annual", showInterpolated = TRUE,
                          show_stable_line = TRUE)
plot(trend_plot)

Getting Help

Type ?bcgroundwater in the R console for full documentation on the package functions and arguments.

Details, rationales and references on the trend and other analytical methods used under the hood 🚘 in the 'bcgroundwater' 📦 can be found here: http://www.env.gov.bc.ca/soe/indicators/water/groundwater-levels.html.

r Sys.Date()



bcgov/bcgroundwater documentation built on March 18, 2024, 5:43 a.m.