class_docstr: Container for inference data storage using xarray.
  
  For a detailed introduction to ``InferenceData`` objects and their usage, see
  :ref:`xarray_for_arviz`. This page provides help and documentation
  on ``InferenceData`` methods and their low level implementation.
class_docstr_tok: ["Container","for","inference","data","storage","using","xarray",".","For","a","detailed","introduction","to","``","InferenceData","``","objects","and","their","usage",",","see",":","ref",":","`","xarray_for_arviz","`",".","This","page","provides","help","and","documentation","on","``","InferenceData","``","methods","and","their","low","level","implementation","."]
docstr: Initialize object from a netcdf file.
  
  Expects that the file will have groups, each of which can be loaded by xarray.
  By default, the datasets of the InferenceData object will be lazily loaded instead
  of being loaded into memory. This
  behaviour is regulated by the value of ``az.rcParams["data.load"]``.
  
  Parameters
  ----------
  filename : str
      location of netcdf file
  engine : {"h5netcdf", "netcdf4"}, default "h5netcdf"
      Library used to read the netcdf file.
  group_kwargs : dict of {str: dict}, optional
      Keyword arguments to be passed into each call of :func:`xarray.open_dataset`.
      The keys of the higher level should be group names or regex matching group
      names, the inner dicts re passed to ``open_dataset``
      This feature is currently experimental.
  regex : bool, default False
      Specifies where regex search should be used to extend the keyword arguments.
      This feature is currently experimental.
  base_group : str, default "/"
      The group in the netCDF file where the InferenceData is stored. By default,
      assumes that the file only contains an InferenceData object.
  
  Returns
  -------
  InferenceData
docstr_tok: ["Initialize","object","from","a","netcdf","file",".","Expects","that","the","file","will","have","groups",",","each","of","which","can","be","loaded","by","xarray",".","By","default",",","the","datasets","of","the","InferenceData","object","will","be","lazily","loaded","instead","of","being","loaded","into","memory",".","This","behaviour","is","regulated","by","the","value","of","``","az.rcParams","[","``","data.load","''","]","``",".","Parameters","--","--","--","--","--","filename",":","str","location","of","netcdf","file","engine",":","{","``","h5netcdf","''",",","``","netcdf4","''","}",",","default","``","h5netcdf","''","Library","used","to","read","the","netcdf","file",".","group_kwargs",":","dict","of","{","str",":","dict","}",",","optional","Keyword","arguments","to","be","passed","into","each","call","of",":","func",":","`","xarray.open_dataset","`",".","The","keys","of","the","higher","level","should","be","group","names","or","regex","matching","group","names",",","the","inner","dicts","re","passed","to","``","open_dataset","``","This","feature","is","currently","experimental",".","regex",":","bool",",","default","False","Specifies","where","regex","search","should","be","used","to","extend","the","keyword","arguments",".","This","feature","is","currently","experimental",".","base_group",":","str",",","default","``","\/","''","The","group","in","the","netCDF","file","where","the","InferenceData","is","stored",".","By","default",",","assumes","that","the","file","only","contains","an","InferenceData","object",".","Returns","--","--","--","-","InferenceData"]
code: def from_netcdf(
      filename,
      *,
      engine="h5netcdf",
      group_kwargs=None,
      regex=False,
      base_group: str = "/",
  ) -> "InferenceData":
      """Initialize object from a netcdf file.
  
      Expects that the file will have groups, each of which can be loaded by xarray.
      By default, the datasets of the InferenceData object will be lazily loaded instead
      of being loaded into memory. This
      behaviour is regulated by the value of ``az.rcParams["data.load"]``.
  
      Parameters
      ----------
      filename : str
          location of netcdf file
      engine : {"h5netcdf", "netcdf4"}, default "h5netcdf"
          Library used to read the netcdf file.
      group_kwargs : dict of {str: dict}, optional
          Keyword arguments to be passed into each call of :func:`xarray.open_dataset`.
          The keys of the higher level should be group names or regex matching group
          names, the inner dicts re passed to ``open_dataset``
          This feature is currently experimental.
      regex : bool, default False
          Specifies where regex search should be used to extend the keyword arguments.
          This feature is currently experimental.
      base_group : str, default "/"
          The group in the netCDF file where the InferenceData is stored. By default,
          assumes that the file only contains an InferenceData object.
  
      Returns
      -------
      InferenceData
      """
      groups = {}
      attrs = {}
  
      if engine == "h5netcdf":
          import h5netcdf
      elif engine == "netcdf4":
          import netCDF4 as nc
      else:
          raise ValueError(
              f"Invalid value for engine: {engine}. Valid options are: h5netcdf or netcdf4"
          )
  
      try:
          with h5netcdf.File(
              filename, mode="r"
          ) if engine == "h5netcdf" else nc.Dataset(
              filename, mode="r"
          ) as file_handle:
              if base_group == "/":
                  data = file_handle
              else:
                  data = file_handle[base_group]
  
              data_groups = list(data.groups)
  
          for group in data_groups:
              group_kws = {}
  
              group_kws = {}
              if group_kwargs is not None and regex is False:
                  group_kws = group_kwargs.get(group, {})
              if group_kwargs is not None and regex is True:
                  for key, kws in group_kwargs.items():
                      if re.search(key, group):
                          group_kws = kws
              group_kws.setdefault("engine", engine)
              with xr.open_dataset(
                  filename, group=f"{base_group}/{group}", **group_kws
              ) as data:
                  if rcParams["data.load"] == "eager":
                      groups[group] = data.load()
                  else:
                      groups[group] = data
  
          with xr.open_dataset(
              filename, engine=engine, group=base_group
          ) as data:
              attrs.update(data.load().attrs)
  
          return InferenceData(attrs=attrs, **groups)
      except OSError as err:
          if err.errno == -101:
              raise type(err)(
                  str(err)
                  + (
                      " while reading a NetCDF file. This is probably an error in HDF5, "
                      "which happens because your OS does not support HDF5 file locking.  See "
                      "https://stackoverflow.com/questions/49317927/"
                      "errno-101-netcdf-hdf-error-when-opening-netcdf-file#49317928"
                      " for a possible solution."
                  )
              ) from err
          raise err
  
imports: import os
  import re
  import sys
  import uuid
  import warnings
  from collections import OrderedDict, defaultdict
  from collections.abc import MutableMapping, Sequence
  from copy import copy
  from copy import deepcopy
  from datetime import datetime
  from html import escape
  from typing import TYPE_CHECKING, Any, Iterable, Iterator, List, Mapping, Optional, Tuple, TypeVar, Union, overload
  import numpy
  import xarray
  from packaging import version
  from ..rcparams import rcParams
  from ..utils import HtmlTemplate, _subset_list, _var_names, either_dict_or_kwargs
  from .base import _extend_xr_method, _make_json_serializable, dict_to_dataset
label_desc: Use image node_id 16 for calling the InferenceData obj's underlying member method code with example usage: obj.from_netcdf(filename) and returns: InferenceData