R Resample Raster表现不一致

时间:2014-10-28 22:59:41

标签: r netcdf r-raster

我有两个不同范围和分辨率的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: iceMaxNineK plot

第二,saltNineK: saltNineK plot

重新取样前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

感谢您的时间。

1 个答案:

答案 0 :(得分:0)

我现在已经解决了这个问题。问题是输入文件,其分辨率为T31_gx3v5(http://www.cgd.ucar.edu/ccr/TraCE/; Yeager等人,2006; Otto-Bliesner等人,2006)。 R并没有意识到这一点。在将它们导入R之前,需要使用ncl语言将这些图层重新划分为1X1度。有关在ncl中重新编译的更多信息,请点击以下链接:https://www.ncl.ucar.edu/Document/Functions/Pop_remap/PopLatLon.shtml