Masking#
- class grs.mask.Masking(prod)[source]#
Bases:
SettingsClass dedicated to pixel classification and masking.
- cirrus_mask(bitmasks=[5, 6], names=['thin_cirrus', 'opac_cirrus'], descriptions=['thin cirrus mask from cirrus band', 'opac cirrus mask from cirrus band'])[source]#
Compute cirrus mask for thin and opac high clouds from spectral band around 1375 nm, if exists
- Parameters:
bitmasks – bit numbers on which the flags are coded
names – name of the flags
descriptions – description of the flags
- Returns:
- cloud_mask(bitmasks=[1, 2], names=['cloud_p06', 'cloud_p08'], descriptions=['low confidence cloud mask from s2cloudless with settings proba.', 'high confidence cloud mask from s2cloudless with settings proba.'])[source]#
Apply s2cloudless masking with two levels of confidence
- Parameters:
bitmasks – bit number on which the flag is coded
names – name of the flag
descriptions – description of the flag
- Returns:
- static create_mask(flags, tomask=[0, 2], tokeep=[3], mask_name='mask', _type=<class 'numpy.uint8'>)[source]#
Create binary mask from bitmask flags, with selection of bitmask to mask or to keep (by bit number). The masking convention is: good pixels for mask == 0, bad pixels when mask == 1
- Parameters:
flags – xarray dataarray with bitmask flags
tomask – array of bitmask flags used to mask
tokeep – array of bitmask flags for which pixels are kept (= good quality)
mask_name – name of the output mask
_type – type of the array (uint8 is recommended)
- Returns:
mask
Example of output mask
>>> mask = create_mask(raster.flags, ... tomask = [0,2,11], ... tokeep = [3], ... mask_name="mask_from_flags" ) <xarray.DataArray> 'mask_from_flags' y: 5490x: 5490 array([[1, 1, 1, ..., 1, 1, 1], [1, 1, 1, ..., 1, 1, 1], [1, 1, 1, ..., 1, 1, 1], ..., [0, 0, 0, ..., 1, 1, 1], [0, 0, 0, ..., 1, 1, 1], [0, 0, 0, ..., 1, 1, 1]], dtype=uint8) Coordinates: x (x) float64 6e+05 6e+05 ... 7.098e+05 7.098e+05 y (y) float64 4.9e+06 4.9e+06 ... 4.79e+06 spatial_ref () int64 0 time () datetime64[ns] 2021-05-12T10:40:21 band () int64 1 Indexes: (2) Attributes: long_name: binary mask from flags description: good pixels for mask == 0, bad pixels when mask == 1
- duplicate_landsat_flags(bitmasks=[11, 12, 13, 14, 15, 16, 17], landsat_bitmasks=[1, 2, 3, 4, 5, 6, 7], names=['l1_dilated_cloud', 'l1_cirrus', 'l1_cloud', 'l1_cloud_shadow', 'l1_snow', 'l1_clear', 'l1_water'], descriptions=['landsat dilated cloud mask', 'landsat cirrus mask', 'landsat cloud mask', 'landsat cloud shadow mask', 'landsat snow mask', 'landsat clear mask', 'landsat water mask'], flags_landsat_band='flags_l1')[source]#
Save and duplicate landsat main masks from level 1 flags
- Parameters:
bitmasks – bit numbers on which the flags are coded
landsat_bitmasks – bit numbers of the landsat flags
names – name of the flags
descriptions – description of the flags
flags_landsat_band – name of the landsat flags band
- Returns:
- high_swir_mask(bitmask=7, name='high_swir', description='high swir (bright cloud, too bright reflection...)')[source]#
Flag to mask (too) high values of the swir bands, generally to remove potential cloud cotamination.
- Parameters:
bitmask – bit number on which the flags are coded
name – name of the flag
description – description used as attribute
- Returns:
- nodata_mask(bitmask=0, name='nodata', description='nodata in input image')[source]#
set flag nodata: condition either nan or crazy numerical values
- Returns:
- print_stats()[source]#
Provide pandas Dataframe with image statistics of each flag
- Returns:
dflags:: pandas Dataframe with statistics
- process(output='prod')[source]#
Generate the flags raster and attributes
- Parameters:
output –
if None returns nothing but the raster is updated within the masking object
if “prod” returns the full raster updated with the flags variable and attributes
if “flags” returns xarray DataArray of the flags plus the dictionary of flags statistics
- Returns:
see :param output
- surfwater_mask(bitmasks=[8, 9, 10], names=['surfwater_land', 'surfwater_water', 'surfwater_cloud_and_shadow'], descriptions=['land mask from surfwater input file', 'water mask from surfwater input file', 'cloud and shadow mask from surfwater input file'])[source]#
apply surfwater masks
TODO give reference for surfwater algorithm and code
- Parameters:
bitmasks – bit numbers on which the flags are coded
names – name of the flags
descriptions – description of the flags
- Returns:
- water_mask(bitmasks=[3, 4], names=['water_swir_visible_index', 'water_red_visible_index'], descriptions=['water mask from normalized index from swir and visible band', 'water mask from normalized index from nir and visible band, warning could fail for turbid waters'])[source]#
apply water/land mask compute mask from NDWI from visible and NIR and visible and SWIR
- Parameters:
bitmasks – bit numbers on which the flags are coded
names – name of the flags
descriptions – description of the flags
- Returns: