pyNCO: extract/subset/slice netcdf by dimensions (bbox) in a single command - 语法问题

pyNCO: extract/subset/slice netcdf by dimensions (bbox) in a single command - syntax issues

使用 NCO 我可以根据给定坐标轻松地从 netCDF 文件创建子集,例如:

ncks -d latitude,40.,50. -d longitude,10.,30. in.nc out.nc

但我不知道用 pyNCO 重现这样的命令。类比语法可以是

nco.ncks(input='in.nc', output='out.nc', dimension="longitude,10.,15.", dimension="latitude,45.,50.")

但我得到一个错误:

SyntaxError: keyword argument repeated

我在文档或论坛中找不到合适的示例。我设法通过单个关键字和使用更多代码行的临时文件(速度较慢)做了一些解决方法……但我相信必须有更优雅的语法。

有人可以在这里提供一些指导吗?

这是 Python 错误,因为您有 (... dimension=..., dimension = ...),这会导致关键字参数重复。不幸的是我没有使用过 PyNCO,只是看看 https://pynco.readthedocs.io/en/latest/#usage 上的例子。似乎给出限制的正确方法是使用选项,并且列表中有几个维度选项。

你的情况:

opt = [
    c.Limit("lat", 45.0, 50.0),
    c.Limit(dmn_name="lon", srt=10.0, end=15.0),
]
nco.ncks(input='in.nc', output='out.nc', options = opt)