Open selected files with open_mfdataset

Viewed 647

I have a folder containing a lot of files with similar names and I want to open two of them with xarray so I get one array (with the time axis consistent).

I know that I can open multiple files with the *

Example:

xarray.open_mfdataset('folder/*.nc') would open all netcdf files in the folder.

Now, say I have file_01, file_02 and file_03 in folder.

How can I open file_01 & file_02, but not file_03 ?

1 Answers

xr.open_mfdataset() can accept wildcards, as you said, but it can also accept an explicit list of files if you want to specify them.

So in your case, you could use:

xr.open_mfdataset(['folder/file1.nc','folder/file2.nc'])

Related