Ejemplo n.º 1
0
def test_bandpass_run():
    '''
    Check if bandpass_insar runs without crashing.
    '''
    # load yaml file
    test_yaml = os.path.join(iscetest.data, 'bandpass_test.yaml')
    with open(test_yaml) as fh_test_yaml:
        test_yaml = fh_test_yaml.read().replace('@ISCETEST@', iscetest.data).\
                replace('@TEST_OUTPUT@', 'rifg_bandpass.h5').\
                replace('@TEST_PRODUCT_TYPES@', 'RIFG')

    # Create CLI input namespace with yaml text instead of filepath
    args = argparse.Namespace(run_config_path=test_yaml, log_file=False)

    # Initialize runconfig object
    runconfig = InsarRunConfig(args)
    runconfig.geocode_common_arg_load()

    h5_prep.run(runconfig.cfg)

    # insar.run(runconfig.cfg)
    out_paths = h5_prep.run(runconfig.cfg)

    persist = Persistence(restart=True)
    persist.run_steps['dense_offsets'] = False
    insar.run(runconfig.cfg, out_paths, persist.run_steps)
Ejemplo n.º 2
0
def test_run():
    '''
    run gcov with same rasters and DEM as geocodeSlc test
    '''
    test_yaml = os.path.join(iscetest.data, 'geocode/test_gcov.yaml')

    # load text then substitude test directory paths since data dir is read only
    with open(test_yaml) as fh_test_yaml:
        test_yaml = ''.join([
            line.replace('@ISCETEST@', iscetest.data) for line in fh_test_yaml
        ])

    # create CLI input namespace with yaml text instead of file path
    args = argparse.Namespace(run_config_path=test_yaml, log_file=False)

    # init runconfig object
    runconfig = GCOVRunConfig(args)
    runconfig.geocode_common_arg_load()

    # geocode same rasters as C++/pybind geocodeCov
    for axis in input_axis:
        #  iterate thru geocode modes
        for key, value in geocode_modes.items():
            runconfig.cfg['product_path_group'][
                'sas_output_file'] = f'{axis}_{key}.h5'

            # prepare output hdf5
            h5_prep.run(runconfig.cfg)

            # geocode test raster
            gcov.run(runconfig.cfg)
Ejemplo n.º 3
0
def test_run():
    '''
    run gslc with same rasters and DEM as geocodeSlc test
    '''
    test_yaml = os.path.join(iscetest.data, 'geocodeslc/test_gslc.yaml')

    # load text then substitude test directory paths since data dir is read only
    with open(test_yaml) as fh_test_yaml:
        test_yaml = ''.join([
            line.replace('@ISCETEST@', iscetest.data) for line in fh_test_yaml
        ])

    # create CLI input namespace with yaml text instead of file path
    args = argparse.Namespace(run_config_path=test_yaml, log_file=False)

    # init runconfig object
    runconfig = GSLCRunConfig(args)
    runconfig.geocode_common_arg_load()

    # geocode same 2 rasters as C++/pybind geocodeSlc
    for xy in ['x', 'y']:
        # adjust runconfig to match just created raster
        runconfig.cfg['product_path_group']['sas_output_file'] = f'{xy}_out.h5'

        # prepare output hdf5
        h5_prep.run(runconfig.cfg)

        # geocode test raster
        gslc.run(runconfig.cfg)
Ejemplo n.º 4
0
def run(cfg: dict, out_paths: dict, run_steps: dict):
    '''
    Run INSAR workflow with parameters in cfg dictionary
    '''
    info_channel = journal.info("insar.run")
    info_channel.log("starting INSAR")

    t_all = time.time()

    if run_steps['bandpass_insar']:
        bandpass_insar.run(cfg)

    if run_steps['h5_prep']:
        h5_prep.run(cfg)

    if run_steps['rdr2geo']:
        rdr2geo.run(cfg)

    if run_steps['geo2rdr']:
        geo2rdr.run(cfg)

    if run_steps['coarse_resample']:
        resample_slc.run(cfg, 'coarse')

    if (run_steps['dense_offsets']) and \
            (cfg['processing']['dense_offsets']['enabled']):
        dense_offsets.run(cfg)

    if run_steps['rubbersheet'] and \
            cfg['processing']['rubbersheet']['enabled']:
        rubbersheet.run(cfg, out_paths['RIFG'])

    # If enabled, run fine_resampling
    if run_steps['fine_resample'] and \
            cfg['processing']['fine_resample']['enabled']:
        resample_slc.run(cfg, 'fine')

    # If fine_resampling is enabled, use fine-coregistered SLC
    # to run crossmul
    if run_steps['crossmul']:
        if cfg['processing']['fine_resample']['enabled']:
            crossmul.run(cfg, out_paths['RIFG'], 'fine')
        else:
            crossmul.run(cfg, out_paths['RIFG'], 'coarse')

    # Run insar_filter only
    if run_steps['filter_interferogram'] and \
        cfg['processing']['filter_interferogram']['filter_type'] != 'no_filter':
        filter_interferogram.run(cfg, out_paths['RIFG'])

    if run_steps['unwrap'] and 'RUNW' in out_paths:
        unwrap.run(cfg, out_paths['RIFG'], out_paths['RUNW'])

    if run_steps['geocode'] and 'GUNW' in out_paths:
        geocode_insar.run(cfg, out_paths['RUNW'], out_paths['GUNW'])

    t_all_elapsed = time.time() - t_all
    info_channel.log(f"successfully ran INSAR in {t_all_elapsed:.3f} seconds")
Ejemplo n.º 5
0
def test_crossmul_run():
    '''
    Check if crossmul runs without crashing.
    '''
    # load yaml file
    test_yaml = os.path.join(iscetest.data, 'insar_test.yaml')
    with open(test_yaml) as fh_test_yaml:
        test_yaml = fh_test_yaml.read().replace('@ISCETEST@', iscetest.data).\
                replace('@TEST_OUTPUT@', 'rifg.h5').\
                replace('@TEST_PRODUCT_TYPES@', 'RIFG').\
                replace('@TEST_RDR2GEO_FLAGS@', 'True')

    # Create CLI input namespace with yaml text instead of filepath
    args = argparse.Namespace(run_config_path=test_yaml, log_file=False)

    # Initialize runconfig object
    runconfig = CrossmulRunConfig(args)
    runconfig.geocode_common_arg_load()

    h5_prep.run(runconfig.cfg)

    crossmul.run(runconfig.cfg)
Ejemplo n.º 6
0
def test_unwrap_run():
    '''
    Test if phase unwrapping runs smoothly
    '''

    test_yaml = os.path.join(iscetest.data, 'insar_test.yaml')
    with open(test_yaml) as fh_test_yaml:
        test_yaml = fh_test_yaml.read().replace('@ISCETEST@', iscetest.data). \
            replace('@TEST_OUTPUT@', 'runw.h5'). \
            replace('@TEST_PRODUCT_TYPES@', 'RUNW').\
            replace('@TEST_RDR2GEO_FLAGS@', 'True')

    # Create CLI input name space with yaml instead of filepath
    args = argparse.Namespace(run_config_path=test_yaml, log_file=False)

    # Initialize runconfig object
    runconfig = UnwrapRunConfig(args)
    runconfig.geocode_common_arg_load()

    out_paths = h5_prep.run(runconfig.cfg)

    product_path = 'science/LSAR/RIFG/swaths/frequencyA/interferogram/HH'

    # Modify interferogram and correlation
    with h5py.File(out_paths['RIFG'], "a", libver='latest',
                   swmr=True) as h_rifg:
        ds = h_rifg[os.path.join(product_path, 'wrappedInterferogram')]
        nrows, ncols = ds.shape

        # Generate a ramp
        x, y = np.meshgrid(np.arange(ncols), np.arange(nrows))
        ref_igram = np.exp(1j * x)

        # Generate all 1 coherence
        ref_coh = np.ones([nrows, ncols])

        # Save reference datasets in RIFG
        h_rifg[os.path.join(product_path,
                            'wrappedInterferogram')][:, :] = ref_igram
        h_rifg[os.path.join(product_path,
                            'coherenceMagnitude')][:, :] = ref_coh
        h_rifg.close()

    # Run unwrapping
    unwrap.run(runconfig.cfg, out_paths['RIFG'], out_paths['RUNW'])
Ejemplo n.º 7
0
def test_insar_run():
    '''
    Run InSAR run
    '''

    # load yaml file
    path_test_yaml = os.path.join(iscetest.data, 'insar_test.yaml')

    for prod_type in ['RIFG', 'RUNW', 'GUNW']:
        test_output = f'{prod_type}.h5'

        # Load text and substitute directory path
        with open(path_test_yaml) as fh_test_yaml:
            test_yaml = fh_test_yaml.read().replace('@ISCETEST@',
                                                    iscetest.data). \
                replace('@TEST_OUTPUT@', test_output). \
                replace('@TEST_PRODUCT_TYPES@', prod_type). \
                replace('@TEST_RDR2GEO_FLAGS@', 'False')

        # create CLI input namespace
        args = argparse.Namespace(run_config_path=test_yaml, log_file=False)

        # Initialize runconfig object
        insar_runcfg = InsarRunConfig(args)
        insar_runcfg.geocode_common_arg_load()
        insar_runcfg.yaml_check()

        out_paths = h5_prep.run(insar_runcfg.cfg)
        persist = Persistence(restart=True)

        # No CPU dense offsets. Turn off dense_offsets,
        # rubbersheet, and fine_resample to avoid test failure
        persist.run_steps['dense_offsets'] = False
        persist.run_steps['rubbersheet'] = False
        persist.run_steps['fine_resample'] = False

        # run insar for prod_type
        insar.run(insar_runcfg.cfg, out_paths, persist.run_steps)

        # check if test_output exists
        assert os.path.isfile(
            test_output), f"{test_output} for {prod_type} not found."
Ejemplo n.º 8
0
def test_filter_interferogram_run():
    '''
    Check if insar_filtering runs without crashing
    '''

    # Load yaml file
    test_yaml = os.path.join(iscetest.data, 'insar_test.yaml')
    with open(test_yaml) as fh_test_yaml:
        test_yaml = fh_test_yaml.read().replace('@ISCETEST@', iscetest.data). \
            replace('@TEST_OUTPUT@', 'RIFG.h5'). \
            replace('@TEST_PRODUCT_TYPES@', 'RIFG'). \
            replace('@TEST_RDR2GEO_FLAGS@', 'True'). \
            replace('interferogram_path:', 'interferogram_path: RIFG.h5')

    # Create CLI input namespace with yaml text instead of filepath
    args = argparse.Namespace(run_config_path=test_yaml, log_file=False)

    # Initialize runconfig object
    runconfig = FilterInterferogramRunConfig(args)
    runconfig.geocode_common_arg_load()

    out_paths = h5_prep.run(runconfig.cfg)

    # Modify the interferogram data to have something meaningful
    product_path = '/science/LSAR/RIFG/swaths/frequencyA/interferogram/HH'
    with h5py.File(out_paths['RIFG'], "a", libver='latest',
                   swmr=True) as h_rifg:
        ds = h_rifg[os.path.join(product_path, 'wrappedInterferogram')]
        nrows, ncols = ds.shape

        # Generate a ramp and add some noise
        x, y = np.meshgrid(np.arange(ncols), np.arange(nrows))
        igram = np.exp(1j * (x + y))
        h_rifg[os.path.join(product_path,
                            'wrappedInterferogram')][:, :] = igram
        h_rifg.close()

    # Set interferogram_path for stand-alone usage of insar_filtering
    filter_interferogram.run(runconfig.cfg, out_paths['RIFG'])
Ejemplo n.º 9
0
def test_geocode_run():
    '''
    Test if phase geocodeping runs smoothly
    '''
    test_yaml_path = os.path.join(iscetest.data, 'insar_test.yaml')
    for pu in ['cpu', 'gpu']:
        # Skip GPU geocode insar if cuda not included
        if pu == 'gpu' and not hasattr(isce3, 'cuda'):
            continue

        with open(test_yaml_path) as fh_test_yaml:
            test_yaml = fh_test_yaml.read().replace('@ISCETEST@', iscetest.data). \
                replace('@TEST_OUTPUT@', f'{pu}_gunw.h5'). \
                replace('@TEST_PRODUCT_TYPES@', 'GUNW'). \
                replace('@TEST_RDR2GEO_FLAGS@', 'True')
            if pu == 'gpu':
                test_yaml = test_yaml.replace('gpu_enabled: False',
                                              'gpu_enabled: True')

        # Create CLI input name space with yaml instead of filepath
        args = argparse.Namespace(run_config_path=test_yaml, log_file=False)

        # Initialize runconfig object
        runconfig = GeocodeInsarRunConfig(args)
        runconfig.geocode_common_arg_load()

        # save geogrid for later validation
        geogrid = runconfig.cfg['processing']['geocode']['geogrids']['A']
        geo_tx = np.array([
            geogrid.start_x, geogrid.spacing_x, 0, geogrid.start_y, 0,
            geogrid.spacing_y
        ])
        geo_tx.tofile('gunw_geogrid.txt', sep=',')

        # prepare HDF5 outputs
        out_paths = h5_prep.run(runconfig.cfg)

        # insert rdr2geo outputs into RUNW HDF5
        rdr2geo_dict = {'x': 'unwrappedPhase', 'y': 'coherenceMagnitude'}
        runw_product_path = 'science/LSAR/RUNW/swaths/frequencyA/interferogram/HH'
        az_looks = runconfig.cfg['processing']['crossmul']['azimuth_looks']
        rg_looks = runconfig.cfg['processing']['crossmul']['range_looks']
        with h5py.File(out_paths['RUNW'], 'a', libver='latest',
                       swmr=True) as h_runw:
            for axis, ds_name in rdr2geo_dict.items():
                # extract rdr2geo raster to array
                f_rdr2geo = f'rdr2geo/freqA/{axis}.rdr'
                ds = gdal.Open(f_rdr2geo, gdal.GA_ReadOnly)
                arr = ds.GetRasterBand(1).ReadAsArray()
                ds = None

                # decimate array (take center pixel of mlook grid) and save to HDF5
                sz_x, sz_y = arr.shape
                arr_mlook = arr[az_looks // 2:sz_x - az_looks // 2:az_looks,
                                az_looks // 2:sz_y - az_looks // 2:az_looks]
                h_runw[f'{runw_product_path}/{ds_name}'][:, :] = arr_mlook

        # disable unused runw dataset
        runconfig.cfg['processing']['geocode']['datasets'][
            'connected_components'] = False

        # run geocodeing of runw
        geocode_insar.run(runconfig.cfg, out_paths['RUNW'], out_paths['GUNW'])
Ejemplo n.º 10
0
                spacing_x=radar_grid_cubes_geogrid.spacing_x,
                spacing_y=radar_grid_cubes_geogrid.spacing_y,
                width=int(radar_grid_cubes_geogrid.width),
                length=int(radar_grid_cubes_geogrid.length),
                epsg=radar_grid_cubes_geogrid.epsg)

            cube_group_name = '/science/LSAR/GSLC/metadata/radarGrid'

            native_doppler.bounds_error = False
            '''
            The native-Doppler LUT bounds error is turned off to
            computer cubes values outside radar-grid boundaries
            '''
            add_radar_grid_cubes_to_hdf5(dst_h5, cube_group_name, cube_geogrid,
                                         radar_grid_cubes_heights, radar_grid,
                                         orbit, native_doppler,
                                         image_grid_doppler, threshold_geo2rdr,
                                         iteration_geo2rdr)

    t_all_elapsed = time.time() - t_all
    info_channel.log(
        f"successfully ran geocode SLC in {t_all_elapsed:.3f} seconds")


if __name__ == "__main__":
    yaml_parser = YamlArgparse()
    args = yaml_parser.parse()
    gslc_runcfg = GSLCRunConfig(args)
    h5_prep.run(gslc_runcfg.cfg)
    run(gslc_runcfg.cfg)
Ejemplo n.º 11
0
        err_str = "Not a valid unwrapping algorithm"
        error_channel.log(err_str)
        raise ValueError(err_str)

    return unwrap


if __name__ == "__main__":
    '''
    Run phase unwrapping from command line
    '''

    # Load command line args
    unwrap_parser = YamlArgparse()
    args = unwrap_parser.parse()

    # Get a runconfig dictionary from command line args
    unwrap_runconfig = UnwrapRunConfig(args)

    # Prepare RUNW HDF5
    unwrap_runconfig.cfg['primary_executable'][
        'product_type'] = 'RUNW_STANDALONE'
    out_paths = h5_prep.run(unwrap_runconfig.cfg)

    # Use RIFG from crossmul_path
    rifg_h5 = unwrap_runconfig.cfg['processing']['phase_unwrap'][
        'crossmul_path']

    # Run phase unwrapping
    run(unwrap_runconfig.cfg, rifg_h5, out_paths['RUNW'])
Ejemplo n.º 12
0
                continue

            add_radar_grid_cube(cfg, freq, radar_grid, slc.getOrbit(), dst_h5)

    t_all_elapsed = time.time() - t_all
    info_channel.log(f"Successfully ran geocode in {t_all_elapsed:.3f} seconds")


if __name__ == "__main__":
    """
    run geocode from command line
    """

    # load command line args
    geocode_insar_parser = YamlArgparse()
    args = geocode_insar_parser.parse()

    # Get a runconfig dictionary from command line args
    geocode_insar_runconfig = GeocodeInsarRunConfig(args)

    # prepare RIFG HDF5
    geocode_insar_runconfig.cfg['primary_executable']['product_type'] = 'GUNW_STANDALONE'
    out_paths = h5_prep.run(geocode_insar_runconfig.cfg)
    runw_path = geocode_insar_runconfig.cfg['processing']['geocode'][
        'runw_path']
    if runw_path is not None:
        out_paths['RUNW'] = runw_path

    # Run geocode
    run(geocode_insar_runconfig.cfg, out_paths["RUNW"], out_paths["GUNW"])
Ejemplo n.º 13
0
       Frequency to process (A or B)
    pol: str
       Polarization to process (HH, HV, VH, VV)
    """
    path = f'science/LSAR/RIFG/swaths/frequency{freq}/pixelOffsets/{pol}/'
    offset_layer = ['slantRangeOffset', 'alongTrackOffset']

    for layer in offset_layer:
        offset_path = f'{path}/{layer}'
        offset_dataset = h5_ds[offset_path]
        offset_raster = isce3.io.Raster(
            f"IH5:::ID={offset_dataset.id.id}".encode("utf-8"))
        compute_stats_real_data(offset_raster, offset_dataset)


if __name__ == "__main__":
    '''
    run crossmul from command line
    '''
    # load command line args
    crossmul_parser = YamlArgparse(resample_type=True)
    args = crossmul_parser.parse()
    # extract resample type
    resample_type = args.resample_type
    # get a runconfig dict from command line args
    crossmul_runconfig = CrossmulRunConfig(args, resample_type)
    # prepare RIFG HDF5
    out_paths = h5_prep.run(crossmul_runconfig.cfg)
    # run crossmul
    run(crossmul_runconfig.cfg, out_paths['RIFG'], resample_type)
Ejemplo n.º 14
0
        <PixelFunctionType>{function_name}</PixelFunctionType>
        <SimpleSource>
          <SourceFilename>{file1}</SourceFilename>
        </SimpleSource>
        <SimpleSource>
          <SourceFilename>{file2}</SourceFilename>
        </SimpleSource>
      </VRTRasterBand>
    </VRTDataset>'''

    with open(out_vrt, 'w') as fid:
        fid.write(vrttmpl)


if __name__ == "__main__":
    '''
    Run rubbersheet to filter out outliers in the
    slant range and azimuth offset fields. Fill no
    data values left by outliers holes and resample
    culled offsets to reference RSLC shape.
    '''
    # Prepare rubbersheet parser & runconfig
    rubbersheet_parser = YamlArgparse()
    args = rubbersheet_parser.parse()
    rubbersheet_runconfig = RubbersheetRunConfig(args)

    # Prepare RIFG. Culled offsets will be
    # allocated in RIFG product
    out_paths = h5_prep.run(rubbersheet_runconfig.cfg)
    run(rubbersheet_runconfig.cfg, out_paths['RIFG'])
Ejemplo n.º 15
0
        elif stats_real_imag_vector is not None:

            stats_obj = stats_real_imag_vector[band]
            dset.attrs.create('min_real_value', data=stats_obj.min_real)
            dset.attrs.create('mean_real_value', data=stats_obj.mean_real)
            dset.attrs.create('max_real_value', data=stats_obj.max_real)
            dset.attrs.create('sample_standard_deviation_real',
                              data=stats_obj.sample_stddev_real)

            dset.attrs.create('min_imag_value', data=stats_obj.min_imag)
            dset.attrs.create('mean_imag_value', data=stats_obj.mean_imag)
            dset.attrs.create('max_imag_value', data=stats_obj.max_imag)
            dset.attrs.create('sample_standard_deviation_imag',
                              data=stats_obj.sample_stddev_imag)

        if valid_min is not None:
            dset.attrs.create('valid_min', data=valid_min)

        if valid_max is not None:
            dset.attrs.create('valid_max', data=valid_max)

    del gdal_ds


if __name__ == "__main__":
    yaml_parser = YamlArgparse()
    args = yaml_parser.parse()
    gcov_runcfg = GCOVRunConfig(args)
    h5_prep.run(gcov_runcfg.cfg)
    run(gcov_runcfg.cfg)