hypertidy / vapour

GDAL API package for R
https://hypertidy.github.io/vapour/
80 stars 9 forks source link

crashy crashy (no crs on source) #229

Closed mdsumner closed 2 weeks ago

mdsumner commented 1 month ago

This should not crash, the crs is missing.

## https://urs.earthdata.nasa.gov/documentation/for_users/user_token
## the token is a long text string, the header is "Authorization: Bearer {token}"

## this is your earthdata token in Authorization Bearer format, I keep mine in a local file (its filename is not relevant)
earthdata <- normalizePath("~/earthdata")
Sys.setenv("GDAL_HTTP_HEADER_FILE" = earthdata)
## could also set GDAL_HTTP_HEADERS to the header itself (don't need a file)
## or use terra::setGDALconfig(), I just like env vars because they work for all GDAL software, and a file
## because the code is purely relative to my local set up and will work

## customize for where you want the files to go
root <- "."
#dir.create(root, recursive = TRUE)

base <- "https://archive.podaac.earthdata.nasa.gov/podaac-ops-cumulus-protected/MUR-JPL-L4-GLOB-v4.1"
date <- as.Date("2024-01-01")
url  <- glue::glue("{base}/{format(date, '%Y')}{format(date, '%m')}{format(date, '%d')}090000-JPL-L4_GHRSST-SSTfnd-MUR-GLOB-v02.0-fv04.1.nc")

## now we start with the GDAL syntax, vsi for lazy internet read, DRIVER:url:sds for the subdataset syntax
dsn <- glue::glue("NETCDF:/vsicurl/{url}:analysed_sst:")

aex <- c(173, 185, -19.85, -15)
library(vapour)
library(ximage)
ximage(gdal_raster_data(dsn, target_ext = aex))
mdsumner commented 1 month ago

I think it crashes R because of this

gdalwarp  NETCDF:/vsicurl/https://archive.podaac.earthdata.nasa.gov/podaac-ops-cumulus-protected/MUR-JPL-L4-GLOB-v4.1/20240101090000-JPL-L4_GHRSST-SSTfnd-MUR-GLOB-v02.0-fv04.1.nc:analysed_sst -t_srs "+proj=laea +lon_0=180" -te -1e5 -1e5 1e5 1e5  out.tif
Creating output file that is 20000000P x 20000000L.
ERROR 3: out.tif: Free disk space available is 3931875180544 bytes, whereas 800000000000000 are at least necessary. You can disable this check by defining the CHECK_DISK_FREE_SPACE configuration option to FALSE.

(because there's no source crs, it's treating the projected extent as a longlat one so it's a massive output)

mdsumner commented 1 month ago

segfaulting on

dsn <- system.file("extdata/sst.tif", package = "vapour")
 X3 <- gdal_raster_data(dsn,  target_ext = c(-1, 1, -1, 1) * 8e6, 
  target_dim = c(512, 678), target_crs = "+proj=stere +lon_0=147 +lat_0=-90")

and on this


  sds <- "NETCDF:/rdsi/PUBLIC/raad/data/www.ncei.noaa.gov/data/sea-surface-temperature-optimum-interpolation/v2.1/access/avhrr/198109/oisst-avhrr-v02r01.19810901.nc:sst"
vapour_warp_raster(sds, extent = c(0, 1, 0, 1), dimension = c(4, 4))

why