From cac3c8eaadcf499428e3a48ef18e2bdf7f70bc08 Mon Sep 17 00:00:00 2001 From: sambhavnoobcoder <94298612+sambhavnoobcoder@users.noreply.github.com> Date: Thu, 18 Jul 2024 04:17:56 +0530 Subject: [PATCH] Implement dynamic carbon pool naming in SDA_downscale function Key Changes in this commit are as follows : - Replace fixed "carbon_data" column with dynamic naming (paste0(C_pool, "_ens", i)) - Update CNN model training to use specific carbon pool column names - Modify metrics calculation to use dynamic column names for each ensemble - Adjust ensemble processing to handle variable carbon pool names This change allows for more flexible handling of different carbon pools. Core functionality remains the same, but now supports multiple named carbon pools. --- modules/assim.sequential/R/downscale_function.R | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/assim.sequential/R/downscale_function.R b/modules/assim.sequential/R/downscale_function.R index 21cd0e0ca9..51e70903c8 100644 --- a/modules/assim.sequential/R/downscale_function.R +++ b/modules/assim.sequential/R/downscale_function.R @@ -94,7 +94,7 @@ SDA_downscale <- function(preprocessed, date, C_pool, covariates_path) { # Rename the carbon_data column for each ensemble member for (i in 1:length(ensembles)) { - colnames(ensembles[[i]])[1] <- "carbon_data" + colnames(ensembles[[i]])[1] <- paste0(C_pool, "_ens", i) } # Split the observations in each data frame into two data frames based on the proportion of 3/4 @@ -111,9 +111,9 @@ SDA_downscale <- function(preprocessed, date, C_pool, covariates_path) { for (i in 1:length(ensembles)) { # Prepare data for CNN x_train <- as.matrix(ensembles[[i]]$training[, c("tavg", "prec", "srad", "vapr")]) - y_train <- as.matrix(ensembles[[i]]$training$carbon_data) + y_train <- as.matrix(ensembles[[i]]$training[[paste0(C_pool, "_ens", i)]]) x_test <- as.matrix(ensembles[[i]]$testing[, c("tavg", "prec", "srad", "vapr")]) - y_test <- as.matrix(ensembles[[i]]$testing$carbon_data) + y_test <- as.matrix(ensembles[[i]]$testing[[paste0(C_pool, "_ens", i)]]) # Normalize the data x_train <- scale(x_train) @@ -179,7 +179,7 @@ SDA_downscale <- function(preprocessed, date, C_pool, covariates_path) { # Calculate performance metrics for each ensemble member metrics <- list() for (i in 1:length(predictions)) { - actual <- ensembles[[i]]$testing$carbon_data + actual <- ensembles[[i]]$testing[[paste0(C_pool, "_ens", i)]] predicted <- predictions[[i]] mse <- mean((actual - predicted)^2) mae <- mean(abs(actual - predicted))