예제 #1
0
def mogi_deformation(shape,
                     source_geom,
                     resolution=60.,
                     scale=1.,
                     display=True):
    """Simulate 2D deformation caused by the overpress of a Mogi source underneath
    
    Parameters: shape: 2-tuple of int in (length, width) or 2D np.ndarray in size of (length, width) in np.bool_
                source_geom : 4-tuple of float, Mogi source geometry: East, North, Depth, Volomn change in SI unit.
    
    """
    if isinstance(shape, np.ndarray):
        mask = np.multiply(np.array(shape != 0), ~np.isnan(shape))
        shape = mask.shape
    else:
        mask = np.ones(shape, np.bool_)

    length, width = shape
    yy, xx = np.mgrid[0:length:length * 1j, 0:width:width * 1j]
    yy *= resolution
    xx *= resolution
    xloc = np.vstack((xx.reshape(1, -1), yy.reshape(1, -1)))

    dis_map = mogi(source_geom, xloc)[0]
    dis_e = dis_map[0, :].reshape(length, width)
    dis_n = dis_map[1, :].reshape(length, width)
    dis_u = dis_map[2, :].reshape(length, width)
    dis_los = ut.enu2los(dis_e, dis_n, dis_u)

    dis_los[mask == 0.] = np.nan
    dis_los *= scale

    if display:
        fig, ax = plt.subplots(1, 4, figsize=[10, 3], sharey=True)
        dmin = np.nanmin(dis_los)
        dmax = np.nanmax(dis_los)
        for i, fig_title in enumerate(['east', 'north', 'vertical']):
            ax[i].imshow(dis_map[i, :].reshape(length, width),
                         vmin=dmin,
                         vmax=dmax)
            ax[i].set_title(fig_title)
        im = ax[3].imshow(dis_los, vmin=dmin, vmax=dmax)
        ax[3].set_title('los - SenD')
        fig.subplots_adjust(right=0.90)
        cax = fig.add_axes([0.92, 0.25, 0.01, 0.5])
        cbar = fig.colorbar(im, cax=cax)
        cbar.set_label('Displacement [m]')
        plt.show()

    return dis_los
예제 #2
0
def cgps_process(gpsname, geometry):
    """process single gps site"""
    gps_obj = CGPS(site=gpsname)
    gps_obj.open()
    if not geometry:
        vel_los = ut.enu2los(gps_obj.vel_e, gps_obj.vel_n, gps_obj.vel_u)
        los_vel = vel_los
    else:
        gps_obj.read_gps_los_velocity(geometry)
        los_vel = gps_obj.vel_los

    site_inve = np.array([[
        gps_obj.site, gps_obj.site_lat, gps_obj.site_lon, los_vel,
        gps_obj.vel_n, gps_obj.vel_e
    ]])

    return site_inve
예제 #3
0
def mogi_deformation(shape, source_geom, resolution=60., scale=1., display=True):
    """Simulate 2D deformation caused by the overpress of a Mogi source underneath
    
    Parameters: shape: 2-tuple of int in (length, width) or 2D np.ndarray in size of (length, width) in np.bool_
                source_geom : 4-tuple of float, Mogi source geometry: East, North, Depth, Volomn change in SI unit.
    
    """
    if isinstance(shape, np.ndarray):
        mask = np.multiply(np.array(shape != 0), ~np.isnan(shape))
        shape = mask.shape
    else:
        mask = np.ones(shape, np.bool_)

    length, width = shape
    yy, xx = np.mgrid[0:length:length*1j, 0:width:width*1j]
    yy *= resolution
    xx *= resolution
    xloc = np.vstack((xx.reshape(1, -1), yy.reshape(1, -1)))

    dis_map = mogi(source_geom, xloc)[0]
    dis_e = dis_map[0, :].reshape(length, width)
    dis_n = dis_map[1, :].reshape(length, width)
    dis_u = dis_map[2, :].reshape(length, width)
    dis_los = ut.enu2los(dis_e, dis_n, dis_u)

    dis_los[mask == 0.] = np.nan
    dis_los *= scale

    if display:
        fig, ax = plt.subplots(1, 4, figsize=[10, 3], sharey=True)
        dmin = np.nanmin(dis_los)
        dmax = np.nanmax(dis_los)
        for i, fig_title in enumerate(['east','north','vertical']):
            ax[i].imshow(dis_map[i, :].reshape(length, width), vmin=dmin, vmax=dmax)
            ax[i].set_title(fig_title)
        im = ax[3].imshow(dis_los, vmin=dmin, vmax=dmax)
        ax[3].set_title('los - SenD')
        fig.subplots_adjust(right=0.90)
        cax = fig.add_axes([0.92, 0.25, 0.01, 0.5])
        cbar = fig.colorbar(im, cax=cax)
        cbar.set_label('Displacement [m]')
        plt.show()

    return dis_los
예제 #4
0
def ngps_process(gpsname, geometry, gps_dir):
    """process ngps sites"""
    gps_obj = GPS(site=gpsname, data_dir=gps_dir)
    print('process {} site'.format(gpsname))
    gps_obj.open()
    if not geometry:
        dis_los = ut.enu2los(gps_obj.dis_e, gps_obj.dis_n, gps_obj.dis_u)
        dates = gps_obj.dates
        los_vel = dis_velocity(dates, dis_los)
    else:
        dates, dis_los = gps_obj.read_gps_los_displacement(geometry)
        gps_obj.get_gps_los_velocity(geometry)
        los_vel = gps_obj.velocity

    e_vel = dis_velocity(dates, gps_obj.dis_e)
    n_vel = dis_velocity(dates, gps_obj.dis_n)

    site_inve = np.array([[
        gps_obj.site, gps_obj.site_lat, gps_obj.site_lon, los_vel, n_vel, e_vel
    ]])

    return site_inve
예제 #5
0
def main(iargs=None):

    inps = cmd_line_parse(iargs)
    print('-' * 50)
    print(os.path.abspath(__file__))

    ## Setup
    # LOS incidence / azimuth angles
    los_inc_angle = np.array([30, 30], dtype=np.float32)
    los_az_angle = np.array([102, -102], dtype=np.float32)

    # specify horz / vert [truth]
    length, width = 5, 5
    simH = np.ones((length, width), dtype=np.float32) * 0.5
    simV = np.ones((length, width), dtype=np.float32) * 1.0
    # azimuth angle in horizontal direction in degrees
    # measured from the north with anti-clockwise as positive
    # [0 for north, -90 for east]
    horz_az_angle = 30

    ## Testing
    # horz / vert --> east / north / up
    dE = simH * np.sin(np.deg2rad(horz_az_angle)) * -1
    dN = simH * np.cos(np.deg2rad(horz_az_angle))
    dU = simV

    # east / north / up --> asc / desc LOS
    dlos0 = ut.enu2los(dE,
                       dN,
                       dU,
                       inc_angle=los_inc_angle[0],
                       az_angle=los_az_angle[0])
    dlos1 = ut.enu2los(dE,
                       dN,
                       dU,
                       inc_angle=los_inc_angle[1],
                       az_angle=los_az_angle[1])

    # asc / desc LOS --> horz / vert [estimation]
    dlos = np.vstack((dlos0.reshape(1, length,
                                    width), dlos1.reshape(1, length, width)))
    estH, estV = asc_desc2horz_vert(dlos, los_inc_angle, los_az_angle,
                                    horz_az_angle)

    # check difference between the trush and estimation
    print(
        f'mean difference for horz / vert: {np.nanmean(estH - simH)} / {np.nanmean(estH - simH)}'
    )
    assert np.allclose(simH, estH)
    assert np.allclose(simV, estV)

    # Plotting
    if inps.plot:
        print('plot test result of {}'.format(os.path.basename(__file__)))
        fig, axs = plt.subplots(nrows=3,
                                ncols=4,
                                figsize=[8, 6],
                                sharex=True,
                                sharey=True)
        kwargs = dict(vmin=-1.5,
                      vmax=1.5,
                      cmap='RdBu',
                      interpolation='nearest')

        # horz / vert [truth]
        ax = axs[0, 0]
        im = ax.imshow(simH, **kwargs)
        ax.set_title('Horz [sim]')
        ax = axs[1, 0]
        im = ax.imshow(simV, **kwargs)
        ax.set_title('Vert [sim]')
        ax = axs[2, 0]
        ax.axis('off')
        # east / north / up
        ax = axs[0, 1]
        im = ax.imshow(dE, **kwargs)
        ax.set_title('East [sim]')
        ax = axs[1, 1]
        im = ax.imshow(dN, **kwargs)
        ax.set_title('North [sim]')
        ax = axs[2, 1]
        im = ax.imshow(dU, **kwargs)
        ax.set_title('Up [sim]')
        # asc / desc
        ax = axs[0, 2]
        im = ax.imshow(dlos0, **kwargs)
        ax.set_title('Asc [obs]')
        ax = axs[1, 2]
        im = ax.imshow(dlos1, **kwargs)
        ax.set_title('Desc [obs]')
        ax = axs[2, 2]
        ax.axis('off')
        # horz / vert [estimation]
        ax = axs[0, 3]
        im = ax.imshow(estH, **kwargs)
        ax.set_title('Horz [est]')
        ax = axs[1, 3]
        im = ax.imshow(estV, **kwargs)
        ax.set_title('Vert [est]')
        ax = axs[2, 3]
        ax.axis('off')

        # axis format
        fig.tight_layout()
        # colorbar
        cax = fig.add_axes([0.6, 0.2, 0.3, 0.02])
        fig.colorbar(im, cax=cax, orientation='horizontal')
        plt.show()