更快的有效方法在R中裁剪NetCDF

发布于 2025-02-07 22:36:55 字数 335 浏览 2 评论 0原文

我有一个.NC/NETCDF文件,大小约为1GB。尝试通过以下代码裁剪并使其更小:

  r <- terra::rast("myfile.nc")
  r2 <- terra::crop(x = r, y=terra::ext(-79, -72, 0, 12.4))

在16GB RAM机器中失败。通过失败,我的意思是,如果我试图停止运行代码,它不会在15分钟内返回任何结果,并冻结我的rstudio会话。因此,我没有错误消息要在此处发布。

我应该考虑在NetCDF文件上使用Terra :: crop()哪种替代方案?

I have a .nc/netcdf file which is about 1GB in size. Trying to crop and make it smaller with the following code:

  r <- terra::rast("myfile.nc")
  r2 <- terra::crop(x = r, y=terra::ext(-79, -72, 0, 12.4))

fails in a 16GB RAM machine. By failing I mean it does not return any results in 15 minutes and freezes my RStudio session if I try to stop the running code. Thus I have no error message to post here.

What alternative to terra::crop() should I consider to use on netcdf files?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

春花秋月 2025-02-14 22:36:55

在使用(使用)GDAL(标准方法)GDAL时,使用多层(时间步长)处理(NETCDF)文件,这就是Terra使用的。我希望在未来几个月内解决这个问题。您想做的事情可能会使用栅格来快得多,因为它将数据作为三维数组接近(它不在图层上循环)。所以我建议

library(raster)
r <- brick("myfile.nc")
r2 <- crop(r, extent(-79, -72, 0, 12.4))

Dealing with (NetCDF) files with many layers (time steps) can be very slow when using (a standard approach with) GDAL, which is what terra uses. I hope to fix this over the coming months. What you want to do may go much faster with raster because it approaches the data as a three-dimensional array (it is not looping over layers). So I would suggest

library(raster)
r <- brick("myfile.nc")
r2 <- crop(r, extent(-79, -72, 0, 12.4))
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文