Skip to content

bcgov/bcsnowdata

Repository files navigation

bcsnowdata

img License

Project Status

This package is currently under development, and subject to future changes and iterations.

This package is maintained by River Forecast Centre, part of the Water Management Branch of the Ministry of Forest Lands, Natural Resource Operations and Rural Development within the Government of British Columbia.

What does bcsnowdata do?

This package contains functions for retrieving snow-related data from the BC Data Catalogue, which can be found here.

Data is collected from both manual and automated snow weather (ASWE) stations around the province. These sites, and data collection, is the responsibility of the Ministry of Environment and Climate Change Strategy’s Snow Survey Program, BC Hydro and other partners. Snow data includes snow water equivalent (SWE; both manual and automated stations), snow depth (ASWE and manual sites), precipitation (ASWE), and temperature (ASWE sites). The authors of this package are not responsible for any errors within the source data, and assume no responsibility or liability for subsequent use of any data resources compiled by these functions.

This package uses the bcdata package to access ASWE and manual snow data from the BC Data Catalogue, and provides a means of quickly accessing different records across the different types of data that exist for snow within the BC Data Catalogue.

Features

This package features functions for retrieving BC snow data from the BC Data Catalogue for ASWE stations and manual snow surveys. It also contains functions for retrieving the location metadata of snow survey and automated snow weather stations, as well as snow basin administrative areas.

Installation

The snow package can be installed from GitHub:

install.packages("remotes", repos = "http://cran.us.r-project.org")
remotes::install_github("bcgov/bcsnowdata")
library(bcsnowdata)

Usage

This package contains seven functions for returning snow-associated data.

get_snow

The get_snow function retrieves either ASWE or manual data, and does not require the user to specify whether the site(s) they are retrieving data for are manual or ASWE sites.

The get_snow function is a wrapper for the get_aswe_databc() and get_manual_swe() functions detailed below.

Variables include:

  • id: Station ID of the site(s) to retrieve data for. Can also be: “All”(all manual and ASWE sites), “automated” (all ASWE sites), or “manual” (all manual snow sites).
  • get_year: water year you want to retrieve data for.
  • survey_period: manual site survey period you want to retrieve data for (in “01-01” or “Jan-01” format). Only for manual data.
  • parameter: Type of data you are retrieving for ASWE data. Only for ASWE data.
  • timestep: Whether you are trying to retrieve hourly or daily ASWE data. Only for ASWE data.
library(bcsnowdata)
# Get hourly swe data for 2022 water year for 1A01P
aswe_test <- get_snow(id = "1A01P", get_year = "2022", parameter = "swe", timestep = "hourly")

# Get manual snow data for all sites for the 2022 water year across all survey
# periods
manual_test <- get_snow(id = "1A06A", get_year = "2022", survey_period = "all")

Automated Snow Function

get_aswe_databc() retrieves data for automated snow stations, including snow water equivalent (swe), snow depth, precipitation and air temperature. Hourly data is available until 2003, and daily data available before that for stations that were established before this point up to (and including) the current water year.

The user can define multiple options within the function, including:

  1. station_id: This function will retrieve data for one station (by specified station ID), or multiple stations specified within a string (i.e., c(“2F05P”, “1C18P”)). The user can also specify to return all ASWE stations within the Data BC Catalogue.

  2. get_year: Specifies the year you want to return. Can be one water year, multiple, or all.

  3. parameter_id: Specifies what type of data you want to retrieve. The choices include SWE, Temperature, SD (snow depth), and Precipitation.

  4. timestep: Specifies what type of data to retrieve (hourly or daily average).

The function in this example will retrieve data for station ID 2F05P for all years on record without updating the cache of historic data (data prior to this water year).

# Get hourly swe data for one station across all years available (no data
# available before 2003 for all stations)
id <- c("2F05P")
SWE_test <- get_aswe_databc(station_id = id, get_year = "All", parameter = "swe",
    timestep = "hourly")

Manual Snow Survey Data Function

The manual snow station data function - get_manual_swe() - is similar to the function that gets data from the ASWE sites.

Specifically, the user can define multiple options within the function, including:

  1. station_id: This function will retrieve data for one station (by specified station ID), or multiple stations specified within a string (i.e., c(“2F05P”, “1C18P”)). The user can also specify to return all manual snow survey locations within the Data BC catalogue. This is significantly faster than the ASWE station function.

  2. survey_period: Specifies what survey period the user wants to return. Can be “All” (the default within the function), or else a specific survey period (or number of them). The format can either be numeric month year (i.e., “03-01” is March 1), or annotated in the format day-month, such as “01-Mar”.

# Retrieve manual snow survey data for one site over all survey periods and
# years
id <- c("1C21")
manual_test <- get_manual_swe(station_id = id, survey_period = "All", get_year = "All")
Automated Snow Weather Station Locations

The snow_auto_location() returns a dataframe containing location metadata for all of the automated snow weather stations. The returned dataframe includes both active as well as inactive stations, in addition to their latitude, longitude and elevation.

Data obtained from the BC Data Catalogue.

ASWE_locations <- snow_auto_location()

head(ASWE_locations)
Manual Snow Survey Locations

The snow_auto_location() function returns a dataframe containing location metadata for all of the manual snow survey locations. The returned dataframe includes both active as well as inactive stations, in addition to their latitude, longitude and elevation.

Data obtained from the BC Data Catalogue.

manual_locations <- snow_manual_location()

head(manual_locations)
Snow Survey Administrative Basin Areas

The snow_auto_location() returns a dataframe containing location metadata for the administrative basin areas. Returned data includes the polygon geometries necessary to map snow basin areas (for example, upon integration with the bcmaps() package).

Data obtained from the BC Data Catalogue.

basin_locations <- snow_basin_areas()

head(basin_locations)
Assign water year

This package also contains the function wtr_yr() for assigning water year to a column of dates. It is meant as an internal function that can also be called externally. The main input is a vector or column of dates that are used to calculate the corresponding water year. The default start to the calendar year is October (start_month = 10).

wtr_yr(as.Date("2018-12-01"))

Project Status

This project is in active development and subject to change.

Getting Help or Reporting an Issue

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

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.

License

Copyright 2022 Province of British Columbia

Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
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 &quot;AS IS&quot; 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 project was created using the bcgovr package.