Skip to content

Commit

Permalink
Use new regional weather
Browse files Browse the repository at this point in the history
  • Loading branch information
gmyenni committed Aug 23, 2023
1 parent 7b6e3dd commit 9e40328
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 37 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: portalr
Title: Create Useful Summaries of the Portal Data
Version: 0.4.0
Version: 0.4.1
Authors@R:
c(person(given = c("Glenda", "M."),
family = "Yenni",
Expand Down
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

Version numbers follow [Semantic Versioning](https://semver.org/).

# [portalr 0.4.1](https://github.com/weecology/portalr/releases/tag/v0.4.1)
*2023-08-223*

### Regional weather filling includes more stations

# [portalr 0.4.0](https://github.com/weecology/portalr/releases/tag/v0.4.0)
*2023-04-21*

Expand Down
24 changes: 1 addition & 23 deletions R/Weather.R
Original file line number Diff line number Diff line change
Expand Up @@ -177,17 +177,7 @@ fill_missing_weather <- function(weather, path = get_default_data_path())
dplyr::filter(.data$date >= "1980-01-01") %>%
dplyr::rename(precipitation = "prcp")

rustys <- read.csv(file.path(path, 'PortalData/Weather/Rustys_regional_weather.csv'),
na.strings = c(""), header = TRUE, stringsAsFactors = FALSE) %>%
dplyr::group_by(.data$year, .data$month, .data$day) %>%
dplyr::summarize(mintemp = min(.data$templow),
maxtemp = max(.data$temphigh),
meantemp = mean(.data$tempavg),
precipitation = sum(.data$preciptotal)) %>%
dplyr::select(dplyr::all_of(c("year", "month", "day", "mintemp", "maxtemp", "meantemp","precipitation"))) %>%
dplyr::arrange(.data$year,.data$month, .data$day)

rodeo <- read.csv(file.path(path, 'PortalData/Weather/Rodeo_regional_weather.csv'),
region1 <- read.csv(file.path(path, 'PortalData/Weather/Rodeo_regional_weather.csv'),
na.strings = c(""), header = TRUE, stringsAsFactors = FALSE) %>%
dplyr::group_by(.data$year, .data$month, .data$day) %>%
dplyr::summarize(mintemp = min(.data$templow),
Expand All @@ -197,18 +187,6 @@ fill_missing_weather <- function(weather, path = get_default_data_path())
dplyr::select(dplyr::all_of(c("year", "month", "day", "mintemp", "maxtemp", "meantemp","precipitation"))) %>%
dplyr::arrange(.data$year,.data$month, .data$day)

region1 <- dplyr::full_join(rodeo, rustys, by = c("year", "month", "day")) %>%
dplyr::group_by(.data$year, .data$month, .data$day) %>%
dplyr::rowwise() %>%
dplyr::mutate(mintemp = mean(c(.data$mintemp.y, .data$mintemp.x), na.rm=TRUE),
maxtemp = mean(c(.data$maxtemp.y, .data$maxtemp.x), na.rm=TRUE),
meantemp = mean(c(.data$meantemp.y, .data$meantemp.x), na.rm=TRUE),
precipitation = mean(c(.data$precipitation.y, .data$precipitation.x), na.rm=TRUE)) %>%
dplyr::ungroup() %>%
dplyr::filter(!(is.na(.data$mintemp) & is.na(.data$maxtemp) &
is.na(.data$meantemp) & is.na(.data$precipitation))) %>%
dplyr::select(dplyr::all_of(c("year", "month", "day", "precipitation", "mintemp", "maxtemp", "meantemp")))

region2 <- dplyr::full_join(portal4sw, sansimon, by = c("date", "year", "month", "day")) %>%
dplyr::group_by(.data$year, .data$month, .data$day, .data$date) %>%
dplyr::rowwise() %>%
Expand Down
15 changes: 7 additions & 8 deletions R/portalr-package.R
Original file line number Diff line number Diff line change
@@ -1,31 +1,30 @@
#' @keywords internal
#' @title Creates summaries of the Portal data
#'
#' @description This package is designed to be an interface to the Portal data, which resides online at \url{https://github.com/weecology/portalData}. Its contains a set of functions to download, clean, and summarize the data.
#'
#' @name portalr
#' @docType package
#' @keywords package
#'
#' @importFrom lubridate "%m+%"
#' @importFrom rlang "!!" "!!!" ":=" .data
#' @importFrom utils head download.file read.csv unzip read.table tail
#' @importFrom stats median na.omit
#' @importFrom httr content GET stop_for_status

NULL
"_PACKAGE"

## quiets concerns of R CMD check re: variables used in NSE functions
if (getRversion() >= "2.15.1") utils::globalVariables(
c(".", "n")
)
c(".", "n")
)

#' @title Return Citation for Portal Data
#'
#' @return An object of class "citation". For more details, see `citation()`
#' @export
get_dataset_citation <- function()
{
path <- system.file("CITATION-PORTAL-DATA",
package = "portalr", mustWork = TRUE)
utils::readCitationFile(path)
path <- system.file("CITATION-PORTAL-DATA",
package = "portalr", mustWork = TRUE)
utils::readCitationFile(path)
}
4 changes: 2 additions & 2 deletions man/load_datafile.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 32 additions & 1 deletion man/portalr.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions tests/testthat/test-99-regression.R
Original file line number Diff line number Diff line change
Expand Up @@ -256,9 +256,9 @@ test_that("data generated by default setting is same (weather)", {
attributes(data) <- attributes(data)[sort(names(attributes(data)))]

# correct for NAs in output
expect_known_hash(is.na(data), "8648ecf05f")
expect_known_hash(is.na(data), "ab7f91f465")
data[is.na(data)] <- -999999
expect_known_hash(data, "fcc6dc4ca0")
expect_known_hash(data, "b302f95927")
})

test_that("data generated by fill = TRUE is same (weather)", {
Expand Down

0 comments on commit 9e40328

Please sign in to comment.