|
14 | 14 | #' this mode should be checked before use. |
15 | 15 | #' @param pixelQualityThreshold Numeric between 0 and 1. Minimum water-scene |
16 | 16 | #' proportion required for a pixel to be retained in the seasonal index. |
| 17 | +#' @param per_month_first Logical, If `TRUE`, the index is first averaged on a |
| 18 | +#' monthly basis and than averaged for the whole season. |
17 | 19 | #' |
18 | 20 | #' @return A list with `x`, `y`, `crs`, `year`, `QualityThreshold`, `RSindex`, and |
19 | 21 | #' `sceneProportions`. `RSindex` is a matrix of seasonal pixel index values; |
20 | 22 | #' pixels below the water-quality threshold are set to `NA`. |
21 | 23 | #' |
22 | 24 | #' @details Water-scene proportions are calculated by [waterscene_proportion()]. |
23 | 25 | #' A warning is issued if no pixel meets `pixelQualityThreshold`. |
| 26 | +#' |
| 27 | +#' The idea of per_month_first is to create a balanced mean throughout the |
| 28 | +#' season, independently of cloudy or sunny periods over a long time. |
24 | 29 | #' |
25 | 30 | #' @export |
26 | 31 | seasonal_index_per_pixel <- function( |
27 | | - imageIndex, nc, water_scenes_only = TRUE, pixelQualityThreshold = 0.8 |
| 32 | + imageIndex, nc, water_scenes_only = TRUE, pixelQualityThreshold = 0.8, |
| 33 | + per_month_first = TRUE |
28 | 34 | ){ |
29 | 35 | output <- list() |
30 | 36 | #output[["lakeInfo"]] <- lakeInfo |
31 | | - imageMonths <- unique(as.numeric(format(imageIndex$t_date, "%m"))) |
| 37 | + imageMonthsVector <- format(imageIndex$t_date, "%m") |
| 38 | + imageMonths <- unique(as.numeric(imageMonthsVector)) |
32 | 39 | imageYear <- unique(as.numeric(format(imageIndex$t_date, "%Y"))) |
33 | 40 |
|
34 | | - cat("Loading values of SCL Band ... \n") |
35 | 41 | sclt <- load_BandLayer( |
36 | 42 | nc = nc, |
37 | 43 | band = "SCL", |
@@ -65,10 +71,19 @@ seasonal_index_per_pixel <- function( |
65 | 71 | ) |
66 | 72 | } |
67 | 73 |
|
68 | | - RSindex <- pixel_wise_average( |
69 | | - list_of_mats = imageIndex$RSindex, |
70 | | - na.rm = TRUE |
71 | | - ) |
| 74 | + if(per_month_first){ |
| 75 | + monthlySplitIndex <- split(x = imageIndex$RSindex, f = imageMonthsVector) |
| 76 | + RSindexMonth <- lapply(monthlySplitIndex, pixel_wise_average, na.rm = TRUE) |
| 77 | + RSindex <- pixel_wise_average( |
| 78 | + list_of_mats = RSindexMonth, |
| 79 | + na.rm = TRUE |
| 80 | + ) |
| 81 | + } else { |
| 82 | + RSindex <- pixel_wise_average( |
| 83 | + list_of_mats = imageIndex$RSindex, |
| 84 | + na.rm = TRUE |
| 85 | + ) |
| 86 | + } |
72 | 87 |
|
73 | 88 | waterLayer <- lakeRS::waterscene_proportion(scl_image = sclt$band) |
74 | 89 |
|
|
0 commit comments