Skip to content

Commit

Permalink
Merge pull request #31 from bluegreen-labs/patch-snow-depth
Browse files Browse the repository at this point in the history
adding snow depth
  • Loading branch information
khufkens authored Sep 29, 2024
2 parents 71e610f + 0023fd3 commit c86e7f0
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 15 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: snotelr
Title: Calculate and Visualize 'SNOTEL' Snow Data and Seasonality
Version: 1.4
Version: 1.5
Authors@R: c(person(
family = "Hufkens",
given = "Koen",
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# snotelr 1.5

* adding snow depth as a return variable

# snotelr 1.4

* update snotel_info() to reflect new CSS (by @dfosterhill)
Expand Down
2 changes: 1 addition & 1 deletion R/snotel_download.r
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ snotel_download <- function(
meta_data$site_id[i], ":",
meta_data$state[i], ":",
meta_data$network[i],
"%7Cid=%22%22%7Cname/POR_BEGIN,POR_END/WTEQ::value,PREC::value,TMAX::value,TMIN::value,TAVG::value,PRCP::value"
"%7Cid=%22%22%7Cname/POR_BEGIN,POR_END/WTEQ::value,SNWD::value,PREC::value,TMAX::value,TMIN::value,TAVG::value,PRCP::value"
)

# try to download the data
Expand Down
5 changes: 3 additions & 2 deletions R/snotel_metric.r
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,15 @@ snotel_metric <- function(df) {
# check the file, if less than 7 columns
# are present this is not a standard file,
# stop processing
if (ncol(df) != 7) {
if (ncol(df) != 8) {
stop("not a standard snotel file")
}

# define new column names
snotel_columns <- c(
"date",
"snow_water_equivalent",
"snow_depth",
"precipitation_cumulative",
"temperature_max",
"temperature_min",
Expand All @@ -41,7 +42,7 @@ snotel_metric <- function(df) {

# if the columns match those in the current data frame
# return it as is (previously processed)
if(length(which(colnames(df) == snotel_columns)) == 7){
if(length(which(colnames(df) == snotel_columns)) == 8){
message("File is already metric, returning original!")
return(df)
}
Expand Down
6 changes: 4 additions & 2 deletions cran-comments.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
Dear CRAN team,

This is an update of the {snotel} package (version 1.4). This package calculates and visualize 'SNOTEL' snow data and seasonality. This update implements a new API endpoint to provide access to the SNOTEL data.
This is an update of the {snotel} package (version 1.5). This package calculates and visualizes 'SNOTEL' snow data and seasonality. This update implements a new variable on the API endpoint (snow depth, in addition to snow water equivalent).

No further changes were made to the package so the update does not affect previous code coverage and testing metrics (which remained the same).

Kind regards,
Koen Hufkens
Expand All @@ -12,7 +14,7 @@ http://cran.r-project.org/web/packages/policies.html

## Test environments, local, github actions

- local 22.04 install on R 4.3.3
- local 22.04 install on R 4.4.1
- github actions (devel / release + macos / windows)
- codecove.io code coverage at ~90%

Expand Down
18 changes: 9 additions & 9 deletions tests/testthat/test_snotel_functions.r
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ test_that("metric conversion - not a proper size data frame",{
expect_error(snotel_metric(df))
})

test_that("metric conversion - alread converted",{
test_that("metric conversion - already converted",{
skip_on_cran()
df <- snotel_download(site_id = 429, internal = TRUE)
df <- df[,12:18]
expect_message(snotel_metric(df))
expect_error(snotel_metric(df))
})

test_that("metric conversion - not a data frame",{
Expand All @@ -60,7 +60,7 @@ test_that("metric conversion - not a data frame",{

test_that("metric conversion - not a data frame",{
skip_on_cran()
df <- read.table("https://wcc.sc.egov.usda.gov/reportGenerator/view_csv/customSingleStationReport/daily/947:AK:SNTL|id=%22%22|name/POR_BEGIN,POR_END/WTEQ::value,PREC::value,TMAX::value,TMIN::value,TAVG::value,PRCP::value",
df <- read.table("https://wcc.sc.egov.usda.gov/reportGenerator/view_csv/customSingleStationReport/daily/947:AK:SNTL|id=%22%22|name/POR_BEGIN,POR_END/WTEQ::value,SNWD::value,PREC::value,TMAX::value,TMIN::value,TAVG::value,PRCP::value",
header = TRUE, sep = ",")
expect_output(str(snotel_metric(df)))
})
Expand All @@ -69,21 +69,21 @@ test_that("metric conversion - not a data frame",{
test_that("check phenology routines",{
skip_on_cran()
df <- snotel_download(site_id = 670, internal = TRUE)
expect_output(str(snotel_phenology(df)))
expect_type(snotel_phenology(df), 'list')
})

test_that("check phenology routines - swe empty",{
skip_on_cran()
df <- snotel_download(site_id = 670, internal = TRUE)
df$snow_water_equivalent <- NA
expect_output(str(snotel_phenology(df)))
expect_warning(snotel_phenology(df))
})

test_that("check phenology routines - swe 0",{
skip_on_cran()
df <- snotel_download(site_id = 670, internal = TRUE)
df$snow_water_equivalent <- 10
expect_output(str(snotel_phenology(df)))
df$snow_water_equivalent <- 0
expect_warning(snotel_phenology(df))
})

test_that("check phenology routines - not metric",{
Expand All @@ -99,11 +99,11 @@ test_that("check phenology routines - missing file",{
})

# find site with no snow (only rainfall) data to implement this
#test_that("check phenology routines - no data returned",{
# test_that("check phenology routines - no data returned",{
# skip_on_cran()
# df <- snotel_download(site_id = 429, internal = TRUE)
# expect_warning(snotel_phenology(df))
#})
# })

test_that("check phenology routines - not a data frame",{
skip_on_cran()
Expand Down

0 comments on commit c86e7f0

Please sign in to comment.