def main():
    # define a shapefile for the study area
    shp = '/.../testsite.shp'

    # define the output name of the DEM (no file extension like .tif etc.!)
    outname = '/path/to/demfile'

    # define a buffer around the study area boundaries (in degrees)
    buffer = 0.01

    # load the defined shapefile
    site = vector.Vector(shp)

    # reproject the shapefile to latlon (in-memory, no file written or modified)
    site.reproject('+proj=longlat +datum=WGS84 +no_defs ')

    # define a GDAL VRT file containing all SRTM tiles
    # this file has all hgt tiles in the same directory registered and is used for subsetting/mosaicing
    srtm_vrt = '/path/to/SRTM_1_HGT.vrt'

    # extract the extent (bounding box) of the shapefile
    ext = site.extent

    # add the buffer to the bounding box
    ext['xmin'] -= buffer
    ext['ymin'] -= buffer
    ext['xmax'] += buffer
    ext['ymax'] += buffer

    # create a temporary directory for writing intermediate files (will be deleted at the end)
    tmpdir = outname + '__tmp'
    if not os.path.isdir(tmpdir):
        os.makedirs(tmpdir)

    # define a name for a temporary DEM file
    dem_tmp = os.path.join(tmpdir, 'srtm_tmp.tif')

    # create a DEM mosaic for the study site
    run([
        'gdalwarp', '-q', '-of', 'GTiff', '-te', ext['xmin'], ext['ymin'],
        ext['xmax'], ext['ymax'], srtm_vrt, dem_tmp
    ])

    # transform the DEM to GAMMA format (including EGM96 geoid to WGS84 ellipsoid height reference correction)
    gamma.process(['srtm2dem', dem_tmp, outname, outname + '.par', 2, '-'],
                  outdir=tmpdir)

    # create an ENVI header file
    hdr(outname + '.par')

    # remove the temporary directory with all intermediate files
    shutil.rmtree(tmpdir)

    # optional: transform DEM to UTM projection
    # the UTM zone is automatically computed for the center of the DEM file
    srtm.transform(outname, outname + '_utm', posting=20)
示例#2
0
def worker(sitename):
    #######################################################################################
    # setup general processing parameters

    resolution = 20
    #######################################################################################
    # define the directories for writing temporary and final results
    sitedir = os.path.join(maindir, sitename)
    outdir = os.path.join(sitedir, 'proc_out')
    #######################################################################################
    # load the test site geometry into a vector object
    sites = vector.Vector('/.../testsites.shp')

    # query the test site by name; a column name 'Site_Name' must be saved in your shapefile
    site = sites['Site_Name={}'.format(sitename)]
    #######################################################################################
    # query the database for scenes to be processed
    with Archive(dbfile) as archive:
        selection_proc = archive.select(vectorobject=site,
                                        processdir=outdir,
                                        sensor=('S1A', 'S1B'),
                                        product='GRD',
                                        acquisition_mode='IW',
                                        vv=1)

    print('{0}: {1} scenes found for site {2}'.format(socket.gethostname(),
                                                      len(selection_proc),
                                                      sitename))
    #######################################################################################
    # call to processing utility
    if len(selection_proc) > 1:
        print('start processing')

        for scene in selection_proc:
            geocode(infile=scene, outdir=outdir, tr=resolution, scaling='db')
    return len(selection_proc)
示例#3
0
def worker(sitename):
    #######################################################################################
    # setup general processing parameters

    resolution = 20

    # number of processes for Python pathos framework (multiple scenes in parallel)
    parallel1 = 6

    # number of parallel OpenMP threads; this is used by GAMMA internally
    parallel2 = 6
    os.environ['OMP_NUM_THREADS'] = str(parallel2)
    #######################################################################################
    # get the maximum date of the precise orbit files
    # as type also 'RES' can be selected. These files are not as precise as POE and thus geocoding might not be
    # quite as accurate
    with OSV(osvdir) as osv:
        maxdate = osv.maxdate(osvtype='POE', datetype='stop')
    #######################################################################################
    # define the directories for writing temporary and final results
    sitedir = os.path.join(maindir, sitename)
    tempdir = os.path.join(sitedir, 'proc_in')
    outdir = os.path.join(sitedir, 'proc_out')
    #######################################################################################
    # load the test site geometry into a vector object
    sites = vector.Vector('/.../testsites.shp')

    # query the test site by name; a column name 'Site_Name' must be saved in your shapefile
    site = sites["Site_Name='{}'".format(sitename)]
    #######################################################################################
    # query the database for scenes to be processed
    with Archive(dbfile) as archive:
        selection_proc = archive.select(vectorobject=site,
                                        processdir=outdir,
                                        maxdate=maxdate,
                                        sensor=('S1A', 'S1B'),
                                        product='GRD',
                                        acquisition_mode='IW',
                                        vv=1)

    print('{0}: {1} scenes found for site {2}'.format(socket.gethostname(),
                                                      len(selection_proc),
                                                      sitename))
    #######################################################################################
    # define the DEM file
    demfile = '{0}/{1}/DEM/{1}_srtm_utm'.format(maindir, sitename)
    if not os.path.isfile(demfile):
        print('DEM missing for site {}'.format(sitename))
        return
    #######################################################################################
    # call to processing utility
    if len(selection_proc) > 1:
        print('start processing')
    if len(selection_proc) > 1:
        if len(selection_proc) < parallel1:
            parallel1 = len(selection_proc)
        # run the function on multiple cores in parallel
        multicore(geocode,
                  cores=parallel1,
                  multiargs={'scene': selection_proc},
                  dem=demfile,
                  tempdir=tempdir,
                  outdir=outdir,
                  targetres=resolution,
                  scaling='db',
                  func_geoback=2,
                  func_interp=0,
                  sarsimulation=False,
                  osvdir=osvdir,
                  cleanup=True,
                  allow_RES_OSV=False)
    elif len(selection_proc) == 1:
        scene = selection_proc[0]
        # run the function on a single core
        geocode(scene,
                dem=demfile,
                tempdir=tempdir,
                outdir=outdir,
                targetres=resolution,
                scaling='db',
                func_geoback=2,
                func_interp=0,
                sarSimCC=False,
                osvdir=osvdir,
                cleanup=True,
                allow_RES_OSV=False)
    return len(selection_proc)