pyroSAR/gamma/srtm.py
def hgt_collect(parfiles, outdir, demdir=None, arcsec=3):
    """
    automatic downloading and unpacking of srtm tiles
    base directory must contain SLC files in GAMMA format including their parameter files for reading coordinates
    additional dem directory may locally contain srtm files. This directory is searched for locally existing files, which are then copied to the current working directory
    """

    # concatenate required hgt tile names
    target_ids = hgt(parfiles)

    targets = []

    pattern = '[NS][0-9]{2}[EW][0-9]{3}'

    # if an additional dem directory has been defined, check this directory for required hgt tiles
    if demdir is not None:
        targets.extend(finder(demdir, target_ids))

    # check for additional potentially existing hgt tiles in the defined output directory
    extras = [os.path.join(outdir, x) for x in target_ids if os.path.isfile(os.path.join(outdir, x)) and not re.search(x, '\n'.join(targets))]
    targets.extend(extras)

    print('found {} relevant SRTM tiles...'.format(len(targets)))

    # search server for all required tiles, which were not found in the local directories
    if len(targets) < len(target_ids):
        print('searching for additional SRTM tiles on the server...')
        onlines = []

        if arcsec == 1:
            remotes = ['http://e4ftl01.cr.usgs.gov/SRTM/SRTMGL1.003/2000.02.11/']
            remotepattern = pattern+'.SRTMGL1.hgt.zip'
        elif arcsec == 3:
            server = 'http://dds.cr.usgs.gov/srtm/version2_1/SRTM3/'
            remotes = [os.path.join(server, x) for x in ['Africa', 'Australia', 'Eurasia', 'Islands', 'North_America', 'South_America']]
            remotepattern = pattern+'[.]hgt.zip'
        else:
            raise ValueError('argument arcsec must be of value 1 or 3')

        for remote in remotes:
            response = urlopen(remote).read()
            items = sorted(set(re.findall(remotepattern, response)))
            for item in items:
                outname = re.findall(pattern, item)[0]+'.hgt'
                if outname in target_ids and outname not in [os.path.basename(x) for x in targets]:
                    onlines.append(os.path.join(remote, item))

        # if additional tiles have been found online, download and unzip them to the local directory
        if len(onlines) > 0:
            print('downloading {} SRTM tiles...'.format(len(onlines)))
            for candidate in onlines:
                localname = os.path.join(outdir, re.findall(pattern, candidate)[0]+'.hgt')
                infile = urlopen(candidate)
                with open(localname+'.zip', 'wb') as outfile:
                    outfile.write(infile.read())
                infile.close()
                with zf.ZipFile(localname+'.zip', 'r') as z:
                    z.extractall(outdir)
                os.remove(localname+'.zip')
                targets.append(localname)
    return targets

    automatic downloading and unpacking of srtm tiles
    base directory must contain SLC files in GAMMA format including their parameter files for reading coordinates
    additional dem directory may locally contain srtm files. This directory is searched for locally existing files, which are then copied to the current working directory
    
automatic downloading and unpacking of srtm tiles
base directory must contain SLC files in GAMMA format including their parameter files for reading coordinates
additional dem directory may locally contain srtm files. This directory is searched for locally existing files, which are then copied to the current working directory
automatic downloading and unpacking of srtm tiles base directory must contain SLC files in GAMMA format including their parameter files for reading coordinates additional dem directory may locally contain srtm files . This directory is searched for locally existing files which are then copied to the current working directory
def hgt_collect(parfiles, outdir, demdir=None, arcsec=3):
    target_ids = hgt(parfiles)
    targets = []
    pattern = '[NS][0-9]{2}[EW][0-9]{3}'
    if demdir is not None:
        targets.extend(finder(demdir, target_ids))
    extras = [os.path.join(outdir, x) for x in target_ids if os.path.isfile(os.path.join(outdir, x)) and not re.search(x, '\n'.join(targets))]
    targets.extend(extras)
    print('found {} relevant SRTM tiles...'.format(len(targets)))
    if len(targets) < len(target_ids):
        print('searching for additional SRTM tiles on the server...')
        onlines = []
        if arcsec == 1:
            remotes = ['http://e4ftl01.cr.usgs.gov/SRTM/SRTMGL1.003/2000.02.11/']
            remotepattern = pattern+'.SRTMGL1.hgt.zip'
        elif arcsec == 3:
            server = 'http://dds.cr.usgs.gov/srtm/version2_1/SRTM3/'
            remotes = [os.path.join(server, x) for x in ['Africa', 'Australia', 'Eurasia', 'Islands', 'North_America', 'South_America']]
            remotepattern = pattern+'[.]hgt.zip'
        else:
            raise ValueError('argument arcsec must be of value 1 or 3')
        for remote in remotes:
            response = urlopen(remote).read()
            items = sorted(set(re.findall(remotepattern, response)))
            for item in items:
                outname = re.findall(pattern, item)[0]+'.hgt'
                if outname in target_ids and outname not in [os.path.basename(x) for x in targets]:
                    onlines.append(os.path.join(remote, item))
        if len(onlines) > 0:
            print('downloading {} SRTM tiles...'.format(len(onlines)))
            for candidate in onlines:
                localname = os.path.join(outdir, re.findall(pattern, candidate)[0]+'.hgt')
                infile = urlopen(candidate)
                with open(localname+'.zip', 'wb') as outfile:
                    outfile.write(infile.read())
                infile.close()
                with zf.ZipFile(localname+'.zip', 'r') as z:
                    z.extractall(outdir)
                os.remove(localname+'.zip')
                targets.append(localname)
    return targets
def hgt_collect ( parfiles , outdir , demdir = None , arcsec = 3 ) : target_ids = hgt ( parfiles ) targets = [ ] pattern = '[NS][0-9]{2}[EW][0-9]{3}' if demdir is not None : targets . extend ( finder ( demdir , target_ids ) ) extras = [ os . path . join ( outdir , x ) for x in target_ids if os . path . isfile ( os . path . join ( outdir , x ) ) and not re . search ( x , '\n' . join ( targets ) ) ] targets . extend ( extras ) print ( 'found {} relevant SRTM tiles...' . format ( len ( targets ) ) ) if len ( targets ) < len ( target_ids ) : print ( 'searching for additional SRTM tiles on the server...' ) onlines = [ ] if arcsec == 1 : remotes = [ 'http://e4ftl01.cr.usgs.gov/SRTM/SRTMGL1.003/2000.02.11/' ] remotepattern = pattern + '.SRTMGL1.hgt.zip' elif arcsec == 3 : server = 'http://dds.cr.usgs.gov/srtm/version2_1/SRTM3/' remotes = [ os . path . join ( server , x ) for x in [ 'Africa' , 'Australia' , 'Eurasia' , 'Islands' , 'North_America' , 'South_America' ] ] remotepattern = pattern + '[.]hgt.zip' else : raise ValueError ( 'argument arcsec must be of value 1 or 3' ) for remote in remotes : response = urlopen ( remote ) . read ( ) items = sorted ( set ( re . findall ( remotepattern , response ) ) ) for item in items : outname = re . findall ( pattern , item ) [ 0 ] + '.hgt' if outname in target_ids and outname not in [ os . path . basename ( x ) for x in targets ] : onlines . append ( os . path . join ( remote , item ) ) if len ( onlines ) > 0 : print ( 'downloading {} SRTM tiles...' . format ( len ( onlines ) ) ) for candidate in onlines : localname = os . path . join ( outdir , re . findall ( pattern , candidate ) [ 0 ] + '.hgt' ) infile = urlopen ( candidate ) with open ( localname + '.zip' , 'wb' ) as outfile : outfile . write ( infile . read ( ) ) infile . close ( ) with zf . ZipFile ( localname + '.zip' , 'r' ) as z : z . extractall ( outdir ) os . remove ( localname + '.zip' ) targets . append ( localname ) return targets
automatic downloading and unpacking of srtm tiles
base directory must contain SLC files in GAMMA format including their parameter files for reading coordinates
additional dem directory may locally contain srtm files.
automatic downloading and unpacking of srtm tiles base directory must contain SLC files in GAMMA format including their parameter files for reading coordinates additional dem directory may locally contain srtm files .
"""
    automatic downloading and unpacking of srtm tiles
    base directory must contain SLC files in GAMMA format including their parameter files for reading coordinates
    additional dem directory may locally contain srtm files. This directory is searched for locally existing files, which are then copied to the current working directory
    """ # concatenate required hgt tile names # if an additional dem directory has been defined, check this directory for required hgt tiles # check for additional potentially existing hgt tiles in the defined output directory # search server for all required tiles, which were not found in the local directories # if additional tiles have been found online, download and unzip them to the local directory
parfiles
outdir
demdir
arcsec