(inputs)
return metadata
Downloads all images from Landsat 5, Landsat 7, Landsat 8 and Sentinel-2
    covering the area of interest and acquired between the specified dates.
    The downloaded images are in .TIF format and organised in subfolders, divided
    by satellite mission. The bands are also subdivided by pixel resolution.

    KV WRL 2018

    Arguments:
    -----------
    inputs: dict with the following keys
        'sitename': str
            name of the site
        'polygon': list
            polygon containing the lon/lat coordinates to be extracted,
            longitudes in the first column and latitudes in the second column,
            there are 5 pairs of lat/lon with the fifth point equal to the first point:
            ```
            polygon = [[[151.3, -33.7],[151.4, -33.7],[151.4, -33.8],[151.3, -33.8],
            [151.3, -33.7]]]
            ```
        'dates': list of str
            list that contains 2 strings with the initial and final dates in
            format 'yyyy-mm-dd':
            ```
            dates = ['1987-01-01', '2018-01-01']
            ```
        'sat_list': list of str
            list that contains the names of the satellite missions to include:
            ```
            sat_list = ['L5', 'L7', 'L8', 'S2']
            ```
        'filepath_data': str
            filepath to the directory where the images are downloaded

    Returns:
    -----------
    metadata: dict
        contains the information about the satellite images that were downloaded:
        date, filename, georeferencing accuracy and image coordinate reference system
Downloads all images from Landsat 5, Landsat 7, Landsat 8 and Sentinel-2
    covering the area of interest and acquired between the specified dates.
    The downloaded images are in .TIF format and organised in subfolders, divided
    by satellite mission. The bands are also subdivided by pixel resolution.
Downloads all images from Landsat 5 Landsat 7 Landsat 8 and Sentinel - 2 covering the area of interest and acquired between the specified dates . The downloaded images are in . TIF format and organised in subfolders divided by satellite mission . The bands are also subdivided by pixel resolution .
def retrieve_images(inputs):
    """
    Downloads all images from Landsat 5, Landsat 7, Landsat 8 and Sentinel-2
    covering the area of interest and acquired between the specified dates.
    The downloaded images are in .TIF format and organised in subfolders, divided
    by satellite mission. The bands are also subdivided by pixel resolution.

    KV WRL 2018

    Arguments:
    -----------
    inputs: dict with the following keys
        'sitename': str
            name of the site
        'polygon': list
            polygon containing the lon/lat coordinates to be extracted,
            longitudes in the first column and latitudes in the second column,
            there are 5 pairs of lat/lon with the fifth point equal to the first point:
            ```
            polygon = [[[151.3, -33.7],[151.4, -33.7],[151.4, -33.8],[151.3, -33.8],
            [151.3, -33.7]]]
            ```
        'dates': list of str
            list that contains 2 strings with the initial and final dates in
            format 'yyyy-mm-dd':
            ```
            dates = ['1987-01-01', '2018-01-01']
            ```
        'sat_list': list of str
            list that contains the names of the satellite missions to include:
            ```
            sat_list = ['L5', 'L7', 'L8', 'S2']
            ```
        'filepath_data': str
            filepath to the directory where the images are downloaded

    Returns:
    -----------
    metadata: dict
        contains the information about the satellite images that were downloaded:
        date, filename, georeferencing accuracy and image coordinate reference system

    """
    
    # initialise connection with GEE server
    ee.Initialize()

    # check image availabiliy and retrieve list of images
    im_dict_T1, im_dict_T2 = check_images_available(inputs)

    # if user also wants to download T2 images, merge both lists
    if 'include_T2' in inputs.keys():
        for key in inputs['sat_list']:
            if key == 'S2': continue
            else: im_dict_T1[key] += im_dict_T2[key]

    # remove UTM duplicates in S2 collections (they provide several projections for same images)
    if 'S2' in inputs['sat_list'] and len(im_dict_T1['S2'])>0:
        im_dict_T1['S2'] = filter_S2_collection(im_dict_T1['S2'])

    # create a new directory for this site with the name of the site
    im_folder = os.path.join(inputs['filepath'],inputs['sitename'])
    if not os.path.exists(im_folder): os.makedirs(im_folder)

    print('\nDownloading images:')
    suffix = '.tif'
    for satname in im_dict_T1.keys():
        print('%s: %d images'%(satname,len(im_dict_T1[satname])))
        # create subfolder structure to store the different bands
        filepaths = create_folder_structure(im_folder, satname)
        # initialise variables and loop through images
        georef_accs = []; filenames = []; all_names = []; im_epsg = []
        for i in range(len(im_dict_T1[satname])):

            im_meta = im_dict_T1[satname][i]

            # get time of acquisition (UNIX time) and convert to datetime
            t = im_meta['properties']['system:time_start']
            im_timestamp = datetime.fromtimestamp(t/1000, tz=pytz.utc)
            im_date = im_timestamp.strftime('%Y-%m-%d-%H-%M-%S')

            # get epsg code
            im_epsg.append(int(im_meta['bands'][0]['crs'][5:]))

            # get geometric accuracy
            if satname in ['L5','L7','L8']:
                if 'GEOMETRIC_RMSE_MODEL' in im_meta['properties'].keys():
                    acc_georef = im_meta['properties']['GEOMETRIC_RMSE_MODEL']
                else:
                    acc_georef = 12 # default value of accuracy (RMSE = 12m)
            elif satname in ['S2']:
                # Sentinel-2 products don't provide a georeferencing accuracy (RMSE as in Landsat)
                # but they have a flag indicating if the geometric quality control was passed or failed
                # if passed a value of 1 is stored if failed a value of -1 is stored in the metadata
                # the name of the property containing the flag changes across the S2 archive
                # check which flag name is used for the image and store the 1/-1 for acc_georef
                flag_names = ['GEOMETRIC_QUALITY_FLAG', 'GEOMETRIC_QUALITY', 'quality_check', 'GENERAL_QUALITY_FLAG']
                for key in flag_names: 
                    if key in im_meta['properties'].keys(): break
                if im_meta['properties'][key] == 'PASSED': acc_georef = 1
                else: acc_georef = -1
            georef_accs.append(acc_georef)

            bands = dict([])
            im_fn = dict([])
            # first delete dimensions key from dictionnary
            # otherwise the entire image is extracted (don't know why)
            im_bands = im_meta['bands']
            for j in range(len(im_bands)): del im_bands[j]['dimensions']

            # Landsat 5 download
            if satname == 'L5':
                bands[''] = [im_bands[0], im_bands[1], im_bands[2], im_bands[3],
                             im_bands[4], im_bands[7]]
                im_fn[''] = im_date + '_' + satname + '_' + inputs['sitename'] + suffix
                # if two images taken at the same date add 'dup' to the name (duplicate)
                if any(im_fn[''] in _ for _ in all_names):
                    im_fn[''] = im_date + '_' + satname + '_' + inputs['sitename'] + '_dup' + suffix
                all_names.append(im_fn[''])
                filenames.append(im_fn[''])
                # download .tif from EE
                while True:
                    try:
                        im_ee = ee.Image(im_meta['id'])
                        local_data = download_tif(im_ee, inputs['polygon'], bands[''], filepaths[1])
                        break
                    except:
                        continue
                # rename the file as the image is downloaded as 'data.tif'
                try:
                    os.rename(local_data, os.path.join(filepaths[1], im_fn['']))
                except: # overwrite if already exists
                    os.remove(os.path.join(filepaths[1], im_fn['']))
                    os.rename(local_data, os.path.join(filepaths[1], im_fn['']))
                # metadata for .txt file
                filename_txt = im_fn[''].replace('.tif','')
                metadict = {'filename':im_fn[''],'acc_georef':georef_accs[i],
                            'epsg':im_epsg[i]}

            # Landsat 7 and 8 download
            elif satname in ['L7', 'L8']:
                if satname == 'L7':
                    bands['pan'] = [im_bands[8]] # panchromatic band
                    bands['ms'] = [im_bands[0], im_bands[1], im_bands[2], im_bands[3],
                                   im_bands[4], im_bands[9]] # multispectral bands
                else:
                    bands['pan'] = [im_bands[7]] # panchromatic band
                    bands['ms'] = [im_bands[1], im_bands[2], im_bands[3], im_bands[4],
                                   im_bands[5], im_bands[11]] # multispectral bands
                for key in bands.keys():
                    im_fn[key] = im_date + '_' + satname + '_' + inputs['sitename'] + '_' + key + suffix
                # if two images taken at the same date add 'dup' to the name (duplicate)
                if any(im_fn['pan'] in _ for _ in all_names):
                    for key in bands.keys():
                        im_fn[key] = im_date + '_' + satname + '_' + inputs['sitename'] + '_' + key + '_dup' + suffix
                all_names.append(im_fn['pan'])
                filenames.append(im_fn['pan'])
                # download .tif from EE (panchromatic band and multispectral bands)
                while True:
                    try:
                        im_ee = ee.Image(im_meta['id'])
                        local_data_pan = download_tif(im_ee, inputs['polygon'], bands['pan'], filepaths[1])
                        local_data_ms = download_tif(im_ee, inputs['polygon'], bands['ms'], filepaths[2])
                        break
                    except:
                        continue
                # rename the files as the image is downloaded as 'data.tif'
                try: # panchromatic
                    os.rename(local_data_pan, os.path.join(filepaths[1], im_fn['pan']))
                except: # overwrite if already exists
                    os.remove(os.path.join(filepaths[1], im_fn['pan']))
                    os.rename(local_data_pan, os.path.join(filepaths[1], im_fn['pan']))
                try: # multispectral
                    os.rename(local_data_ms, os.path.join(filepaths[2], im_fn['ms']))
                except: # overwrite if already exists
                    os.remove(os.path.join(filepaths[2], im_fn['ms']))
                    os.rename(local_data_ms, os.path.join(filepaths[2], im_fn['ms']))
                # metadata for .txt file
                filename_txt = im_fn['pan'].replace('_pan','').replace('.tif','')
                metadict = {'filename':im_fn['pan'],'acc_georef':georef_accs[i],
                            'epsg':im_epsg[i]}

            # Sentinel-2 download
            elif satname in ['S2']:
                bands['10m'] = [im_bands[1], im_bands[2], im_bands[3], im_bands[7]] # multispectral bands
                bands['20m'] = [im_bands[11]] # SWIR band
                bands['60m'] = [im_bands[15]] # QA band
                for key in bands.keys():
                    im_fn[key] = im_date + '_' + satname + '_' + inputs['sitename'] + '_' + key + suffix
                # if two images taken at the same date add 'dup' to the name (duplicate)
                if any(im_fn['10m'] in _ for _ in all_names):
                    for key in bands.keys():
                        im_fn[key] = im_date + '_' + satname + '_' + inputs['sitename'] + '_' + key + '_dup2' + suffix
                    # also check for triplicates (only on S2 imagery) and add 'tri' to the name
                    if im_fn['10m'] in all_names:
                        for key in bands.keys():
                            im_fn[key] = im_date + '_' + satname + '_' + inputs['sitename'] + '_' + key + '_dup3' + suffix
                        # also check for quadruplicates (only on S2 imagery) add 'qua' to the name
                        if im_fn['10m'] in all_names:
                            for key in bands.keys():
                                im_fn[key] = im_date + '_' + satname + '_' + inputs['sitename'] + '_' + key + '_dup4' + suffix
                all_names.append(im_fn['10m'])
                filenames.append(im_fn['10m'])
                # download .tif from EE (multispectral bands at 3 different resolutions)
                while True:
                    try:
                        im_ee = ee.Image(im_meta['id'])
                        local_data_10m = download_tif(im_ee, inputs['polygon'], bands['10m'], filepaths[1])
                        local_data_20m = download_tif(im_ee, inputs['polygon'], bands['20m'], filepaths[2])
                        local_data_60m = download_tif(im_ee, inputs['polygon'], bands['60m'], filepaths[3])
                        break
                    except:
                        continue
                # rename the files as the image is downloaded as 'data.tif'
                try: # 10m
                    os.rename(local_data_10m, os.path.join(filepaths[1], im_fn['10m']))
                except: # overwrite if already exists
                    os.remove(os.path.join(filepaths[1], im_fn['10m']))
                    os.rename(local_data_10m, os.path.join(filepaths[1], im_fn['10m']))
                try: # 20m
                    os.rename(local_data_20m, os.path.join(filepaths[2], im_fn['20m']))
                except: # overwrite if already exists
                    os.remove(os.path.join(filepaths[2], im_fn['20m']))
                    os.rename(local_data_20m, os.path.join(filepaths[2], im_fn['20m']))
                try: # 60m
                    os.rename(local_data_60m, os.path.join(filepaths[3], im_fn['60m']))
                except: # overwrite if already exists
                    os.remove(os.path.join(filepaths[3], im_fn['60m']))
                    os.rename(local_data_60m, os.path.join(filepaths[3], im_fn['60m']))
                # metadata for .txt file
                filename_txt = im_fn['10m'].replace('_10m','').replace('.tif','')
                metadict = {'filename':im_fn['10m'],'acc_georef':georef_accs[i],
                            'epsg':im_epsg[i]}

            # write metadata
            with open(os.path.join(filepaths[0],filename_txt + '.txt'), 'w') as f:
                for key in metadict.keys():
                    f.write('%s\t%s\n'%(key,metadict[key]))
            # print percentage completion for user
            print('\r%d%%' %int((i+1)/len(im_dict_T1[satname])*100), end='')

        print('')

    # once all images have been downloaded, load metadata from .txt files
    metadata = get_metadata(inputs)

    # merge overlapping images (necessary only if the polygon is at the boundary of an image)
    if 'S2' in metadata.keys():
        try:
            metadata = merge_overlapping_images(metadata,inputs)
        except:
            print('WARNING: there was an error while merging overlapping S2 images,'+
                  ' please open an issue on Github at https://github.com/kvos/CoastSat/issues'+
                  ' and include your script so we can find out what happened.')

    # save metadata dict
    with open(os.path.join(im_folder, inputs['sitename'] + '_metadata' + '.pkl'), 'wb') as f:
        pickle.dump(metadata, f)

    return metadata
def retrieve_images ( inputs ) : # initialise connection with GEE server ee . Initialize ( ) # check image availabiliy and retrieve list of images im_dict_T1 , im_dict_T2 = check_images_available ( inputs ) # if user also wants to download T2 images, merge both lists if 'include_T2' in inputs . keys ( ) : for key in inputs [ 'sat_list' ] : if key == 'S2' : continue else : im_dict_T1 [ key ] += im_dict_T2 [ key ] # remove UTM duplicates in S2 collections (they provide several projections for same images) if 'S2' in inputs [ 'sat_list' ] and len ( im_dict_T1 [ 'S2' ] ) > 0 : im_dict_T1 [ 'S2' ] = filter_S2_collection ( im_dict_T1 [ 'S2' ] ) # create a new directory for this site with the name of the site im_folder = os . path . join ( inputs [ 'filepath' ] , inputs [ 'sitename' ] ) if not os . path . exists ( im_folder ) : os . makedirs ( im_folder ) print ( '\nDownloading images:' ) suffix = '.tif' for satname in im_dict_T1 . keys ( ) : print ( '%s: %d images' % ( satname , len ( im_dict_T1 [ satname ] ) ) ) # create subfolder structure to store the different bands filepaths = create_folder_structure ( im_folder , satname ) # initialise variables and loop through images georef_accs = [ ] filenames = [ ] all_names = [ ] im_epsg = [ ] for i in range ( len ( im_dict_T1 [ satname ] ) ) : im_meta = im_dict_T1 [ satname ] [ i ] # get time of acquisition (UNIX time) and convert to datetime t = im_meta [ 'properties' ] [ 'system:time_start' ] im_timestamp = datetime . fromtimestamp ( t / 1000 , tz = pytz . utc ) im_date = im_timestamp . strftime ( '%Y-%m-%d-%H-%M-%S' ) # get epsg code im_epsg . append ( int ( im_meta [ 'bands' ] [ 0 ] [ 'crs' ] [ 5 : ] ) ) # get geometric accuracy if satname in [ 'L5' , 'L7' , 'L8' ] : if 'GEOMETRIC_RMSE_MODEL' in im_meta [ 'properties' ] . keys ( ) : acc_georef = im_meta [ 'properties' ] [ 'GEOMETRIC_RMSE_MODEL' ] else : acc_georef = 12 # default value of accuracy (RMSE = 12m) elif satname in [ 'S2' ] : # Sentinel-2 products don't provide a georeferencing accuracy (RMSE as in Landsat) # but they have a flag indicating if the geometric quality control was passed or failed # if passed a value of 1 is stored if failed a value of -1 is stored in the metadata # the name of the property containing the flag changes across the S2 archive # check which flag name is used for the image and store the 1/-1 for acc_georef flag_names = [ 'GEOMETRIC_QUALITY_FLAG' , 'GEOMETRIC_QUALITY' , 'quality_check' , 'GENERAL_QUALITY_FLAG' ] for key in flag_names : if key in im_meta [ 'properties' ] . keys ( ) : break if im_meta [ 'properties' ] [ key ] == 'PASSED' : acc_georef = 1 else : acc_georef = - 1 georef_accs . append ( acc_georef ) bands = dict ( [ ] ) im_fn = dict ( [ ] ) # first delete dimensions key from dictionnary # otherwise the entire image is extracted (don't know why) im_bands = im_meta [ 'bands' ] for j in range ( len ( im_bands ) ) : del im_bands [ j ] [ 'dimensions' ] # Landsat 5 download if satname == 'L5' : bands [ '' ] = [ im_bands [ 0 ] , im_bands [ 1 ] , im_bands [ 2 ] , im_bands [ 3 ] , im_bands [ 4 ] , im_bands [ 7 ] ] im_fn [ '' ] = im_date + '_' + satname + '_' + inputs [ 'sitename' ] + suffix # if two images taken at the same date add 'dup' to the name (duplicate) if any ( im_fn [ '' ] in _ for _ in all_names ) : im_fn [ '' ] = im_date + '_' + satname + '_' + inputs [ 'sitename' ] + '_dup' + suffix all_names . append ( im_fn [ '' ] ) filenames . append ( im_fn [ '' ] ) # download .tif from EE while True : try : im_ee = ee . Image ( im_meta [ 'id' ] ) local_data = download_tif ( im_ee , inputs [ 'polygon' ] , bands [ '' ] , filepaths [ 1 ] ) break except : continue # rename the file as the image is downloaded as 'data.tif' try : os . rename ( local_data , os . path . join ( filepaths [ 1 ] , im_fn [ '' ] ) ) except : # overwrite if already exists os . remove ( os . path . join ( filepaths [ 1 ] , im_fn [ '' ] ) ) os . rename ( local_data , os . path . join ( filepaths [ 1 ] , im_fn [ '' ] ) ) # metadata for .txt file filename_txt = im_fn [ '' ] . replace ( '.tif' , '' ) metadict = { 'filename' : im_fn [ '' ] , 'acc_georef' : georef_accs [ i ] , 'epsg' : im_epsg [ i ] } # Landsat 7 and 8 download elif satname in [ 'L7' , 'L8' ] : if satname == 'L7' : bands [ 'pan' ] = [ im_bands [ 8 ] ] # panchromatic band bands [ 'ms' ] = [ im_bands [ 0 ] , im_bands [ 1 ] , im_bands [ 2 ] , im_bands [ 3 ] , im_bands [ 4 ] , im_bands [ 9 ] ] # multispectral bands else : bands [ 'pan' ] = [ im_bands [ 7 ] ] # panchromatic band bands [ 'ms' ] = [ im_bands [ 1 ] , im_bands [ 2 ] , im_bands [ 3 ] , im_bands [ 4 ] , im_bands [ 5 ] , im_bands [ 11 ] ] # multispectral bands for key in bands . keys ( ) : im_fn [ key ] = im_date + '_' + satname + '_' + inputs [ 'sitename' ] + '_' + key + suffix # if two images taken at the same date add 'dup' to the name (duplicate) if any ( im_fn [ 'pan' ] in _ for _ in all_names ) : for key in bands . keys ( ) : im_fn [ key ] = im_date + '_' + satname + '_' + inputs [ 'sitename' ] + '_' + key + '_dup' + suffix all_names . append ( im_fn [ 'pan' ] ) filenames . append ( im_fn [ 'pan' ] ) # download .tif from EE (panchromatic band and multispectral bands) while True : try : im_ee = ee . Image ( im_meta [ 'id' ] ) local_data_pan = download_tif ( im_ee , inputs [ 'polygon' ] , bands [ 'pan' ] , filepaths [ 1 ] ) local_data_ms = download_tif ( im_ee , inputs [ 'polygon' ] , bands [ 'ms' ] , filepaths [ 2 ] ) break except : continue # rename the files as the image is downloaded as 'data.tif' try : # panchromatic os . rename ( local_data_pan , os . path . join ( filepaths [ 1 ] , im_fn [ 'pan' ] ) ) except : # overwrite if already exists os . remove ( os . path . join ( filepaths [ 1 ] , im_fn [ 'pan' ] ) ) os . rename ( local_data_pan , os . path . join ( filepaths [ 1 ] , im_fn [ 'pan' ] ) ) try : # multispectral os . rename ( local_data_ms , os . path . join ( filepaths [ 2 ] , im_fn [ 'ms' ] ) ) except : # overwrite if already exists os . remove ( os . path . join ( filepaths [ 2 ] , im_fn [ 'ms' ] ) ) os . rename ( local_data_ms , os . path . join ( filepaths [ 2 ] , im_fn [ 'ms' ] ) ) # metadata for .txt file filename_txt = im_fn [ 'pan' ] . replace ( '_pan' , '' ) . replace ( '.tif' , '' ) metadict = { 'filename' : im_fn [ 'pan' ] , 'acc_georef' : georef_accs [ i ] , 'epsg' : im_epsg [ i ] } # Sentinel-2 download elif satname in [ 'S2' ] : bands [ '10m' ] = [ im_bands [ 1 ] , im_bands [ 2 ] , im_bands [ 3 ] , im_bands [ 7 ] ] # multispectral bands bands [ '20m' ] = [ im_bands [ 11 ] ] # SWIR band bands [ '60m' ] = [ im_bands [ 15 ] ] # QA band for key in bands . keys ( ) : im_fn [ key ] = im_date + '_' + satname + '_' + inputs [ 'sitename' ] + '_' + key + suffix # if two images taken at the same date add 'dup' to the name (duplicate) if any ( im_fn [ '10m' ] in _ for _ in all_names ) : for key in bands . keys ( ) : im_fn [ key ] = im_date + '_' + satname + '_' + inputs [ 'sitename' ] + '_' + key + '_dup2' + suffix # also check for triplicates (only on S2 imagery) and add 'tri' to the name if im_fn [ '10m' ] in all_names : for key in bands . keys ( ) : im_fn [ key ] = im_date + '_' + satname + '_' + inputs [ 'sitename' ] + '_' + key + '_dup3' + suffix # also check for quadruplicates (only on S2 imagery) add 'qua' to the name if im_fn [ '10m' ] in all_names : for key in bands . keys ( ) : im_fn [ key ] = im_date + '_' + satname + '_' + inputs [ 'sitename' ] + '_' + key + '_dup4' + suffix all_names . append ( im_fn [ '10m' ] ) filenames . append ( im_fn [ '10m' ] ) # download .tif from EE (multispectral bands at 3 different resolutions) while True : try : im_ee = ee . Image ( im_meta [ 'id' ] ) local_data_10m = download_tif ( im_ee , inputs [ 'polygon' ] , bands [ '10m' ] , filepaths [ 1 ] ) local_data_20m = download_tif ( im_ee , inputs [ 'polygon' ] , bands [ '20m' ] , filepaths [ 2 ] ) local_data_60m = download_tif ( im_ee , inputs [ 'polygon' ] , bands [ '60m' ] , filepaths [ 3 ] ) break except : continue # rename the files as the image is downloaded as 'data.tif' try : # 10m os . rename ( local_data_10m , os . path . join ( filepaths [ 1 ] , im_fn [ '10m' ] ) ) except : # overwrite if already exists os . remove ( os . path . join ( filepaths [ 1 ] , im_fn [ '10m' ] ) ) os . rename ( local_data_10m , os . path . join ( filepaths [ 1 ] , im_fn [ '10m' ] ) ) try : # 20m os . rename ( local_data_20m , os . path . join ( filepaths [ 2 ] , im_fn [ '20m' ] ) ) except : # overwrite if already exists os . remove ( os . path . join ( filepaths [ 2 ] , im_fn [ '20m' ] ) ) os . rename ( local_data_20m , os . path . join ( filepaths [ 2 ] , im_fn [ '20m' ] ) ) try : # 60m os . rename ( local_data_60m , os . path . join ( filepaths [ 3 ] , im_fn [ '60m' ] ) ) except : # overwrite if already exists os . remove ( os . path . join ( filepaths [ 3 ] , im_fn [ '60m' ] ) ) os . rename ( local_data_60m , os . path . join ( filepaths [ 3 ] , im_fn [ '60m' ] ) ) # metadata for .txt file filename_txt = im_fn [ '10m' ] . replace ( '_10m' , '' ) . replace ( '.tif' , '' ) metadict = { 'filename' : im_fn [ '10m' ] , 'acc_georef' : georef_accs [ i ] , 'epsg' : im_epsg [ i ] } # write metadata with open ( os . path . join ( filepaths [ 0 ] , filename_txt + '.txt' ) , 'w' ) as f : for key in metadict . keys ( ) : f . write ( '%s\t%s\n' % ( key , metadict [ key ] ) ) # print percentage completion for user print ( '\r%d%%' % int ( ( i + 1 ) / len ( im_dict_T1 [ satname ] ) * 100 ) , end = '' ) print ( '' ) # once all images have been downloaded, load metadata from .txt files metadata = get_metadata ( inputs ) # merge overlapping images (necessary only if the polygon is at the boundary of an image) if 'S2' in metadata . keys ( ) : try : metadata = merge_overlapping_images ( metadata , inputs ) except : print ( 'WARNING: there was an error while merging overlapping S2 images,' + ' please open an issue on Github at https://github.com/kvos/CoastSat/issues' + ' and include your script so we can find out what happened.' ) # save metadata dict with open ( os . path . join ( im_folder , inputs [ 'sitename' ] + '_metadata' + '.pkl' ) , 'wb' ) as f : pickle . dump ( metadata , f ) return metadata