#NEWLINE# def save_mfdataset( datasets , paths , mode = 'w' , format = None , groups = None , engine = None ) : #NEWLINE# #INDENT# "Write multiple datasets to disk as netCDF files simultaneously.\n\n    This function is intended for use with datasets consisting of dask.array\n    objects, in which case it can write the multiple datasets to disk\n    simultaneously using a shared thread pool.\n\n    When not using dask, it is no different than calling ``to_netcdf``\n    repeatedly.\n\n    Parameters\n    ----------\n    datasets : list of xarray.Dataset\n        List of datasets to save.\n    paths : list of str\n        List of paths to which to save each corresponding dataset.\n    mode : {'w', 'a'}, optional\n        Write ('w') or append ('a') mode. If mode='w', any existing file at\n        these locations will be overwritten.\n    format : {'NETCDF4', 'NETCDF4_CLASSIC', 'NETCDF3_64BIT', 'NETCDF3_CLASSIC'}, optional\n        File format for the resulting netCDF file:\n\n        * NETCDF4: Data is stored in an HDF5 file, using netCDF4 API\n          features.\n        * NETCDF4_CLASSIC: Data is stored in an HDF5 file, using only\n          netCDF 3 compatibile API features.\n        * NETCDF3_64BIT: 64-bit offset version of the netCDF 3 file format,\n          which fully supports 2+ GB files, but is only compatible with\n          clients linked against netCDF version 3.6.0 or later.\n        * NETCDF3_CLASSIC: The classic netCDF 3 file format. It does not\n          handle 2+ GB files very well.\n\n        All formats are supported by the netCDF4-python library.\n        scipy.io.netcdf only supports the last two formats.\n\n        The default format is NETCDF4 if you are saving a file to disk and\n        have the netCDF4-python library available. Otherwise, xarray falls\n        back to using scipy to write netCDF files and defaults to the\n        NETCDF3_64BIT format (scipy does not support netCDF4).\n    groups : list of str, optional\n        Paths to the netCDF4 group in each corresponding file to which to save\n        datasets (only works for format='NETCDF4'). The groups will be created\n        if necessary.\n    engine : {'netcdf4', 'scipy', 'h5netcdf'}, optional\n        Engine to use when writing netCDF files. If not provided, the\n        default engine is chosen based on available dependencies, with a\n        preference for 'netcdf4' if writing to a file on disk.\n\n    Examples\n    --------\n\n    Save a dataset into one netCDF per year of data:\n\n    >>> years, datasets = zip(*ds.groupby('time.year'))\n    >>> paths = ['%s.nc' % y for y in years]\n    >>> xr.save_mfdataset(datasets, paths)\n    " #NEWLINE# if ( ( mode == 'w' ) and ( len ( set ( paths ) ) < len ( paths ) ) ) : #NEWLINE# #INDENT# raise ValueError ( "cannot use mode='w' when writing multiple datasets to the same path" ) #NEWLINE# #UNINDENT# if ( groups is None ) : #NEWLINE# #INDENT# groups = ( [ None ] * len ( datasets ) ) #NEWLINE# #UNINDENT# if ( len ( set ( [ len ( datasets ) , len ( paths ) , len ( groups ) ] ) ) > 1 ) : #NEWLINE# #INDENT# raise ValueError ( 'must supply lists of the same length for the datasets, paths and groups arguments to save_mfdataset' ) #NEWLINE# #UNINDENT# writer = ArrayWriter ( ) #NEWLINE# stores = [ to_netcdf ( ds , path , mode , format , group , engine , writer ) for ( ds , path , group ) in zip ( datasets , paths , groups ) ] #NEWLINE# try : #NEWLINE# #INDENT# writer . sync ( ) #NEWLINE# for store in stores : #NEWLINE# #INDENT# store . sync ( ) #NEWLINE# #UNINDENT# #UNINDENT# finally : #NEWLINE# #INDENT# for store in stores : #NEWLINE# #INDENT# store . close ( )