Esempio n. 1
0
def radar_coord_int(demminmax, i12s, cohs, h2phs, ref=None, multilook=1, samples=1000, stepsize=None, study_area=None):
    """radar_coord_dem(dem, i12s, cohs, dem_std=10, ref=None):
    demminmax=vector: minimum and maximum values for dem.
    i12s: [K,M,N]
    cohs: [K,M,N]
    h2phs: [K,M,N]
    dem_std: scalar or [M,N]
    ref: None or tuple (m,n)
    multilook: level of SAR multilooking
    samples=1000, number of samples for search domain
    stepsize= height sensitivity to use instead of samples to constract search space.
    study_area= [m0, mM, n0, nN] 
    """
    i12s=i12s*tile( conj(i12s[:,ref[0],ref[1]]), (i12s.shape[2], i12s.shape[1], 1) ).T   #zero reference
    if study_area is not None:
        i12s = i12s[:, study_area[0]:study_area[1], study_area[2]:study_area[3]]
        cohs = cohs[:, study_area[0]:study_area[1], study_area[2]:study_area[3]]
        h2phs=h2phs[:, study_area[0]:study_area[1], study_area[2]:study_area[3]]
    M=i12s.shape[1];
    N=i12s.shape[2];
    z=zeros([M,N]); #initialize output
        
    t=0;
    for m in xrange(M):
        for n in xrange(N):
            z[m,n]=point_solve_int(demminmax, i12s[:,m,n], cohs[:,m,n], h2phs[:,m,n], multilook, samples=samples, stepsize=stepsize);
        if basic.progresstime(t0=t,timeSpan=30):
            t=basic.time.time()
            basic.progress(p=m,t=M,f="%.3f ")        
    return z    
Esempio n. 2
0
def data_from_image(im, classes, mask, limits=[0., 1.]):
    """ This function extracts the data from a image, based on the classes and a mask. 
      Once the data is masked, a look-up-table is used to set values to the classes. 
  """
    import time
    N = int(basic.nonan(classes).max() + 1)
    # zero is a class...
    classes[mask] = np.nan
    classLimits = np.linspace(np.min(limits), np.max(limits), N)

    cmax = 2**np.round(np.log2(im.max()))
    imSingle = im[:, :, 0] * (cmax**0) + im[:, :, 1] * (
        cmax**1) + im[:, :, 2] * (cmax**2.)
    data = np.zeros(imSingle.shape)
    t0 = 0
    for k in xrange(N - 1):
        #for each class do a linear interpolation
        if np.any(classes == k):
            data[classes == k] = basic.rescale(imSingle[classes == k],
                                               classLimits[k:k + 2],
                                               quiet=True)
        if basic.progresstime(t0):
            basic.progress(k, N)
            t0 = time.time()
    data[mask] = np.nan
    return data
Esempio n. 3
0
def radar_coord_int(demminmax,
                    i12s,
                    cohs,
                    h2phs,
                    ref=None,
                    multilook=1,
                    samples=1000,
                    stepsize=None,
                    study_area=None):
    """radar_coord_dem(dem, i12s, cohs, dem_std=10, ref=None):
    demminmax=vector: minimum and maximum values for dem.
    i12s: [K,M,N]
    cohs: [K,M,N]
    h2phs: [K,M,N]
    dem_std: scalar or [M,N]
    ref: None or tuple (m,n)
    multilook: level of SAR multilooking
    samples=1000, number of samples for search domain
    stepsize= height sensitivity to use instead of samples to constract search space.
    study_area= [m0, mM, n0, nN] 
    """
    i12s = i12s * tile(conj(i12s[:, ref[0], ref[1]]),
                       (i12s.shape[2], i12s.shape[1], 1)).T  #zero reference
    if study_area is not None:
        i12s = i12s[:, study_area[0]:study_area[1],
                    study_area[2]:study_area[3]]
        cohs = cohs[:, study_area[0]:study_area[1],
                    study_area[2]:study_area[3]]
        h2phs = h2phs[:, study_area[0]:study_area[1],
                      study_area[2]:study_area[3]]
    M = i12s.shape[1]
    N = i12s.shape[2]
    z = zeros([M, N])
    #initialize output

    t = 0
    for m in xrange(M):
        for n in xrange(N):
            z[m, n] = point_solve_int(demminmax,
                                      i12s[:, m, n],
                                      cohs[:, m, n],
                                      h2phs[:, m, n],
                                      multilook,
                                      samples=samples,
                                      stepsize=stepsize)
        if basic.progresstime(t0=t, timeSpan=30):
            t = basic.time.time()
            basic.progress(p=m, t=M, f="%.3f ")
    return z
Esempio n. 4
0
def radar_coord_dem(dem, i12s, cohs, h2phs, dem_std=10, ref=None, multilook=1, samples=1000, stepsize=None, study_area=None):
    """radar_coord_dem(dem, i12s, cohs, dem_std=10, ref=None):
    dem:  [M,N]
    i12s: [K,M,N]
    cohs: [K,M,N]
    h2phs: [K,M,N]
    dem_std: scalar or [M,N]
    ref: None or tuple (m,n)
    multilook: level of SAR multilooking
    samples=1000, number of samples for search domain
    stepsize= height sensitivity to use instead of samples to constract search space.
    study_area= [m0, mM, n0, nN] 
    """
    z_ref=dem[ref[0],ref[1]];
    dem=dem-z_ref;  #zero reference
    i12s=i12s*tile( conj(i12s[:,ref[0],ref[1]]), (i12s.shape[2], i12s.shape[1], 1) ).T   #zero reference
    if study_area is not None:
        dem  = dem [study_area[0]:study_area[1], study_area[2]:study_area[3]]
        i12s = i12s[:, study_area[0]:study_area[1], study_area[2]:study_area[3]]
        cohs = cohs[:, study_area[0]:study_area[1], study_area[2]:study_area[3]]
        h2phs=h2phs[:, study_area[0]:study_area[1], study_area[2]:study_area[3]]
        if size(dem_std) != 1:
            dem_std=dem_std[study_area[0]:study_area[1], study_area[2]:study_area[3]]
    M,N=dem.shape
    z=zeros(dem.shape); #initialize output
    if size(dem_std) == 1:
        #scalar dem_std convert to array
        dem_std=ones(dem.shape)*dem_std
    elif size(dem_std) != size(dem):
        #dem and dem_std has to be the same size
        print 'DEM_STD has to be a scalar or the same size as DEM.'
        return -1
        
    t=0;
    for m in xrange(M):
        for n in xrange(N):
            z[m,n]=point_solve_dem(dem[m,n], i12s[:,m,n], cohs[:,m,n], h2phs[:,m,n], dem_std[m,n], multilook, samples=samples, stepsize=stepsize);
        if basic.progresstime(t0=t,timeSpan=30):
            t=basic.time.time()
            basic.progress(p=m,t=M,f="%.3f ")        
    z=z+z_ref
    return z
Esempio n. 5
0
def distance_from_colorbar(im, c=P.cm.jet(np.arange(256))):
    """ This function calculates a distance value for all pixels of an image given a colorbar. 
      It also returns the best fitting colorbar class for each pixel.
  e.g.: 
    import cv2
    im=cv2.cvtColor(cv2.imread('REsults_zonaSur_cut.tiff'), cv2.COLOR_BGR2RGB);
    dist, classes=distance_from_colorbar(im);
  """
    import time
    N = c.shape[0]
    cmax = 2**np.round(np.log2(im.max()))
    if c.max() != cmax:
        c256 = c * cmax / c.max()
        #colorbar in uint8
    else:
        c256 = c

    dist = np.ones((im.shape[0], im.shape[1])) * np.inf
    distOld = dist.copy()
    classes = np.zeros((im.shape[0], im.shape[1]))
    ccc = 0
    #current class counter
    t0 = 0
    #time.time(); #show 0.0 at the beginning of the loop.
    for k in c256:
        dist = np.dstack([
            dist,
            np.sqrt((im[:, :, 0] - k[0])**2. + (im[:, :, 1] - k[1])**2. +
                    (im[:, :, 2] - k[2])**2.)
        ]).min(2)
        classes[dist != distOld] = ccc
        ccc = ccc + 1
        distOld = dist
        if basic.progresstime(t0):
            basic.progress(ccc, N)
            t0 = time.time()
    return dist, classes
Esempio n. 6
0
def radar_coord_dem(dem,
                    i12s,
                    cohs,
                    h2phs,
                    dem_std=10,
                    ref=None,
                    multilook=1,
                    samples=1000,
                    stepsize=None,
                    study_area=None):
    """radar_coord_dem(dem, i12s, cohs, dem_std=10, ref=None):
    dem:  [M,N]
    i12s: [K,M,N]
    cohs: [K,M,N]
    h2phs: [K,M,N]
    dem_std: scalar or [M,N]
    ref: None or tuple (m,n)
    multilook: level of SAR multilooking
    samples=1000, number of samples for search domain
    stepsize= height sensitivity to use instead of samples to constract search space.
    study_area= [m0, mM, n0, nN] 
    """
    z_ref = dem[ref[0], ref[1]]
    dem = dem - z_ref
    #zero reference
    i12s = i12s * tile(conj(i12s[:, ref[0], ref[1]]),
                       (i12s.shape[2], i12s.shape[1], 1)).T  #zero reference
    if study_area is not None:
        dem = dem[study_area[0]:study_area[1], study_area[2]:study_area[3]]
        i12s = i12s[:, study_area[0]:study_area[1],
                    study_area[2]:study_area[3]]
        cohs = cohs[:, study_area[0]:study_area[1],
                    study_area[2]:study_area[3]]
        h2phs = h2phs[:, study_area[0]:study_area[1],
                      study_area[2]:study_area[3]]
        if size(dem_std) != 1:
            dem_std = dem_std[study_area[0]:study_area[1],
                              study_area[2]:study_area[3]]
    M, N = dem.shape
    z = zeros(dem.shape)
    #initialize output
    if size(dem_std) == 1:
        #scalar dem_std convert to array
        dem_std = ones(dem.shape) * dem_std
    elif size(dem_std) != size(dem):
        #dem and dem_std has to be the same size
        print 'DEM_STD has to be a scalar or the same size as DEM.'
        return -1

    t = 0
    for m in xrange(M):
        for n in xrange(N):
            z[m, n] = point_solve_dem(dem[m, n],
                                      i12s[:, m, n],
                                      cohs[:, m, n],
                                      h2phs[:, m, n],
                                      dem_std[m, n],
                                      multilook,
                                      samples=samples,
                                      stepsize=stepsize)
        if basic.progresstime(t0=t, timeSpan=30):
            t = basic.time.time()
            basic.progress(p=m, t=M, f="%.3f ")
    z = z + z_ref
    return z
allDates = master + slave  #merge master and slave lists
allDates = sort(list(set(allDates)))
I = len(allDates)
#Number of images (dates)
N = len(ifiles)  #Number of interferograms
## the individual ramps are solved in a network fashion such that:
## A x = b where
## Design matrix
## A= SBAS design matrix [1 0 0 0... 0 -1 0 ...]
## x= ramp estimated for each date
## b= ramp estimated for each inteferogram
tk = 0
A = zeros([N + 1, I])
for k in xrange(N):
    A[k, :] = (allDates == master[k]) * -1 + (allDates == slave[k]) * 1
    if basic.progresstime(tk):
        basic.progress(
            k,
            N,
        )
        tk = basic.time.time()
A[-1, 0] = 1
pinvA = linalg.pinv(A)
x0 = dot(pinvA, list(ramps[0, :]) + [0])  #merge zero to the end of list
x1 = dot(pinvA, list(ramps[1, :]) + [0])  #merge zero to the end of list

#deramp
print "Deramping interferograms..."
## Calculate Ax
r0 = dot(A, x0)
r1 = dot(A, x1)