satpy.tests.test_writers module

Test generic writer functions.

class satpy.tests.test_writers.TestBaseWriter[source]

Bases: object

Test the base writer class.

setup_method()[source]

Set up tests.

teardown_method()[source]

Remove the temporary directory created for a test.

test_save_dataset_dynamic_filename(fmt_fn, exp_fns)[source]

Test saving a dataset with a format filename specified.

test_save_dataset_dynamic_filename_with_dir()[source]

Test saving a dataset with a format filename that includes a directory.

test_save_dataset_static_filename()[source]

Test saving a dataset with a static filename specified.

class satpy.tests.test_writers.TestComplexSensorEnhancerConfigs[source]

Bases: _BaseCustomEnhancementConfigTests

Test enhancement configs that use or expect multiple sensors.

ENH_FN = 'test_sensor1.yaml'
ENH_FN2 = 'test_sensor2.yaml'
TEST_CONFIGS: dict[str, str] = {'test_sensor1.yaml': '\nenhancements:\n  test1_sensor1_specific:\n    name: test1\n    sensor: test_sensor1\n    operations:\n    - name: stretch\n      method: !!python/name:satpy.enhancements.stretch\n      kwargs: {stretch: crude, min_stretch: 0, max_stretch: 200}\n\n        ', 'test_sensor2.yaml': '\nenhancements:\n  default:\n    operations:\n    - name: stretch\n      method: !!python/name:satpy.enhancements.stretch\n      kwargs: {stretch: crude, min_stretch: 0, max_stretch: 100}\n  test1_sensor2_specific:\n    name: test1\n    sensor: test_sensor2\n    operations:\n    - name: stretch\n      method: !!python/name:satpy.enhancements.stretch\n      kwargs: {stretch: crude, min_stretch: 0, max_stretch: 50}\n  exact_multisensor_comp:\n    name: my_comp\n    sensor: [test_sensor1, test_sensor2]\n    operations:\n    - name: stretch\n      method: !!python/name:satpy.enhancements.stretch\n      kwargs: {stretch: crude, min_stretch: 0, max_stretch: 20}\n            '}
test_enhance_bad_query_value()[source]

Test Enhancer doesn’t fail when query includes bad values.

test_multisensor_choice(test_configs_path)[source]

Test that a DataArray with two sensors works.

test_multisensor_exact(test_configs_path)[source]

Test that a DataArray with two sensors can match exactly.

class satpy.tests.test_writers.TestComputeWriterResults[source]

Bases: object

Test compute_writer_results().

setup_method()[source]

Create temporary directory to save files to and a mock scene.

teardown_method()[source]

Remove the temporary directory created for a test.

test_empty()[source]

Test empty result list.

test_geotiff()[source]

Test writing to mitiff file.

test_mixed()[source]

Test writing to multiple mixed-type files.

test_multiple_geotiff()[source]

Test writing to mitiff file.

test_multiple_simple()[source]

Test writing to geotiff files.

test_simple_image()[source]

Test writing to PNG file.

class satpy.tests.test_writers.TestEnhancer[source]

Bases: object

Test basic Enhancer functionality with builtin configs.

test_basic_init_no_args()[source]

Test Enhancer init with no arguments passed.

test_basic_init_no_enh()[source]

Test Enhancer init requesting no enhancements.

test_basic_init_provided_enh()[source]

Test Enhancer init with string enhancement configs.

test_init_nonexistent_enh_file()[source]

Test Enhancer init with a nonexistent enhancement configuration file.

class satpy.tests.test_writers.TestEnhancerUserConfigs[source]

Bases: _BaseCustomEnhancementConfigTests

Test Enhancer functionality when user’s custom configurations are present.

ENH_ENH_FN = 'enhancements/test_sensor.yaml'
ENH_ENH_FN2 = 'enhancements/test_sensor2.yaml'
ENH_FN = 'test_sensor.yaml'
ENH_FN2 = 'test_sensor2.yaml'
ENH_FN3 = 'test_empty.yaml'
TEST_CONFIGS: dict[str, str] = {'enhancements/test_sensor.yaml': '\nenhancements:\n  test1_kelvin:\n    name: test1\n    units: kelvin\n    operations:\n    - name: stretch\n      method: !!python/name:satpy.enhancements.stretch\n      kwargs: {stretch: crude, min_stretch: 0, max_stretch: 20}\n\n        ', 'enhancements/test_sensor2.yaml': '\n\n        ', 'test_empty.yaml': '', 'test_sensor.yaml': '\nenhancements:\n  test1_default:\n    name: test1\n    operations:\n    - name: stretch\n      method: !!python/name:satpy.enhancements.stretch\n      kwargs: {stretch: linear, cutoffs: [0., 0.]}\n\n        ', 'test_sensor2.yaml': '\n\n\n        '}
test_enhance_empty_config(test_configs_path)[source]

Test Enhancer doesn’t fail with empty enhancement file.

test_enhance_with_sensor_entry(test_configs_path)[source]

Test enhancing an image with a configuration section.

test_enhance_with_sensor_entry2(test_configs_path)[source]

Test enhancing an image with a more detailed configuration section.

test_enhance_with_sensor_no_entry(test_configs_path)[source]

Test enhancing an image that has no configuration sections.

test_no_enhance()[source]

Test turning off enhancements.

test_writer_custom_enhance()[source]

Test using custom enhancements with writer.

test_writer_no_enhance()[source]

Test turning off enhancements with writer.

class satpy.tests.test_writers.TestOverlays[source]

Bases: object

Tests for add_overlay and add_decorate functions.

setup_method()[source]

Create test data and mock pycoast/pydecorate.

teardown_method()[source]

Turn off pycoast/pydecorate mocking.

test_add_decorate_basic_l()[source]

Test basic add_decorate usage with L data.

test_add_decorate_basic_rgb()[source]

Test basic add_decorate usage with RGB data.

test_add_overlay_basic_l()[source]

Test basic add_overlay usage with L data.

test_add_overlay_basic_rgb()[source]

Test basic add_overlay usage with RGB data.

class satpy.tests.test_writers.TestReaderEnhancerConfigs[source]

Bases: _BaseCustomEnhancementConfigTests

Test enhancement configs that use reader name.

ENH_FN = 'test_sensor1.yaml'
TEST_CONFIGS: dict[str, str] = {'test_sensor1.yaml': '\nenhancements:\n  default_reader2:\n    reader: reader2\n    operations:\n    - name: stretch\n      method: !!python/name:satpy.enhancements.stretch\n      kwargs: {stretch: crude, min_stretch: 0, max_stretch: 75}\n  default:\n    operations:\n    - name: stretch\n      method: !!python/name:satpy.enhancements.stretch\n      kwargs: {stretch: crude, min_stretch: 0, max_stretch: 100}\n  test1_reader2_specific:\n    name: test1\n    reader: reader2\n    operations:\n    - name: stretch\n      method: !!python/name:satpy.enhancements.stretch\n      kwargs: {stretch: crude, min_stretch: 0, max_stretch: 50}\n  test1_reader1_specific:\n    name: test1\n    reader: reader1\n    operations:\n    - name: stretch\n      method: !!python/name:satpy.enhancements.stretch\n      kwargs: {stretch: crude, min_stretch: 0, max_stretch: 200}\n            '}
_get_enhanced_image(data_arr, test_configs_path)[source]
_get_test_data_array()[source]
test_no_matching_reader(test_configs_path)[source]

Test that a DataArray with no matching ‘reader’ works.

test_no_reader(test_configs_path)[source]

Test that a DataArray with no ‘reader’ metadata works.

test_only_reader_matches(test_configs_path)[source]

Test that a DataArray with only a matching ‘reader’ works.

test_reader_and_name_match(test_configs_path)[source]

Test that a DataArray with a matching ‘reader’ and ‘name’ works.

class satpy.tests.test_writers.TestWritersModule[source]

Bases: object

Test the writers module.

test_show(mock_get_image)[source]

Check showing.

test_to_image_1d()[source]

Conversion to image.

test_to_image_2d(mock_geoimage)[source]

Conversion to image.

test_to_image_3d(mock_geoimage)[source]

Conversion to image.

class satpy.tests.test_writers.TestYAMLFiles[source]

Bases: object

Test and analyze the writer configuration files.

test_available_writers()[source]

Test the ‘available_writers’ function.

test_filename_matches_writer_name()[source]

Test that every writer filename matches the name in the YAML.

class satpy.tests.test_writers._BaseCustomEnhancementConfigTests[source]

Bases: object

TEST_CONFIGS: dict[str, str] = {}
test_configs_path(tmp_path_factory)[source]

Create test enhancement configuration files in a temporary directory.

The root temporary directory is changed to and returned.

class satpy.tests.test_writers._CustomImageWriter(**kwargs)[source]

Bases: ImageWriter

Initialize image 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 .attrs of a DataArray object may be included. Format and conversion specifiers provided by the trollsift package 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.

  • enhance (bool or Enhancer) – Whether to automatically enhance data to be more visually useful and to fit inside the file format being saved to. By default, this will default to using the enhancement configuration files found using the default Enhancer class. This can be set to False so that no enhancments are performed. This can also be an instance of the Enhancer class if further custom enhancement is needed.

  • kwargs (dict) – Additional keyword arguments to pass to the Writer base class.

Changed in version 0.10: Deprecated enhancement_config_file and ‘enhancer’ in favor of enhance. Pass an instance of the Enhancer class to enhance instead.

save_image(img, **kwargs)[source]

Save Image object to a given filename.

Parameters:
  • img (trollimage.xrimage.XRImage) – Image object to save to disk.

  • filename (str) – Optionally specify the filename to save this dataset to. It may include string formatting patterns that will be filled in by dataset attributes.

  • 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.

  • **kwargs – Other keyword arguments to pass to this 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 to dask.array.store(). If target is provided the the caller is responsible for calling target.close() if the target has this method.

satpy.tests.test_writers.test_group_results_by_output_file(tmp_path)[source]

Test grouping results by output file.

Add a test for grouping the results from save_datasets(…, compute=False) by output file. This is useful if for some reason we want to treat each output file as a seperate computation (that can still be computed together later).