CMIP5未来气候资料中的经度为0- 360度。如何使用光栅包将其转换为-180 - 180度?
我试过用shift(r0,-180)
和shift(r0,-360)
。它不起作用。任何帮助都将不胜感激。这里的r0
是一个栅格。
发布于 2014-09-09 03:37:47
试试rotate()
。它的帮助页面甚至提到了它对您正在处理的数据类型的实用程序:
将x坐标(经度)为0到360的光栅*对象旋转到-180度到180度之间的标准坐标。在全球气候模型的数据中,经常使用0到360之间的经度。
下面是一个简单的可重现的例子来说明它的作用:
library(raster)
r <- raster(matrix(1:100, ncol=10), 0, 360, -90, 90, crs="+proj=merc")
r2 <- rotate(r)
r2
# class : RasterLayer
# dimensions : 10, 10, 100 (nrow, ncol, ncell)
# resolution : 36, 18 (x, y)
# extent : -180, 180, -90, 90 (xmin, xmax, ymin, ymax)
# coord. ref. : +proj=merc
# data source : in memory
# names : layer
# values : 1, 100 (min, max)
发布于 2014-09-09 02:19:52
这很简单:
ifelse(r0 > 180, -360 + r0, r0)
发布于 2014-09-09 03:10:17
这是一种技巧,在raster
中可能有一种更简单的方法来实现,但这里有一个选择。首先,您需要从您的栅格对象创建一个矩阵,然后修改一些经度值(仅那些大于180的值),并切换回栅格。marmap
包可以为您进行来回切换:
# Switching from a raster to a matrix of class 'bathy'
library(marmap)
temp <- as.bathy(r0)
summary(temp)
# Changing the relevant longitude
names <- as.numeric(row.names(temp))
names[names > 180] <- names[names > 180] - 360
# Renaming the longitudes and switching back from a 'bathy' object to a raster
rownames(temp) <- names
r0.modified <- as.raster(temp)
https://stackoverflow.com/questions/25730625
复制相似问题