satpy.writers.core.base module
Shared objects and base classes for writers.
- class satpy.writers.core.base.Writer(name=None, filename=None, base_dir=None, **kwargs)[source]
Bases:
Plugin,DataDownloadMixinBase Writer class for all other writers.
A minimal writer subclass should implement the save_dataset method.
Initialize the writer object.
- Parameters:
name (str) – A name for this writer for log and error messages. If this writer is configured in a YAML file its name should match the name of the YAML file. Writer names may also appear in output file attributes.
filename (str) –
Filename to save data to. This filename can and should specify certain python string formatting fields to differentiate between data written to the files. Any attributes provided by the
.attrsof a DataArray object may be included. Format and conversion specifiers provided by thetrollsiftpackage may also be used. Any directories in the provided pattern will be created if they do not exist. Example:{platform_name}_{sensor}_{name}_{start_time:%Y%m%d_%H%M%S}.tif
base_dir (str) – Base destination directories for all created files.
kwargs (dict) – Additional keyword arguments to pass to the
Pluginclass.
- __init__(name=None, filename=None, base_dir=None, **kwargs)[source]
Initialize the writer object.
- Parameters:
name (str) – A name for this writer for log and error messages. If this writer is configured in a YAML file its name should match the name of the YAML file. Writer names may also appear in output file attributes.
filename (str) –
Filename to save data to. This filename can and should specify certain python string formatting fields to differentiate between data written to the files. Any attributes provided by the
.attrsof a DataArray object may be included. Format and conversion specifiers provided by thetrollsiftpackage may also be used. Any directories in the provided pattern will be created if they do not exist. Example:{platform_name}_{sensor}_{name}_{start_time:%Y%m%d_%H%M%S}.tif
base_dir (str) – Base destination directories for all created files.
kwargs (dict) – Additional keyword arguments to pass to the
Pluginclass.
- create_filename_parser(base_dir)[source]
Create a
trollsift.parser.Parserobject for later use.
- get_filename(**kwargs)[source]
Create a filename where output data will be saved.
- Parameters:
kwargs (dict) – Attributes and other metadata to use for formatting the previously provided filename.
- save_dataset(dataset, filename=None, fill_value=None, compute=True, units=None, **kwargs)[source]
Save the
datasetto a givenfilename.This method must be overloaded by the subclass.
- Parameters:
dataset (xarray.DataArray) – Dataset to save using this writer.
filename (str) – Optionally specify the filename to save this dataset to. If not provided then filename which can be provided to the init method will be used and formatted by dataset attributes.
fill_value (int or float) – Replace invalid values in the dataset with this fill value if applicable to this writer.
compute (bool) – If True (default), compute and save the dataset. If False return either a Dask Delayed object or tuple of (source, target). See the return values below for more information.
units (str or None) – If not None, will convert the dataset to the given unit using pint-xarray before saving. Default is not to do any conversion.
**kwargs – Other keyword arguments for this particular writer.
- Returns:
Value returned depends on compute. If compute is True then the return value is the result of computing a Dask Delayed object or running
dask.array.store(). If compute is False then the returned value is either a Dask Delayed object that can be computed using delayed.compute() or a tuple of (source, target) that should be passed todask.array.store(). If target is provided the caller is responsible for calling target.close() if the target has this method.
- save_datasets(datasets, compute=True, **kwargs)[source]
Save all datasets to one or more files.
Subclasses can use this method to save all datasets to one single file or optimize the writing of individual datasets. By default this simply calls save_dataset for each dataset provided.
- Parameters:
datasets (Iterable) – Iterable of xarray.DataArray objects to save using this writer.
compute (bool) – If True (default), compute all the saves to disk. If False then the return value is either a Dask Delayed object or two lists to be passed to a
dask.array.store()call. See return values below for more details.**kwargs – Keyword arguments to pass to save_dataset. See that documentation for more details.
- Returns:
Value returned depends on compute keyword argument. If compute is True the value is the result of either a
dask.array.store()operation or a Dask Delayed compute, typically this is None. If compute is False then the result is either a Dask Delayed object that can be computed with delayed.compute() or a two element tuple of sources and targets to be passed todask.array.store(). If targets is provided then it is the caller’s responsibility to close any objects that have a “close” method.
- classmethod separate_init_kwargs(kwargs)[source]
Help separating arguments between init and save methods.
Currently the
Sceneis passed one set of arguments to represent the Writer creation and saving steps. This is not preferred for Writer structure, but provides a simpler interface to users. This method splits the provided keyword arguments between those needed for initialization and those needed for thesave_datasetandsave_datasetsmethod calls.Writer subclasses should try to prefer keyword arguments only for the save methods only and leave the init keyword arguments to the base classes when possible.