【问题标题】:Combining temp/lat/lon netcdf files via python通过 python 组合 temp/lat/lon netcdf 文件
【发布时间】:2015-04-21 04:24:09
【问题描述】:

我正在尝试将两个 netcdf 文件合并为一个,以便我的 python 脚本具有更少的 I/O。 netcdf 文件排列如下:float tasmax(time, lat, lon) 和float tasmin(time, lat, lon)。我想组合这两个温度文件并拥有一个“tasavg”netcdf 文件。我该怎么做呢?如果您需要任何其他信息,请告诉我。

【问题讨论】:

    标签: python latitude-longitude netcdf


    【解决方案1】:

    假设time 是一个记录维度,您可以使用NCO 包中的ncrcatncra

    # Combine the two files into one, along the 'time' dimension
    ncrcat file1.nc file2.nc -O new_file.nc
    
    # Average along the 'time' dimension
    ncra new_file.nc -O new_file_avg.nc 
    

    编辑:

    这就是如何完成你实际要求的......

    假设这两个文件名为 tasmin.nc 和 tasmax.nc。我们需要先将这两个文件的内容合并为一个文件:

    ncks -A tasmin.nc tasmax.nc
    

    这会将 tasmin.nc 的内容附加到 tasmax.nc。所以 tasmax.nc 现在将在其中包含变量 tasmaxtasmin

    接下来我们需要通过将tasmintasmax 相加然后除以2 来找到平均温度:

    ncap -s "tasavg=(tasmin+tasmax)/2" tasmax.nc -O tasavg.nc
    

    这将生成一个新的 netcdf 文件 tasavg.nc,其中将包含变量 tasmintasmaxtasavg。您现在可以在 Python 中阅读 tasavg.nc 并提取 tasavg 以进一步使用。

    【讨论】:

    • 我尝试了第一步,得到以下错误: 错误:nco_inq_varid() 报告请求的变量“tasmax”不在输入文件中 nco_err_exit():错误 NCO 生成的短消息(通常名称为触发错误的函数): nco_inq_varid() nco_err_exit(): ERROR 错误代码为 -49。用 nc_strerror(-49) 翻译成英文是 "NetCDF: Variable not found" nco_err_exit(): ERROR NCO will now exit with system call exit(EXIT_FAILURE)
    • 我误读了您最初的问题的一部分,请查看我编辑后的回复。
    猜你喜欢
    • 1970-01-01
    • 2016-02-20
    • 2021-09-18
    • 1970-01-01
    • 2020-10-09
    • 2018-09-05
    • 2018-02-13
    • 2014-01-04
    • 2021-08-14
    相关资源
    最近更新 更多