【问题标题】:Merging Netcdf files on python在 python 上合并 Netcdf 文件
【发布时间】:2021-06-10 01:28:39
【问题描述】:

我想合并两个 netcdf 文件。问题是第一个文件中的所有变量都包含在第二个文件中(具有不同的数据),而第二个文件有一些额外的变量。所以,我想获得一个 netcdf 文件,其中包含第二个文件的所有变量以及第一个文件的数据(定义时)。 谢谢大家。

【问题讨论】:

    标签: python merge netcdf


    【解决方案1】:

    您应该可以使用 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")
    

    【讨论】:

    • 嗨,谢谢罗伯特。我已经尝试过你的方法,但我有一个“文件”/cluster/home/rleblanc/python_venv/lib/python3.6/site-packages/nctoolkit/mergers.py”,第 43 行,合并引发 TypeError(“提供的匹配项是ds.merge(ds2) 的不是列表")" 错误。你知道为什么会这样吗?
    • 我的错。我已经确定了答案
    • 您可能需要修改 match 参数,因为这会检查文件中的时间是否兼容
    猜你喜欢
    • 2013-06-28
    • 2017-12-19
    • 2015-05-11
    • 2018-10-10
    • 1970-01-01
    • 2022-01-08
    • 2018-09-06
    • 1970-01-01
    • 2013-12-18
    相关资源
    最近更新 更多