#' Convert a raster or brick to a array for WRF-Chem
#'
#' @description Conversion a raster or brick to a array for WRF-Chem model
#'
#' @param r input raster
#' @param na_value value for missing values
#'
#' @return array
#'
#' @import raster
#'
#' @examples
#'
#' r <- raster::raster(paste0(system.file("extdata", package = "hackWRF"),
#' "/wrf.day1.o3.nc"))
#' a <- raster_to_ncdf(r)
#'
#' @export
#'
raster_to_ncdf <- function(r,na_value = 0){
N_times <- dim(r)[3]
a <- array(na_value,c(dim(r)[2],dim(r)[1],N_times))
for(i in 1:N_times){
flipado <- suppressWarnings(raster::flip(r[[i]],2))
a[,,i] <- as.matrix(t(flipado))
}
return(a)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.