Skip to content

Commit daeb89f

Browse files
committed
Include temporal aggregtion per month prior to aggregation per season
1 parent 3dbdb81 commit daeb89f

2 files changed

Lines changed: 30 additions & 8 deletions

File tree

R/seasonal_index_per_pixel.R

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,30 @@
1414
#' this mode should be checked before use.
1515
#' @param pixelQualityThreshold Numeric between 0 and 1. Minimum water-scene
1616
#' 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.
1719
#'
1820
#' @return A list with `x`, `y`, `crs`, `year`, `QualityThreshold`, `RSindex`, and
1921
#' `sceneProportions`. `RSindex` is a matrix of seasonal pixel index values;
2022
#' pixels below the water-quality threshold are set to `NA`.
2123
#'
2224
#' @details Water-scene proportions are calculated by [waterscene_proportion()].
2325
#' 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.
2429
#'
2530
#' @export
2631
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
2834
){
2935
output <- list()
3036
#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))
3239
imageYear <- unique(as.numeric(format(imageIndex$t_date, "%Y")))
3340

34-
cat("Loading values of SCL Band ... \n")
3541
sclt <- load_BandLayer(
3642
nc = nc,
3743
band = "SCL",
@@ -65,10 +71,19 @@ seasonal_index_per_pixel <- function(
6571
)
6672
}
6773

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+
}
7287

7388
waterLayer <- lakeRS::waterscene_proportion(scl_image = sclt$band)
7489

man/seasonal_index_per_pixel.Rd

Lines changed: 8 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)