satpy.cf.datasets module

Utility to generate a CF-compliant Datasets.

satpy.cf.datasets._collect_cf_dataset(list_dataarrays, epoch=None, flatten_attrs=False, exclude_attrs=None, include_lonlats=True, pretty=False, include_orig_name=True, numeric_name_prefix='CHANNEL_')[source]

Process a list of xr.DataArray and return a dictionary with CF-compliant xr.Dataset.

Parameters:
  • list_dataarrays (list) – List of DataArrays to make CF compliant and merge into an xr.Dataset.

  • epoch (str, optional) – Reference time for encoding the time coordinates. Example format: “seconds since 1970-01-01 00:00:00”. If None, the default reference time is defined using from satpy.cf.coords import EPOCH.

  • flatten_attrs (bool, optional) – If True, flatten dict-type attributes.

  • exclude_attrs (list, optional) – List of xr.DataArray attribute names to be excluded.

  • include_lonlats (bool, optional) – If True, includes ‘latitude’ and ‘longitude’ coordinates also for a satpy.Scene defined on an AreaDefinition. If the ‘area’ attribute is a SwathDefinition, it always includes latitude and longitude coordinates.

  • pretty (bool, optional) – Don’t modify coordinate names, if possible. Makes the file prettier, but possibly less consistent.

  • include_orig_name (bool, optional) – Include the original dataset name as a variable attribute in the xr.Dataset.

  • numeric_name_prefix (str, optional) – Prefix to add to each variable with a name starting with a digit. Use ‘’ or None to leave this out.

Returns:

A partially CF-compliant xr.Dataset.

Return type:

xr.Dataset

satpy.cf.datasets._get_extra_ds(dataarray, keys=None)[source]

Get the ancillary_variables DataArrays associated to a dataset.

satpy.cf.datasets._get_group_dataarrays(group_members, list_dataarrays)[source]

Yield DataArrays that are part of a specific group.

satpy.cf.datasets._get_groups(groups, list_datarrays)[source]

Return a dictionary with the list of xr.DataArray associated to each group.

If no groups (groups=None), return all DataArray attached to a single None key. Else, collect the DataArrays associated to each group.

satpy.cf.datasets.collect_cf_datasets(list_dataarrays, header_attrs=None, exclude_attrs=None, flatten_attrs=False, pretty=True, include_lonlats=True, epoch=None, include_orig_name=True, numeric_name_prefix='CHANNEL_', groups=None)[source]

Process a list of xr.DataArray and return a dictionary with CF-compliant xr.Datasets.

If the xr.DataArrays does not share the same dimensions, it creates a collection of xr.Datasets sharing the same dimensions.

Parameters:
  • list_dataarrays (list) – List of DataArrays to make CF compliant and merge into groups of xr.Datasets.

  • header_attrs (dict) – Global attributes of the output xr.Dataset.

  • epoch (str, optional) – Reference time for encoding the time coordinates. Example format: “seconds since 1970-01-01 00:00:00”. If None, the default reference time is retrieved using from satpy.cf.coords import EPOCH.

  • flatten_attrs (bool, optional) – If True, flatten dict-type attributes.

  • exclude_attrs (list, optional) – List of xr.DataArray attribute names to be excluded.

  • include_lonlats (bool, optional) – If True, includes ‘latitude’ and ‘longitude’ coordinates also for a satpy.Scene defined on an AreaDefinition. If the ‘area’ attribute is a SwathDefinition, it always includes latitude and longitude coordinates.

  • pretty (bool, optional) – Don’t modify coordinate names, if possible. Makes the file prettier, but possibly less consistent.

  • include_orig_name (bool, optional) – Include the original dataset name as a variable attribute in the xr.Dataset.

  • numeric_name_prefix (str, optional) – Prefix to add to each variable with a name starting with a digit. Use ‘’ or None to leave this out.

  • groups (dict, optional) – Group datasets according to the given assignment: {‘<group_name>’: [‘dataset_name1’, ‘dataset_name2’, …]}. Used to create grouped netCDFs using the CF_Writer. If None, no groups will be created.

Returns:

A tuple containing:
  • grouped_datasets (dict): A dictionary of CF-compliant xr.Dataset: {group_name: xr.Dataset}.

  • header_attrs (dict): Global attributes to be attached to the xr.Dataset / netCDF4.

Return type:

tuple