英文:
Convert units in a netcdf file efficiently
问题
我有降水单位为kg m-2 s-1的netcdf数据。我想将其转换为毫米(1 kg/m2/s = 86400毫米/天)。我的计划是将数据转换为数据框,然后遍历每个单元格。是否有更简单的方法来实现这一目标?
英文:
I have netcdf data with precipitation units in kg m-2 s-1. I want to convert it to mm. (1 kg/m2/s = 86400 mm/day)
my plan would be to change the data to a dataframe and then go over each cell.
is there an easier way to achieve this?
答案1
得分: 1
考虑使用 terra 软件包。它专门用于处理栅格数据,而且它的大多数例程都是内存安全的,而且速度相当快,因为它是用 C++ 编写的,而不是纯 R。
你可以尝试像这样做:
library(terra)
x <- rast("file.nc")
y <- x * 86400
英文:
Consider using the terra package. It was made to work with raster data and most of its routines are memory safe and quite fast since it is written in C++ instead of pure R.
You can probably do something like this
library(terra)
x <- rast("file.nc")
y <- x * 86400
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论