% Williamson, A., Banwell, A., Willis, I., & Arnold, N. (2018). Dual-satellite (Sentinel-2 and Landsat 8) remote sensing of supraglacial lakes in Greenland.

% Function to return a SGL mask based on a specified NDWI threshold, and
% using the red and blue bands of Sentinel-2 or Landsat-8 (both work in the
% same way...) 

function NDWI_defined_SGLs = S2_NDWI(blue_band,red_band,NDWI_threshold) 

% get the NDWI (standard approach) 
NDWI_definition = (blue_band - red_band) ./ (blue_band + red_band);

NDWI_defined_SGLs = zeros(size(blue_band)); % pre-allocate 

% mask lake areas based on this 
NDWI_defined_SGLs(NDWI_definition >= NDWI_threshold) = 1; 

% show a figure of the lake mask 
imagesc(NDWI_defined_SGLs)

end 