satpy.cf.coords module

Set CF-compliant spatial and temporal coordinates.

class satpy.cf.coords._TimeBoundsCalculator(ds, time_dim)[source]

Bases: object

Initialize time bounds calculator.

Parameters:
  • ds (Dataset) – Dataset to be analyzed

  • time_dim (str) – Name of time dimension

__init__(ds, time_dim)[source]

Initialize time bounds calculator.

Parameters:
  • ds (Dataset) – Dataset to be analyzed

  • time_dim (str) – Name of time dimension

_get_bounds_for_all_but_last_timestep()[source]
_get_bounds_for_last_timestep()[source]
_get_bounds_multiple_timesteps()[source]

Get time bounds for a dataset with multiple timesteps.

Computes bounds based on time coordinates and for the last timestep uses the “end_time” attribute. Example for 3 timesteps:

bounds = [
    (t[0], t[1]),
    (t[1], t[2]),
    (t[2], max_end_time_from_attrs)
]
_get_bounds_single_timestep()[source]

Get time bounds for a dataset with a single timestep.

Computes time bounds entirely from dataset attributes start_time and end_time.

_get_time_from_attrs(time_attr, min_or_max)[source]
get_time_bounds()[source]

Get time bounds for the given dataset.

Return type:

DataArray

satpy.cf.coords._add_declared_coordinates(data_arrays, dataarray_name)[source]

Add declared coordinates to the dataarray if they exist.

Return type:

dict[str, DataArray]

satpy.cf.coords._add_xy_geographic_coords_attrs(data_arr, x='x', y='y')[source]

Add relevant attributes to x, y coordinates of a geographic CRS.

Return type:

DataArray

satpy.cf.coords._add_xy_projected_coords_attrs(data_arr, x='x', y='y')[source]

Add relevant attributes to x, y coordinates of a projected CRS.

Return type:

DataArray

satpy.cf.coords._get_coordinates_list(data_arr)[source]

Return a list with the coordinates names specified in the ‘coordinates’ attribute.

Return type:

list[str]

satpy.cf.coords._get_is_nondimensional_coords_dict(data_arrays)[source]
Return type:

dict[str, bool]

satpy.cf.coords._is_area(data_arr)[source]
Return type:

bool

satpy.cf.coords._is_lon_or_lat_dataarray(data_arr)[source]

Check if the DataArray represents the latitude or longitude coordinate.

Return type:

bool

satpy.cf.coords._is_projected(data_arr)[source]

Guess whether data are projected or not.

Return type:

bool

satpy.cf.coords._is_swath(data_arr)[source]
Return type:

bool

satpy.cf.coords._rename_coords(data_arrays, coord_name)[source]

Rename coordinates in the datasets.

Return type:

dict[str, DataArray]

satpy.cf.coords._try_add_coordinate(data_arrays, dataarray_name, coord)[source]

Try to add a coordinate to the dataarray, warn if not possible.

Return type:

dict[str, DataArray]

satpy.cf.coords._try_get_units_from_coords(data_arr)[source]

Try to retrieve coordinate x/y units.

Return type:

str | None

satpy.cf.coords._try_to_get_crs(data_arr)[source]

Try to get a CRS from attributes.

Return type:

CRS

satpy.cf.coords._warn_if_pretty_but_not_unique(pretty, coord_name)[source]

Warn if coordinates cannot be pretty-formatted due to non-uniqueness.

satpy.cf.coords.add_coordinates_attrs_coords(data_arrays)[source]

Add to DataArrays the coordinates specified in the ‘coordinates’ attribute.

It deal with the ‘coordinates’ attributes indicating lat/lon coords The ‘coordinates’ attribute is dropped from each DataArray

If the coordinates attribute of a data array links to other dataarrays in the scene, for example coordinates=’lon lat’, add them as coordinates to the data array and drop that attribute.

In the final call to xr.Dataset.to_netcdf() all coordinate relations will be resolved and the coordinates attributes be set automatically.

Return type:

dict[str, DataArray]

satpy.cf.coords.add_time_bounds_dimension(ds, time='time')[source]

Add time bound dimension to xr.Dataset.

Return type:

Dataset

satpy.cf.coords.add_xy_coords_attrs(data_arr)[source]

Add relevant attributes to x, y coordinates.

Return type:

DataArray

satpy.cf.coords.check_unique_projection_coords(data_arrays)[source]

Check that all datasets share the same projection coordinates x/y.

Return type:

None

satpy.cf.coords.ensure_unique_nondimensional_coords(data_arrays, pretty=False)[source]

Make non-dimensional coordinates unique among all datasets.

Non-dimensional coordinates, such as scanline timestamps, may occur in multiple datasets with the same name and dimension but different values.

In order to avoid conflicts, prepend the dataset name to the coordinate name. If a non-dimensional coordinate is unique among all datasets and pretty=True, its name will not be modified.

Since all datasets must have the same projection coordinates, this is not applied to latitude and longitude.

Parameters:
  • data_arrays (dict[str, DataArray]) – Dictionary of (dataset name, dataset)

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

Return type:

dict[str, DataArray]

Returns:

Dictionary holding the updated datasets

satpy.cf.coords.has_projection_coords(data_arrays)[source]

Check if DataArray collection has a “longitude” or “latitude” DataArray.

Return type:

bool

satpy.cf.coords.set_cf_time_info(data_arr, epoch)[source]

Set CF time attributes and encoding.

It expand the DataArray with a time dimension if does not yet exists.

The function assumes

  • that x and y dimensions have at least shape > 1

  • the time coordinate has size 1

Return type:

DataArray