satpy.tests.test_writers module
Test generic writer functions.
- class satpy.tests.test_writers.TestBaseWriter[source]
Bases:
object
Test the base writer class.
- test_save_dataset_dynamic_filename(fmt_fn, exp_fns)[source]
Test saving a dataset with a format 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 '}
- class satpy.tests.test_writers.TestComputeWriterResults[source]
Bases:
object
Test compute_writer_results().
- class satpy.tests.test_writers.TestEnhancer[source]
Bases:
object
Test basic Enhancer functionality with builtin configs.
- 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.
- class satpy.tests.test_writers.TestOverlays[source]
Bases:
object
Tests for add_overlay and add_decorate functions.
- 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 '}
- test_no_matching_reader(test_configs_path)[source]
Test that a DataArray with no matching ‘reader’ works.
- class satpy.tests.test_writers.TestYAMLFiles[source]
Bases:
object
Test and analyze the writer configuration files.
- 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 thetrollsift
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 theEnhancer
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 todask.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).