class_docstr: Test case for CF reader.
class_docstr_tok: ["Test","case","for","CF","reader","."]
docstr: Save a dataset with a swath definition to file with cf_writer and read the data again.
docstr_tok: ["Save","a","dataset","with","a","swath","definition","to","file","with","cf_writer","and","read","the","data","again","."]
code: def test_write_and_read_with_swath_definition(
      self, cf_scene, nc_filename
  ):
      """Save a dataset with a swath definition to file with cf_writer and read the data again."""
      with warnings.catch_warnings():
          # Filter out warning about missing lon/lat DataArray coordinates
          warnings.filterwarnings(
              "ignore",
              category=UserWarning,
              message=r"Coordinate .* referenced",
          )
          cf_scene.save_datasets(
              writer="cf",
              filename=nc_filename,
              engine="h5netcdf",
              flatten_attrs=True,
              pretty=True,
              datasets=["swath_data"],
          )
      scn_ = Scene(reader="satpy_cf_nc", filenames=[nc_filename])
      scn_.load(["swath_data"])
      expected_area = cf_scene["swath_data"].attrs["area"]
      actual_area = scn_["swath_data"].attrs["area"]
      assert expected_area.shape == actual_area.shape
      np.testing.assert_array_equal(
          expected_area.lons.data, actual_area.lons.data
      )
      np.testing.assert_array_equal(
          expected_area.lats.data, actual_area.lats.data
      )
  
imports: import warnings
  from datetime import datetime
  import numpy
  import pytest
  import xarray
  from pyresample import AreaDefinition, SwathDefinition
  from satpy import Scene
  from satpy.dataset.dataid import WavelengthRange
  from satpy.readers.satpy_cf_nc import SatpyCFFileHandler
label_desc: Use image node_id 2 for calling the TestCFReader obj's underlying member method code with example usage: obj.test_write_and_read_with_swath_definition(cf_scene, nc_filename) without return types