def stack_corr_for_ref_unwrapped_isce(intf_files,
                                      rowref,
                                      colref,
                                      ts_output_dir,
                                      label=""):
    # WE MAKE THE SIGNAL SPREAD FOR THE CUT IMAGES
    cor_files = [
        i.replace("fully_processed.unwrappedphase", "cut.cor")
        for i in intf_files
    ]
    # get for isce
    netcdfname = ts_output_dir + '/signalspread_cut_ref' + label + '.nc'
    cor_value = np.nan
    cor_data = readmytupledata.reader_isce(cor_files)
    a = stack_corr.stack_corr(cor_data, cor_value)
    rwr.produce_output_netcdf(cor_data.xvalues, cor_data.yvalues, a,
                              'Percentage', netcdfname)
    rwr.produce_output_plot(netcdfname,
                            'Signal Spread above cor=' + str(cor_value),
                            ts_output_dir + '/signalspread_cut_ref' + label +
                            '.png',
                            'Percentage of coherence',
                            aspect=1 / 4,
                            invert_yaxis=False,
                            dot_points=[[colref], [rowref]])
    signal_spread_ref = a[rowref, colref]
    print("Signal Spread of the reference pixel = %.2f " % (signal_spread_ref))
    if signal_spread_ref < 50:
        print(
            "WARNING: Your reference pixel has very low coherence. Consider picking a different one."
        )
        print("STOPPING ON PURPOSE.")
        sys.exit(0)
    return
Exemple #2
0
def drive_full_TS_isce(intf_files,
                       nsbas_min_intfs,
                       sbas_smoothing,
                       wavelength,
                       rowref,
                       colref,
                       outdir,
                       baseline_file=None,
                       coh_files=None):
    # SETUP.
    signal_spread_file = outdir + "/signalspread_cut.nc"
    intf_tuple = rmd.reader_isce(intf_files)
    coh_tuple = None
    if coh_files is not None:
        coh_tuple = rmd.reader_isce(coh_files)
    xdates = stacking_utilities.get_xdates_from_intf_tuple(intf_tuple)
    signal_spread_data = rwr.read_grd(signal_spread_file)

    # TIME SERIES
    TS = nsbas.Full_TS(intf_tuple,
                       nsbas_min_intfs,
                       sbas_smoothing,
                       wavelength,
                       rowref,
                       colref,
                       signal_spread_data,
                       baseline_file=baseline_file,
                       coh_tuple=coh_tuple)

    # OUTPUTS
    TS_NC_file = outdir + "/TS.nc"
    TS_image_file = outdir + "/TS.png"
    rwr.produce_output_timeseries(intf_tuple.xvalues, intf_tuple.yvalues, TS,
                                  xdates, 'mm', TS_NC_file)
    stacking_utilities.plot_full_timeseries(TS_NC_file,
                                            xdates,
                                            TS_image_file,
                                            vmin=-50,
                                            vmax=200,
                                            aspect=1 / 8)
    return
def drive_coseismic_stack_isce(intf_files, wavelength, rowref, colref, outdir):
    intf_tuple = rmd.reader_isce(intf_files)
    average_coseismic = get_avg_coseismic(intf_tuple, rowref, colref,
                                          wavelength)
    rwr.produce_output_netcdf(intf_tuple.xvalues, intf_tuple.yvalues,
                              average_coseismic, 'mm',
                              outdir + '/coseismic.grd')
    rwr.produce_output_plot(outdir + '/coseismic.grd',
                            'LOS Displacement',
                            outdir + '/coseismic.png',
                            'displacement (mm)',
                            aspect=1 / 8,
                            invert_yaxis=False,
                            vmin=-50,
                            vmax=200)
    return
def make_corrections_isce(config_params):
    if config_params.startstage > 1:  # if we're starting after, we don't do this.
        return
    if config_params.endstage < 1:  # if we're ending before, we don't do this.
        return
    print("Start Stage 1 - optional atm corrections")

    # For ISCE, we might want to re-make all the interferograms and unwrap them in custom fashion.
    # This operates on files in the Igram directory, no need to move directories yourself.
    if config_params.solve_unwrap_errors:
        unwrapping_isce_custom.main_function(config_params.rlks,
                                             config_params.alks,
                                             config_params.filt,
                                             config_params.xbounds,
                                             config_params.ybounds,
                                             config_params.cor_cutoff_mask)

    # WE ALSO MAKE THE SIGNAL SPREAD FOR FULL IMAGES
    cor_value = 0.5
    filepathslist = glob.glob("../Igrams/????????_????????/filt*.cor")
    # *** This may change
    cor_data = readmytupledata.reader_isce(filepathslist)
    a = stack_corr.stack_corr(cor_data, cor_value)
    rwr.produce_output_netcdf(
        cor_data.xvalues, cor_data.yvalues, a, 'Percentage',
        config_params.ts_output_dir + '/signalspread_full.nc')
    rwr.produce_output_plot(
        config_params.ts_output_dir + '/signalspread_full.nc',
        'Signal Spread above cor=' + str(cor_value),
        config_params.ts_output_dir + '/signalspread_full.png',
        'Percentage of coherence',
        aspect=1 / 4,
        invert_yaxis=False)
    print("End Stage 1 - optional atm corrections\n")

    return
def get_100p_pixels_get_ref(filenameslist, ref_idx, outdir):
    # This function helps you manually choose a reference pixel.
    # You might have to run through this function a number of times
    # To select your boxes and your eventual reference pixel.
    # I pick one in a stable area, outside of the deformation, ideally in a desert.

    print("Finding the pixels that are 100 percent coherent")
    # Finding pixels that are completely non-nan
    mydata = readmytupledata.reader_isce(filenameslist, band=1)
    # if it's straight from SNAPHU, band = 2
    # if it's manually processed first, band = 1
    total_pixels = np.shape(mydata.zvalues)[1] * np.shape(mydata.zvalues)[2]
    total_images = np.shape(mydata.zvalues)[0]
    xvalues = range(np.shape(mydata.zvalues)[2])
    yvalues = range(np.shape(mydata.zvalues)[1])
    count = 0
    ypixels_good = []
    xpixels_good = []
    ypixels_options = []
    xpixels_options = []

    for i in range(np.shape(mydata.zvalues)[1]):
        for j in range(np.shape(mydata.zvalues)[2]):
            oneslice = mydata.zvalues[:, i, j]
            if np.sum(~np.isnan(oneslice)
                      ) == total_images:  # if we have perfect coherence
                count = count + 1
                xpixels_good.append(j)
                ypixels_good.append(i)
                # Here we will adjust parameters until we find a reference pixel that we like.
                if 280 < j < 300 and 2500 < i < 2700:
                    xpixels_options.append(j)
                    ypixels_options.append(i)

    idx_lucky = 710
    xref = xpixels_options[idx_lucky]
    yref = ypixels_options[idx_lucky]

    print("%d of %d (%f percent) are totally coherent. " %
          (count, total_pixels, 100 * (count / total_pixels)))
    print(np.shape(mydata.zvalues))
    print("%d pixels are good options for the reference pixel. " %
          (len(xpixels_options)))

    # Make a plot that shows where those pixels are
    # a=rwr.read_grd(outdir+'/signalspread_cut.nc');
    fig = plt.figure()
    # plt.imshow(a,aspect=1/4, cmap='rainbow');
    plt.plot(xpixels_good, ypixels_good, '.', color='k')
    plt.plot(xpixels_options, ypixels_options, '.', color='g')
    plt.plot(xref, yref, '.', color='r')
    plt.savefig(outdir + '/best_pixels.png')
    plt.close()

    print(
        "Based on 100p pixels, selecting reference pixel at row/col %d, %d " %
        (yref, xref))
    print(
        "STOPPING ON PURPOSE: Please write your reference pixel in your config file."
    )

    return yref, xref