class_docstr: Test cases for CF spatial dimension and coordinates.
class_docstr_tok: ["Test","cases","for","CF","spatial","dimension","and","coordinates","."]
docstr: Check that coordinates link has been established correctly.
docstr_tok: ["Check","that","coordinates","link","has","been","established","correctly","."]
code: def test_add_coordinates_attrs_coords(self):
      """Check that coordinates link has been established correctly."""
      from satpy.cf.coords import add_coordinates_attrs_coords
  
      data = [[1, 2], [3, 4]]
      lon = np.zeros((2, 2))
      lon2 = np.zeros((1, 2, 2))
      lat = np.ones((2, 2))
      datasets = {
          "var1": xr.DataArray(
              data=data,
              dims=("y", "x"),
              attrs={"coordinates": "lon lat"},
          ),
          "var2": xr.DataArray(data=data, dims=("y", "x")),
          "var3": xr.DataArray(
              data=data,
              dims=("y", "x"),
              attrs={"coordinates": "lon2 lat"},
          ),
          "var4": xr.DataArray(
              data=data,
              dims=("y", "x"),
              attrs={"coordinates": "not_exist lon lat"},
          ),
          "lon": xr.DataArray(data=lon, dims=("y", "x")),
          "lon2": xr.DataArray(data=lon2, dims=("time", "y", "x")),
          "lat": xr.DataArray(data=lat, dims=("y", "x")),
      }
  
      datasets = add_coordinates_attrs_coords(datasets)
  
      # Check that link has been established correctly and 'coordinate' atrribute has been dropped
      assert "lon" in datasets["var1"].coords
      assert "lat" in datasets["var1"].coords
      np.testing.assert_array_equal(datasets["var1"]["lon"].data, lon)
      np.testing.assert_array_equal(datasets["var1"]["lat"].data, lat)
      assert "coordinates" not in datasets["var1"].attrs
  
      # There should be no link if there was no 'coordinate' attribute
      assert "lon" not in datasets["var2"].coords
      assert "lat" not in datasets["var2"].coords
  
      # The non-existent dimension or coordinate should be dropped
      assert "time" not in datasets["var3"].coords
      assert "not_exist" not in datasets["var4"].coords
  
file_path: satpy/satpy/tests/cf_tests/test_coords.py
imports: import logging
  import numpy
  import pytest
  import xarray
  from pyresample import AreaDefinition
label_desc: Use image node_id 2 for calling the TestCFcoords obj's underlying member method code with example usage: obj.test_add_coordinates_attrs_coords() without return types