A curated list of open technology projects to sustain a stable climate, energy supply, biodiversity and natural resources.

canwqdata

An R package to download open water quality data from Environment and Climate Change Canada's National Long-term Water Quality Monitoring Data.
https://github.com/bcgov/canwqdata

Category: Natural Resources
Sub Category: Water Supply and Quality

Keywords

data-science env r r-package rlang rstats

Keywords from Contributors

soe citz flnr species-sensitivity-distribution

Last synced: about 24 hours ago
JSON representation

Repository metadata

R 📦 to download 🇨🇦 open water quality data

README.Rmd

          ---
output: github_document
---

```{r, echo = FALSE}
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "tools/readme/", 
  message = FALSE
)
```


[![img](https://img.shields.io/badge/Lifecycle-Experimental-339999)](https://github.com/bcgov/repomountie/blob/master/doc/lifecycle-badges.md)
[![Travis-CI Build Status](https://travis-ci.org/bcgov/canwqdata.svg?branch=master)](https://travis-ci.org/bcgov/canwqdata)[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
[![R build status](https://github.com/bcgov/canwqdata/workflows/R-CMD-check/badge.svg)](https://github.com/bcgov/canwqdata/actions?workflow=R-CMD-check)
[![Codecov test coverage](https://codecov.io/gh/bcgov/canwqdata/branch/master/graph/badge.svg)](https://codecov.io/gh/bcgov/canwqdata?branch=master)



# canwqdata

An R `r emo::ji("package")`  to download open water quality data from Environment and Climate Change Canada's [National Long-term Water Quality Monitoring Data](http://donnees.ec.gc.ca/data/substances/monitor/national-long-term-water-quality-monitoring-data/).

### Features

This package is designed to get Canadian Water Quality Monitoring data into R quickly and easily. You can get data from a single monitoring station, multiple stations, or from an entire basin. Note that current version of this package can only retrieve data from BC, not from other provinces.

### Installation

```r
remotes::install_github("bcgov/canwqdata")
```

### Usage

First load the package:

```{r}
library(canwqdata)
library(tidyverse)
```


The first thing you will probably want to do is get a list of the available BC sites and associated metadata:

```{r}
sites <- wq_sites()

sites
```

Then get some data from a particular station:

`BC08EF0001` is a site in BC called *`r tools::toTitleCase(tolower(sites$SITE_NAME[sites$SITE_NO == "BC08EF0001"]))`*

```{r}
skeena_river <- wq_site_data("BC08EF0001")

skeena_river
```

We can also get data from more than one station:

```{r}
wq_site_data(c("BC08NF0001", "BC08NM0160"))
```

Or an entire basin:

The basins are in the `PEARSEDA` column of the data.frame returned by `wq_sites()`:

```{r}
basins <- sort(unique(sites$PEARSEDA))
basins

fraser <- wq_basin_data("FRASER-LOWER MAINLAND")
```

Do some quick summary stats of the fraser dataset:

```{r}
library(dplyr)

fraser %>% 
  group_by(SITE_NO) %>% 
  summarise(first_date = min(DATE_TIME_HEURE), 
            latest_date = max(DATE_TIME_HEURE), 
            n_params = length(unique(VARIABLE)), 
            total_samples = n())
```


We can also look at metadata that helps us understand what is in the different columns.

`wq_params()` returns a list of water quality parameters (variables), and related data - units, methods, codes, etc:

```{r}
params <- wq_params()
glimpse(params)

# wq_param_desc shows the column headings (in all other tables) and what they mean
wq_data_desc() %>% 
  glimpse()
```

Let's look at Total Nitrogen in the Fraser basin:

```{r}
fraser_n_total <- fraser %>% filter(VARIABLE == "NITROGEN TOTAL")
```

Now lets do some plotting - plot Total Nitrogen over time at all the sites, 
(plot it on a log scale so that they all fit)

```{r}
library(ggplot2)

ggplot(fraser_n_total, aes(x = DATE_TIME_HEURE, y = VALUE_VALEUR)) + 
  geom_point(size = 0.4, alpha = 0.4, colour = "purple") + 
  facet_wrap(~ SITE_NO) + 
  scale_y_log10()
```


It's also possible to download data from an entire BC:

```{r}
bc_sites <- sites %>% 
  pull(SITE_NO)

all_bc_data <- wq_site_data(bc_sites)

glimpse(all_bc_data)
```

### Project Status

Under development, but ready for use and testing.

### Getting Help or Reporting an Issue

To report bugs/issues/feature requests, please file an [issue](https://github.com/bcgov/canwqdata/issues/).

### How to Contribute

If you would like to contribute to the package, please see our 
[CONTRIBUTING](CONTRIBUTING.md) guidelines.

Please note that this project is released with a [Contributor Code of Conduct](CODE_OF_CONDUCT.md). By participating in this project you agree to abide by its terms.

### License

    Copyright 2025 Province of British Columbia

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at 

       http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.


This repository is maintained by [Environmental Reporting BC](http://www2.gov.bc.ca/gov/content?id=FF80E0B985F245CEA62808414D78C41B). Click [here](https://github.com/bcgov/EnvReportBC-RepoList) for a complete list of our repositories on GitHub.

        

Owner metadata


GitHub Events

Total
Last Year

Committers metadata

Last synced: 5 days ago

Total Commits: 107
Total Committers: 5
Avg Commits per committer: 21.4
Development Distribution Score (DDS): 0.29

Commits in past year: 25
Committers in past year: 1
Avg Commits per committer in past year: 25.0
Development Distribution Score (DDS) in past year: 0.0

Name Email Commits
Andy Teucher a****r@g****a 76
szy-al Z****g@g****a 25
repo-mountie[bot] 4****] 3
stephhazlitt s****t@g****a 2
KarHarker k****r@g****a 1

Committer domains:


Issue and Pull Request metadata

Last synced: 2 days ago

Total issues: 5
Total pull requests: 4
Average time to close issues: about 2 months
Average time to close pull requests: 5 days
Total issue authors: 2
Total pull request authors: 3
Average comments per issue: 0.6
Average comments per pull request: 1.5
Merged pull request: 4
Bot issues: 4
Bot pull requests: 2

Past year issues: 0
Past year pull requests: 1
Past year average time to close issues: N/A
Past year average time to close pull requests: 27 minutes
Past year issue authors: 0
Past year pull request authors: 1
Past year average comments per issue: 0
Past year average comments per pull request: 0.0
Past year merged pull request: 1
Past year bot issues: 0
Past year bot pull requests: 0

More stats: https://issues.ecosyste.ms/repositories/lookup?url=https://github.com/bcgov/canwqdata

Top Issue Authors

  • repo-mountie[bot] (4)
  • KarHarker (1)

Top Pull Request Authors

  • repo-mountie[bot] (2)
  • szy-al (1)
  • ateucher (1)

Top Issue Labels

Top Pull Request Labels


Dependencies

DESCRIPTION cran
  • dplyr >= 0.7 imports
  • httr >= 1.3 imports
  • memoise >= 1.1 imports
  • readr >= 1.1 imports
  • rvest >= 0.3 imports
  • stats * imports
  • xml2 >= 1.1 imports
  • covr * suggests
  • knitr * suggests
  • rmarkdown * suggests
  • testthat * suggests
.github/workflows/R-CMD-check.yaml actions
  • actions/cache v4 composite
  • actions/checkout v4 composite
  • actions/upload-artifact v4 composite
  • r-lib/actions/setup-pandoc v2 composite
  • r-lib/actions/setup-r v2 composite
  • r-lib/actions/setup-tinytex v2 composite

Score: 4.0943445622221