Skip to content

Commit

Permalink
add combination of temp and precip sd correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisJones687 committed Sep 24, 2023
1 parent c8107cb commit ae4891d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
5 changes: 4 additions & 1 deletion R/configuration.R
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,10 @@ configuration <- function(config) {

weather_coefficient_stack <- weather_coefficient_stack * precipitation_coefficient
if (config$weather_type == "probabilistic") {
weather_coefficient_sd_stack <- weather_coefficient_sd_stack * precipitation_coefficient_sd
# compute sd from combined sd of the two rasters hard coded 10 years as our current
weather_coefficient_sd_stack <-
combined_sd(temperature_coefficient_sd, precipitation_coefficient_sd,
temperature_coefficient, precipitation_coefficient, 10, 10)
}
}
} else if (config$precip == TRUE) {
Expand Down
6 changes: 6 additions & 0 deletions R/helpers.R
Original file line number Diff line number Diff line change
Expand Up @@ -264,3 +264,9 @@ output_from_raster_mean_and_sd <- function(x) {
x2 <- suppressWarnings(terra::app(x, fun))
return(x2)
}

# Combine two standard deviation spatRasters
combined_sd <- function(v1, v2, m1, m2, n1, n2) {
(((n1 - 1) * v1 + (n2 - 1) * v2) / (n1 + n2 -1)) +
(((n1 * n2) * (m1 - m2)^2) / ((n1 +n2) * (n1 + n2 -1)))
}

0 comments on commit ae4891d

Please sign in to comment.