我有两个不同范围和分辨率的 netCDF 文件。我想从具有相同范围和分辨率的两个文件创建栅格。我想要一个文件的分辨率和另一个文件的范围。
这是我正在使用的代码:
require(raster);
#Get information
iceMaxNineK <- raster("~/Desktop/TRACE-21k_Data/NineK.ICEFRAC.max.avg.nc")
saltNineK <- brick("~/Desktop/TRACE-21k_Data/NineK.SALT.nc", lvar = 4)
#Making everything nice and uniform and useable
#==============================================
#set up an initial "sampling raster"
e <- extent(0, 360, -90, 90) #xmin,xmax,ymin,ymax
e <- raster(e,nrows=1,ncols=1,crs=saltNineK@crs)
res(e) <- res(saltNineK)
values(e) <- 0
#Resample ice
iceMaxNineK <- resample(iceMaxNineK, e, method="ngb")
plot(iceMaxNineK)
#Resample salt
saltNineK <- resample(saltNineK, e, method="ngb")
plot(saltNineK)
重采样 iceMaxNineK 有效,但重采样 saltNineK 会导致地图卡在已定义范围区域的一个角落,如下图所示。
一、iceMaxNineK:
二、saltNineK:
重采样前iceMaxNineK的尺寸:
class : RasterLayer
dimensions : 48, 96, 4608 (nrow, ncol, ncell)
resolution : 3.75, 3.708898 (x, y)
extent : -1.875, 358.125, -89.01354, 89.01354 (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0
data source : /Users/Hannah/Desktop/TRACE-21k_Data/NineK.ICEFRAC.max.avg.nc
names : Fraction.of.sfc.area.covered.by.sea.ice
z-value : -8.99945876078469
zvar : ICEFRAC
重采样后iceMaxNineK的尺寸:
class : RasterLayer
dimensions : 180, 360, 64800 (nrow, ncol, ncell)
resolution : 1, 1 (x, y)
extent : 0, 360, -90, 90 (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0
data source : in memory
names : Fraction.of.sfc.area.covered.by.sea.ice
values : 0, 0.9997393 (min, max)
重采样前 saltNineK 的尺寸:
class : RasterBrick
dimensions : 116, 100, 11600, 25 (nrow, ncol, ncell, nlayers)
resolution : 1, 1 (x, y)
extent : 0.5, 100.5, 0.5, 116.5 (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0
data source : /Users/Hannah/Desktop/TRACE-21k_Data/NineK.SALT.nc
names : X400, X1222.02453613281, X2108.88061523438, X3100.537109375, X4239.19677734375, X5577.873046875, X7187.42822265625, X9166.115234375, X11653.9140625, X14854.84765625, X19072.095703125, X24762.70703125, X32618.9296875, X43673.65625, X59384.83984375, ...
centimeters : 400, 475128.78125 (min, max)
varname : SALT
level : 1
重采样后 saltNineK 的尺寸:
class : RasterBrick
dimensions : 180, 360, 64800, 25 (nrow, ncol, ncell, nlayers)
resolution : 1, 1 (x, y)
extent : 0, 360, -90, 90 (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0
data source : in memory
names : X400, X1222.02453613281, X2108.88061523438, X3100.537109375, X4239.19677734375, X5577.873046875, X7187.42822265625, X9166.115234375, X11653.9140625, X14854.84765625, X19072.095703125, X24762.70703125, X32618.9296875, X43673.65625, X59384.83984375, ...
min values : 6.842899, 6.850603, 6.853004, 6.853779, 6.853567, 23.148109, 23.148115, 23.148115, 23.148119, 23.148121, 23.148121, 23.148121, 23.148121, 23.148121, 23.148121, ...
max values : 39.60786, 39.60786, 39.60783, 39.60777, 39.60769, 39.60766, 39.60765, 39.60757, 39.60755, 39.60742, 39.60739, 39.60732, 39.60730, 39.60730, 39.60730, ...
可以通过以下链接访问示例文件:https ://www.dropbox.com/s/x8oqem317vmr7yq/DataForRResample.zip?dl=0
感谢您的时间。