Skip to content

Commit

Permalink
release tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
boshek committed Oct 4, 2024
1 parent b07d42d commit c2cf1d8
Show file tree
Hide file tree
Showing 16 changed files with 675 additions and 658 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@
Thumbs.db
Rplots.pdf
revdep/

/.quarto/
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: tidyhydat
Title: Extract and Tidy Canadian 'Hydrometric' Data
Version: 0.6.1.9000
Version: 0.7.0
Authors@R: c(person("Sam", "Albers", email = "[email protected]", role = c("aut", "cre"),
comment = c(ORCID = "0000-0002-9270-7884")),
person("David", "Hutchinson", email = "[email protected]", role = "ctb"),
Expand Down
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# tidyhydat 0.6.1.9000
# tidyhydat 0.7.0
- bump minimum R version to 4.0.0
- dropped httr in favour of httr2
- fix bug where `download_hydat()` fails if `tempdir()` is on a different device than `hydat_path` (@mpdavison, #192)
Expand Down
22 changes: 22 additions & 0 deletions cran-comments.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
tidyhydat 0.7.0
=========================

There were zero WARNINGS and zero ERRORS.

## NEWS
- bump minimum R version to 4.0.0
- dropped httr in favour of httr2
- fix bug where `download_hydat()` fails if `tempdir()` is on a different device than `hydat_path` (@mpdavison, #192)
- fix bug where `download_hydat()` wasn't checking alternative paths for success (@Travis-Simmons)

## Test environments
* win-builder (via `devtools::check_win_devel()` and `devtools::check_win_release()`)
* local macOS, R 4.3.1 (via R CMD check --as-cran)
* ubuntu-20.04, r: 'release' (github actions)
* ubuntu-20.04, r: 'devel' (github actions)
* macOS, r: 'release' (github actions)
* windows, r: 'release' (github actions)
* Fedora Linux, R-devel, clang, gfortran - r-hub
* Debian Linux, R-release, GCC (debian-gcc-release) - r-hub
* Windows Server 2008 R2 SP1, R-devel, 32/64 bit - r-hub

tidyhydat 0.6.1
=========================

Expand Down
1,071 changes: 541 additions & 530 deletions data-raw/HYDAT_internal_data/allstations.csv

Large diffs are not rendered by default.

Binary file modified data/allstations.rda
Binary file not shown.
Binary file modified data/hy_data_symbols.rda
Binary file not shown.
Binary file modified data/hy_data_types.rda
Binary file not shown.
Binary file modified man/figures/README-unnamed-chunk-8-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified man/figures/README-unnamed-chunk-9-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
117 changes: 57 additions & 60 deletions vignettes/tidyhydat_an_introduction.Rmd
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: "tidyhydat: An Introduction"
author: "Sam Albers"
date: "2024-01-09"
date: "2024-10-04"
output:
html_vignette:
keep_md: true
Expand All @@ -15,7 +15,7 @@ vignette: >
## Package loading
In addition to tidyhydat, this vignette makes use of the [dplyr](https://dplyr.tidyverse.org/) package for data manipulations and [ggplot2](https://ggplot2.tidyverse.org/) for plotting.

```r
``` r
library(tidyhydat)
library(dplyr)
library(ggplot2)
Expand All @@ -27,7 +27,7 @@ This vignette will outline a few key options that will hopefully make `tidyhydat
## HYDAT download
To use many of the functions in the `tidyhydat` package you will need to download a version of the HYDAT database, Environment and Climate Change Canada's database of historical hydrometric data then tell R where to find the database. Conveniently `tidyhydat` does all this for you via:

```r
``` r
download_hydat()
```
This downloads the most recent version of HYDAT and then saves it in a location on your computer where `tidyhydat`'s function will look for it. Do be patient though as this takes a long time! To see where HYDAT was saved you can run `hy_dir()`. Now that you have HYDAT downloaded and ready to go, you are all set to begin some hydrologic analysis.
Expand All @@ -37,20 +37,20 @@ Most functions in `tidyhydat` follow a common argument structure. We will use th

The simplest case is if you would like to extract only station. You can supply this directly to the `station_number` argument:

```r
``` r
hy_daily_flows(station_number = "08LA001")
```

```
## Queried from version of HYDAT released on 2023-11-20
## Observations: 31,351
## Measurement flags: 6,166
## Queried from version of HYDAT released on 2024-07-18
## Observations: 31,716
## Measurement flags: 6,218
## Parameter(s): Flow
## Date range: 1914-01-01 to 2021-12-31
## Date range: 1914-01-01 to 2022-12-31
## Station(s) returned: 1
## Stations requested but not returned:
## All stations returned.
## # A tibble: 31,351 × 5
## # A tibble: 31,716 × 5
## STATION_NUMBER Date Parameter Value Symbol
## <chr> <date> <chr> <dbl> <chr>
## 1 08LA001 1914-01-01 Flow 144 <NA>
Expand All @@ -63,13 +63,13 @@ hy_daily_flows(station_number = "08LA001")
## 8 08LA001 1914-01-08 Flow 140 <NA>
## 9 08LA001 1914-01-09 Flow 140 <NA>
## 10 08LA001 1914-01-10 Flow 140 <NA>
## # ℹ 31,341 more rows
## # ℹ 31,706 more rows
```

Another method is to use `hy_stations()` to generate your vector which is then given the `station_number` argument. For example, we could take a subset for only those active stations within Prince Edward Island (Province code:PE) and then create vector for `hy_daily_flows()`:


```r
``` r
PEI_stns <- hy_stations() |>
filter(HYD_STATUS == "ACTIVE") |>
filter(PROV_TERR_STATE_LOC == "PE") |>
Expand All @@ -79,24 +79,23 @@ PEI_stns
```

```
## [1] "01CA003" "01CB002" "01CB004" "01CB018" "01CC002"
## [6] "01CC005" "01CC010" "01CC011" "01CD005"
## [1] "01CA003" "01CB002" "01CB004" "01CB018" "01CC002" "01CC005" "01CC010" "01CC011" "01CD005"
```

```r
``` r
hy_daily_flows(station_number = PEI_stns)
```

```
## Queried from version of HYDAT released on 2023-11-20
## Observations: 117,530
## Measurement flags: 20,867
## Queried from version of HYDAT released on 2024-07-18
## Observations: 123,370
## Measurement flags: 21,918
## Parameter(s): Flow
## Date range: 1961-08-01 to 2021-12-31
## Date range: 1961-08-01 to 2023-12-31
## Station(s) returned: 9
## Stations requested but not returned:
## All stations returned.
## # A tibble: 117,530 × 5
## # A tibble: 123,370 × 5
## STATION_NUMBER Date Parameter Value Symbol
## <chr> <date> <chr> <dbl> <chr>
## 1 01CA003 1961-08-01 Flow NA <NA>
Expand All @@ -109,27 +108,27 @@ hy_daily_flows(station_number = PEI_stns)
## 8 01CB002 1961-08-04 Flow NA <NA>
## 9 01CA003 1961-08-05 Flow NA <NA>
## 10 01CB002 1961-08-05 Flow NA <NA>
## # ℹ 117,520 more rows
## # ℹ 123,360 more rows
```

We can also merge our station choice and data extraction into one unified pipe which accomplishes a single goal. For example if for some reason we wanted all the stations in Canada that had the name "Canada" in them we unify that selection and data extraction process into a single pipe:

```r
``` r
search_stn_name("canada") |>
pull_station_number() |>
hy_daily_flows()
```

```
## Queried from version of HYDAT released on 2023-11-20
## Observations: 87,669
## Measurement flags: 26,754
## Queried from version of HYDAT released on 2024-07-18
## Observations: 91,319
## Measurement flags: 27,879
## Parameter(s): Flow
## Date range: 1918-08-01 to 2023-05-31
## Date range: 1918-08-01 to 2023-12-31
## Station(s) returned: 7
## Stations requested but not returned:
## All stations returned.
## # A tibble: 87,669 × 5
## # A tibble: 91,319 × 5
## STATION_NUMBER Date Parameter Value Symbol
## <chr> <date> <chr> <dbl> <chr>
## 1 01AK001 1918-08-01 Flow NA <NA>
Expand All @@ -142,12 +141,12 @@ search_stn_name("canada") |>
## 8 01AK001 1918-08-08 Flow 1.78 <NA>
## 9 01AK001 1918-08-09 Flow 1.5 <NA>
## 10 01AK001 1918-08-10 Flow 1.78 <NA>
## # ℹ 87,659 more rows
## # ℹ 91,309 more rows
```

We saw above that if we were only interested in a subset of dates we could use the `start_date` and `end_date` arguments. A date must be supplied to both these arguments in the form of YYYY-MM-DD. If you were interested in all daily flow data from station number "08LA001" for 1981, you would specify all days in 1981 :

```r
``` r
hy_daily_flows(station_number = "08LA001",
start_date = "1981-01-01",
end_date = "1981-12-31")
Expand All @@ -163,13 +162,13 @@ In addition to the approved and vetted data in the HYDAT database ECCC also offe

Not every stations is currently part of the real-time network. Therefore `realtime_stations()` points to a (hopefully) updated ECCC data file of active real-time stations. We can use the `realtime_stations()` functionality to get a vector of stations by jurisdiction. For example, we can choose all the stations in Prince Edward Island using the following:

```r
``` r
realtime_stations(prov_terr_state_loc = "PE")
```

`hy_stations()` and `realtime_stations()` perform similar tasks albeit on different data sources. `hy_stations()` extracts directly from HYDAT. In addition to real-time stations, `hy_stations()` outputs discontinued and non-real-time stations:

```r
``` r
hy_stations(prov_terr_state_loc = "PE")
```

Expand All @@ -178,65 +177,63 @@ This is contrast to `realtime_stations()` which downloads all real-time stations
### Meterological Service of Canada datamart - `realtime_dd()`
To download real-time data using the datamart we can use approximately the same conventions discussed above. Using `realtime_dd()` we can easily select specific stations by supplying a station of interest:

```r
``` r
realtime_dd(station_number = "08LG006")
```
Another option is to provide simply the province as an argument and download all stations from that province:

```r
``` r
realtime_dd(prov_terr_state_loc = "PE")
```

## Search functions
You can also make use of auxiliary functions in `tidyhydat` called `search_stn_name()` and `search_stn_number()` to look for matches when you know part of a name of a station. For example:

```r
``` r
search_stn_name("liard")
```

```
## # A tibble: 9 × 5
## STATION_NUMBER STATION_NAME PROV_TERR_STATE_LOC LATITUDE
## <chr> <chr> <chr> <dbl>
## 1 10AA001 LIARD RIVER A… YT 60.1
## 2 10AA006 LIARD RIVER B… YT 60.8
## 3 10BE001 LIARD RIVER A… BC 59.4
## 4 10ED001 LIARD RIVER A… NT 60.2
## 5 10ED002 LIARD RIVER N… NT 61.7
## 6 10BE005 LIARD RIVER A… BC 59.7
## 7 10BE006 LIARD RIVER A… BC 59.7
## 8 10ED008 LIARD RIVER A… NT 61.1
## 9 10GC004 MACKENZIE RIV… NT 61.9
## # ℹ 1 more variable: LONGITUDE <dbl>
## STATION_NUMBER STATION_NAME PROV_TERR_STATE_LOC LATITUDE LONGITUDE
## <chr> <chr> <chr> <dbl> <dbl>
## 1 10AA001 LIARD RIVER AT UPPER CROSSING YT 60.1 -129.
## 2 10AA006 LIARD RIVER BELOW SCURVY CREEK YT 60.8 -131.
## 3 10BE001 LIARD RIVER AT LOWER CROSSING BC 59.4 -126.
## 4 10ED001 LIARD RIVER AT FORT LIARD NT 60.2 -123.
## 5 10ED002 LIARD RIVER NEAR THE MOUTH NT 61.7 -121.
## 6 10BE005 LIARD RIVER ABOVE BEAVER RIVER BC 59.7 -124.
## 7 10BE006 LIARD RIVER ABOVE KECHIKA RIVER BC 59.7 -127.
## 8 10ED008 LIARD RIVER AT LINDBERG LANDING NT 61.1 -123.
## 9 10GC004 MACKENZIE RIVER ABOVE LIARD RIVER NT 61.9 -121.
```
Similarly, `search_stn_number()` can be useful if you are interested in all stations from the *08MF* sub-sub-drainage:

```r
``` r
search_stn_number("08MF")
```

```
## # A tibble: 54 × 5
## STATION_NUMBER STATION_NAME PROV_TERR_STATE_LOC LATITUDE
## <chr> <chr> <chr> <dbl>
## 1 08MF005 FRASER RIVERBC 49.4
## 2 08MF040 FRASER RIVERBC 50.6
## 3 08MF062 COQUIHALLA R… BC 49.5
## 4 08MF065 NAHATLATCH R… BC 50.0
## 5 08MF068 COQUIHALLA R… BC 49.4
## 6 08MF075 FRASER RIVERBC 49.2
## 7 08MF001 ANDERSON RIV… BC 49.8
## 8 08MF002 BOULDER CREE… BC 49.3
## 9 08MF003 COQUIHALLA R… BC 49.4
## 10 08MF004 FRASER RIVER… BC 50.2
## STATION_NUMBER STATION_NAME PROV_TERR_STATE_LOC LATITUDE LONGITUDE
## <chr> <chr> <chr> <dbl> <dbl>
## 1 08MF005 FRASER RIVER AT HOPE BC 49.4 -121.
## 2 08MF040 FRASER RIVER ABOVE TEXAS CREEK BC 50.6 -122.
## 3 08MF062 COQUIHALLA RIVER BELOW NEEDLE CREEK BC 49.5 -121.
## 4 08MF065 NAHATLATCH RIVER BELOW TACHEWANA CREEK BC 50.0 -122.
## 5 08MF068 COQUIHALLA RIVER ABOVE ALEXANDER CREEK BC 49.4 -121.
## 6 08MF001 ANDERSON RIVER NEAR BOSTON BAR BC 49.8 -121.
## 7 08MF002 BOULDER CREEK NEAR LAIDLAW BC 49.3 -122.
## 8 08MF003 COQUIHALLA RIVER NEAR HOPE BC 49.4 -121.
## 9 08MF004 FRASER RIVER ABOVE THOMPSON RIVER BC 50.2 -122.
## 10 08MF006 WAHLEACH CREEK NEAR LAIDLAW (UPPER STATION) BC 49.3 -122.
## # ℹ 44 more rows
## # ℹ 1 more variable: LONGITUDE <dbl>
```

## Using joins
Sometimes it is required to make use of information from two tables from HYDAT. In some cases, we need to combine the information into one table using a common column. Here we will illustrate calculating runoff by combining the `hy_stations` tables with the `hy_daily_flows` table by the `STATION_NUMBER` column:

```r
``` r
stns <- c("08NH130", "08NH005")
runoff_data <- hy_daily_flows(station_number = stns, start_date = "2000-01-01") |>
left_join(
Expand Down
Loading

0 comments on commit c2cf1d8

Please sign in to comment.