【发布时间】:2021-06-10 01:28:39
【问题描述】:
我想合并两个 netcdf 文件。问题是第一个文件中的所有变量都包含在第二个文件中(具有不同的数据),而第二个文件有一些额外的变量。所以,我想获得一个 netcdf 文件,其中包含第二个文件的所有变量以及第一个文件的数据(定义时)。 谢谢大家。
【问题讨论】:
我想合并两个 netcdf 文件。问题是第一个文件中的所有变量都包含在第二个文件中(具有不同的数据),而第二个文件有一些额外的变量。所以,我想获得一个 netcdf 文件,其中包含第二个文件的所有变量以及第一个文件的数据(定义时)。 谢谢大家。
【问题讨论】:
您应该可以使用 nctoolkit (https://nctoolkit.readthedocs.io/en/latest/) 轻松处理此问题,如下所示:
import nctoolkit as nc
# read in the files
ds = nc.open_data("infile1.nc")
ds2 = nc.open_data("infile2.nc")
# remove the 1st netcdf files variables from the second's
ds2.drop(ds.variables)
# merge the files
ds.append(ds2)
ds.merge()
# save the files as a netcdf file
ds.to_nc("merged.nc")
【讨论】: