将多维NETCDF转换为r中的TIF
我的.NC文件大约为651 MB,其中有几个数据集(每日)(RR_MRG_19810101_20181231_ENACT.NC)数据。我需要将(RR_MRG_198101011_20181231_ENACT.NC)转换为多个geotiff(每个时间切片,每月一个.tif)。同样,我想阅读时间序列。但是我发现
Error in .local(x, time, ...) :
time must has the same length as the number of layers in RasterBrick][1]
这是我所做的,
library(raster)
library(zoo)
library(rts)
TRF = brick("rr_mrg_19810101_20181231_ENACT.nc")
crs(TRF) <- "+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84
+towgs84=0,0,0"
Awash_Extent<-c(37,44, 7,12)
Awash_E_resize<- crop(TRF,Awash_Extent)
Awash_Month<-seq(as.Date('1981-01-01'),as.Date('2018-12-31'),by =
"month")
rt <- rts(Awash_E_resize, Awash_Month)
write.rts(Awash_E_resize, filename='Awash_TRF_1981_2018_mon.tif',
overwrite=TRUE)
您能帮我解决这个问题吗?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这样简单的事情可以
根据您的扩展问题来完成此操作:
使用
Terra
(不需要其他软件包)我在这里创建类似的内容:
现在按月汇总:
您可以添加
filename =
tapp
的参数,但是如果要将这些层保存为单独的文件,则可以使用writeraster
。但是有了Terra,您需要自己提供文件名。(有一个关于file_ext的警告,您可以忽略)
Something as simple as this can do that
Based on your expanded question:
Read the values with
terra
(no need for other packages)I create something similar here:
Now aggregate by month:
You could add a
filename=
argument totapp
, but if you want to save the layers as separate files you can usewriteRaster
instead. But with terra you need to provide the filenames yourself.(there is a warning about file_ext that you can ignore)