微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

合并 netCDF 文件:各种不成功的尝试

如何解决合并 netCDF 文件:各种不成功的尝试

我正在尝试为一个变量合并 3 个数据集(1981-1990、1991-2000、2001-2010)。 以 Jupyter (Python) 为例,1981-1990 年的特征是:

enter image description here

每个数据集包含一个 10 年的时间段,其大小约为 4 GB。

看了一些帖子后,我在 Windows 10 中尝试了 4 种解决方案:

Jupyter (Python)

1.第一个建议

 import xarray as xr
    t2m_81_90 = xr.open_dataset('era5land_2m_temperature_hourly_ene-dic_1981-1990.nc')
    t2m_91_00 = xr.open_dataset('era5land_2m_temperature_hourly_ene-dic_1991-2000.nc')
    t2m_81_00 = xr.merge([t2m_1981_1990,t2m_1991_2000])

结果表明:

C:\Users\eleph\anaconda3\lib\site-packages\xarray\core\alignment.py:307: FutureWarning: Index.__or__ 
operating as a set operation is deprecated,in the future this will be a logical operation matching 
Series.__or__.  Use index.union(other) instead index = joiner(matching_indexes)

MemoryError: Unable to allocate 15.5 GiB for an array with shape (175319,184,129) and data type float32

2.第二个建议

ncrcat era5land_2m_temperature_hourly_ene-dic_1981-1990.nc era5land_2m_temperature_hourly_ene-dic_1991-2000.nc temper_all.nc

结果:

SyntaxError: invalid Syntax

3.第三个建议

import netCDF4
from netCDF4 import Dataset

dataset = netCDF4.MFDataset(['era5land_2m_temperature_hourly_ene-dic_1981-1990.nc','era5land_2m_temperature_hourly_ene-dic_1991-2000.nc'])

结果:

ModuleNotFoundError: No module named 'netCDF4'

我认为错误是因为未安装“netCDF4”,但在尝试安装后,显示

Found conflicts! Looking for incompatible packages.
This can take several minutes.  Press CTRL-C to abort. Failed

CDO (Cygwin)

4.第四条建议

$ cdo mergetime era5land_2m_temperature_hourly_ene-dic_1981-1990.nc era5land_2m_temperature_hourly_ene-dic_1991-2000.nc 2m_tempmerature_1981-2000.nc

结果:

cdf_put_vara_double: name=t2m  type=NC_SHORT  minval=-32767.000000  maxval=33531.000000

Error (cdf_put_vara_double): NetCDF: Numeric conversion not representable

我知道这篇文章很长,但我想展示我所做的试验。也许其中一些可以修复。 任何合并这些数据集的帮助都将得到认可!

解决方法

使用

xarray.open_mfdataset([
    'era5land_2m_temperature_hourly_ene-dic_1981-1990.nc','era5land_2m_temperature_hourly_ene-dic_1991-2000.nc'
]) 

并定义参数 concat_dim 。我想它应该是一个可以连接数据集的时间维度。

提示:打开多个文件时打开并行模式。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。