Skip to content

Commit

Permalink
Update files
Browse files Browse the repository at this point in the history
  • Loading branch information
dinilu committed Dec 18, 2024
1 parent be69cc9 commit cd3810e
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Description: The package provides to ease the use of climate4R R-package to down
License: GPL (>= 3)
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.1
RoxygenNote: 7.3.1
LazyData: true
Imports:
climate4R.UDG,
Expand Down
10 changes: 5 additions & 5 deletions R/CMIP5_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ loadCMIP5 <- function(indir, rcp, mod, vars = NULL, cmip5_vars = NULL, lon_lim =
downscaleCMIP5 <- function(rcp, mod, indir, uerra, outdir, vars = NULL, cmip5_vars = NULL, lon_lim = c(-11, 12), lat_lim = c(28, 44), years = 1991:2100, dictionary = system.file("extdata", "CMIP5_dictionary.csv", package = "dsclim"), method = "GLM", family_link = stats::gaussian(link = "identity"), local.predictors = NULL, global.vars = NULL, spatial.predictors = NULL, extended.predictors = NULL, combined.only = TRUE, globalAttributes = NULL) {
y.var <- uerra$Variable$varName

if (!dir.exists(paste0(outdir, rcp, "/", mod, "/", y.var, "/dat"))) {
dir.create(paste0(outdir, rcp, "/", mod, "/", y.var, "/dat"), recursive = TRUE)
if (!dir.exists(paste0(outdir, "/", rcp, "/", mod, "/", y.var))) {
dir.create(paste0(outdir, "/", rcp, "/", mod, "/", y.var), recursive = TRUE)
}

if (is.null(cmip5_vars)) {
Expand Down Expand Up @@ -171,19 +171,19 @@ downscaleCMIP5 <- function(rcp, mod, indir, uerra, outdir, vars = NULL, cmip5_va

pred$Data <- round(pred$Data, 2)

# loadeR.2nc::grid2nc(pred, NetCDFOutFile = paste0(outdir, rcp, "/", mod, "/", y.var, "/", y.var, "1991-2100.nc"), missval = -9999, globalAttributes = globalAttributes)
# loadeR.2nc::grid2nc(pred, NetCDFOutFile = paste0(outdir, "/", rcp, "/", mod, "/", y.var, "/", y.var, "1991-2100.nc"), missval = -9999, globalAttributes = globalAttributes)

for (i in 1:length(years)) {
message("SAVING YEAR: ", years[i])
y <- years[i]
yBP <- (years - 1950)[i]
pred_i <- transformeR::subsetGrid(pred, years = y)

loadeR.2nc::grid2nc(pred_i, NetCDFOutFile = paste0(outdir, rcp, "/", mod, "/", y.var, "/", y.var, yBP, ".nc"), missval = -9999, globalAttributes = globalAttributes)
loadeR.2nc::grid2nc(pred_i, NetCDFOutFile = paste0(outdir, "/", rcp, "/", mod, "/", y.var, "/", y.var, yBP, ".nc"), missval = -9999, globalAttributes = globalAttributes)

# pred_df <- grid2spatialdf(pred_i)

# file_name <- paste0(outdir, rcp, "/", mod, "/", y.var, "/dat/", y.var, yBP, ".dat")
# file_name <- paste0(outdir, "/", rcp, "/", mod, "/", y.var, "/dat/", y.var, yBP, ".dat")
# utils::write.table(pred_df, file = file_name, sep = "\t")
}
return("Done")
Expand Down
4 changes: 2 additions & 2 deletions R/TraCE21ka_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -297,8 +297,8 @@ loadTraceGrid <- function(file, var, lon_lim = c(-25, 25), lat_lim = c(25, 50),
downscaleTrace <- function(files_n, indir, outdir, mod_data, model, model_bin = NULL, vars = NULL, lon_lim = c(-25, 25), lat_lim = c(25, 50), selection_vars = NULL, globalAttributes = NULL) {
y.var <- mod_data$y$Variable$varName

if (!dir.exists(paste0(outdir, y.var, "/dat"))) {
dir.create(paste0(outdir, y.var, "/dat"), recursive = TRUE)
if (!dir.exists(paste0(outdir, y.var))) {
dir.create(paste0(outdir, y.var), recursive = TRUE)
}

if (is.null(selection_vars)) {
Expand Down
5 changes: 5 additions & 0 deletions R/UERRA_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ loadUerra <- function(file, var, lon_lim = c(-11, 12), lat_lim = c(28, 44), dict
data <- transformeR::upscaleGrid(data, times = aggr_times, aggr.fun = list(FUN = aggr_fun))
}

if(data$Variable$varName == "cld"){
attributes(data$Variable)$units <- "%"
attributes(data$Variable)$longname <- "Total Cloud Cover"
}

data <- modifyDates(data)

return(data)
Expand Down

0 comments on commit cd3810e

Please sign in to comment.