Skip to content

Commit

Permalink
updating code to run w/ new soils data
Browse files Browse the repository at this point in the history
  • Loading branch information
aestears committed Aug 28, 2024
1 parent 8685746 commit 8a9bc9c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 15 deletions.
47 changes: 32 additions & 15 deletions main/implementation/01_main-simulation-runner.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
################### ----------------------------------------------------------
Expand All @@ -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])

Expand Down
3 changes: 3 additions & 0 deletions main/test_code/TestGISSMOutput.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 8a9bc9c

Please sign in to comment.