def top_level_driver():
    baselinefile = 'baseline_table.dat'
    intf_file = 'intf_initial.in'
    intf_file_out = 'intf_record.in'

    crit_days = 30
    # days
    crit_baseline = 20
    # meters

    [stems, times, baselines,
     missiondays] = sentinel_utilities.read_baseline_table(baselinefile)
    intf_pairs_initial = sentinel_utilities.read_intf_table(intf_file)
    intf_pairs_initial = list(intf_pairs_initial)

    # Computing new pairs.
    new_intfs = compute_new_pairs(stems, times, baselines, crit_days,
                                  crit_baseline)

    # Combining the existing and new interferogram lists.
    all_intfs = intf_pairs_initial + new_intfs

    # Outputs
    sentinel_utilities.make_network_plot(all_intfs, stems, times, baselines,
                                         'network_plot.png')
    sentinel_utilities.write_intf_table(all_intfs, intf_file_out)
    return
Example #2
0
def analyze_coherence_function():
    corr_file='corr_results.txt';
    baseline_table = 'raw/baseline_table.dat';
    write_corr_results(corr_file);
    [stem1, stem2, mean_corr] = sentinel_utilities.read_corr_results(corr_file);
    [stems_blt,tbaseline,xbaseline,mission_days]=sentinel_utilities.read_baseline_table(baseline_table);
    make_coh_vs_others_plots(stem1, stem2, mean_corr, stems_blt, xbaseline);
    return;
def get_total_intf_all(config_params):
    # Make a selection of interferograms to form.
    [stems, times, baselines,
     _] = sentinel_utilities.read_baseline_table('F1' +
                                                 '/raw/baseline_table.dat')
    # hard coding for consistency.

    # Retrieving interferogram pairs based on settings in config_files.
    intf_pairs = []
    if "SBAS" in config_params.intf_type:
        intf_pairs = intf_pairs + sentinel_utilities.get_small_baseline_subsets(
            stems, times, baselines, config_params.tbaseline,
            config_params.xbaseline)
    if "CHAIN" in config_params.intf_type:
        intf_pairs = intf_pairs + sentinel_utilities.get_chain_subsets(
            stems, times)
    if "1YR" in config_params.intf_type:
        intf_pairs = intf_pairs + rose_baseline_plot.compute_new_pairs(
            stems, times, baselines, config_params.annual_crit_days,
            config_params.annual_crit_baseline, 1)
        # 1 year
    if "2YR" in config_params.intf_type:
        intf_pairs = intf_pairs + rose_baseline_plot.compute_new_pairs(
            stems, times, baselines, config_params.annual_crit_days,
            config_params.annual_crit_baseline, 2)
        # 2 years
    if "3YR" in config_params.intf_type:
        intf_pairs = intf_pairs + rose_baseline_plot.compute_new_pairs(
            stems, times, baselines, config_params.annual_crit_days,
            config_params.annual_crit_baseline, 3)
        # 3 years
    if intf_pairs == []:
        print(
            "config_params.intf_type is probably not a valid intf_type [combinations of SBAS, CHAIN, 1YR, SBAS+CHAIN, etc.]"
        )
        sys.exit(1)
    intf_pairs = sentinel_utilities.reduce_by_start_end_time(
        intf_pairs, config_params.start_time, config_params.end_time)
    intf_all = list(set(intf_pairs))
    # removing duplicates.
    print("Finding %d unique interferograms. " % len(intf_all))

    # Make the stick plot of baselines
    sentinel_utilities.make_network_plot(
        intf_all, stems, times, baselines,
        "F" + str(config_params.swath) + "/Total_Network_Geometry.eps")
    return intf_all
def analyze_coherence_function():
    [corr_file, baseline_table, corr_dirlist, plotname] = correlation_config()

    # Correlation vs. Other Things.
    calc_write_corr_results(corr_dirlist, corr_file)
    # ONLY NEED TO DO AT THE BEGINNING
    [stem1, stem2, mean_corr] = sentinel_utilities.read_corr_results(corr_file)
    [stems_blt, tbaseline, xbaseline,
     mission_days] = sentinel_utilities.read_baseline_table(baseline_table)
    make_coh_vs_others_plots(stem1, stem2, mean_corr, stems_blt, xbaseline,
                             plotname)

    # # Histograms, in 12-panel figures, one small panel for each interferogram
    # [file_names]=configure_histograms();
    # [xdata,ydata,corr_all,date_pairs]=rwr.reader_simple_format(file_names);
    # stack_metrics_tools.all_gridded_histograms(corr_all,date_pairs);
    return
Example #5
0
def driver(ts_vector, datestrs, baseline_file):
    # A function to implement Fattahi and Amelung's 2013 paper
    # Right now, this assumes a linear velocity, although more complicated time histories can be implemented.
    # stems format: 'S1_20190105_ALL_F2'
    # times format: float years
    # xbaselines format: meters (first one 0 by definition)
    # datestrs format: '2015134'

    [_, times, baselines,
     _] = sentinel_utilities.read_baseline_table(baseline_file)
    dtarray = []
    for i in range(len(times)):
        dtarray.append(dt.datetime.strptime(str(int(times[i] + 1)), '%Y%j'))

    # Re-order times and baselines in chronological order
    baselines = [x for _, x in sorted(zip(dtarray, baselines))]
    dtarray = sorted(dtarray)

    # design matrix: phase(t) = v(t-t0) + other terms + .... (4pi/lamda B(ti)/rsin(theta) z_error)
    # Baseline history: Bdot(i) = B(t_i)-B(t_i-t_i-1) / (t_i-t_i-1), i=[1-N]
    # velocity history: v(i) = phi(t_i)-phi(t_i-1)  / (t_i-t_i-1), i=[1-N]
    # The model we're solving for is [velocity, (4pi/lamda z_error/rsin(theta))].
    # I call that constant K_z_error
    G = np.ones((len(datestrs) - 1, 2))
    v = np.zeros((len(datestrs) - 1))
    Bdot = np.zeros((len(datestrs) - 1))
    for i in range(0, len(datestrs) - 1):
        v[i] = (ts_vector[i + 1] - ts_vector[i]) / (dtarray[i + 1] -
                                                    dtarray[i]).days / 365.24
        Bdot[i] = (baselines[i + 1] -
                   baselines[i]) / (dtarray[i + 1] - dtarray[i]).days / 365.24
        G[i, 1] = Bdot[i]

    model = np.linalg.lstsq(G, v, rcond=0.001)
    # rcond helps the solution converge
    K_z_error = model[0][1]  # constant time z_error;

    topo_phase = [K_z_error * (x - baselines[0]) for x in baselines]

    corrected_ts_vector = np.subtract(ts_vector, topo_phase)
    return corrected_ts_vector
Example #6
0
def make_interferograms(config_params):
    """
    1. form interferogram pairs from baseline_table
    2. make network plot
    3. write README_proc.txt
    """
    if config_params.startstage > 4:  # if we're starting at sbas, we don't do this.
        return
    if config_params.endstage < 4:  # if we're ending at topo, we don't do this.
        return

    [stems, times, baselines, missiondays
     ] = sentinel_utilities.read_baseline_table('raw/baseline_table.dat')
    if config_params.ts_type == "SBAS" or config_params.ts_type == "NSBAS":
        intf_pairs_sbas = sentinel_utilities.get_small_baseline_subsets(
            stems, times, baselines, config_params.tbaseline,
            config_params.xbaseline, '', '')
        intf_pairs_manual = sentinel_utilities.get_manual_chain(
            stems, times, config_params.tbaseline, ['20151118'])
        intf_pairs = intf_pairs_sbas + intf_pairs_manual
        print("README_proc.txt will be printed with tbaseline_max = " +
              str(config_params.tbaseline) + " days and xbaseline_max = " +
              str(config_params.xbaseline) + "m. ")
    elif config_params.ts_type == "CHAIN":
        intf_pairs = sentinel_utilities.get_chain_subsets(
            stems, times, baselines, config_params.bypass)
    elif config_params.ts_type == "MANUAL":
        intf_pairs = sentinel_utilities.get_manual_chain(
            stems, times, config_params.tbaseline, ['20151118'])
    else:
        print("config_params.ts_type is not a valid ts_type")
        sys.exit(1)

    # intf_pairs is the list of interferogram pairs made from SBAS or NSBAS or manual or chain
    # Now we want to add the longer interferograms.
    crit_days = 30
    crit_baseline = 20
    # days, meters
    long_intfs = rose_baseline_plot.compute_new_pairs(stems, times, baselines,
                                                      crit_days, crit_baseline)
    intf_all = intf_pairs + long_intfs

    # Make the stick plot of baselines
    sentinel_utilities.make_network_plot(intf_all, stems, times, baselines,
                                         "Total_Network_Geometry.eps")

    # Write the intf.in files
    # Writing to process interferograms.
    outfile = open("README_proc.txt", 'w')
    outfile.write("#!/bin/bash\n")
    outfile.write(
        "# Script to batch process Sentinel-1 TOPS mode data sets.\n\n")
    outfile.write("# First, create the files needed for intf_tops.csh\n\n")
    outfile.write("rm intf*.in\n")
    for i, item in enumerate(intf_all):
        outfile.write('echo "' + item + '" >> intf_record.in\n')
    for i, item in enumerate(intf_all):
        outfile.write('echo "' + item + '" >> intf' +
                      str(np.mod(i, config_params.numproc)) + '.in\n')
    outfile.write("\n# Process the interferograms.\n\n")
    outfile.write("ls intf?.in | parallel --eta 'intf_batch_tops_mod.csh {} " +
                  config_params.config_file + "'\n\n\n")
    outfile.close()
    print("Ready to call README_proc.txt.")
    call("chmod +x README_proc.txt", shell=True)
    call("./README_proc.txt", shell=True)

    print("Summarizing correlation for all interferograms.")
    analyze_coherence.analyze_coherence_function()

    return
Example #7
0
def do_sbas(config_params, staging_directory):
    [stems, tbaseline, xbaseline, mission_days] = sentinel_utilities.read_baseline_table('raw/baseline_table.dat');
    t_int = [];
    for t in tbaseline:
        t_int.append(round(float(t)));  # a list of integers like 2016214 for 2016-day-214.

    mission_days_sorted = [x for (y, x) in sorted(zip(t_int, mission_days))];
    t_int.sort();
    tbaseline.sort();

    intf_computed = sentinel_utilities.glob_intf_computed();  # looks like a list of labels like 2016217_2016205
    n_intf = len(intf_computed);
    outfile = open("README_sbas.txt", 'w');
    outfile.write("# First, prepare the input files needed for sbas\n#\n");
    outfile.write("rm -f SBAS\nmkdir SBAS\ncd SBAS\n\n\n");
    outfile.write("# based on baseline_table.dat create the intf.tab and scene.tab for sbas\n");

    # writing intf.tab
    outfile.write("# phase  corherence  ref_id  rep_id  baseline\n")
    for img_pair in intf_computed:
        first_image = img_pair[0:7]
        second_image = img_pair[8:]
        for a, b in zip(xbaseline, t_int):
            if abs(int(np.floor(b)) - int(first_image)) <= 1:
                # print "first image found";
                # print int(np.floor(b))
                # print int(first_image)
                master_xbaseline = a;
            if abs(int(np.floor(b)) - int(second_image)) <= 1:
                slave_xbaseline = a;
                # print "second image found";
                # print int(np.floor(b))
                # print int(second_image)                
        total_baseline = slave_xbaseline - master_xbaseline;
        outfile.write('echo "../intf_all/' + img_pair + '/unwrap.grd ')
        outfile.write('../intf_all/' + img_pair + '/corr.grd ')
        outfile.write(first_image + ' ' + second_image + ' ')
        outfile.write(str(total_baseline))
        outfile.write('" >> intf.tab\n');
    outfile.write("#\n\n");

    # writing scene.tab (only the scenes that are actually used in SBAS processing)
    # Right now this isn't producing anything. 
    outfile.write("# scene_id  day\n");
    scenes_used = '';
    n_scenes = 0;
    scenes_used = [];
    for intf in intf_computed:
        scenes_used.append(intf[0:7]);  # catch which scenes are actually used in SBAS processing. 
        scenes_used.append(intf[8:15]);
    for x in range(len(tbaseline)):
        temp = tbaseline[x];
        tempint = int(np.round(temp))
        if str(tempint) in scenes_used or str(tempint + 1) in scenes_used or str(tempint - 1) in scenes_used:
            outfile.write('echo "' + str(tempint) + ' ' + mission_days_sorted[x] + '" >> scene.tab\n');
            n_scenes += 1;
    outfile.write("\n\n");

    intf_ex = intf_computed[0];  # an example interferogram where we get the geographic coordinates for grdinfo
    outfile.write("xdim=`gmt grdinfo -C ../intf_all/" + intf_ex + "/unwrap.grd | awk '{print $10}'`\n");
    outfile.write("ydim=`gmt grdinfo -C ../intf_all/" + intf_ex + "/unwrap.grd | awk '{print $11}'`\n\n\n");

    outfile.write("# run sbas\n");
    outfile.write("sbas intf.tab scene.tab " + str(n_intf) + " " + str(
        n_scenes) + " $xdim $ydim -smooth 1.0 -wavelength 0.0554658 -incidence 30 -range 800184.946186 -rms -dem\n\n\n")

    outfile.write("# project the velocity to Geocooridnates\n");
    outfile.write('echo "writing to georeferenced coordinates..."\n');
    outfile.write("ln -s ../topo/trans.dat .\n");
    outfile.write("proj_ra2ll.csh trans.dat vel.grd vel_ll.grd\n");
    outfile.write("gmt grd2cpt vel_ll.grd -T= -Z -Cjet > vel_ll.cpt\n");
    outfile.write("grd2kml.csh vel_ll vel_ll.cpt\n");
    outfile.write("cd ..\n\n");
    outfile.write('echo "SBAS operation performed!"\n\n')

    outfile.close();
    print("README_sbas.txt written. Ready to call README_sbas.txt.")
    call("chmod u+x README_sbas.txt", shell=True);
    call("./README_sbas.txt", shell=True);  # Make sbas!
    return;