MyNixOS website logo
Description

Extract and Tidy Canadian 'Hydrometric' Data.

Provides functions to access historical and real-time national 'hydrometric' data from Water Survey of Canada data sources (<https://dd.weather.gc.ca/hydrometric/csv/> and <https://collaboration.cmc.ec.gc.ca/cmc/hydrometrics/www/>) and then applies tidy data principles.

tidyhydat

Licenseß R buildstatus

CRAN_Status_Badge CRANDownloads cranchecks r-universe DOI DOI R-CMD-check

What does tidyhydat do?

  • Provides functions (hy_*) that access hydrometric data from the HYDAT database, a national archive of Canadian hydrometric data and return tidy data.
  • Provides functions (realtime_*) that access Environment and Climate Change Canada’s real-time hydrometric data source.
  • Provides functions (search_*) that can search through the approximately 7000 stations in the database and aid in generating station vectors
  • Keep functions as simple as possible. For example, for daily flows, the hy_daily_flows() function queries the database, tidies the data and returns a tibble of daily flows.

Installation

You can install tidyhydat from CRAN:

install.packages("tidyhydat")

To install the development version of the tidyhydat package, you can install directly from the rOpenSci development server:

install.packages("tidyhydat", repos = "https://dev.ropensci.org")

Usage

More documentation on tidyhydat can found at the rOpenSci doc page: https://docs.ropensci.org/tidyhydat/

When you install tidyhydat, several other packages will be installed as well. One of those packages, dplyr, is useful for data manipulations and is used regularly here. To use actually use dplyr in a session you must explicitly load it. A helpful dplyr tutorial can be found here.

library(tidyhydat)
library(dplyr)

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:

download_hydat()

This downloads (with your permission) 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 can take a long time! To see where HYDAT was saved you can run hy_default_db(). Now that you have HYDAT downloaded and ready to go, you are all set to begin looking at Canadian hydrometric data.

Real-time

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:

realtime_dd(station_number = "08MF005")
#>   Queried on: 2024-01-09 05:08:33.18974 (UTC)
#>   Date range: 2023-12-10 to 2024-01-09 
#> # A tibble: 10,972 × 8
#>    STATION_NUMBER PROV_TERR_STATE_LOC Date               
#>    <chr>          <chr>               <dttm>             
#>  1 08MF005        BC                  2023-12-10 08:00:00
#>  2 08MF005        BC                  2023-12-10 08:05:00
#>  3 08MF005        BC                  2023-12-10 08:10:00
#>  4 08MF005        BC                  2023-12-10 08:15:00
#>  5 08MF005        BC                  2023-12-10 08:20:00
#>  6 08MF005        BC                  2023-12-10 08:25:00
#>  7 08MF005        BC                  2023-12-10 08:30:00
#>  8 08MF005        BC                  2023-12-10 08:35:00
#>  9 08MF005        BC                  2023-12-10 08:40:00
#> 10 08MF005        BC                  2023-12-10 08:45:00
#> # ℹ 10,962 more rows
#> # ℹ 5 more variables: Parameter <chr>, Value <dbl>,
#> #   Grade <chr>, Symbol <chr>, Code <chr>

Or we can use realtime_ws:

realtime_ws(
  station_number = "08MF005",
  parameters = c(46, 5), ## see param_id for a list of codes
  start_date = Sys.Date() - 14,
  end_date = Sys.Date()
)
#> All station successfully retrieved
#> All parameters successfully retrieved
#> # A tibble: 1,323 × 10
#>    STATION_NUMBER Date                Name_En    Value Unit 
#>    <chr>          <dttm>              <chr>      <dbl> <chr>
#>  1 08MF005        2023-12-25 00:00:00 Water tem…  5.14 °C   
#>  2 08MF005        2023-12-25 01:00:00 Water tem…  5.12 °C   
#>  3 08MF005        2023-12-25 02:00:00 Water tem…  5.11 °C   
#>  4 08MF005        2023-12-25 03:00:00 Water tem…  5.1  °C   
#>  5 08MF005        2023-12-25 04:00:00 Water tem…  5.1  °C   
#>  6 08MF005        2023-12-25 05:00:00 Water tem…  5.07 °C   
#>  7 08MF005        2023-12-25 06:00:00 Water tem…  5.06 °C   
#>  8 08MF005        2023-12-25 07:00:00 Water tem…  5.04 °C   
#>  9 08MF005        2023-12-25 08:00:00 Water tem…  5.02 °C   
#> 10 08MF005        2023-12-25 09:00:00 Water tem…  5    °C   
#> # ℹ 1,313 more rows
#> # ℹ 5 more variables: Grade <chr>, Symbol <chr>,
#> #   Approval <chr>, Parameter <dbl>, Code <chr>

Compare realtime_ws and realtime_dd

tidyhydat provides two methods to download realtime data. realtime_dd() provides a function to import .csv files from here. realtime_ws() is an client for a web service hosted by ECCC. realtime_ws() has several difference to realtime_dd(). These include:

  • Speed: The realtime_ws() is much faster for larger queries (i.e. many stations). For single station queries to realtime_dd() is more appropriate.
  • Length of record: realtime_ws() records goes back further in time.
  • Type of parameters: realtime_dd() are restricted to river flow (either flow and level) data. In contrast realtime_ws() can download several different parameters depending on what is available for that station. See data("param_id") for a list and explanation of the parameters.
  • Date/Time filtering: realtime_ws() provides argument to select a date range. Selecting a data range with realtime_dd() is not possible until after all files have been downloaded.

Plotting

Plot methods are also provided to quickly visualize realtime data:

realtime_ex <- realtime_dd(station_number = "08MF005")

plot(realtime_ex)

and also historical data:

hy_ex <- hy_daily_flows(station_number = "08MF005", start_date = "2013-01-01")

plot(hy_ex)

Getting Help or Reporting an Issue

To report bugs/issues/feature requests, please file an issue.

These are very welcome!

How to Contribute

If you would like to contribute to the package, please see our CONTRIBUTING guidelines.

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

Citation

Get citation information for tidyhydat in R by running:

To cite package 'tidyhydat' in publications use:

  Albers S (2017). "tidyhydat: Extract and Tidy
  Canadian Hydrometric Data." _The Journal of Open
  Source Software_, *2*(20). doi:10.21105/joss.00511
  <https://doi.org/10.21105/joss.00511>,
  <http://dx.doi.org/10.21105/joss.00511>.

A BibTeX entry for LaTeX users is

  @Article{,
    title = {tidyhydat: Extract and Tidy Canadian Hydrometric Data},
    author = {Sam Albers},
    doi = {10.21105/joss.00511},
    url = {http://dx.doi.org/10.21105/joss.00511},
    year = {2017},
    publisher = {The Open Journal},
    volume = {2},
    number = {20},
    journal = {The Journal of Open Source Software},
  }

ropensci_footer

License

Copyright 2017 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

https://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.

Metadata

Version

0.6.1

License

Unknown

Platforms (77)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-freebsd
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64-windows
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows