예제 #1
0
def main(inps=None):
    '''
        Main driver.
    '''
    inps = cmdLineParse()

    print("***Time-series Preparation Function:***")
    # if user bbox was specified, file(s) not meeting imposed spatial criteria are rejected.
    # Outputs = arrays ['standardproduct_info.products'] containing grouped “radarmetadata info” and “data layer keys+paths” dictionaries for each standard product
    # In addition, path to bbox file ['standardproduct_info.bbox_file'] (if bbox specified)
    standardproduct_info = ARIA_standardproduct(inps.imgfile, bbox=inps.bbox, workdir=inps.workdir, verbose=inps.verbose)

    # extract/merge productBoundingBox layers for each pair and update dict,
    # report common track bbox (default is to take common intersection, but user may specify union), and expected shape for DEM.
    standardproduct_info.products[1], standardproduct_info.bbox_file, prods_TOTbbox, arrshape, proj = merged_productbbox(standardproduct_info.products[1], os.path.join(inps.workdir,'productBoundingBox'), standardproduct_info.bbox_file, inps.croptounion)

    # Load or download mask (if specified).
    if inps.mask is not None:
        inps.mask = prep_mask(inps.mask, standardproduct_info.bbox_file, prods_TOTbbox, proj, amp_thresh=inps.amp_thresh, arrshape=arrshape, workdir=inps.workdir, outputFormat=inps.outputFormat)


    # Download/Load DEM & Lat/Lon arrays, providing bbox, expected DEM shape, and output dir as input.
    if inps.demfile is not None:
        print('Download/cropping DEM')
        # Pass DEM-filename, loaded DEM array, and lat/lon arrays
        inps.demfile, demfile, Latitude, Longitude = prep_dem(inps.demfile, standardproduct_info.bbox_file, prods_TOTbbox, proj, arrshape=arrshape, workdir=inps.workdir, outputFormat=inps.outputFormat)

    # Extract
    layers=['unwrappedPhase','coherence']
    print('Extracting unwrapped phase, coherence, and connected components for each interferogram pair')
    export_products(standardproduct_info.products[1], standardproduct_info.bbox_file, prods_TOTbbox, layers, dem=demfile, lat=Latitude, lon=Longitude, mask=inps.mask, outDir=inps.workdir, outputFormat=inps.outputFormat, stitchMethodType='overlap', verbose=inps.verbose)

    layers=['incidenceAngle','lookAngle','azimuthAngle']
    print('Extracting incidence angle, look angle and azimuth angle grids of the first interferogram pair')
    export_products([standardproduct_info.products[1][0]], standardproduct_info.bbox_file, prods_TOTbbox, layers, dem=demfile, lat=Latitude, lon=Longitude, mask=inps.mask, outDir=inps.workdir, outputFormat=inps.outputFormat, stitchMethodType='overlap', verbose=inps.verbose)

    if inps.bperp==True:
        layers=['bPerpendicular']
        print('Extracting perpendicular baseline grids for each interferogram pair')
        export_products(standardproduct_info.products[1], standardproduct_info.bbox_file, prods_TOTbbox, layers, dem=demfile, lat=Latitude, lon=Longitude, mask=inps.mask, outDir=inps.workdir, outputFormat=inps.outputFormat, stitchMethodType='overlap', verbose=inps.verbose)

    # Generate Stack
    generateStack(standardproduct_info,'unwrappedPhase','unwrapStack',workdir=inps.workdir)
    generateStack(standardproduct_info,'coherence','cohStack',workdir=inps.workdir)
    generateStack(standardproduct_info,'connectedComponents','connCompStack',workdir=inps.workdir)
예제 #2
0
def main(inps=None):
    inps = cmdLineParse()

    print("***Time-series Preparation Function:***")
    # if user bbox was specified, file(s) not meeting imposed spatial criteria are rejected.
    # Outputs = arrays ['standardproduct_info.products'] containing grouped “radarmetadata info” and “data layer keys+paths” dictionaries for each standard product
    # In addition, path to bbox file ['standardproduct_info.bbox_file'] (if bbox specified)
    standardproduct_info = ARIA_standardproduct(inps.imgfile, bbox=inps.bbox, workdir=inps.workdir, verbose=inps.verbose)

    # pass number of threads for gdal multiprocessing computation
    if inps.num_threads.lower()=='all':
        import multiprocessing
        print('User specified use of all %s threads for gdal multiprocessing'%(str(multiprocessing.cpu_count())))
        inps.num_threads='ALL_CPUS'
    print('Thread count specified for gdal multiprocessing = %s'%(inps.num_threads))

    # extract/merge productBoundingBox layers for each pair and update dict,
    # report common track bbox (default is to take common intersection, but user may specify union), and expected shape for DEM.
    standardproduct_info.products[0], standardproduct_info.products[1], standardproduct_info.bbox_file, prods_TOTbbox, prods_TOTbbox_metadatalyr, arrshape, proj = merged_productbbox(standardproduct_info.products[0], standardproduct_info.products[1], os.path.join(inps.workdir,'productBoundingBox'), standardproduct_info.bbox_file, inps.croptounion, num_threads=inps.num_threads, minimumOverlap=inps.minimumOverlap, verbose=inps.verbose)


    # Download/Load DEM & Lat/Lon arrays, providing bbox, expected DEM shape, and output dir as input.
    if inps.demfile is not None:
        print('Download/cropping DEM')
        # Pass DEM-filename, loaded DEM array, and lat/lon arrays
        inps.demfile, demfile, Latitude, Longitude = prep_dem(inps.demfile, standardproduct_info.bbox_file, prods_TOTbbox, \
            prods_TOTbbox_metadatalyr, proj, arrshape=arrshape, workdir=inps.workdir, outputFormat=inps.outputFormat, num_threads=inps.num_threads)

    # Load or download mask (if specified).
    if inps.mask is not None:
        inps.mask = prep_mask([[item for sublist in [list(set(d['amplitude'])) for d in standardproduct_info.products[1] if 'amplitude' in d] for item in sublist], [item for sublist in [list(set(d['pair_name'])) for d in standardproduct_info.products[1] if 'pair_name' in d] for item in sublist]],inps.mask, standardproduct_info.bbox_file, prods_TOTbbox, proj, amp_thresh=inps.amp_thresh, arrshape=arrshape, workdir=inps.workdir, outputFormat=inps.outputFormat, num_threads=inps.num_threads)

    # Extract
    layers=['unwrappedPhase','coherence']
    print('\nExtracting unwrapped phase, coherence, and connected components for each interferogram pair')
    export_products(standardproduct_info.products[1], standardproduct_info.bbox_file, prods_TOTbbox, layers, dem=demfile, lat=Latitude, lon=Longitude, mask=inps.mask, outDir=inps.workdir, outputFormat=inps.outputFormat, stitchMethodType='overlap', verbose=inps.verbose, num_threads=inps.num_threads, multilooking=inps.multilooking)

    layers=['incidenceAngle','lookAngle','azimuthAngle']
    print('\nExtracting single incidence angle, look angle and azimuth angle files valid over common interferometric grid')
    export_products([dict(zip([k for k in set(k for d in standardproduct_info.products[1] for k in d)], [[item for sublist in [list(set(d[k])) for d in standardproduct_info.products[1] if k in d] for item in sublist] for k in set(k for d in standardproduct_info.products[1] for k in d)]))], standardproduct_info.bbox_file, prods_TOTbbox, layers, dem=demfile, lat=Latitude, lon=Longitude, mask=inps.mask, outDir=inps.workdir, outputFormat=inps.outputFormat, stitchMethodType='overlap', verbose=inps.verbose, num_threads=inps.num_threads, multilooking=inps.multilooking)

    if inps.bperp==True:
        layers=['bPerpendicular']
        print('\nExtracting perpendicular baseline grids for each interferogram pair')
        export_products(standardproduct_info.products[1], standardproduct_info.bbox_file, prods_TOTbbox, layers, dem=demfile, lat=Latitude, lon=Longitude, mask=inps.mask, outDir=inps.workdir, outputFormat=inps.outputFormat, stitchMethodType='overlap', verbose=inps.verbose, num_threads=inps.num_threads, multilooking=inps.multilooking)

    # Extracting other layers, if specified
    if inps.layers:
        if inps.layers.lower()=='all':
            inps.layers=list(standardproduct_info.products[1][0].keys())
            # Must also remove productBoundingBoxes & pair-names because they are not raster layers
            layers=[i for i in inps.layers if i not in ['unwrappedPhase','coherence','incidenceAngle','lookAngle','azimuthAngle','bPerpendicular','productBoundingBox','productBoundingBoxFrames','pair_name']]
        else:
            inps.layers=list(inps.layers.split(','))
            layers=[i for i in inps.layers if i not in ['unwrappedPhase','coherence','incidenceAngle','lookAngle','azimuthAngle','bPerpendicular']]
            layers=[i.replace(' ','') for i in layers]

        if layers!=[]:
            print('\nExtracting optional, user-specified layers %s for each interferogram pair'%(layers))
            export_products(standardproduct_info.products[1], standardproduct_info.bbox_file, prods_TOTbbox, layers, dem=demfile, lat=Latitude, lon=Longitude, mask=inps.mask, outDir=inps.workdir, outputFormat=inps.outputFormat, stitchMethodType='overlap', verbose=inps.verbose, num_threads=inps.num_threads, multilooking=inps.multilooking)

    # If necessary, resample DEM/mask AFTER they have been used to extract metadata layers and mask output layers, respectively
    if inps.multilooking is not None:
        # Import functions
        from ARIAtools.shapefile_util import open_shapefile
        from ARIAtools.vrtmanager import resampleRaster
        bounds=open_shapefile(standardproduct_info.bbox_file, 0, 0).bounds
        # Resample mask
        if inps.mask is not None:
            resampleRaster(inps.mask.GetDescription(), inps.multilooking, bounds, prods_TOTbbox, inps.rankedResampling, outputFormat=inps.outputFormat, num_threads=inps.num_threads)
        # Resample DEM
        if demfile is not None:
            resampleRaster(demfile.GetDescription(), inps.multilooking, bounds, prods_TOTbbox, inps.rankedResampling, outputFormat=inps.outputFormat, num_threads=inps.num_threads)

    # Perform GACOS-based tropospheric corrections (if specified).
    if inps.tropo_products:
        tropo_correction(standardproduct_info.products, inps.tropo_products, standardproduct_info.bbox_file, prods_TOTbbox, outDir=inps.workdir, outputFormat=inps.outputFormat, verbose=inps.verbose, num_threads=inps.num_threads)

    # Generate Stack
    generateStack(standardproduct_info,'coherence','cohStack',workdir=inps.workdir)
    generateStack(standardproduct_info,'connectedComponents','connCompStack',workdir=inps.workdir)
    if inps.tropo_products:
        generateStack(standardproduct_info,'tropocorrected_products','unwrapStack',workdir=inps.workdir)
    else:
        generateStack(standardproduct_info,'unwrappedPhase','unwrapStack',workdir=inps.workdir)
예제 #3
0
def main(inps=None):
    from ARIAtools.ARIAProduct import ARIA_standardproduct
    logger.setLevel(logging.INFO)
    print('*****************************************************************')
    print('*** Plotting Function ***')
    print('*****************************************************************')
    # if user bbox was specified, file(s) not meeting imposed spatial criteria are rejected.
    # Outputs = arrays ['standardproduct_info.products'] containing grouped “radarmetadata info” and “data layer keys+paths” dictionaries for each standard product
    # In addition, path to bbox file ['standardproduct_info.bbox_file'] (if bbox specified)
    standardproduct_info = ARIA_standardproduct(inps.imgfile,
                                                bbox=inps.bbox,
                                                workdir=inps.workdir,
                                                num_threads=inps.num_threads,
                                                url_version=inps.version,
                                                verbose=inps.verbose)

    # If user requests to generate all plots.
    if inps.plotall:
        log.info('"-plotall"==True. All plots will be made.')
        inps.plottracks = True
        inps.plotbperp = True
        inps.plotcoh = True
        inps.plotbperpcoh = True
        inps.makeavgoh = True

    # pass number of threads for gdal multiprocessing computation
    if inps.num_threads.lower() == 'all':
        import multiprocessing
        log.info(
            'User specified use of all %s threads for gdal multiprocessing',
            multiprocessing.cpu_count())
        inps.num_threads = 'ALL_CPUS'
    log.info('Thread count specified for gdal multiprocessing = %s',
             inps.num_threads)

    if inps.plottracks or inps.plotcoh or inps.makeavgoh or inps.plotbperpcoh:
        from ARIAtools.extractProduct import merged_productbbox

        # extract/merge productBoundingBox layers for each pair and update dict,
        # report common track bbox (default is to take common intersection, but user may specify union), and expected shape for DEM.
        standardproduct_info.products[0], standardproduct_info.products[1], \
        standardproduct_info.bbox_file, prods_TOTbbox, \
            prods_TOTbbox_metadatalyr, arrshape, proj = merged_productbbox(
            standardproduct_info.products[0], standardproduct_info.products[1],
            os.path.join(inps.workdir, 'productBoundingBox'),
            standardproduct_info.bbox_file, inps.croptounion,
            num_threads=inps.num_threads,
            minimumOverlap=inps.minimumOverlap, verbose=inps.verbose)

        # Load or download mask (if specified).
        if inps.mask is not None:
            inps.mask = prep_mask(
                [[
                    item for sublist in [
                        list(set(d['amplitude']))
                        for d in standardproduct_info.products[1]
                        if 'amplitude' in d
                    ] for item in sublist
                ],
                 [
                     item for sublist in [
                         list(set(d['pair_name']))
                         for d in standardproduct_info.products[1]
                         if 'pair_name' in d
                     ] for item in sublist
                 ]],
                inps.mask,
                standardproduct_info.bbox_file,
                prods_TOTbbox,
                proj,
                amp_thresh=inps.amp_thresh,
                arrshape=arrshape,
                workdir=inps.workdir,
                outputFormat=inps.outputFormat,
                num_threads=inps.num_threads)

    # Make spatial extent plot
    if inps.plottracks:
        log.info(
            "- Make plot of track latitude extents vs bounding bbox/common track extent."
        )
        make_plot = PlotClass([[
            j['productBoundingBox'] for j in standardproduct_info.products[1]
        ], [j["pair_name"] for j in standardproduct_info.products[1]]],
                              workdir=inps.workdir,
                              bbox_file=standardproduct_info.bbox_file,
                              prods_TOTbbox=prods_TOTbbox,
                              croptounion=inps.croptounion)
        make_plot.plot_extents(figwidth=inps.figwidth)

    # Make pbaseline plot
    if inps.plotbperp:
        log.info("- Make baseline plot and histogram.")
        make_plot = PlotClass(
            [[j['bPerpendicular'] for j in standardproduct_info.products[1]],
             [j["pair_name"] for j in standardproduct_info.products[1]]],
            workdir=inps.workdir)
        make_plot.plot_pbaselines()

    # Make average land coherence plot
    if inps.plotcoh:
        log.info(
            "- Make average IFG coherence plot in time, and histogram of average IFG coherence."
        )
        make_plot = PlotClass(
            [[j['coherence'] for j in standardproduct_info.products[1]],
             [j["pair_name"] for j in standardproduct_info.products[1]]],
            workdir=inps.workdir,
            bbox_file=standardproduct_info.bbox_file,
            prods_TOTbbox=prods_TOTbbox,
            mask=inps.mask,
            num_threads=inps.num_threads)
        make_plot.plot_coherence()

    # Generate average land coherence raster
    if inps.makeavgoh:
        log.info("- Generate 2D raster of average coherence.")
        make_plot = PlotClass(
            [[j['coherence'] for j in standardproduct_info.products[1]],
             [j["pair_name"] for j in standardproduct_info.products[1]]],
            workdir=inps.workdir,
            bbox_file=standardproduct_info.bbox_file,
            prods_TOTbbox=prods_TOTbbox,
            mask=inps.mask,
            outputFormat=inps.outputFormat,
            num_threads=inps.num_threads)
        make_plot.plot_avgcoherence()

    # Make pbaseline/coherence combo plot
    if inps.plotbperpcoh:
        log.info(
            "- Make baseline plot that is color-coded with respect to mean IFG coherence."
        )
        make_plot = PlotClass(
            [[j['bPerpendicular'] for j in standardproduct_info.products[1]],
             [j["pair_name"] for j in standardproduct_info.products[1]],
             [j['coherence'] for j in standardproduct_info.products[1]]],
            workdir=inps.workdir,
            bbox_file=standardproduct_info.bbox_file,
            prods_TOTbbox=prods_TOTbbox,
            mask=inps.mask)
        make_plot.plotbperpcoh()
예제 #4
0
def main(inps=None):
    '''
        Main workflow for extracting layers from ARIA products
    '''

    from ARIAtools.ARIAProduct import ARIA_standardproduct
    from ARIAtools.shapefile_util import open_shapefile

    print("***Extract Product Function:***")
    # if user bbox was specified, file(s) not meeting imposed spatial criteria are rejected.
    # Outputs = arrays ['standardproduct_info.products'] containing grouped “radarmetadata info” and “data layer keys+paths” dictionaries for each standard product
    # In addition, path to bbox file ['standardproduct_info.bbox_file'] (if bbox specified)
    standardproduct_info = ARIA_standardproduct(inps.imgfile,
                                                bbox=inps.bbox,
                                                workdir=inps.workdir,
                                                verbose=inps.verbose)

    if not inps.layers:
        print('No layers specified; only creating bounding box shapes')

    elif inps.layers.lower() == 'all':
        print('All layers are to be extracted, pass all keys.')
        inps.layers = list(standardproduct_info.products[1][0].keys())
        # Must remove productBoundingBoxes & pair-names because they are not raster layers
        inps.layers = [
            i for i in inps.layers if i not in
            ['productBoundingBox', 'productBoundingBoxFrames', 'pair_name']
        ]

    else:
        inps.layers = list(inps.layers.split(','))

    # extract/merge productBoundingBox layers for each pair and update dict,
    # report common track bbox (default is to take common intersection, but user may specify union), and expected shape for DEM.
    standardproduct_info.products[
        1], standardproduct_info.bbox_file, prods_TOTbbox, arrshape, proj = merged_productbbox(
            standardproduct_info.products[1],
            os.path.join(inps.workdir, 'productBoundingBox'),
            standardproduct_info.bbox_file, inps.croptounion)
    # Load or download mask (if specified).
    if inps.mask is not None:
        inps.mask = prep_mask(
            [[j['amplitude'] for j in standardproduct_info.products[1]],
             [j["pair_name"] for j in standardproduct_info.products[1]]],
            inps.mask,
            standardproduct_info.bbox_file,
            prods_TOTbbox,
            proj,
            amp_thresh=inps.amp_thresh,
            arrshape=arrshape,
            workdir=inps.workdir,
            outputFormat=inps.outputFormat)

    # Download/Load DEM & Lat/Lon arrays, providing bbox, expected DEM shape, and output dir as input.
    if inps.demfile is not None:
        # Pass DEM-filename, loaded DEM array, and lat/lon arrays
        inps.demfile, demfile, Latitude, Longitude = prep_dem(
            inps.demfile,
            standardproduct_info.bbox_file,
            prods_TOTbbox,
            proj,
            arrshape=arrshape,
            workdir=inps.workdir,
            outputFormat=inps.outputFormat)
    else:
        demfile = None
        Latitude = None
        Longitude = None

    # Extract user expected layers
    export_products(standardproduct_info.products[1],
                    standardproduct_info.bbox_file,
                    prods_TOTbbox,
                    inps.layers,
                    dem=demfile,
                    lat=Latitude,
                    lon=Longitude,
                    mask=inps.mask,
                    outDir=inps.workdir,
                    outputFormat=inps.outputFormat,
                    stitchMethodType='overlap',
                    verbose=inps.verbose)
예제 #5
0
def main(inps=None):
    from ARIAtools.ARIAProduct import ARIA_standardproduct
    from ARIAtools.shapefile_util import open_shapefile

    print("***Plotting Function:***")
    # if user bbox was specified, file(s) not meeting imposed spatial criteria are rejected.
    # Outputs = arrays ['standardproduct_info.products'] containing grouped “radarmetadata info” and “data layer keys+paths” dictionaries for each standard product
    # In addition, path to bbox file ['standardproduct_info.bbox_file'] (if bbox specified)
    standardproduct_info = ARIA_standardproduct(inps.imgfile,
                                                bbox=inps.bbox,
                                                workdir=inps.workdir,
                                                verbose=inps.verbose)

    # If user requests to generate all plots.
    if inps.plotall:
        print('"-plotall"==True. All plots will be made.')
        inps.plottracks = True
        inps.plotbperp = True
        inps.plotcoh = True
        inps.plotbperpcoh = True
        inps.makeavgoh = True

    if inps.plottracks or inps.plotcoh or inps.makeavgoh or inps.plotbperpcoh:
        # Import functions
        from ARIAtools.extractProduct import merged_productbbox

        # extract/merge productBoundingBox layers for each pair and update dict,
        # report common track bbox (default is to take common intersection, but user may specify union), and expected shape for DEM.
        standardproduct_info.products[
            1], standardproduct_info.bbox_file, prods_TOTbbox, arrshape, proj = merged_productbbox(
                standardproduct_info.products[1],
                os.path.join(inps.workdir, 'productBoundingBox'),
                standardproduct_info.bbox_file, inps.croptounion)

        # Load or download mask (if specified).
        if inps.mask is not None:
            inps.mask = prep_mask(inps.mask,
                                  standardproduct_info.bbox_file,
                                  prods_TOTbbox,
                                  proj,
                                  amp_thresh=inps.amp_thresh,
                                  arrshape=arrshape,
                                  workdir=inps.workdir,
                                  outputFormat=inps.outputFormat)

    # Make spatial extent plot
    if inps.plottracks:
        print(
            "- Make plot of track latitude extents vs bounding bbox/common track extent."
        )
        make_plot = plot_class([[
            j['productBoundingBox'] for j in standardproduct_info.products[1]
        ], [j["pair_name"] for j in standardproduct_info.products[1]]],
                               workdir=inps.workdir,
                               bbox_file=standardproduct_info.bbox_file,
                               prods_TOTbbox=prods_TOTbbox,
                               croptounion=inps.croptounion)
        make_plot.plot_extents()

    # Make pbaseline plot
    if inps.plotbperp:
        print("- Make baseline plot and histogram.")
        make_plot = plot_class(
            [[j['bPerpendicular'] for j in standardproduct_info.products[1]],
             [j["pair_name"] for j in standardproduct_info.products[1]]],
            workdir=inps.workdir)
        make_plot.plot_pbaselines()

    # Make average land coherence plot
    if inps.plotcoh:
        print(
            "- Make average IFG coherence plot in time, and histogram of average IFG coherence."
        )
        make_plot = plot_class(
            [[j['coherence'] for j in standardproduct_info.products[1]],
             [j["pair_name"] for j in standardproduct_info.products[1]]],
            workdir=inps.workdir,
            bbox_file=standardproduct_info.bbox_file,
            prods_TOTbbox=prods_TOTbbox,
            mask=inps.mask)
        make_plot.plot_coherence()

    # Generate average land coherence raster
    if inps.makeavgoh:
        print("- Generate 2D raster of average coherence.")
        make_plot = plot_class(
            [[j['coherence'] for j in standardproduct_info.products[1]],
             [j["pair_name"] for j in standardproduct_info.products[1]]],
            workdir=inps.workdir,
            bbox_file=standardproduct_info.bbox_file,
            prods_TOTbbox=prods_TOTbbox,
            mask=inps.mask,
            outputFormat=inps.outputFormat)
        make_plot.plot_avgcoherence()

    # Make pbaseline/coherence combo plot
    if inps.plotbperpcoh:
        print(
            "- Make baseline plot that is color-coded with respect to mean IFG coherence."
        )
        make_plot = plot_class(
            [[j['bPerpendicular'] for j in standardproduct_info.products[1]],
             [j["pair_name"] for j in standardproduct_info.products[1]],
             [j['coherence'] for j in standardproduct_info.products[1]]],
            workdir=inps.workdir,
            bbox_file=standardproduct_info.bbox_file,
            prods_TOTbbox=prods_TOTbbox,
            mask=inps.mask)
        make_plot.plotbperpcoh()