(metadata, settings, **kwargs)
Saves a .jpg image for all the images contained in metadata.

    KV WRL 2018

    Arguments:
    -----------
    metadata: dict
        contains all the information about the satellite images that were downloaded
    settings: dict with the following keys
        'inputs': dict
            input parameters (sitename, filepath, polygon, dates, sat_list)
        'cloud_thresh': float
            value between 0 and 1 indicating the maximum cloud fraction in 
            the cropped image that is accepted
        'cloud_mask_issue': boolean
            True if there is an issue with the cloud mask and sand pixels
            are erroneously being masked on the images
            
    Returns:
    -----------
    Stores the images as .jpg in a folder named /preprocessed
Saves a .jpg image for all the images contained in metadata.
Saves a . jpg image for all the images contained in metadata .
def save_jpg(metadata, settings, **kwargs):
    """
    Saves a .jpg image for all the images contained in metadata.

    KV WRL 2018

    Arguments:
    -----------
    metadata: dict
        contains all the information about the satellite images that were downloaded
    settings: dict with the following keys
        'inputs': dict
            input parameters (sitename, filepath, polygon, dates, sat_list)
        'cloud_thresh': float
            value between 0 and 1 indicating the maximum cloud fraction in 
            the cropped image that is accepted
        'cloud_mask_issue': boolean
            True if there is an issue with the cloud mask and sand pixels
            are erroneously being masked on the images
            
    Returns:
    -----------
    Stores the images as .jpg in a folder named /preprocessed
    
    """
    
    sitename = settings['inputs']['sitename']
    cloud_thresh = settings['cloud_thresh']
    filepath_data = settings['inputs']['filepath']

    # create subfolder to store the jpg files
    filepath_jpg = os.path.join(filepath_data, sitename, 'jpg_files', 'preprocessed')
    if not os.path.exists(filepath_jpg):
            os.makedirs(filepath_jpg)

    # loop through satellite list
    for satname in metadata.keys():

        filepath = SDS_tools.get_filepath(settings['inputs'],satname)
        filenames = metadata[satname]['filenames']

        # loop through images
        for i in range(len(filenames)):
            # image filename
            fn = SDS_tools.get_filenames(filenames[i],filepath, satname)
            # read and preprocess image
            im_ms, georef, cloud_mask, im_extra, im_QA, im_nodata = preprocess_single(fn, satname, settings['cloud_mask_issue'])

            # compute cloud_cover percentage (with no data pixels)
            cloud_cover_combined = np.divide(sum(sum(cloud_mask.astype(int))),
                                    (cloud_mask.shape[0]*cloud_mask.shape[1]))
            if cloud_cover_combined > 0.99: # if 99% of cloudy pixels in image skip
                continue

            # remove no data pixels from the cloud mask (for example L7 bands of no data should not be accounted for)
            cloud_mask_adv = np.logical_xor(cloud_mask, im_nodata)
            # compute updated cloud cover percentage (without no data pixels)
            cloud_cover = np.divide(sum(sum(cloud_mask_adv.astype(int))),
                                    (sum(sum((~im_nodata).astype(int)))))
            # skip image if cloud cover is above threshold
            if cloud_cover > cloud_thresh or cloud_cover == 1:
                continue
            # save .jpg with date and satellite in the title
            date = filenames[i][:19]
            plt.ioff()  # turning interactive plotting off
            create_jpg(im_ms, cloud_mask, date, satname, filepath_jpg)

    # print the location where the images have been saved
    print('Satellite images saved as .jpg in ' + os.path.join(filepath_data, sitename,
                                                    'jpg_files', 'preprocessed'))
def save_jpg ( metadata , settings , * * kwargs ) : sitename = settings [ 'inputs' ] [ 'sitename' ] cloud_thresh = settings [ 'cloud_thresh' ] filepath_data = settings [ 'inputs' ] [ 'filepath' ] # create subfolder to store the jpg files filepath_jpg = os . path . join ( filepath_data , sitename , 'jpg_files' , 'preprocessed' ) if not os . path . exists ( filepath_jpg ) : os . makedirs ( filepath_jpg ) # loop through satellite list for satname in metadata . keys ( ) : filepath = SDS_tools . get_filepath ( settings [ 'inputs' ] , satname ) filenames = metadata [ satname ] [ 'filenames' ] # loop through images for i in range ( len ( filenames ) ) : # image filename fn = SDS_tools . get_filenames ( filenames [ i ] , filepath , satname ) # read and preprocess image im_ms , georef , cloud_mask , im_extra , im_QA , im_nodata = preprocess_single ( fn , satname , settings [ 'cloud_mask_issue' ] ) # compute cloud_cover percentage (with no data pixels) cloud_cover_combined = np . divide ( sum ( sum ( cloud_mask . astype ( int ) ) ) , ( cloud_mask . shape [ 0 ] * cloud_mask . shape [ 1 ] ) ) if cloud_cover_combined > 0.99 : # if 99% of cloudy pixels in image skip continue # remove no data pixels from the cloud mask (for example L7 bands of no data should not be accounted for) cloud_mask_adv = np . logical_xor ( cloud_mask , im_nodata ) # compute updated cloud cover percentage (without no data pixels) cloud_cover = np . divide ( sum ( sum ( cloud_mask_adv . astype ( int ) ) ) , ( sum ( sum ( ( ~ im_nodata ) . astype ( int ) ) ) ) ) # skip image if cloud cover is above threshold if cloud_cover > cloud_thresh or cloud_cover == 1 : continue # save .jpg with date and satellite in the title date = filenames [ i ] [ : 19 ] plt . ioff ( ) # turning interactive plotting off create_jpg ( im_ms , cloud_mask , date , satname , filepath_jpg ) # print the location where the images have been saved print ( 'Satellite images saved as .jpg in ' + os . path . join ( filepath_data , sitename , 'jpg_files' , 'preprocessed' ) )