(fn, mask)
Masks a .tif raster using GDAL.
    
    Arguments:
    -----------
    fn: str
        filepath + filename of the .tif raster
    mask: np.array
        array of boolean where True indicates the pixels that are to be masked
        
    Returns:    
    -----------
    Overwrites the .tif file directly
Masks a .tif raster using GDAL.
    
    Arguments:
    -----------
    fn: str
        filepath + filename of the .tif raster
    mask: np.array
        array of boolean where True indicates the pixels that are to be masked
        
    Returns:    
    -----------
    Overwrites the .tif file directly
Masks a . tif raster using GDAL . Arguments : ----------- fn : str filepath + filename of the . tif raster mask : np . array array of boolean where True indicates the pixels that are to be masked Returns : ----------- Overwrites the . tif file directly
def mask_raster(fn, mask):
    """
    Masks a .tif raster using GDAL.
    
    Arguments:
    -----------
    fn: str
        filepath + filename of the .tif raster
    mask: np.array
        array of boolean where True indicates the pixels that are to be masked
        
    Returns:    
    -----------
    Overwrites the .tif file directly
        
    """ 
    
    # open raster
    raster = gdal.Open(fn, gdal.GA_Update)
    # mask raster
    for i in range(raster.RasterCount):
        out_band = raster.GetRasterBand(i+1)
        out_data = out_band.ReadAsArray()
        out_band.SetNoDataValue(0)
        no_data_value = out_band.GetNoDataValue()
        out_data[mask] = no_data_value
        out_band.WriteArray(out_data)
    # close dataset and flush cache
    raster = None
def mask_raster ( fn , mask ) : # open raster raster = gdal . Open ( fn , gdal . GA_Update ) # mask raster for i in range ( raster . RasterCount ) : out_band = raster . GetRasterBand ( i + 1 ) out_data = out_band . ReadAsArray ( ) out_band . SetNoDataValue ( 0 ) no_data_value = out_band . GetNoDataValue ( ) out_data [ mask ] = no_data_value out_band . WriteArray ( out_data ) # close dataset and flush cache raster = None