I was converting the .nc file downloaded from here to raster to map the SST spatial variation. The unit is supposed to be in Kelvin. But the values I got are not in normal ranges (degree celsius or Kelvin). Here's my code:
library(ncdf4)
nasa.temp <- nc_open("20171012090000-JPL-L4_GHRSST-SSTfnd-MUR-GLOB-v02.0-fv04.1.nc")
lon <- ncvar_get(nasa.temp, "lon")
lat <- ncvar_get(nasa.temp, "lat", verbose = F)
t <- ncvar_get(nasa.temp, "time")
ndvi.array <- ncvar_get(nasa.temp, "analysed_sst")
fillvalue <- ncatt_get(nasa.temp, "analysed_sst", "_FillValue")
ncatt_get(nasa.temp, "analysed_sst","units")
ndvi.array[ndvi.array == fillvalue$value] <- NA
r <- raster(t(ndvi.array), xmn=min(lon), xmx=max(lon), ymn=min(lat), ymx=max(lat),
crs=CRS("+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs+ towgs84=0,0,0"))
r <- flip(r, direction='y')
MY.ext <- extent(99.64072, 120.2697, 0.05372, 8.380556)
sst.crop <- crop(r, MY.ext)
plot(sst.crop)
writeRaster(sst.crop, "nasa/sst.tif", "GTiff", overwrite=TRUE)
Really appreciate it if anyone can help to point out my mistakes!