在栅格中重新投影 oceancolor 数据?

Reprojection oceancolor data in raster?

关于我之前的问题 Read/Open Oceancolor data from MODIS with nc format. I have tried to read the ncdf oceancolor data download here 使用 ncdf4 package 和此代码

library(ncdf4)
nc <- nc_open('A2014325053500.L2_LAC_SST.nc')

# Get data for each variabel name as a large matrix
sst <- ncvar_get(nc, varid = 'geophysical_data/sst')
lon <- ncvar_get(nc, varid = 'navigation_data/longitude')
lat <- ncvar_get(nc, varid = 'navigation_data/latitude')

比这个数据,我转换成光栅。但是我未能重新投影光栅 figure 1。图片应该像 figure 2

library(sp)
library(raster)

r <- raster(sst,
        xmn=min(lat), xmx=max(lat), 
        ymn=min(lon), ymx=max(lon),
        crs=CRS('+proj=longlat +ellps=WGS84 +datum=WGS84'))

proj='+proj=longlat +ellps=WGS84 +datum=WGS84'
r2 <- projectRaster(r, crs=proj, method = 'ngb')
plot(r2)

根据 jbaums 的第一个建议,结果未正确重新投影figure 3

当我提高分辨率时,我才意识到结果有问题。在西部和东部变白(无数据)。我在下面使用了这段代码:

r <- rasterize(df, raster(extent(df), res=0.0103011), 'sst', fun=mean)

图1

图2

图3

图4

在他们当前的投影中,坐标不落在规则的网格上。

解决此问题的一种方法是将坐标表示为 SpatialPoints 对象,然后,如果需要光栅,rasterize 它。

library(ncdf4)
library(raster)

# Read in the data
nc <- nc_open('~/../Downloads/A2014325053500.L2_LAC_SST.nc')
sst <- ncvar_get(nc, varid = 'geophysical_data/sst')
lon <- ncvar_get(nc, varid = 'navigation_data/longitude')
lat <- ncvar_get(nc, varid = 'navigation_data/latitude')
nc_close(nc)

# Create a SpatialPointsDataFrame
p <- data.frame(lon=c(lon), lat=c(lat), sst=c(sst))
coordinates(p) <- ~lon+lat
proj4string(p) <- '+init=epsg:4326'

# Rasterize with appropriate resolution and aggregation function
r <- rasterize(p, raster(extent(p) * 1.04, res=0.05), 'sst', fun=mean)
# for high resolution look at ?gdalUtils::gdal_rasterize for efficiency

这是一个情节:

library(rasterVis)
levelplot(r, at=seq(-75, 75, length=100), margin=FALSE, par.settings=BuRdTheme,
              colorkey=list(height=0.6), main='MODIS Sea Surface Temperature')