diff --git a/NEWS.md b/NEWS.md index 39bc031..f0e8383 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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/). diff --git a/R/NDVI.R b/R/NDVI.R index 5957e45..9868b3f 100644 --- a/R/NDVI.R +++ b/R/NDVI.R @@ -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) @@ -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 = "")) @@ -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") %>%