[英]how to open multiple netcdf files stored in multiple folders Python
right now I am able to open multiple netcdf files from a single folder using the command given below: 现在,我可以使用以下命令从单个文件夹中打开多个netcdf文件:
dsmerged = xarray.open_mfdataset('F:/netcdf/example/*.nc')
However, I am unable to open multiple netcdf files from different folders or directories using this command. 但是,我无法使用此命令从不同的文件夹或目录中打开多个netcdf文件。 Suppose I am having multiple netcdf files stored in multiple folders so how can I open together?
假设我将多个netcdf文件存储在多个文件夹中,那么如何一起打开? Suggestions are appreciated.
建议表示赞赏。
From the docs , you can either pass in a glob string (like you have) or a list of explicit filenames to open. 在docs中 ,您可以传递glob字符串(如您所愿)或显式文件名列表以打开。 Therefore I would do the following:
因此,我将执行以下操作:
import glob
# Get a list of all .nc files available in different folders
filenames = glob.glob("/parent/directory/*/*/*.nc")
dsmerged = xarray.open_mfdataset(filenames)
This works on Python 2.7 and 3.6. 这适用于Python 2.7和3.6。
Note you may have to run this a few times and concatenate the returned lists if not all files are in the same directory structure. 请注意 ,如果不是所有文件都位于同一目录结构中,则可能必须运行几次并连接返回的列表。 Ie if some .nc files are in /path/one/here/file.nc and others are in /path/here/file.nc
也就是说,如果某些.nc文件位于/path/one/here/file.nc中,而其他文件位于/path/here/file.nc中
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.