在一个netcdf文件中高效地转换单位。

huangapple go评论124阅读模式
英文:

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 &lt;- rast(&quot;file.nc&quot;) 
y &lt;- x * 86400

huangapple
  • 本文由 发表于 2023年3月7日 20:34:27
  • 转载请务必保留本文链接:https://go.coder-hub.com/75662038.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定