Skip to content

Commit

Permalink
Merge pull request #306 from weecology/ndvi
Browse files Browse the repository at this point in the history
Filter NDVI by sensor before configuring time, closes #287
  • Loading branch information
gmyenni authored Sep 19, 2024
2 parents 387ffc7 + 6af1a46 commit 6597af0
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* `load_rodent_data()` now returns an object with an S3 class, and provides a useful message on `print`.
* Users can now pass arguments to `download_observations()` from `load_rodent_data()` and other calling functions.
* Fix bug in `na_drop = FALSE` that failed to complete missing rows to the species level when `time = "newmoon"`.
* Fix bug in `ndvi()` that filtered by sensor only for higher levels.

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

Expand Down
7 changes: 3 additions & 4 deletions R/NDVI.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ ndvi <- function(level = "monthly", sensor = "landsat", fill = FALSE,

NDVI <- load_datafile(file.path("NDVI", "ndvi.csv"),
na.strings = "", path = path,
download_if_missing = download_if_missing)
download_if_missing = download_if_missing) %>%
dplyr::filter(.data$sensor %in% filtering)
moon_dates <- load_datafile(file.path("Rodents", "moon_dates.csv"),
na.strings = "", path = path,
download_if_missing = download_if_missing)
Expand All @@ -34,14 +35,13 @@ ndvi <- function(level = "monthly", sensor = "landsat", fill = FALSE,
if (level == "monthly") {

NDVI <- NDVI %>%
dplyr::filter(.data$sensor %in% filtering) %>%
dplyr::mutate(date = as.Date(paste(.data$year, .data$month, "01", sep = "-"))) %>%
dplyr::group_by(.data$year, .data$month) %>%
dplyr::summarize(ndvi = mean(.data$ndvi, na.rm = T),
date = min(.data$date)) %>%
dplyr::arrange(.data$date) %>%
dplyr::ungroup() %>%
dplyr::select( "date", "ndvi")
dplyr::select("date", "ndvi")
if (fill) {
curr_yearmonth <- format(Sys.Date(), "%Y-%m")
last_time <- as.Date(paste(curr_yearmonth, "-01", sep = ""))
Expand All @@ -63,7 +63,6 @@ ndvi <- function(level = "monthly", sensor = "landsat", fill = FALSE,

NDVI$newmoonnumber <- nm_match_number[match(as.Date(NDVI$date), nm_match_date)]
NDVI <- NDVI %>%
dplyr::filter(.data$sensor %in% filtering) %>%
dplyr::group_by(.data$newmoonnumber) %>%
dplyr::summarize(ndvi = mean(.data$ndvi, na.rm = T)) %>%
tidyr::drop_na("newmoonnumber") %>%
Expand Down

0 comments on commit 6597af0

Please sign in to comment.