简体   繁体   English

如何从每日 netcdf 计算每月数据

[英]How to calculate monthly data from a daily netcdf

I was able to open a netcdf file in R using the package "ncdf4" and extract rainfall (using ncvar_get).我能够使用 package "ncdf4" 在 R 中打开一个 netcdf 文件并提取降雨量(使用 ncvar_get)。 However I can't find information on how to calculate monthly values from daily values.但是,我找不到有关如何从每日值计算每月值的信息。 Is this possible while staying in the netcdf format or should I convert it to something else?在保持 netcdf 格式时这是否可能,还是应该将其转换为其他格式? - but what format would keep the lat, long and time information associated with each rainfall value? - 但是什么格式可以保留与每个降雨值相关的纬度、经度和时间信息? I am not familiar with netcdfs so any help will be appreciated.我对 netcdfs 不熟悉,因此将不胜感激。

The exact command with cdo is cdo 的确切命令是

cdo monmean in.nc out.nc

EDIT:编辑:

As in the comment of JW you can also calculate the "average" instead of the "mean"正如 JW 的评论一样,您还可以计算“平均值”而不是“平均值”

cdo monavg in.nc out.nc

The difference between the two is in the way they handle missing data.两者之间的区别在于它们处理缺失数据的方式。 monmean ignores missing values, while monavg includes missing. monmean忽略缺失值,而monavg包括缺失值。 Quoting the manual: "the mean of 1, 2, miss and 3 is (1+2+3)/3 = 2, whereas the average is (1+2+miss+3)/4 = miss/4 = miss" - see section 2.8 of the manual for more details.引用手册:“1、2、miss 和 3 的平均值是 (1+2+3)/3 = 2,而平均值是 (1+2+miss+3)/4 = miss/4 = miss” - 有关更多详细信息, 请参阅手册第 2.8 节

Last, but not least, you can also use CDO commands directly from R using this package which provides R wrappers for CDO最后但并非最不重要的是,您还可以使用此包直接从 R 使用 CDO 命令,该包为 CDO 提供 R 包装器

I'm not an R programmer but I can recommend the command-line tools nco and/or cdo for these sorts of operations我不是的R程序员,但我可以推荐的命令行工具nco和/或cdo这些各种操作

http://nco.sourceforge.net/nco.html -- see averagers nces , ncra and ncwa . http://nco.sourceforge.net/nco.html -看平均程序ncesncrancwa You probably want the record averager ncra你可能想要记录平均器ncra

https://code.zmaw.de/projects/cdo -- see https://code.zmaw.de/projects/cdo/embedded/1.6.4/cdo_refcard.pdf for the commands for monthly, daily, seasonal, statistics https://code.zmaw.de/projects/cdo - 有关每月、每日、季节性、统计数据的命令,请参阅https://code.zmaw.de/projects/cdo/embedded/1.6.4/cdo_refcard.pdf

Quite late to the party, just wanted to add the following code in CDO can easily do the required job as well迟到了,只想在CDO中添加以下代码也可以轻松完成所需的工作

cdo monsum dailydatafile.nc monfile.nc

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM