【发布时间】:2020-06-26 17:57:36
【问题描述】:
我正在尝试覆盖包含夏威夷上空气溶胶高度数据的 netcdf4 栅格。有一个示例文件here. 我感兴趣的变量是纬度、经度、时间和气溶胶高度。这是一些可重复的数据。
s1 <- data.frame(as.vector(lon), as.vector(lat), as.vector(ah))
s1
# as.vector.lon. as.vector.lat. as.vector.ah.
#1 -127.45199 -79.15431 NA
#2 -126.99632 -79.16919 NA
#3 -126.54577 -79.18321 NA
#4 -126.10027 -79.19641 NA
#5 -125.65974 -79.20880 NA
#6 -125.22412 -79.22042 NA
#7 -124.79333 -79.23129 NA
crsLatLon <- "+proj=longlat +datum=WGS84"
ex <- extent(c(-180,180,-90,90))
#empty raster with 0.1 degree resolution
pmraster <- raster(ncol=360*10, nrow=180*10, crs=crsLatLon,ext=ex)
#fills the empty raster with values from dataframe, s1
pmraster <- rasterize(s1[,1:2], pmraster, s1[,3], fun=mean, na.rm=T)
show(pmraster)
#class : RasterLayer
#dimensions : 1800, 3600, 6480000 (nrow, ncol, ncell)
#resolution : 0.1, 0.1 (x, y)
#extent : -180, 180, -90, 90 (xmin, xmax, ymin, ymax)
#crs : +proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0
#source : r_tmp_2020-06-26_114048_16840_75885.grd
#names : layer
#values : 0.1314196, 9424.118 (min, max)
#specifies region over Hawaii
exHI <- extent(c(-180,-140,10,30))
levelplot(crop(pmraster,exHI))
#Error: $ operator is invalid for atomic vectors
#In addition: Warning messages:
#1: In min(x) : no non-missing arguments to min; returning Inf
#2: In max(x) : no non-missing arguments to max; returning -Inf
#3: In min(x) : no non-missing arguments to min; returning Inf
#4: In max(x) : no non-missing arguments to max; returning -Inf
谁能帮助解释我收到此错误消息的原因以及如何继续生成所需的光栅图像?提前谢谢!
【问题讨论】:
-
您应该提供一个最小的、自包含的、可重现的示例,使用代码创建一些数据或使用 R 包附带的数据。您的问题是关于将 levelplot 与 Raster 对象一起使用,这很容易完成,但没有示例数据就不容易回答,而且您的问题充满了我们无法运行的代码,与手头的问题无关。请编辑您的问题。
-
对此我很抱歉,罗伯特。感谢您对我的 R 问题的回应。我已经修改了这个问题,希望能更简洁并提供一些可重复的数据。
标签: geospatial raster rasterizing satellite