I am using terra (1.7.57) to open and manipulate a large .nc file. This raster opens upside down. I am using terra::flip to vertically flip all layers of the raster. It takes anywhere from 20 min to 2 hours to flip the raster, and then I get this error: Error: [flip] incorrect start and/or nrows value

I have tried to subset the raster by selecting the layers I need, and the same error occurs. I have tried flipping the raster both before and after the CRS & extent are assigned, with the same outcome.

The input .nc file is 5G. It is available here: https://drive.google.com/drive/folders/1p6SkrYjtaAhFXYnUsR1jX-mYa_jtUSop?usp=drive_link.

Why am I getting this error and what is the next step for trouble shooting?

Here is my code:

    require(terra)

    s2file <- "S2B_MSI_2021_04_14_18_49_19_T10SFH_L2W.nc"

    rastcrs <- "+proj=utm +zone=10 +datum=WGS84 +units=m +no_defs"
    extent <- c(600000, 709800, 4190220, 4300020)

    S2Rrsf <- rast(s2file)
    crs(S2Rrsf) <- rastcrs
    ext(S2Rrsf) <- rextent
    S2Rrs <- subset(S2Rrsf, c(31:41, 12:15, 3:5))

    S2Rrs <- terra::flip(S2Rrs, direction = "vertical")`

S2Rrs object identifying info:

S2Rrs
class       : SpatRaster 
dimensions  : 5490, 5490, 18  (nrow, ncol, nlyr)
resolution  : 20, 20  (x, y)
extent      : 6e+05, 709800, 4190220, 4300020  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=utm +zone=10 +datum=WGS84 +units=m +no_defs 
sources     : S2A_MSI_2019_07_19_18_49_21_T10SFH_L2W.nc:Rrs_443  
              S2A_MSI_2019_07_19_18_49_21_T10SFH_L2W.nc:Rrs_492  
              S2A_MSI_2019_07_19_18_49_21_T10SFH_L2W.nc:Rrs_560  
              ... and 15 more source(s)
varnames    : Rrs_443 (Remote sensing reflectance) 
              Rrs_492 (Remote sensing reflectance) 
              Rrs_560 (Remote sensing reflectance) 
              ...
names       : Rrs_443, Rrs_492, Rrs_560, Rrs_665, Rrs_704, Rrs_740, ... 
unit        :       1,       1,       1,       1,       1,       1, 
0

There are 0 answers