satpy.writers.geotiff module

GeoTIFF writer objects for creating GeoTIFF files from DataArray objects.

class satpy.writers.geotiff.GeoTIFFWriter(dtype=None, tags=None, **kwargs)[source]

Bases: satpy.writers.ImageWriter

Writer to save GeoTIFF images.

Basic example from Scene:

>>> scn.save_datasets(writer='geotiff')

By default the writer will use the Enhancer class to linear stretch the data (see Enhancements). To get Un-enhanced images enhance=False can be specified which will write a geotiff with the data type of the dataset. The fill value defaults to the the datasets "_FillValue" attribute if not None and no value is passed to fill_value for integer data. In case of float data if fill_value is not passed NaN will be used. If a geotiff with a certain datatype is desired for example 32 bit floating point geotiffs:

>>> scn.save_datasets(writer='geotiff', dtype=np.float32, enhance=False)

To add custom metadata use tags:

>>> scn.save_dataset(dataset_name, writer='geotiff',
...                  tags={'offset': 291.8, 'scale': -0.35})

For performance tips on creating geotiffs quickly and making them smaller see the Frequently Asked Questions.

Init the writer.

GDAL_OPTIONS = ('tfw', 'rpb', 'rpctxt', 'interleave', 'tiled', 'blockxsize', 'blockysize', 'nbits', 'compress', 'num_threads', 'predictor', 'discard_lsb', 'sparse_ok', 'jpeg_quality', 'jpegtablesmode', 'zlevel', 'photometric', 'alpha', 'profile', 'bigtiff', 'pixeltype', 'copy_src_overviews')
save_image(img, filename=None, dtype=None, fill_value=None, compute=True, keep_palette=False, cmap=None, tags=None, overviews=None, overviews_minsize=256, overviews_resampling=None, include_scale_offset=False, **kwargs)[source]

Save the image to the given filename in geotiff format.

Note for faster output and reduced memory usage the rasterio library must be installed. This writer currently falls back to using gdal directly, but that will be deprecated in the future.

Parameters
  • img (xarray.DataArray) – Data to save to geotiff.

  • filename (str) – Filename to save the image to. Defaults to filename passed during writer creation. Unlike the creation filename keyword argument, this filename does not get formatted with data attributes.

  • dtype (numpy.dtype) – Numpy data type to save the image as. Defaults to 8-bit unsigned integer (np.uint8) or the data type of the data to be saved if enhance=False. If the dtype argument is provided during writer creation then that will be used as the default.

  • fill_value (int or float) – Value to use where data values are NaN/null. If this is specified in the writer configuration file that value will be used as the default.

  • compute (bool) – Compute dask arrays and save the image immediately. If False then the return value can be passed to compute_writer_results() to do the computation. This is useful when multiple images may share input calculations where dask can benefit from not repeating them multiple times. Defaults to True in the writer by itself, but is typically passed as False by callers where calculations can be combined.

  • keep_palette (bool) – Save palette/color table to geotiff. To be used with images that were palettized with the “palettize” enhancement. Setting this to True will cause the colormap of the image to be written as a “color table” in the output geotiff and the image data values will represent the index values in to that color table. By default, this will use the colormap used in the “palettize” operation. See the cmap option for other options. This option defaults to False and palettized images will be converted to RGB/A.

  • cmap (trollimage.colormap.Colormap or None) – Colormap to save as a color table in the output geotiff. See keep_palette for more information. Defaults to the palette of the provided img object. The colormap’s range should be set to match the index range of the palette (ex. cmap.set_range(0, len(colors))).

  • tags (dict) – Extra metadata to store in geotiff.

  • overviews (list) –

    The reduction factors of the overviews to include in the image, eg:

    scn.save_datasets(overviews=[2, 4, 8, 16])
    

    If provided as an empty list, then levels will be computed as powers of two until the last level has less pixels than overviews_minsize. Default is to not add overviews.

  • overviews_minsize (int) – Minimum number of pixels for the smallest overview size generated when overviews is auto-generated. Defaults to 256.

  • overviews_resampling (str) – Resampling method to use when generating overviews. This must be the name of an enum value from rasterio.enums.Resampling and only takes effect if the overviews keyword argument is provided. Common values include nearest (default), bilinear, average, and many others. See the rasterio documentation for more information.

  • include_scale_offset (bool) – Activate inclusion of scale and offset factors in the geotiff to allow retrieving original values from the pixel values. False by default.

classmethod separate_init_kwargs(kwargs)[source]

Separate the init keyword args.