0

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?

  • 1
    Questions with warnings of errors should include a small code example that allows recreation. With R that would include sufficient `library` calls to load needed non-core packages as well as a concrete specification of any external data needed.. – IRTFM May 19 '21 at 16:51

2 Answers2

0

This messages

Error in rgdal::getRasterData(con, offset = offs, region.dim = reg, band = object@data@band) : 
  Failure during raster IO

Suggests there is a bad input raster.

Whereas this message

Warning messages:
1: In writeBin(as.vector(v[start:end, ]), x@file@con, size = x@file@dsize) :
  problem writing to connection

suggest that you are running out of disk space, perhaps in the temp folder.

Robert Hijmans
  • 40,301
  • 4
  • 55
  • 63
  • Interesting... It's always the same three rasters, regardless of where they are in the processing sequence. – mtnscience May 19 '21 at 21:19
0

Discovered the issue- it was a single corrupt tile from Google Earth Engine. I loaded each tile individually into ArcMap and found the corrupted one. It works fine without that tile.