Skip to content

Commit

Permalink
udpate typo in attributes file, and update code to new soils database
Browse files Browse the repository at this point in the history
  • Loading branch information
aestears committed Aug 28, 2024
1 parent a6c4713 commit 39442ce
Show file tree
Hide file tree
Showing 9 changed files with 2,844 additions and 2,781 deletions.
181 changes: 91 additions & 90 deletions functions/netcdf_functions_HPC.R

Large diffs are not rendered by default.

2,652 changes: 1,326 additions & 1,326 deletions main/CurrentAnomalyPPTData.csv

Large diffs are not rendered by default.

2,652 changes: 1,326 additions & 1,326 deletions main/CurrentAnomalyTempData.csv

Large diffs are not rendered by default.

21 changes: 11 additions & 10 deletions main/implementation/01.1_create-netcdfs.R
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,16 @@ if(today_julian <= 183) {

year(c2[year(c2) == lastYear]) <- 2023
year(c2[year(c2) == currYear]) <- 2024
year(c2[year(c2) == nextYear]) <- 2025
year(c2[year(c2) == nextYear]) <- 2025 ##AES change to not be hard coded?? (along w/ other year values))

} else {

year(c1[year(c1) == currYear]) <- 1991
year(c1[year(c1) == nextYear]) <- 1992
year(c1[year(c1) == nextYear & !is.na(c1)]) <- 1992


year(c2[year(c2) == currYear]) <- 2023
year(c2[year(c2) == nextYear]) <- 2024
year(c2[year(c2) == nextYear & !is.na(c2)]) <- 2024

}

Expand Down Expand Up @@ -240,15 +241,15 @@ for(nc in 1:106){
)

## time bounds --------------------------------
time_bounds <- if(nc_time$units == "days since 1970-01-01" && attributes$TP[nc] == 'P') {
time_bounds <- if (nc_time$units == "days since 1970-01-01" && attributes$TP[nc] == 'P') {
time_bounds_daily_p
} else if(nc_time$units == "days since 1970-01-01" && attributes$TP[nc] == 'H') {
} else if (nc_time$units == "days since 1970-01-01" && attributes$TP[nc] == 'H') {
time_bounds_daily_h
} else if(nc_time$units == "days since 1970-01-01" && attributes$TP[nc] == 'RP') {
} else if (nc_time$units == "days since 1970-01-01" && attributes$TP[nc] == 'RP') {
time_bounds_daily_rp
} else if(nc_time$units == "days since 1970-01-01" && attributes$TP[nc] == 'EH') {
} else if (nc_time$units == "days since 1970-01-01" && attributes$TP[nc] == 'EH') {
time_bounds_annually_h
} else if(nc_time$units == "days since 1970-01-01" && attributes$TP[nc] == 'EP') {
} else if (nc_time$units == "days since 1970-01-01" && attributes$TP[nc] == 'EP') {
time_bounds_annually_p
} else if (nc_time$units == 'days since 1970-01-01' && attributes$TP[nc] == 'OC') {
time_bounds_March
Expand Down Expand Up @@ -304,8 +305,8 @@ for(nc in 1:106){
data = western_region.nc1[["data"]],
data_str = "xyzt",
data_dims = data_dims_nc,
vertical_values = 1:30,
vertical_attributes = list(units = "simulationNumber", positive = "up"),
simAxis_values = 1:30,
simAxis_attributes = list(units = "simulationNumber", positive = "up"),
var_attributes = nc_vars,
xy_attributes = nc_att_xy,
crs_attributes = nc_att_crs,
Expand Down
2 changes: 1 addition & 1 deletion main/implementation/01.2_input-values-into-ncdfs.R
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ for(n in seq_along(netCDFnames)){
if (valueName_short[n] == "oconnor-stemp_95CI_upper") {
vals <- c(Oconnor_Stats[TP == "Forecast",]$sTemp_mean) + c(Oconnor_Stats[TP == "Forecast",]$sTemp_CI95)
}
}
}
if (valueName_short[n] == "shriver_historical") vals <- c(Shriver_Stats[TP == 'Historical', 'Prob'])[["Prob"]]
if (valueName_short[n] == "shriver_prediction") {
vals <- c(Shriver_Stats[TP != 'Historical', 'Prob'])$Prob
Expand Down
53 changes: 29 additions & 24 deletions main/implementation/01_main-simulation-runner.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ rm(list=ls(all=TRUE))
# LDFLAGS=-L/sw/lib LIBS=-lhdf5 --with-mpicc=mpicc --with-mpiexec=mpiexec" \
# RNetCDF_2.9-1.tar.gz

remotes::install_github("DrylandEcology/rSW2st")
remotes::install_github("DrylandEcology/rSOILWAT2", build_vignettes = FALSE)
remotes::install_github("DrylandEcology/rSW2funs")
#remotes::install_github("DrylandEcology/rSW2st")
#remotes::install_github("DrylandEcology/rSOILWAT2", build_vignettes = FALSE)
#remotes::install_github("DrylandEcology/rSW2funs")
suppressMessages(library(rSOILWAT2, quiet = TRUE))

suppressMessages(library(rSW2data, quiet = TRUE))
Expand All @@ -26,7 +26,7 @@ suppressMessages(library(RNetCDF, quiet = TRUE))
suppressMessages(library(ncdf4, quiet = TRUE))

# variables --------------------------------------------------------------------
isParallel <- TRUE # set to FALSE if you dont want to use pbdMPI to execute runs in parallel
isParallel <- FALSE # set to FALSE if you dont want to use pbdMPI to execute runs in parallel
nRuns = 30 #is 30 for point based netCDF, but changed to 5 here for testing purposes (this is the number of simulations for each grid?? I think? )

# Begin ------------------------------------------------------------------------
Expand Down Expand Up @@ -65,14 +65,14 @@ Sites <- as.data.frame(data.table::fread("main/Data/WeatherDBSitesTable_WestInde
sites <- dim(Sites)[1]

# load gridded soils data from Daniel (currently an old version, will be updated w/ SOLUS100 data)
soils_gridClay <- RNetCDF::open.nc(con = "./main/Data/soilsDB/slclay_fx_SOILWAT2_wUS-gm_gn.nc")
soils_gridSand <- RNetCDF::open.nc(con = "./main/Data/soilsDB/slsand_fx_SOILWAT2_wUS-gm_gn.nc")
soils_gridSilt <- RNetCDF::open.nc(con = "./main/Data/soilsDB/slsilt_fx_SOILWAT2_wUS-gm_gn.nc")
soils_gridDensity <- RNetCDF::open.nc(con = "./main/Data/soilsDB/slbdensity_fx_SOILWAT2_wUS-gm_gn.nc")
soils_gridThickness <- RNetCDF::open.nc(con = "./main/Data/soilsDB/slthick_fx_SOILWAT2_wUS-gm_gn.nc")
soils_gridCoarse <- RNetCDF::open.nc(con = "./main/Data/soilsDB/slcoarse_fx_SOILWAT2_wUS-gm_gn.nc")
soilGridLats <- var.get.nc(soils_gridClay, "lat")
soilGridLons <- var.get.nc(soils_gridClay, "lon")
soils_gridClay <- RNetCDF::open.nc(con = "./main/Data/soilsDB_new/claytotal_PED-CONUS4km_SOLUS100.nc")
soils_gridSand <- RNetCDF::open.nc(con = "./main/Data/soilsDB_new/sandtotal_PED-CONUS4km_SOLUS100.nc")
soils_gridSilt <- RNetCDF::open.nc(con = "./main/Data/soilsDB_new/silttotal_PED-CONUS4km_SOLUS100.nc")
soils_gridDensity <- RNetCDF::open.nc(con = "./main/Data/soilsDB_new/dbovendry_PED-CONUS4km_SOLUS100.nc")
soils_gridThickness <- RNetCDF::open.nc(con = "./main/Data/soilsDB_new/hzthk_PED-CONUS4km_SOLUS100.nc")
soils_gridCoarse <- RNetCDF::open.nc(con = "./main/Data/soilsDB_new/fragvol_PED-CONUS4km_SOLUS100.nc")
soilGridLats <- var.get.nc(soils_gridClay, "latitude")
soilGridLons <- var.get.nc(soils_gridClay, "longitude")

if(isParallel) {
alljid <- get.jid(n = sites, method = "block", all = FALSE)
Expand Down Expand Up @@ -152,23 +152,28 @@ for (j in 1:2){#alljid) { # TO DO: use "while" not "for"

### get soils data for this gridcell
# get indices for soil grid Lat and Lon
soilLat_i <- which(round(soilGridLats,5)==round(Lat,5))
soilLon_i <- which(round(soilGridLons,5)==round(Long,5))
# the closest latitude
soilLat_i <- which((soilGridLats-Lat) == min(abs(soilGridLats - Lat)))

# the closest longitude
soilLon_i <- which((soilGridLons-Long) == min(abs(soilGridLons-Long)))
#round(soilGridLons,2)==round(Long,2))
#clay
clay_i <- var.get.nc(soils_gridClay, "slclay", start = c(soilLon_i, soilLat_i,1),
count = c(1,1,12))
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
sand_i <- var.get.nc(soils_gridSand, "slsand", start = c(soilLon_i, soilLat_i,1),
count = c(1,1,12))
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
silt_i <- var.get.nc(soils_gridSilt, "slsilt", start = c(soilLon_i, soilLat_i,1),
count = c(1,1,12))
#silt
coarse_i <- var.get.nc(soils_gridCoarse, "slcoarse", start = c(soilLon_i, soilLat_i,1),
count = c(1,1,12))
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
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))
#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))

Expand Down Expand Up @@ -363,7 +368,7 @@ for (j in 1:2){#alljid) { # TO DO: use "while" not "for"
if(!interactive() & isParallel) comm.print('Inserting into netCDFs.', Sys.time())


#TO DO: Make this into a function not a script #AES not working as of 3/4/24
#TO DO: Make this into a function not a script
source('./main/implementation/01.2_input-values-into-ncdfs.R')

}
Expand Down
2 changes: 1 addition & 1 deletion main/implementation/nc_atts-all.csv
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ swp-deep_90_diff,NearFut.SWP.Deep.diffs.90,swp-deep_dy_gridSTDF_90pct-diffs_pred
shriver_historical,,shriver_yr_gridSTDF_historical,probability,probability of sagebrush seeding success,,Historical Probability of Sagebrush Seeding Success ,"Based on Shriver, R.K. et al. (2018). Adapting management to a changing world: Warm temperatures, dry soil, and inter-annual variability limit restoration success of dominant woody shrub in temperate drylands. Global Change Biology. 24","Historical climate data (1991 - last year) is run through Soilwat. Results are used to generate probabilities of seeding success in previous years, based upon the model presented in Shriver et al. 2018.",time: mean within days time: mean over years,days since 1970-01-01,1,32,EH,timeseries
shriver_prediction,,shriver_yr_gridSTDF_prediction,probability,probability of sagebrush seeding success,,Future Sagebrush Seeding Success for the current year and next year (for 30 realizations of T&P anomalies),"Based on Shriver, R.K. et al. (2018). Adapting management to a changing world: Warm temperatures, dry soil, and inter-annual variability limit restoration success of dominant woody shrub in temperate drylands. Global Change Biology. 24","30 realizations of the current year are generated via multivariate sampling based upon by NWS 'long-lead forecasts' anomalies for temperature and precipitation. These realizations are run through Soilwat. Results are used to generate probabilities of seeding success in the current and next year, based upon the model presented in Shriver et al. 2018. There are data for two years (the t dimension = 2), and 30 values for each year, which are stored along the ""z"" axis ",time: mean within days time: mean over years,days since 1970-01-01,1,2,EP,timeseries
GISSM_historical,,GISSM_yr_gridSTDF_historical,probability,probability (frequency) of years when big sagebrush seedlings survive in undisturbed natural vegetation,,Historical Mean Establishment,"Based on Schlaepfer, D. R. et al. (2014). Modeling regeneration responses of big sagebrush (Artemisia tridentata) to abiotic conditions. Ecological Modelling. 286 https://doi.org/10.1016/j.ecolmodel.2014.04.021",Historical climate data (1991 - last year) is run through Soilwat. Results are the probability (frequency) of years when big sagebrush seedlings survive in undisturbed natural vegetation,time: mean within days time: mean over years,days since 1970-01-01,1,32,EH,timeseries
GISSM_prediction,,GISSM_yr_gridSTDF_prediction,probability,probability (frequency) of years when big sagebrush seedlings survive in undisturbed natural vegetation,,Future Establishment Probability for the current year and the next year (for 30 realizations of T&P anomalies),"Based on Schlaepfer, D. R. et al. (2014). Modeling regeneration responses of big sagebrush (Artemisia tridentata) to abiotic conditions. Ecological Modelling. 286 https://doi.org/10.1016/j.ecolmodel.2014.04.021","30 realizations of the current year are generated via multivariate sampling based upon by NWS 'long-lead forecasts' anomalies for temperature and precipitation. These realizations are run through Soilwat. Results represent the probability (frequency) of realization of the current and next year when big sagebrush seedlings survive in undisturbed natural vegetation. ; There are data for two years (the t dimension = 2), and 30 values for each year, which are stored along the ""z"" axis ",time: mean within days time: mean over years,days since 1970-01-01,1,2,OC,timeseries
GISSM_prediction,,GISSM_yr_gridSTDF_prediction,probability,probability (frequency) of years when big sagebrush seedlings survive in undisturbed natural vegetation,,Future Establishment Probability for the current year and the next year (for 30 realizations of T&P anomalies),"Based on Schlaepfer, D. R. et al. (2014). Modeling regeneration responses of big sagebrush (Artemisia tridentata) to abiotic conditions. Ecological Modelling. 286 https://doi.org/10.1016/j.ecolmodel.2014.04.021","30 realizations of the current year are generated via multivariate sampling based upon by NWS 'long-lead forecasts' anomalies for temperature and precipitation. These realizations are run through Soilwat. Results represent the probability (frequency) of realization of the current and next year when big sagebrush seedlings survive in undisturbed natural vegetation. ; There are data for two years (the t dimension = 2), and 30 values for each year, which are stored along the ""z"" axis ",time: mean within days time: mean over years,days since 1970-01-01,1,2,EP,timeseries
oconnor-swp_mean,,oconnor-swp_dy_gridSTDF_mean-prediction,swp,soil_water_potential,MPa,Daily Soil Water Potential in 0 - 5 cm soil depth for the month of March in the upcoming year,Based on O'Connor et al. (2020). Small scale water deficits after wildfires create long-lasting ecological impacts. Environmental Research Letters. 15(4),,time: mean within days time: mean over days,days since 1970-01-01,1,31,OC,timeseries
oconnor-swp_95CI_lower,,oconnor-swp_dy_gridSTDF_95CI_lower-prediction,swp,soil_water_potential,MPa,Daily Soil Water Potential in 0 - 5 cm soil depth for the month of March in the upcoming year,Based on O'Connor et al. (2020). Small scale water deficits after wildfires create long-lasting ecological impacts. Environmental Research Letters. 15(4),,time: mean within days time: mean over days,days since 1970-01-01,1,31,OC,timeseries
oconnor-swp_95CI_upper,,oconnor-swp_dy_gridSTDF_95CI_upper-prediction,swp,soil_water_potential,MPa,Daily Soil Water Potential in 0 - 5 cm soil depth for the month of March in the upcoming year,Based on O'Connor et al. (2020). Small scale water deficits after wildfires create long-lasting ecological impacts. Environmental Research Letters. 15(4),,time: mean within days time: mean over days,days since 1970-01-01,1,31,OC,timeseries
Expand Down
22 changes: 22 additions & 0 deletions main/test_code/TestGISSMOutput.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# determining the accuracy of GISSM output
# Alice Stears
# 27 August 2024


# load packages -----------------------------------------------------------

library(tidyverse)
library(RNetCDF)
library(terra)

# Load data ---------------------------------------------------------------

gissm_hist <- terra::rast(x = "./projects/07_TestOutputForFRESC/trimmed_netCDFs/GISSM_yr_gridSTDF_historical_042024.nc")
gissm_pred <- terra::rast(x = "./outputs/20240827/GISSM_yr_gridSTDF_prediction_082024.nc", drivers="NETCDF")

# get the prediction data as a netCDF
gissm_pred_nc <- open.nc("./outputs/20240827/GISSM_yr_gridSTDF_prediction_082024.nc")
# 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))

RNetCDF::print.nc(gissm_pred_nc)
40 changes: 37 additions & 3 deletions projects/07_TestOutputForFRESC/GenerateOutputForFRESC.R
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,16 @@ Sites <- whichSites

sites <- dim(Sites)[1]

# load gridded soils data from Daniel (currently an old version, will be updated w/ SOLUS100 data)
soils_gridClay <- RNetCDF::open.nc(con = "./main/Data/soilsDB/slclay_fx_SOILWAT2_wUS-gm_gn.nc")
soils_gridSand <- RNetCDF::open.nc(con = "./main/Data/soilsDB/slsand_fx_SOILWAT2_wUS-gm_gn.nc")
soils_gridSilt <- RNetCDF::open.nc(con = "./main/Data/soilsDB/slsilt_fx_SOILWAT2_wUS-gm_gn.nc")
soils_gridDensity <- RNetCDF::open.nc(con = "./main/Data/soilsDB/slbdensity_fx_SOILWAT2_wUS-gm_gn.nc")
soils_gridThickness <- RNetCDF::open.nc(con = "./main/Data/soilsDB/slthick_fx_SOILWAT2_wUS-gm_gn.nc")
soils_gridCoarse <- RNetCDF::open.nc(con = "./main/Data/soilsDB/slcoarse_fx_SOILWAT2_wUS-gm_gn.nc")
soilGridLats <- var.get.nc(soils_gridClay, "lat")
soilGridLons <- var.get.nc(soils_gridClay, "lon")

alljid <- sites


Expand Down Expand Up @@ -111,7 +121,7 @@ suppressWarnings(source('./main/implementation/01.1_create-netcdfs.R')) # TO DO:
################### ------------------------------------------------------------
# Run simulation --------------------------------------------------------------

for (j in 1:alljid){#1:alljid) { # TO DO: use "while" not "for"
for (j in 1:10){#alljid){#1:alljid) { # TO DO: use "while" not "for"
i <- j

################### ------------------------------------------------------------
Expand Down Expand Up @@ -152,16 +162,40 @@ for (j in 1:alljid){#1:alljid) { # TO DO: use "while" not "for"
wdata[[names(wdata)[k]]]@data[wdata[[names(wdata)[k]]]@data[, "Tmax_C"] < wdata[[names(wdata)[k]]]@data[, "Tmin_C"], "Tmax_C"]
}
}

### get soils data for this gridcell
# get indices for soil grid Lat and Lon
soilLat_i <- which(round(soilGridLats,5)==round(Lat,5))
soilLon_i <- which(round(soilGridLons,5)==round(Long,5))
#clay
clay_i <- var.get.nc(soils_gridClay, "slclay", start = c(soilLon_i, soilLat_i,1),
count = c(1,1,12))
#sand
sand_i <- var.get.nc(soils_gridSand, "slsand", start = c(soilLon_i, soilLat_i,1),
count = c(1,1,12))
#silt
silt_i <- var.get.nc(soils_gridSilt, "slsilt", start = c(soilLon_i, soilLat_i,1),
count = c(1,1,12))
#silt
coarse_i <- var.get.nc(soils_gridCoarse, "slcoarse", start = c(soilLon_i, soilLat_i,1),
count = c(1,1,12))
#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
bulkdensity_i <- var.get.nc(soils_gridDensity, "slbdensity", start = c(soilLon_i, soilLat_i,1),
count = c(1,1,12))

################### ----------------------------------------------------------
# Part 2 - Sets SW parameters besides weather
################### ----------------------------------------------------------
#setting soilWat specific options
#sw_in <- new("swInputData") # baseline data # new() creates an empty object of this class, but everything needs to be addedd manually... which may be cumbersome
sw_in <- swInputData()
sw_in <- setVeg(sw_in, AllProdInfo, i)
sw_in <- setSW(sw_in, Lat, Long, clim)
sw_in <- setSW(sw_in, Lat, Long, clim,
clay_i, sand_i, silt_i, coarse_i, thickness_i, bulkdensity_i)
#sw_in <- set_soils(sw_in, 2, 35, 35) #AES is done elsewhere in the setSW() function
sw_in@site@SoilTemperatureFlag <- TRUE # turns off the soil temp option #AES follow-up with Caitlin why it was turned off?
sw_in@site@SoilTemperatureFlag <- TRUE # turns on the soil temperature
swCarbon_Use_Bio(sw_in) <- FALSE # turns off carbon #turns off CO2 fertilization effects... something we could potentially change
swCarbon_Use_WUE(sw_in) <- FALSE # turns off Water use efficiency
swYears_EndYear(sw_in) <- currYear - 1 # the setting for the historical simulation
Expand Down

0 comments on commit 39442ce

Please sign in to comment.