how to open many datasets using xarray code example

Example: how to open many datasets using xarray

import xarray as xr, glob

netcdf_file_list = [netcdf_file_1, netcdf_file_2, netcdf_file_3, netcdf_file_n]
xr.open_mfdataset(netcdf_file_list)

#now that you have all the datasets opened you can perform computations on this
#for example you can get a median plot based on a subset of information found
#in all the datasets which can then be used to make one median dataset for
#example

#for example:
glob_pattern = glob.glob(/directory_path/*.nc)

#take all the nc files in the directory and combine them
#based on the coordinates
mfds = xr.open_mfdataset(netcdf_file_list,
                        glob_pattern,
                        combine='by_coords' #for example
                        )

Tags:

Misc Example