From 8a9bc9c36c69dae9e2ca0b2daf4b90f0ed7d9742 Mon Sep 17 00:00:00 2001 From: Alice Stears Date: Wed, 28 Aug 2024 13:50:13 -0600 Subject: [PATCH] updating code to run w/ new soils data --- .../01_main-simulation-runner.R | 47 +++++++++++++------ main/test_code/TestGISSMOutput.R | 3 ++ 2 files changed, 35 insertions(+), 15 deletions(-) diff --git a/main/implementation/01_main-simulation-runner.R b/main/implementation/01_main-simulation-runner.R index 92bc3ca..5bf7627 100644 --- a/main/implementation/01_main-simulation-runner.R +++ b/main/implementation/01_main-simulation-runner.R @@ -158,25 +158,42 @@ for (j in 1:2){#alljid) { # TO DO: use "while" not "for" # the closest longitude soilLon_i <- which((soilGridLons-Long) == min(abs(soilGridLons-Long))) #round(soilGridLons,2)==round(Long,2)) - #clay + #clay (as a percentage...convert to a fraction by dividing by 100) clay_i <- var.get.nc(soils_gridClay, "claytotal", start = c(soilLon_i, soilLat_i,1), - count = c(1,1,dim.inq.nc(soils_gridClay, "vertical")$length)) - #sand + count = c(1,1,dim.inq.nc(soils_gridClay, "vertical")$length))/100 + #sand (as a percentage...convert to a fraction by dividing by 100) sand_i <- var.get.nc(soils_gridSand, "sandtotal", start = c(soilLon_i, soilLat_i,1), - count = c(1,1,dim.inq.nc(soils_gridSand, "vertical")$length)) - #silt + count = c(1,1,dim.inq.nc(soils_gridSand, "vertical")$length))/100 + #silt (as a percentage...convert to a fraction by dividing by 100) silt_i <- var.get.nc(soils_gridSilt, "silttotal", start = c(soilLon_i, soilLat_i,1), - count = c(1,1,dim.inq.nc(soils_gridSilt, "vertical")$length)) - #coarse material + count = c(1,1,dim.inq.nc(soils_gridSilt, "vertical")$length))/100 + #coarse material (as a percentage...convert to a fraction by dividing by 100) coarse_i <- var.get.nc(soils_gridCoarse, "fragvol", start = c(soilLon_i, soilLat_i,1), - count = c(1,1,dim.inq.nc(soils_gridCoarse, "vertical")$length)) + count = c(1,1,dim.inq.nc(soils_gridCoarse, "vertical")$length))/100 #thickness - thickness_i <- 100*var.get.nc(soils_gridThickness, "slthick", start = c(soilLon_i, soilLat_i,1), - count = c(1,1,12)) # also convert thickness to centimeters from meters - # bulk density - bulkdensity_i <- var.get.nc(soils_gridDensity, "slbdensity", start = c(soilLon_i, soilLat_i,1), - count = c(1,1,12)) - + thickness_i <- var.get.nc(soils_gridThickness, "hzthk", start = c(soilLon_i, soilLat_i,1), + count = c(1,1,dim.inq.nc(soils_gridThickness, "vertical")$length)) + # units are in cm + + bulkdensity_i <- var.get.nc(soils_gridDensity, "dbovendry", start = c(soilLon_i, soilLat_i,1), + count = c(1,1,dim.inq.nc(soils_gridDensity, "vertical")$length)) # units = g/cm3 + + ## get the depths also (the "vertical_bnds" dimension contains a matrix with + # the upper and lower bounds of each depth band--we want the lower bounds) + + depths_i <- var.get.nc(soils_gridThickness, "vertical_bnds")[2,] + ##AES this part below is a test... see what other folks think about this... + # trim soils data so that there are not NAs (the data stops at the depth for which we have data) + # also get the depths for the layers included + depths_i <- depths_i[!is.na(clay_i)] + clay_i <- clay_i[!is.na(clay_i)] + sand_i <- sand_i[!is.na(sand_i)] + silt_i <- silt_i[!is.na(silt_i)] + coarse_i <- coarse_i[!is.na(coarse_i)] + thickness_i <- thickness_i[!is.na(thickness_i)] + bulkdensity_i <- bulkdensity_i[!is.na(bulkdensity_i)] + + # depths ################### ---------------------------------------------------------- # Part 2 - Sets SW parameters besides weather ################### ---------------------------------------------------------- @@ -202,7 +219,7 @@ for (j in 1:2){#alljid) { # TO DO: use "while" not "for" # could be problematic if some soils are shallow--maybe should indicate how much depth is represented in each Soils <- data.frame(sw_in@soils@Layers)[,c('depth_cm', 'sand_frac', 'clay_frac')] - Soils$width <- diff(c(0, Soils$depth_cm)) + Soils$width <- thickness_i#diff(c(0, Soils$depth_cm)) SoilsDF <- merge(Soils, SoilsDF, by = 'depth_cm') SoilsDF$variable <- paste0('Lyr_',1:dim(SoilsDF)[1]) diff --git a/main/test_code/TestGISSMOutput.R b/main/test_code/TestGISSMOutput.R index b953d30..0038b31 100644 --- a/main/test_code/TestGISSMOutput.R +++ b/main/test_code/TestGISSMOutput.R @@ -19,4 +19,7 @@ gissm_pred_nc <- open.nc("./outputs/20240827/GISSM_yr_gridSTDF_prediction_082024 # get the data in the netcdf test <- var.get.nc(gissm_pred_nc, variable = "probability")#, start = c(194, 435, 1, 1), count = c(10, 1, 30, 2)) +LonDat<- RNetCDF::var.get.nc(gissm_pred_nc, variable = "simulation") + RNetCDF::print.nc(gissm_pred_nc) +