satpy.composites.mask module

Composites.

class satpy.composites.mask.CloudCompositor(name, transition_min=258.15, transition_max=298.15, transition_gamma=3.0, invert_alpha=False, **kwargs)[source]

Bases: GenericCompositor

Detect clouds based on thresholding and use it as a mask for compositing.

Collect custom configuration values.

Parameters:
  • transition_min (float) – Values below or equal to this are clouds -> opaque white

  • transition_max (float) – Values above this are cloud free -> transparent

  • transition_gamma (float) – Gamma correction to apply at the end

  • invert_alpha (bool) – Invert the alpha channel to make low data values transparent and high data values opaque.

__init__(name, transition_min=258.15, transition_max=298.15, transition_gamma=3.0, invert_alpha=False, **kwargs)[source]

Collect custom configuration values.

Parameters:
  • transition_min (float) – Values below or equal to this are clouds -> opaque white

  • transition_max (float) – Values above this are cloud free -> transparent

  • transition_gamma (float) – Gamma correction to apply at the end

  • invert_alpha (bool) – Invert the alpha channel to make low data values transparent and high data values opaque.

class satpy.composites.mask.HighCloudCompositor(name, transition_min_limits=(210.0, 230.0), latitude_min_limits=(30.0, 60.0), transition_max=300, transition_gamma=1.0, **kwargs)[source]

Bases: CloudCompositor

Detect high clouds based on latitude-dependent thresholding and use it as a mask for compositing.

This compositor aims at identifying high clouds and assigning them a transparency based on the brightness temperature (cloud opacity). In contrast to the CloudCompositor, the brightness temperature threshold at the lower end, used to identify high opaque clouds, is made a function of the latitude in order to have tropopause level clouds appear opaque at both high and low latitudes. This follows the Geocolor implementation of high clouds in Miller et al. (2020, DOI:10.1175/JTECH-D-19-0134.1), but with some adjustments to the thresholds based on recent developments and feedback from CIRA.

The two brightness temperature thresholds in transition_min are used together with the corresponding latitude limits in latitude_min to compute a modified version of transition_min that is later used when calling CloudCompositor. The modified version of transition_min will be an array with the same shape as the input projectable dataset, where the actual values of threshold_min are a function of the dataset latitude:

  • transition_min = transition_min[0] where abs(latitude) < latitude_min(0)

  • transition_min = transition_min[1] where abs(latitude) > latitude_min(0)

  • transition_min = linear interpolation between transition_min[0] and transition_min[1] as a function

    of where abs(latitude).

Collect custom configuration values.

Parameters:
  • transition_min_limits (tuple) – Brightness temperature values used to identify opaque white clouds at different latitudes

  • transition_max (float) – Brightness temperatures above this value are not considered to be high clouds -> transparent

  • latitude_min_limits (tuple) – Latitude values defining the intervals for computing latitude-dependent transition_min values from transition_min_limits.

  • transition_gamma (float) – Gamma correction to apply to the alpha channel within the brightness temperature range (transition_min to transition_max).

__init__(name, transition_min_limits=(210.0, 230.0), latitude_min_limits=(30.0, 60.0), transition_max=300, transition_gamma=1.0, **kwargs)[source]

Collect custom configuration values.

Parameters:
  • transition_min_limits (tuple) – Brightness temperature values used to identify opaque white clouds at different latitudes

  • transition_max (float) – Brightness temperatures above this value are not considered to be high clouds -> transparent

  • latitude_min_limits (tuple) – Latitude values defining the intervals for computing latitude-dependent transition_min values from transition_min_limits.

  • transition_gamma (float) – Gamma correction to apply to the alpha channel within the brightness temperature range (transition_min to transition_max).

class satpy.composites.mask.LongitudeMaskingCompositor(name, lon_min=None, lon_max=None, **kwargs)[source]

Bases: SingleBandCompositor

Masks areas outside defined longitudes.

Collect custom configuration values.

Parameters:
  • lon_min (float) – lower longitude limit

  • lon_max (float) – upper longitude limit

__init__(name, lon_min=None, lon_max=None, **kwargs)[source]

Collect custom configuration values.

Parameters:
  • lon_min (float) – lower longitude limit

  • lon_max (float) – upper longitude limit

class satpy.composites.mask.LowCloudCompositor(name, values_land=(1,), values_water=(0,), range_land=(0.0, 4.0), range_water=(0.0, 4.0), transition_gamma=1.0, invert_alpha=True, **kwargs)[source]

Bases: CloudCompositor

Detect low-level clouds based on thresholding and use it as a mask for compositing during night-time.

This compositor computes the brightness temperature difference between a window channel (e.g. 10.5 micron) and the near-infrared channel e.g. (3.8 micron) and uses this brightness temperature difference, BTD, to create a partially transparent mask for compositing.

Pixels with BTD values below a given threshold will be transparent, whereas pixels with BTD values above another threshold will be opaque. The transparency of all other BTD values will be a linear function of the BTD value itself. Two sets of thresholds are used, one set for land surface types (range_land) and another one for water surface types (range_water), respectively. Hence, this compositor requires a land-water-mask as a prerequisite input. This follows the GeoColor implementation of night-time low-level clouds in Miller et al. (2020, DOI:10.1175/JTECH-D-19-0134.1), but with some adjustments to the thresholds based on recent developments and feedback from CIRA.

Please note that the spectral test and thus the output of the compositor (using the expected input data) is only applicable during night-time.

Init info.

Collect custom configuration values.

Parameters:
  • values_land (list) – List of values used to identify land surface pixels in the land-water-mask.

  • values_water (list) – List of values used to identify water surface pixels in the land-water-mask.

  • range_land (tuple) – Threshold values used for masking low-level clouds from the brightness temperature difference over land surface types.

  • range_water (tuple) – Threshold values used for masking low-level clouds from the brightness temperature difference over water.

  • transition_gamma (float) – Gamma correction to apply to the alpha channel within the brightness temperature difference range.

  • invert_alpha (bool) – Invert the alpha channel to make low data values transparent and high data values opaque.

__init__(name, values_land=(1,), values_water=(0,), range_land=(0.0, 4.0), range_water=(0.0, 4.0), transition_gamma=1.0, invert_alpha=True, **kwargs)[source]

Init info.

Collect custom configuration values.

Parameters:
  • values_land (list) – List of values used to identify land surface pixels in the land-water-mask.

  • values_water (list) – List of values used to identify water surface pixels in the land-water-mask.

  • range_land (tuple) – Threshold values used for masking low-level clouds from the brightness temperature difference over land surface types.

  • range_water (tuple) – Threshold values used for masking low-level clouds from the brightness temperature difference over water.

  • transition_gamma (float) – Gamma correction to apply to the alpha channel within the brightness temperature difference range.

  • invert_alpha (bool) – Invert the alpha channel to make low data values transparent and high data values opaque.

class satpy.composites.mask.MaskingCompositor(name, transparency=None, conditions=None, mode='LA', **kwargs)[source]

Bases: GenericCompositor

A compositor that masks e.g. IR 10.8 channel data using cloud products from NWC SAF.

Collect custom configuration values.

Kwargs:
transparency (dict): transparency for each cloud type as

key-value pairs in a dictionary. Will be converted to conditions. DEPRECATED.

conditions (list): list of three items determining the masking

settings.

mode (str, optional): Image mode to return. For single-band input,

this shall be “LA” (default) or “RGBA”. For multi-band input, this argument is ignored as the result is always RGBA.

Each condition in conditions consists of three items:

  • method: Numpy method name. The following are supported

    operations: less, less_equal, equal, greater_equal, greater, not_equal, isnan, isfinite, isinf, isneginf, or isposinf.

  • value: threshold value of the mask applied with the

    operator. Can be a string, in which case the corresponding value will be determined from flag_meanings and flag_values attributes of the mask. NOTE: the value should not be given to ‘is*` methods.

  • transparency: transparency from interval [0 … 100] used

    for the method/threshold. Value of 100 is fully transparent.

Example:

>>> conditions = [{'method': 'greater_equal', 'value': 0,
                   'transparency': 100},
                  {'method': 'greater_equal', 'value': 1,
                   'transparency': 80},
                  {'method': 'greater_equal', 'value': 2,
                   'transparency': 0},
                  {'method': 'isnan',
                   'transparency': 100}]
>>> compositor = MaskingCompositor("masking compositor",
                                   transparency=transparency)
>>> result = compositor([data, mask])

This will set transparency of data based on the values in the mask dataset. Locations where mask has values of 0 will be fully transparent, locations with 1 will be semi-transparent and locations with 2 will be fully visible in the resulting image. In the end all NaN areas in the mask are set to full transparency. All the unlisted locations will be visible.

The transparency is implemented by adding an alpha layer to the composite. The locations with transparency of 100 will be set to NaN in the data. If the input data contains an alpha channel, it will be discarded.

__init__(name, transparency=None, conditions=None, mode='LA', **kwargs)[source]

Collect custom configuration values.

Kwargs:
transparency (dict): transparency for each cloud type as

key-value pairs in a dictionary. Will be converted to conditions. DEPRECATED.

conditions (list): list of three items determining the masking

settings.

mode (str, optional): Image mode to return. For single-band input,

this shall be “LA” (default) or “RGBA”. For multi-band input, this argument is ignored as the result is always RGBA.

Each condition in conditions consists of three items:

  • method: Numpy method name. The following are supported

    operations: less, less_equal, equal, greater_equal, greater, not_equal, isnan, isfinite, isinf, isneginf, or isposinf.

  • value: threshold value of the mask applied with the

    operator. Can be a string, in which case the corresponding value will be determined from flag_meanings and flag_values attributes of the mask. NOTE: the value should not be given to ‘is*` methods.

  • transparency: transparency from interval [0 … 100] used

    for the method/threshold. Value of 100 is fully transparent.

Example:

>>> conditions = [{'method': 'greater_equal', 'value': 0,
                   'transparency': 100},
                  {'method': 'greater_equal', 'value': 1,
                   'transparency': 80},
                  {'method': 'greater_equal', 'value': 2,
                   'transparency': 0},
                  {'method': 'isnan',
                   'transparency': 100}]
>>> compositor = MaskingCompositor("masking compositor",
                                   transparency=transparency)
>>> result = compositor([data, mask])

This will set transparency of data based on the values in the mask dataset. Locations where mask has values of 0 will be fully transparent, locations with 1 will be semi-transparent and locations with 2 will be fully visible in the resulting image. In the end all NaN areas in the mask are set to full transparency. All the unlisted locations will be visible.

The transparency is implemented by adding an alpha layer to the composite. The locations with transparency of 100 will be set to NaN in the data. If the input data contains an alpha channel, it will be discarded.

_get_alpha_bands(data, mask_in, alpha_attrs)[source]

Get alpha bands.

From input data, masks, and attributes, get alpha band.

_get_mask(method, value, mask_data)[source]

Get mask array from mask_data using method and threshold value.

The method is the name of a numpy function.

_select_data_bands(data_in)[source]

Select data to be composited from input data.

From input data, select the bands that need to have masking applied.

_set_data_nans(data, mask, attrs)[source]

Set data to nans where mask is True.

The attributes attrs* will be written to each band in data.

_supported_modes = {'LA', 'RGBA'}
class satpy.composites.mask.SimpleFireMaskCompositor(name, prerequisites=None, optional_prerequisites=None, **kwargs)[source]

Bases: CompositeBase

Class for a simple fire detection compositor.

Initialise the compositor.

satpy.composites.mask._get_flag_value(mask, val)[source]

Get a numerical value of the named flag.

This function assumes the naming used in product generated with NWC SAF GEO/PPS softwares.