Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/bcgov/canwqdata

R 📦 to download 🇨🇦 open water quality data
https://github.com/bcgov/canwqdata

data-science env r r-package rlang rstats

Last synced: 3 months ago
JSON representation

R 📦 to download 🇨🇦 open water quality data

Awesome Lists containing this project

README

        

---
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-Stable-97ca00)](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.

### Installation

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

### Usage

First load the package:

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

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

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

sites
```

Then get some data from a particular station:

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

```{r}
athabasca_falls <- wq_site_data("AL07AA0015")

athabasca_falls
```

We can also get data from more than one station:

```{r}
wq_site_data(c("YT09FC0002", "SA05JM0014"))
```

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 province:

```{r}
bc_sites <- sites %>%
filter(PROV_TERR == "BC") %>%
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 2018 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.