I have a 35 year time series of rasters. There's two rasters per year. They were downloaded from Google Earth Engine, which forced me to break my rasters into 30+ tiles for download. I'm mosaicking them back together in R with the following code.
library(readxl)
library(tidyverse)
library(raster)
library(rgdal)
max13files <- list.files('./max13', pattern="*.tif$", full.names = T)
a <- lapply(max13files, stack)
max13<-do.call(mosaic, c(a, fun=max))
namesa<-c("NDVI_13max"," NBR_13max", "Bright_13max", "Green_13max", "Wet_13max")
s13max<- unstack(max13)
for(i in seq_along(s13max)){writeRaster(s13max[[i]], file=namesa[i], format="GTiff")}
This has worked great 90% of the time, except there's a few rasters that consistently experience the following error.
> max13<-do.call(mosaic, c(a, fun=max))
Error in rgdal::getRasterData(con, offset = offs, region.dim = reg, band = object@data@band) :
Failure during raster IO
In addition: There were 50 or more warnings (use warnings() to see the first 50)
In addition: There were 50 or more warnings (use warnings() to see the first 50)
Warning messages:
1: In writeBin(as.vector(v[start:end, ]), x@file@con, size = x@file@dsize) :
problem writing to connection
The same warning message repeats 50 times.
Of the 70 rasters in the timeseries, three consistently have this error. The rest work fine. The extent, projection and bands are the same as the rasters that worked fine. I've tried deleting and redownloading one of the error years. It didn't fix the issue. It also takes about a day to download each raster from GEE since they're spatially large, so I'd like to minimize the number of times I need to do that if possible.
What might be the issue?