Skip to content

Floodplain-wide tiled composite: terra::mask cannot read the merged mosaic after a 3-hour read #88

Description

@NewGraphEnvironment

Problem

A floodplain-wide dft_stac_composite() over BULK (bulk_co_ff04, tile_size = 20000, 2023 Jul–Aug, clip = TRUE) reads every tile and then fails after the read, on the merged mosaic:

Error: [mask] cannot read from /private/tmp/Rtmp.../spat_16d103f4b1e92_93456_SskviV5XwhZb4QV.tif

That is stac_cube_clip() → terra::mask() failing to read the temp GeoTIFF that mosaic_stacks() (terra::merge(terra::sprc(tiles))) wrote. The same path is dft_stac_cube()'s tiled read, so a floodplain-scale tiled cube is presumably affected too.

Established (drift#79 BULK runs, 2026-09-28)

run what happened
2 30 tiles in 54 min, 15 of them lost to expired tokens (fixed in #79). Died at writeRaster(filetype = "COG"), which reads the same merged mosaic
4 all 30 tiles read, 0 chunk failures, in 3 h 16 min; peak RSS 3.90 GiB; then the mask error above

The R session exited on the error, so its tempdir, and the evidence, went with it.

Ruled out

  • Disk: 1 TB free on /private/tmp.
  • Writing a floodplain-size COG: an in-memory synthetic raster with the same dims and options writes fine (82 s, 459 MB).
  • terra deleting a temp file when its parent object is collected: subset, reassign, gc() and mask() on a disk-forced merge all work (terra 1.9.50).
  • Merge plus mask at this scale, in general: 30 synthetic NetCDF tiles on the exact BULK tile grid, merged to a file-backed spat_*.tif, reordered by name and masked with the real 104,584-vertex floodplain polygon. OK in 0.7 min.

Not yet separated

What the live run has and the offline rebuild does not:

  • gdalcubes' float64 NetCDF with a time dimension as the merge sources;
  • 3 hours of elapsed time, and temp files created early being read late;
  • per-tile NA patterns from cloud masking.

data-raw/benchmark_composite_bulk.R now catches the error and inventories the temp files before exit: names, sizes, mtimes, and gdalinfo -checksum of every spat_*.tif. The next floodplain run leaves the evidence this one lost. A cheaper way to separate the first candidate is the offline rebuild with tiles written by gdalcubes::write_ncdf() from a local image collection. The #79 review built such a collection in its scratch scripts.

Acceptance

  • A floodplain-wide BULK composite completes and caches one COG.
  • A test pins the cause (fixture from real gdalcubes NetCDF tiles if that is the discriminator).
  • The numbers go in the scale-test record: wall time and peak RSS for the full run.

Relates: drift#79, drift#87

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions