code: def to_netcdf(
      data,
      filename,
      *,
      group="posterior",
      engine="h5netcdf",
      coords=None,
      dims=None,
  ):
      """Save dataset as a netcdf file.
  
      WARNING: Only idempotent in case `data` is InferenceData
  
      Parameters
      ----------
      data : InferenceData, or any object accepted by `convert_to_inference_data`
          Object to be saved
      filename : str
          name or path of the file to load trace
      group : str (optional)
          In case `data` is not InferenceData, this is the group it will be saved to
      engine : {"h5netcdf", "netcdf4"}, default "h5netcdf"
          Library used to read the netcdf file.
      coords : dict (optional)
          See `convert_to_inference_data`
      dims : dict (optional)
          See `convert_to_inference_data`
  
      Returns
      -------
      str
          filename saved to
      """
      inference_data = convert_to_inference_data(
          data, group=group, coords=coords, dims=dims
      )
      file_name = inference_data.to_netcdf(filename, engine=engine)
      return file_name
  
imports: from .converters import convert_to_inference_data
  from .inference_data import InferenceData
label_desc: Use image node_id 2 for calling a global function with example usage: to_netcdf(data, filename) and returns: file_name