Skip to content

Commit

Permalink
Implement dynamic carbon pool naming in SDA_downscale function
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sambhavnoobcoder authored Jul 17, 2024
1 parent f2bab83 commit cac3c8e
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions modules/assim.sequential/R/downscale_function.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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))
Expand Down

0 comments on commit cac3c8e

Please sign in to comment.