xcdat.open_dataset

Contents

xcdat.open_dataset#

xcdat.open_dataset(path, data_var=None, add_bounds=['X', 'Y'], decode_times=True, center_times=False, lon_orient=None, **kwargs)[source]#

Wraps xarray.open_dataset() with post-processing options.

Parameters:
  • path (str, Path, file-like or DataStore) – Strings and Path objects are interpreted as a path to a netCDF file or an OpenDAP URL and opened with python-netCDF4, unless the filename ends with .gz, in which case the file is gunzipped and opened with scipy.io.netcdf (only netCDF3 supported). Byte-strings or file-like objects are opened by scipy.io.netcdf (netCDF3) or h5py (netCDF4/HDF).

  • data_var (Optional[str], optional) – The key of the non-bounds data variable to keep in the Dataset, alongside any existing bounds data variables, by default None.

  • add_bounds (List[CFAxisKey] | None | bool) – List of CF axes to try to add bounds for (if missing), by default [“X”, “Y”]. Set to None to not add any missing bounds. Please note that bounds are required for many xCDAT features.

  • 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.

  • center_times (bool, optional) – If True, attempt to center time coordinates using the midpoint between its upper and lower bounds. Otherwise, use the provided time coordinates, by default False.

  • lon_orient (Optional[Tuple[float, float]], optional) – The orientation to use for the Dataset’s longitude axis (if it exists). Either (-180, 180) or (0, 360), by default None. Supported options include:

    • None: use the current orientation (if the longitude axis exists)

    • (-180, 180): represents [-180, 180) in math notation

    • (0, 360): represents [0, 360) in math notation

  • **kwargs (Dict[str, Any]) – Additional arguments passed on to xarray.open_dataset. Refer to the [1] xarray docs for accepted keyword arguments.

Returns:

xr.Dataset – Dataset after applying operations.

Notes

xarray.open_dataset opens the file with read-only access. When you modify values of a Dataset, even one linked to files on disk, only the in-memory copy you are manipulating in xarray is modified: the original file on disk is never touched.

References