Skip to content

Instantly share code, notes, and snippets.

@mdsumner
Last active March 19, 2024 23:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mdsumner/63274b2069bbdfbc297b350f5d53dd2f to your computer and use it in GitHub Desktop.
Save mdsumner/63274b2069bbdfbc297b350f5d53dd2f to your computer and use it in GitHub Desktop.

Note that the authorization mechanism requires GDAL 3.6 or later, find your version in terra with terra::gdal().

library(terra)
url <- "https://archive.podaac.earthdata.nasa.gov/podaac-ops-cumulus-protected/MUR-JPL-L4-GLOB-v4.1/20240318090000-JPL-L4_GHRSST-SSTfnd-MUR-GLOB-v02.0-fv04.1.nc"

## make a GDAL dsn for an online file
dsn <- sprintf("/vsicurl/%s", url)

## we need our earthdata token set (how you input the token is an open topic, maybe use an env var with Sys.getenv)
Sys.setenv("GDAL_HTTP_HEADERS" = sprintf("Authorization: Bearer %s", mytoken))

## open it and select analysed_sst
sst <- rast(dsn, "analysed_sst")
 sst
class       : SpatRaster
dimensions  : 17999, 36000, 1  (nrow, ncol, nlyr)
resolution  : 0.01, 0.01  (x, y)
extent      : -179.995, 180.005, -89.995, 89.995  (xmin, xmax, ymin, ymax)
coord. ref. : lon/lat WGS 84 (CRS84) (OGC:CRS84)
source      : 20240318090000-JPL-L4_GHRSST-SSTfnd-MUR-GLOB-v02.0-fv04.1.nc:analysed_sst
varname     : analysed_sst (analysed sea surface temperature)
name        : analysed_sst
unit        :       kelvin
time        : 2024-03-18 09:00:00 UTC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment