Example #1
0
    def test_array_transff_wavenumber(self):
        coords = np.array([[10., 60., 0.],
                           [200., 50., 0.],
                           [-120., 170., 0.],
                           [-100., -150., 0.],
                           [30., -220., 0.]])

        coords /= 1000.

        coordsll = np.zeros(coords.shape)
        for i in np.arange(len(coords)):
            coordsll[i, 0], coordsll[i, 1] = util_lon_lat(0., 0., coords[i, 0],
                                                          coords[i, 1])

        klim = 40.
        kstep = klim / 2.

        transff = array_transff_wavenumber(coords, klim, kstep, coordsys='xy')
        transffll = array_transff_wavenumber(coordsll, klim, kstep,
                                             coordsys='lonlat')

        transffth = np.array(
            [[3.13360360e-01, 4.23775796e-02, 6.73650243e-01,
              4.80470652e-01, 8.16891615e-04],
             [2.98941684e-01, 2.47377842e-01, 9.96352135e-02,
              6.84732871e-02, 5.57078203e-01],
             [1.26523678e-01, 2.91010683e-01, 1.00000000e+00,
              2.91010683e-01, 1.26523678e-01],
             [5.57078203e-01, 6.84732871e-02, 9.96352135e-02,
              2.47377842e-01, 2.98941684e-01],
             [8.16891615e-04, 4.80470652e-01, 6.73650243e-01,
              4.23775796e-02, 3.13360360e-01]])

        np.testing.assert_array_almost_equal(transff, transffth, decimal=6)
        np.testing.assert_array_almost_equal(transffll, transffth, decimal=6)
Example #2
0
def _colormap_plot_array_response(cmaps):
    """
    Plot for illustrating colormaps: array response.

    :param cmaps: list of :class:`~matplotlib.colors.Colormap`
    :rtype: None
    """
    import matplotlib.pyplot as plt
    from obspy.signal.array_analysis import array_transff_wavenumber
    # generate array coordinates
    coords = np.array([[10., 60., 0.], [200., 50., 0.], [-120., 170., 0.],
                       [-100., -150., 0.], [30., -220., 0.]])
    # coordinates in km
    coords /= 1000.
    # set limits for wavenumber differences to analyze
    klim = 40.
    kxmin = -klim
    kxmax = klim
    kymin = -klim
    kymax = klim
    kstep = klim / 100.
    # compute transfer function as a function of wavenumber difference
    transff = array_transff_wavenumber(coords, klim, kstep, coordsys='xy')
    # plot
    for cmap in cmaps:
        plt.figure()
        plt.pcolor(np.arange(kxmin, kxmax + kstep * 1.1, kstep) - kstep / 2.,
                   np.arange(kymin, kymax + kstep * 1.1, kstep) - kstep / 2.,
                   transff.T, cmap=cmap)
        plt.colorbar()
        plt.clim(vmin=0., vmax=1.)
        plt.xlim(kxmin, kxmax)
        plt.ylim(kymin, kymax)
    plt.show()
Example #3
0
def plotARF_k(coords, klim, kstep, coordsys='xy'):
    transff = array_transff_wavenumber(coords, klim, kstep, coordsys=coordsys)
    xgrid = np.arange(-klim, klim+kstep, kstep)
    cmap = cm.RdYlBu
    fig = plt.figure(figsize=(8, 8))
    cax = fig.add_axes([0.85, 0.2, 0.05, 0.5])
    ax = fig.add_axes([0.10, 0.1, 0.70, 0.7])
    ax.pcolormesh(xgrid, xgrid, transff, vmin=0., vmax=1.0, cmap=cmap)
    ax.grid()
    ax.set_xlabel('kx (1/km)')
    ax.set_ylabel('ky (1/km)')
    fig.suptitle('Array response function')
    ColorbarBase(cax, cmap=cmap, norm=Normalize(vmin=0., vmax=1.0))
    plt.show()
Example #4
0
def plotARF_k(coords, klim, kstep, coordsys='xy'):
    transff = array_transff_wavenumber(coords, klim, kstep, coordsys=coordsys)
    xgrid = np.arange(-klim, klim + kstep, kstep)
    cmap = cm.RdYlBu
    fig = plt.figure(figsize=(8, 8))
    cax = fig.add_axes([0.85, 0.2, 0.05, 0.5])
    ax = fig.add_axes([0.10, 0.1, 0.70, 0.7])
    ax.pcolormesh(xgrid, xgrid, transff, vmin=0., vmax=1.0, cmap=cmap)
    ax.grid()
    ax.set_xlabel('kx (1/km)')
    ax.set_ylabel('ky (1/km)')
    fig.suptitle('Array response function')
    ColorbarBase(cax, cmap=cmap, norm=Normalize(vmin=0., vmax=1.0))
    plt.show()
# generate array coordinates
coords = np.array([[10., 60., 0.], [200., 50., 0.], [-120., 170., 0.],
                   [-100., -150., 0.], [30., -220., 0.]])

# coordinates in km
coords /= 1000.

# set limits for wavenumber differences to analyze
klim = 40.
kxmin = -klim
kxmax = klim
kymin = -klim
kymax = klim
kstep = klim / 100.

# compute transfer function as a function of wavenumber difference
transff = array_transff_wavenumber(coords, klim, kstep, coordsys='xy')

# plot
plt.pcolor(np.arange(kxmin, kxmax + kstep * 1.1, kstep) - kstep / 2.,
           np.arange(kymin, kymax + kstep * 1.1, kstep) - kstep / 2.,
           transff.T,
           cmap=obspy_sequential)

plt.colorbar()
plt.clim(vmin=0., vmax=1.)
plt.xlim(kxmin, kxmax)
plt.ylim(kymin, kymax)
plt.show()

# generate array coordinates
coords = np.array([[10., 60., 0.], [200., 50., 0.], [-120., 170., 0.],
                   [-100., -150., 0.], [30., -220., 0.]])

# coordinates in km
coords /= 1000.

# set limits for wavenumber differences to analyze
klim = 40.
kxmin = -klim
kxmax = klim
kymin = -klim
kymax = klim
kstep = klim / 100.

# compute transfer function as a function of wavenumber difference
transff = array_transff_wavenumber(coords, klim, kstep, coordsys='xy')

# plot
plt.pcolor(np.arange(kxmin, kxmax + kstep * 1.1, kstep) - kstep / 2.,
           np.arange(kymin, kymax + kstep * 1.1, kstep) - kstep / 2.,
           transff.T, cmap=obspy_sequential)

plt.colorbar()
plt.clim(vmin=0., vmax=1.)
plt.xlim(kxmin, kxmax)
plt.ylim(kymin, kymax)
plt.show()
Example #7
0
# coordinates in km
#coords /= 1000.

# set limits for wavenumber differences to analyze
klim = 30.
kxmin = -klim
kxmax = klim
kymin = -klim
kymax = klim
kstep = klim / 200.

# compute transfer function as a function of wavenumber difference

# transfer function is in units of power - so convert to dB using 10*log(10)
transff = 10*np.log10(array_transff_wavenumber(coords, klim, kstep, coordsys='lonlat'))

# plot

dKX =  np.arange(kxmin, kxmax + kstep , kstep) 
dKY =  np.arange(kymin, kymax + kstep , kstep) 

X_Grid, Y_Grid = np.meshgrid(dKX, dKY)

if debug:
    print(np.shape(dKX), np.shape(transff))

plt.pcolor(dKX, dKY, transff.T, cmap=obspy_sequential)   
plt.tick_params(length=6, width=3, labelsize=12)     

cbar = plt.colorbar()