File I/O
1 Overview
WaterGAP3 uses the armadillo binary format for all data files. The WG3Tools package provides helper functions for reading and writing these files: .fmat for matrices and .fvec for vectors.
library(WaterGAP3Cpp)
library(WG3Tools)
path_Root <- "/projects/WaterGAP/WaterGAP3M/ProjectRun/Demo/Data/"
str_Continent <- c("eu", "af", "as", "au", "na", "sa")
names(str_Continent) <- str_Continent2 Write a matrix to .fmat
mat_Arma_TEST <- matrix(runif(n_Cell_Conti["eu"] * 10), n_Cell_Conti["eu"], 10)
save_fmat(mat_Arma_TEST, paste0(path_Root, "mat_Arma_TEST.fmat"))3 Load parameter vectors (.fvec) for all continents
lst_param_INFILT_hbv_beta <- purrr::map(str_Continent, \(idx_Conti) {
load_fvec(paste0(
path_Root, "HydroParam/",
"param_INFILT_hbv_beta_", idx_Conti, ".fvec"
))
})4 Raster conversion
Convert WaterGAP3 vector data to raster format for visualisation or further analysis. The examples below use a parameter vector loaded via the helper functions described in File I/O.
4.1 Single continent
rst_HBV_beta_eu <- wg3_2_raster(lst_param_INFILT_hbv_beta$eu, "eu")
plot(rst_HBV_beta_eu)4.2 Global (all continents combined)
rst_HBV_beta <- wg3_2_raster_global(lst_param_INFILT_hbv_beta)
plot(rst_HBV_beta)