0

I have a folder with files whose name goes from f000 to f168, and I would like to select only files above f000, that is, from f003, f006, to f168. How can I do this ?

The file name starts like this:

gfs.0p25.2020010100.f000.WE.grib2

  • You can pass a list to `open_mfdataset` rather than a glob string (assuming that’s what you’re asking about?). So you can simply exclude the paths you don’t want from the list. – Michael Delgado Jan 23 '23 at 07:14

1 Answers1

1

As suggested above, you can always filter the list of files before passing them to open_mfdataset:

import glob
import xarray as xr

files = glob.glob('/path/to/files/*grib2')
filtered = [f for f in files if 'f000' in f]

ds = xr.open_mfdataset(filtered)

Alternatively, you may be able to tune your glob string to do this automatically:

ds = xr.open_mfdataset('/path/to/files/*.f000.*.grib2')
jhamman
  • 5,867
  • 19
  • 39