简体   繁体   English

在 python 上合并 Netcdf 文件

[英]Merging Netcdf files on python

I would like to merge two netcdf files.我想合并两个 netcdf 文件。 The problem is that all the variables from the first file are contained in the second file (with different data) and the second file has some extra variables.问题是第一个文件中的所有变量都包含在第二个文件中(具有不同的数据),而第二个文件有一些额外的变量。 So, I would like to get a netcdf file having all the variables of the second file with the data of the first one (when defined).所以,我想获得一个 netcdf 文件,其中包含第二个文件的所有变量以及第一个文件的数据(定义时)。 Thank you all.谢谢你们。

You should be able to handle this easily using nctoolkit ( https://nctoolkit.readthedocs.io/en/latest/ ), as follows:您应该能够使用 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")

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

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