I am trying to create a raster stack / brick from a list of ncdf files with the dimensions 160x160x24x1).

r = stack(files) 

This gives me a raster stack but without the 4th dimensions which is required in the output ncdf file even when the dimension is 1.

Currently I am creating an array and filling in the raster stack and writing the output file via the ncdf package.

data1 <- array(0,dim=c(160,160,1,dims-1))
data1[,,1,] <- as.array(r)

sm1 = var.def.ncdf(var,var, list(x,y,l,t), 1.e30)
ncout1 <- create.ncdf(paste (cmemvar,".nc", sep = "", collapse = NULL), sm1)
put.var.ncdf(ncout1, sm1, data1)

However with a large amount of files this hits memory limitations. Is there any better way, at best directly with the raster package, to write the 4-dim ncdf?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.