diff --git a/NAMESPACE b/NAMESPACE index 0da5c05..b538a59 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -52,6 +52,7 @@ importFrom(rJava,.jfield) importFrom(rJava,.jinit) importFrom(rJava,.jnew) importFrom(rJava,.jpackage) +importFrom(terra,`nlyr<-`) importFrom(terra,ncell) importFrom(terra,rast) importFrom(terra,readStart) diff --git a/R/NewhallData.R b/R/NewhallData.R index 7fc4e65..0e1d8ef 100644 --- a/R/NewhallData.R +++ b/R/NewhallData.R @@ -586,8 +586,7 @@ newhall_cmip6_rast <- function(model, resolution = "10m", version = "2.1", CMIP6_PATH = file.path(newhall_data_dir("cache"), "CMIP6"), - tiffile = list.files(file.path(CMIP6_PATH, "climate", - paste0("wc", version, "_", resolution)), + tiffile = list.files(file.path(CMIP6_PATH, paste0("wc", version, "_", resolution)), pattern = "\\.tif$", recursive = TRUE)) { @@ -607,7 +606,7 @@ newhall_cmip6_rast <- function(model, } colnames(tif) <- c("tiffile", "version", "resolution", "variable", "model", "ssp", "month") - f <- file.path(CMIP6_PATH, "climate", paste0("wc", version, "_", resolution), + f <- file.path(CMIP6_PATH, paste0("wc", version, "_", resolution), tif$tiffile[which(tif$resolution == resolution)]) if (length(f) != 3) { stop("One or more CMIP6 monthly grids are missing from ", diff --git a/man/newhall_cmip6.Rd b/man/newhall_cmip6.Rd index a1d9cca..9a75b21 100644 --- a/man/newhall_cmip6.Rd +++ b/man/newhall_cmip6.Rd @@ -23,8 +23,8 @@ newhall_cmip6_rast( resolution = "10m", version = "2.1", CMIP6_PATH = file.path(newhall_data_dir("cache"), "CMIP6"), - tiffile = list.files(file.path(CMIP6_PATH, "climate", paste0("wc", version, "_", - resolution)), pattern = "\\\\.tif$", recursive = TRUE) + tiffile = list.files(file.path(CMIP6_PATH, paste0("wc", version, "_", resolution)), + pattern = "\\\\.tif$", recursive = TRUE) ) newhall_cmip6_subset( diff --git a/man/writeRasterLayers.Rd b/man/writeRasterLayers.Rd index fd7cae9..56d3c6c 100644 --- a/man/writeRasterLayers.Rd +++ b/man/writeRasterLayers.Rd @@ -21,8 +21,12 @@ This function is a simple wrapper around \code{terra:writeRaster()} that makes i to separate the individual layers of an input or output grid as separate files. } \examples{ +library(terra) + x <- writeRaster(rast(list(a = rast(matrix(1)), b = rast(matrix(2)))), "test.tif") + writeRasterLayers("test.tif", "test") + unlink(c("test.tif", "test"), recursive=TRUE) } diff --git a/misc/cmip6_demo.R b/misc/cmip6_demo.R index edb5a54..e0562e5 100644 --- a/misc/cmip6_demo.R +++ b/misc/cmip6_demo.R @@ -1,7 +1,7 @@ library(jNSMR) library(terra) -newhall_cmip6_cache("EC-Earth3-Veg", +f <- newhall_cmip6_cache("EC-Earth3-Veg", resolution = "2.5m", ssp = "585", time = "2061-2080") @@ -13,7 +13,6 @@ x <- newhall_cmip6_subset(b, "EC-Earth3-Veg", resolution = "2.5m", ssp = "585", time = "2061-2080") - x$elev <- 0 x$awc <- 200 @@ -28,3 +27,10 @@ y$awc <- 200 res2 <- newhall_batch(y) plot(res2$temperatureRegime, col = hcl.colors(10), main = "PRISM Normals (4km); 1991-2020") + +ncdm8c1 <- terra::project(res$numConsecutiveDaysMoistInSomePartsOver8C, res2) +df <- res2$numConsecutiveDaysMoistInSomePartsOver8C - ncdm8c1 +df <- terra::crop(df, ext(ncdm8c1) * 0.95) +plot(df, col=rev(hcl.colors(50))) +title(main = "\n\nChange in Number Consecutive Days Moist in Some Parts over 8 degrees C\n + EC-Earth3-Veg (2.5 minute); SSP: 585; 2061-2080\nvs.\nPRISM Normals (4km); 1991-2020")