pcmdi_metrics.io.xcdat_open

pcmdi_metrics.io.xcdat_open(infile, data_var=None, decode_times=True)[source]

Open input file (netCDF, or xml generated by cdscan)

Parameters:
  • infile (Union[str, list]) – list of string, or string, for path of file(s) to open using xcdat.

  • data_var (str, optional) – key of the non-bounds data variable to keep in the Dataset, alongside any existing bounds data variables. By default None, which loads all data variables.

  • decode_times (bool, optional) – If True, attempt to decode times encoded in the standard NetCDF datetime format into cftime.datetime objects. Otherwise, leave them encoded as numbers. This keyword may not be supported by all the backends, by default True.

Returns:

xr.Dataset – xarray dataset opened via xcdat

Examples

>>> from pcmdi_metrics.io import xcdat_open
# Open a single netCDF file
>>> ds = xcdat_open('mydata.nc')
# Open multiple files
>>> ds = xcdat_open(['mydata1.nc', 'mydata2.nc'])  # Open multipe netCDF files
# Open multiple files using a wildcard
>>> ds = xcdat_open('mydata*.nc')
# Open with specifing the variable 'ts'
>>> ds = xcdat_open(['mydata1.nc', 'mydata2.nc'], data_var='ts')
# Open an xml file
>>> ds = xcdat_open('mydata.xml')