将2个NETCDF文件与Xarray结合在时间维度
我尝试使用此命令将两个NETCDF文件组合在一起。第一个文件运行了1到10天,然后从11到20天进行了下一个文件。时间记录为NETCDF文件中的年/月/天。
ds = xr.open_mfdataset([file1, file2], combine='nested',concat_dim=["time"])
这些文件具有3-D(时间,LON,LAT)维度的数据变量,其中LON和LAT在两个文件中的每个文件中保持恒定。时间数组确实扩展到20天,但是在执行上面命令后,数据阵列在合并后的输出文件中保持10天。
使用CDO Mergetime实用程序,我能够通过这样做来克服问题
cdo mergetime file1.nc file2.nc mergedfile.nc
,但是我试图在脚本中执行此操作,而更喜欢使用Xarray而不是CDO。有任何评论会对为什么Xarray在这种情况下不将非时数阵列结合在一起?
I tried to combine two netcdf files along the time dimension using this command. The first file ran 1 to 10 days and then the next one from 11 to 20 days. Time was recorded as year/month/days in the netcdf files.
ds = xr.open_mfdataset([file1, file2], combine='nested',concat_dim=["time"])
The files have data variables that are 3-d (time, lon, lat) dimensions where lon and lat stay constant in each of the two files. The time array did expand to 20 days but data arrays remained as 10 days in the merged output file after executing the command above.
Using cdo mergetime utility, I was able to overcome the problem by doing
cdo mergetime file1.nc file2.nc mergedfile.nc
However, I am trying to do this in a script and prefer using xarray over cdo. Any comments would help on why xarray doesn't combine non-time arrays in this scenario?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该在MF_DATASET中尝试不同的选项。我能够复制您的问题并通过更改一些选项来解决此问题:
因此,“ Merged_default.nc”将原始的2D和3D变量同时为3D变量,但在“ Merged_minimal.nc”中,2D变量为2D和3D变量是3D。
You should try different options in mf_dataset. I was able to replicate your problem and solve this by changing some options:
So, the "merged_default.nc" has both the original 2D and 3D variables as 3D variables but in the "merged_minimal.nc" the 2D variable is 2D and 3D variable is 3D.
您可以使用我的软件包 nctoolkit 来执行此操作。这使用CDO作为后端,因此将与您的CDO选项相同。
You could do this in Python using my package nctoolkit. This uses CDO as a backend, so will do the same thing as your CDO option.