예제 #1
0
def save_rate(outdir, xvec, yvec, rate, grdnaming):
    os.makedirs(outdir, exist_ok=True)
    grd_io.write_grd(xvec,
                     yvec,
                     rate,
                     '%s/rate_mm_yr.grd' % outdir,
                     naming=grdnaming)
예제 #2
0
def save_ts(outdir, xvec, yvec, dates, ts, grdnaming):
    os.makedirs(outdir, exist_ok=True)
    for i in range(len(dates)):
        grd_io.write_grd(xvec,
                         yvec,
                         ts[i],
                         '%s/ts_mm_%04d.grd' % (outdir, dates[i]),
                         naming=grdnaming)
예제 #3
0
def check_ts(ts, data, igram_ids, xvec, yvec, unw_check_threshold, grdnaming):
    #predict each interferogram from the timeseries, and compare it to the actual
    os.makedirs('ts_check', exist_ok=True)
    for i, pair in enumerate(igram_ids):
        synth_igram = ts[pair[1], :, :] - ts[pair[0], :, :]
        resid = synth_igram - data[i, :, :]
        grd_io.write_grd(xvec,
                         yvec,
                         resid,
                         'ts_check/resid_%d.grd' % i,
                         naming=grdnaming)
        #mask any data that exceed the threshold
        mask = ~np.isnan(resid)
        mask[mask] = np.abs(resid[mask]) > unw_check_threshold
        #print(i)
        #print('non-nan before masking: %d'%np.count_nonzero(~np.isnan(data[i])))
        data[i, mask] = np.nan
        #print('non-nan after masking:  %d'%np.count_nonzero(~np.isnan(data[i])))

    return data
예제 #4
0
def check_data(xvec, yvec, data, nt, igram_ids, unw_check_threshold,
               grdnaming):
    # function to check all loops and identify pixels where the loop value is close to zero. Mark these pixels as valid for each igram in the triplet
    # create a NaN matrix the same size as data (a 3D matrix containing all of the interferograms)
    validdata = np.zeros(np.shape(data))

    # output directory
    os.makedirs('unw_check', exist_ok=True)
    #iterate over loop list
    for loop in itertools.combinations(range(nt), 3):
        #get interferogram IDs for each loop
        try:
            i0 = igram_ids.index((loop[0], loop[1]))
            i1 = igram_ids.index((loop[1], loop[2]))
            i2 = igram_ids.index((loop[0], loop[2]))
        except ValueError:
            #one of the interferograms does not exist, skip this loop
            continue
        #compute the loop residual
        cycle = data[i0, :, :] + data[i1, :, :] - data[i2, :, :]
        #get zero if the pixel has a large residual, otherwise 1

        #cyclevalid checks if the values are less than the threshold. Any NaN values in the loop will just result in zero vote
        mask = ~np.isnan(cycle)
        mask[mask] = np.abs(cycle[mask]) < unw_check_threshold
        cyclevalid = 1 * mask
        #note, testing 'less than' on NaN throws a RuntimeWarning, but still gives the correct answer:
        #cyclevalid=1*(np.abs(cycle)<threshold)

        #validdata tracks the number of total 'votes' for a good pixel for each interferogram.
        validdata[i0, :, :] += cyclevalid
        validdata[i1, :, :] += cyclevalid
        validdata[i2, :, :] += cyclevalid

        loopname = '%d_%d_%d' % (loop[0], loop[1], loop[2])
        grd_io.write_grd(xvec,
                         yvec,
                         cycle,
                         'unw_check/loop_%s.grd' % loopname,
                         naming=grdnaming)
        grd_io.write_grd(xvec,
                         yvec,
                         cyclevalid,
                         'unw_check/cyclevalid_%s.grd' % loopname,
                         naming=grdnaming)

    # mask pixels with too few votes.
    # note, it's possible for a bad pixel to still get 1 vote, if there is an opposing unwrapping error in another ifg.
    minvalid = 2
    data[validdata < minvalid] = np.nan

    # TODO: get the interferogram directory and write out valid / invalid / (number of votes)

    for i in range(len(validdata)):
        grd_io.write_grd(xvec,
                         yvec,
                         validdata[i, :, :],
                         'unw_check/valid_%d.grd' % i,
                         naming=grdnaming)

    return data
예제 #5
0
    args = parser.parse_args()

    xvec, yvec, insardat = grd_io.read_grd(args.insarfile)
    print('read %s, dimensions (%d,%d)' %
          (args.insarfile, len(xvec), len(yvec)))

    X, Y = np.meshgrid(xvec, yvec)
    gpsdat = np.loadtxt(args.gpsfile)
    print('read %s, length %d' % (args.gpsfile, len(gpsdat)))

    G, d = detrend_ts.construct_gpsconstraint(0, insardat, gpsdat, X, Y)

    #select the specified number of trend parameters
    G = G[:, 0:3]

    #invert for a trend that matches the value around given GPS points
    m = np.dot(np.linalg.pinv(G), d)
    print(m)
    #reconstruct the model - a bit ugly here dealing with unknown number of trendparams
    onemat = np.ones(np.shape(X))
    model = detrend_ts.reconstruct_model_nparams(3, m, X, Y, onemat)

    insar_detrend = insardat - model

    grdnaming = grd_io.read_naming(args.insarfile)
    outfile = '%s_fitgps.grd' % os.path.splitext(args.insarfile)[0]

    print('writing %s' % outfile)

    grd_io.write_grd(xvec, yvec, insar_detrend, outfile, naming=grdnaming)
예제 #6
0
        #convert to NetCDF-3 file type
        subprocess.call('nccopy -k classic %s temp_nc3.grd' % args.infile,
                        shell=True)
        datfile = 'temp_nc3.grd'
    else:
        datfile = args.infile

    if args.lonlat:
        grdnaming = 'lonlat'
    else:
        grdnaming = 'xy'

    #read input file
    x, y, z = grd_io.read_grd(datfile, naming=grdnaming)

    if args.ncconvert:
        #remove temporary NetCDF-3 file
        os.remove('temp_nc3.grd')

    #do nearest neighbor interpolation
    interpdata = nneigh_interp(x, y, z)

    #write output file
    grd_io.write_grd(x, y, interpdata, args.outfile, naming=grdnaming)

    if args.plots:
        import matplotlib.pyplot as plt
        plot_grid(z, 'input data')
        plot_grid(interpdata, 'interpolated data')
        plt.show()