本文介绍了如何每天将NetCDF文件转换为每月的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我以netcdf文件的形式下载了气候模型输出,该文件每天在全球范围内具有一个变量(pr).我的最终目标是获得欧洲的每月数据.

I have downloaded climate model output in the form of netcdf files with one variable (pr) for the whole world with a daily time-step. My final goal is to have monthly data for Europe.

我以前从未使用过netcdf文件,而且我能找到的所有适用于netcdf的特定软件在Windows中似乎都无法正常工作.自从我在R中编程以来,我尝试使用ncdf4包,但是遇到内存大小问题(我的文件大约为2Gb)...现在,我正在python中尝试netCDF4模块(第一次使用python-所以我要轻松一点).

I have never used netcdf files before and all the specific software for netcdf I could find doesn't seems to work in windows. Since I programme in R, I tried using the ncdf4 package but run into memory size problems (my files are around 2Gb)... I am now trying the netCDF4 module in python (first time I am using python - so go easy on me).

我设法安装了所有内容,并在线找到了一些代码来导入数据集:

I have managed to install everything and found some code online to import the dataset:

nc_fid = Dataset(nc_f, 'r')  
# Extract data from NetCDF file
lats = nc_fid.variables['lat'][:]
lons = nc_fid.variables['lon'][:]
time = nc_fid.variables['time'][:]
pp  = nc_fid.variables['pr'][:]  

但是,我发现的所有教程都是关于如何制作netcdf文件的...我不知道如何将每天的降雨量(可变pr)汇总到每月.另外,我在不同文件中有不同类型的压延机,但我什至不知道如何访问该信息:

However all the tutorials I found are on how to make a netcdf file... I have no idea how to aggregate this daily rainfall (variable pr) into monthly. Also, I have different types of calender in different files, but I don't even know how to access that information:

time.calendar
AttributeError: 'numpy.ndarray' object has no attribute 'calendar'

请帮助,我不想只学习Linux,所以我可以整理出一些数据:(

Please help, I don't want to have to learn Linux just so I can sort-out some data :(

推荐答案

为什么不完全避免编程并使用 NCO 该命令提供了 ncrcat 命令,从而可以汇总数据:

Why not avoid programming entirely and use NCO which supplies the ncrcat command that aggregates data thusly:

ncrcat day*.nc month.nc

Voilà.查看更多 ncrcat 示例此处.

Voilà. See more ncrcat examples here.

添加了20160628:如果您想要一个月的平均时间而不是一个月的时间序列,则仅对 ncra 而不是 ncrcat 使用相同的命令.手册解释了这样的事情.

Added 20160628: If instead of a month-long timeseries you want a monthly average then use the same command only with ncra instead of ncrcat. The manual explains things like this.

这篇关于如何每天将NetCDF文件转换为每月的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-24 11:04