Skip to content

Commit 116494b

Browse files
authored
Merge pull request #11 from weecology/years
Post-move cleanup
2 parents 56b4710 + c336000 commit 116494b

15 files changed

+98
-38
lines changed

DESCRIPTION

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: edenR
22
Title: Access data from the Everglades Depth Estimation Network (EDEN)
3-
Version: 0.0.0.9000
3+
Version: 0.0.1
44
Authors@R:
55
c(person(given = c("Ethan", "P."),
66
family = "White",
@@ -15,6 +15,7 @@ Authors@R:
1515
Description: Access data from the Everglades Depth Estimation Network (EDEN)
1616
License: MIT + file LICENSE
1717
Imports:
18+
cubelyr,
1819
dplyr,
1920
glue,
2021
httr,
@@ -30,4 +31,4 @@ Imports:
3031
units
3132
Encoding: UTF-8
3233
Roxygen: list(markdown = TRUE)
33-
RoxygenNote: 7.3.2
34+
RoxygenNote: 7.3.3

NAMESPACE

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Generated by roxygen2: do not edit by hand
22

3+
export("%>%")
34
export(available_years)
45
export(calc_dry_days)
56
export(calc_recession)
@@ -17,3 +18,4 @@ export(load_boundaries)
1718
export(reshape_star)
1819
export(update_last_download)
1920
export(update_water)
21+
importFrom(magrittr,"%>%")

R/download_eden.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ get_data_urls <- function(file_names) {
5656
#'
5757
#' @export
5858
#'
59-
get_last_download <- function(eden_path = file.path("Water"),
59+
get_last_download <- function(eden_path = file.path("~/water"),
6060
metadata = get_metadata(),
6161
force_update = FALSE) {
6262
if ("last_download.csv" %in% list.files(eden_path) & !force_update) {
@@ -134,7 +134,7 @@ update_last_download <- function(eden_path, metadata) {
134134
#'
135135
#' @export
136136
#'
137-
download_eden_depths <- function(eden_path = file.path("Water"),
137+
download_eden_depths <- function(eden_path = file.path("~/water"),
138138
force_update = FALSE) {
139139
if (!dir.exists(eden_path)) {
140140
dir.create(eden_path, recursive = TRUE)

R/eden_covariates.R

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@
99
#'
1010
#' @export
1111
#'
12-
load_boundaries <- function(path = file.path("SiteandMethods/regions"),
12+
load_boundaries <- function(path = "https://raw.githubusercontent.com/weecology/EvergladesWadingBird/refs/heads/main/SiteandMethods/regions/",
1313
level = "subregions") {
14+
1415
level <- tolower(level)
15-
boundaries <- sf::st_read(file.path(path,paste(level,".shp",sep = "")))
16+
boundaries <- sf::st_read(paste0(path,level,".geojson"))
17+
1618
return(boundaries)
1719
}
1820

@@ -103,10 +105,10 @@ extract_region_means <- function(raster, regions) {
103105
dplyr::mutate(variable = var_name, value = NA)
104106
} else {
105107
region_means_spdf <- regions %>%
106-
dplyr::mutate(variable = var_name, value = as.numeric(region_means$value)) %>%
107-
dplyr::mutate_if(is.numeric, list(~dplyr::na_if(., Inf))) %>%
108-
dplyr::mutate_if(is.numeric, list(~dplyr::na_if(., -Inf))) %>%
109-
dplyr::mutate_if(is.numeric, list(~dplyr::na_if(., NaN)))
108+
dplyr::mutate(variable = var_name, value = as.double(region_means$value)) %>%
109+
dplyr::mutate_if(is.double, list(~dplyr::na_if(., Inf))) %>%
110+
dplyr::mutate_if(is.double, list(~dplyr::na_if(., -Inf))) %>%
111+
dplyr::mutate_if(is.double, list(~dplyr::na_if(., NaN)))
110112
}
111113
return(region_means_spdf)
112114
}
@@ -116,15 +118,22 @@ extract_region_means <- function(raster, regions) {
116118
#' @title Get list of years available for covariate calculation
117119
#'
118120
#' @param eden_path path where the EDEN data should be stored
121+
#' @param new logical, should `available_years` only list years which have changed
122+
#' since last download
119123
#'
120124
#' @return vector of years
121125
#'
122126
#' @export
123127
#'
124128

125-
available_years <- function(eden_path = file.path("Water")) {
129+
available_years <- function(eden_path = file.path("~/water"), new = FALSE) {
126130
eden_data_files <- list.files(file.path(eden_path), pattern = '_depth.nc')
127-
131+
years <- eden_data_files %>%
132+
stringr::str_split('_', simplify = TRUE) %>%
133+
.[, 1] %>%
134+
unique()
135+
136+
if(new) {
128137
# Find which years need to be updated since last download
129138
metadata <- get_metadata()
130139
last_download <- get_last_download(eden_path, metadata)
@@ -135,7 +144,8 @@ available_years <- function(eden_path = file.path("Water")) {
135144
stringr::str_split('_', simplify = TRUE) %>%
136145
.[, 1] %>%
137146
unique() %>%
138-
.[. %in% c(new$year, new$year+1, new$year+2)]
147+
.[. %in% c(new$year, new$year+1, new$year+2)] }
148+
139149
return(years)
140150
}
141151

@@ -156,9 +166,9 @@ available_years <- function(eden_path = file.path("Water")) {
156166
#' @export
157167
#'
158168
get_eden_covariates <- function(level = "subregions",
159-
eden_path = file.path("Water"),
169+
eden_path = file.path("~/water"),
160170
years = available_years(eden_path),
161-
boundaries_path = file.path("SiteandMethods/regions"))
171+
boundaries_path = "https://raw.githubusercontent.com/weecology/EvergladesWadingBird/refs/heads/main/SiteandMethods/regions/")
162172
{
163173

164174
eden_data_files <- list.files(file.path(eden_path), pattern = '_depth.nc')
@@ -252,7 +262,7 @@ get_eden_covariates <- function(level = "subregions",
252262
get_eden_depths <- function(level="subregions",
253263
eden_path = file.path("Water"),
254264
years = available_years(eden_path),
255-
boundaries_path = file.path("SiteandMethods/regions"))
265+
boundaries_path = "https://raw.githubusercontent.com/weecology/EvergladesWadingBird/refs/heads/main/SiteandMethods/regions/")
256266
{
257267

258268
eden_data_files <- list.files(eden_path, pattern = '_depth.nc', full.names = TRUE)

R/get_water_data.R

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#' @export
88
#'
99

10-
get_eden_data <- function(eden_path = file.path("Water")) {
10+
get_eden_data <- function(eden_path = file.path("~/water")) {
1111

1212
metadata <- get_metadata()
1313
last_download <- get_last_download(eden_path) %>% dplyr::select(-X)
@@ -16,12 +16,19 @@ if(identical(metadata,last_download)) {
1616
return(NULL)
1717
} else {
1818

19-
download_eden_depths()
19+
download_eden_depths(eden_path, force_update = FALSE)
20+
21+
years = available_years(eden_path, new = TRUE)
2022

21-
covariate_data <- read.table("Water/eden_covariates.csv", header = TRUE, sep = ",")
22-
new_covariates <- get_eden_covariates(eden_path) %>%
23-
dplyr::bind_rows(get_eden_covariates(level="all")) %>%
24-
dplyr::bind_rows(get_eden_covariates(level="wcas")) %>%
23+
covariate_data <- read.table(file.path(eden_path,"eden_covariates.csv"), header = TRUE, sep = ",")
24+
new_covariates <- get_eden_covariates(eden_path = eden_path,
25+
years=years) %>%
26+
dplyr::bind_rows(get_eden_covariates(eden_path = eden_path,
27+
level="all",
28+
years=years)) %>%
29+
dplyr::bind_rows(get_eden_covariates(eden_path = eden_path,
30+
level="wcas",
31+
years=years)) %>%
2532
dplyr::select(year, region=Name, variable, value) %>%
2633
as.data.frame() %>%
2734
dplyr::select(-geometry) %>%
@@ -32,11 +39,16 @@ covariate_data <- dplyr::filter(covariate_data, !year %in% new_covariates$year)
3239
rbind(new_covariates) %>%
3340
dplyr::arrange("year", "region")
3441

35-
depth_data <- read.table("Water/eden_depth.csv", header = TRUE, sep = ",") %>%
42+
depth_data <- read.table(file.path(eden_path,"eden_depth.csv"), header = TRUE, sep = ",") %>%
3643
dplyr::mutate(date=as.Date(date))
37-
new_depths <- get_eden_depths(eden_path) %>%
38-
dplyr::bind_rows(get_eden_depths(level="all")) %>%
39-
dplyr::bind_rows(get_eden_depths(level="wcas")) %>%
44+
new_depths <- get_eden_depths(eden_path = eden_path,
45+
years=years) %>%
46+
dplyr::bind_rows(get_eden_depths(eden_path = eden_path,
47+
level="all",
48+
years=years)) %>%
49+
dplyr::bind_rows(get_eden_depths(eden_path = eden_path,
50+
level="wcas",
51+
years=years)) %>%
4052
dplyr::mutate(date=as.Date(date))
4153

4254
depth_data <- dplyr::filter(depth_data, !date %in% new_depths$date) %>%
@@ -66,10 +78,10 @@ update_water <- function(eden_path) {
6678
return(cat("...No new data..."))
6779
} else {
6880

69-
write.table(data$covariate_data, "Water/eden_covariates.csv", row.names = FALSE, col.names = TRUE,
81+
write.table(data$covariate_data, file = file.path(eden_path,"eden_covariates.csv"), row.names = FALSE, col.names = TRUE,
7082
na="", sep = ",", quote = FALSE)
7183

72-
write.table(data$depth_data, file = "Water/eden_depth.csv",
84+
write.table(data$depth_data, file = file.path(eden_path,"eden_depth.csv"),
7385
row.names = FALSE, col.names = TRUE, na = "", sep = ",", quote = FALSE)
7486
}
7587
}

R/utils-pipe.R

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#' Pipe operator
2+
#'
3+
#' See \code{magrittr::\link[magrittr]{\%>\%}} for details.
4+
#'
5+
#' @name %>%
6+
#' @rdname pipe
7+
#' @keywords internal
8+
#' @export
9+
#' @importFrom magrittr %>%
10+
#' @usage lhs \%>\% rhs
11+
NULL

man/available_years.Rd

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/download_eden_depths.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/get_eden_covariates.Rd

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/get_eden_data.Rd

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)