Exemple #1
0
def make_impulse_data(n=1024, dt=0.05, t0=-5.0):
    # Compute lag for spike at time=0
    lag0 = int(-t0 / dt)
    z = make_impulse_vector([lag0], [150.0], n)
    rf_lags = (lag0, lag0 + 50, lag0 + 60, lag0 + 150, lag0 + 180)
    amps1 = (10.0, 20.0, -60.0, -3.0, 2.0)
    amps2 = (-15.0, 30.0, 10.0, -20.0, 15.0)
    ns = make_impulse_vector(rf_lags, amps1, n)
    ew = make_impulse_vector(rf_lags, amps2, n)
    d = Seismogram(n)
    d.set_t0(t0)
    d.set_dt(dt)
    d.set_live()
    d.tref = TimeReferenceType.Relative
    for i in range(n):
        d.data[0, i] = ew[i]
        d.data[1, i] = ns[i]
        d.data[2, i] = z[i]
    return d
Exemple #2
0
def get_live_seismogram(ts_size=255, sampling_rate=20.0):
    seis = Seismogram()
    seis.set_live()
    seis.set_as_origin("test", "0", "0", AtomicType.SEISMOGRAM)
    seis.dt = 1 / sampling_rate
    seis.npts = ts_size
    # seis.put('net', 'IU')
    seis.put("npts", ts_size)
    seis.put("sampling_rate", sampling_rate)
    seis.tref = TimeReferenceType.UTC
    seis.t0 = 0
    seis["delta"] = 0.1
    seis["calib"] = 0.1
    seis["site_id"] = bson.objectid.ObjectId()
    seis["source_id"] = bson.objectid.ObjectId()
    seis.data = dmatrix(3, ts_size)
    for i in range(3):
        for j in range(ts_size):
            seis.data[i, j] = np.random.rand()
    return seis
Exemple #3
0
def get_live_seismogram():
    seis = Seismogram()
    seis.set_live()
    seis.set_as_origin('test', '0', '0', AtomicType.SEISMOGRAM)
    seis.dt = 1 / sampling_rate
    seis.npts = ts_size
    # seis.put('net', 'IU')
    seis.put('npts', ts_size)
    seis.put('sampling_rate', sampling_rate)
    seis.tref = TimeReferenceType.UTC
    seis.t0 = 0
    seis['delta'] = 0.1
    seis['calib'] = 0.1
    seis['site_id'] = bson.objectid.ObjectId()
    seis['channel_id'] = [bson.objectid.ObjectId()]
    seis['source_id'] = bson.objectid.ObjectId()
    seis.data = dmatrix(3, ts_size)
    for i in range(3):
        for j in range(ts_size):
            seis.data[i, j] = np.random.rand()
    return seis
Exemple #4
0
def test_Seismogram():
    seis = Seismogram()
    seis.npts = 100
    assert seis.data.rows() == 3
    assert seis.data.columns() == 100

    seis.t0 = 0.0
    seis.dt = 0.001
    seis.live = 1
    seis.tref = TimeReferenceType.Relative
    seis.data = dmatrix(np.random.rand(3, 6))
    assert seis.npts != 6
    seis.sync_npts()
    assert seis.npts == 6
    assert seis.npts == seis["npts"]

    seis.npts = 4
    assert seis.data.columns() == 4

    seis.npts = 10
    assert (seis.data[0:3, 4:10] == 0).all()

    seis.data = dmatrix(np.random.rand(3, 100))
    seis.sync_npts()
    seis_copy = pickle.loads(pickle.dumps(seis))
    assert seis_copy.t0 == seis.t0
    assert seis_copy.dt == seis.dt
    assert seis_copy.live == seis.live
    assert seis_copy.tref == seis.tref
    assert (seis_copy.data[:] == seis.data[:]).all()

    # test the += operator
    seis1 = Seismogram(seis)
    seis2 = Seismogram(seis)
    seis1 += seis2
    assert (np.isclose(seis1.data[:], seis.data + seis.data)).all()

    seis.npts = 0
    assert seis.data.rows() == 0

    seis.npts = 100
    for i in range(3):
        for j in range(100):
            if i == 0:
                seis.data[i, j] = 1.0
            else:
                seis.data[i, j] = 0.0
    seis.data[0, 1] = 1.0
    seis.data[0, 2] = 1.0
    seis.data[0, 3] = 0.0
    seis.data[1, 1] = 1.0
    seis.data[1, 2] = 1.0
    seis.data[1, 3] = 0.0
    seis.data[2, 1] = 1.0
    seis.data[2, 2] = 0.0
    seis.data[2, 3] = 1.0

    sc = SphericalCoordinate()
    sc.phi = 0.0
    sc.theta = np.pi / 4
    seis.rotate(sc)
    assert all(np.isclose(seis.data[:, 3], [0, -0.707107, 0.707107]))
    seis.rotate_to_standard()
    assert all(seis.data[:, 3] == [0, 0, 1])
    sc.phi = -np.pi / 4
    seis.data[:, 3] = sc.unit_vector
    seis.rotate(sc)
    assert all(seis.data[:, 3] == [0, 0, 1])
    seis.rotate_to_standard()
    assert all(np.isclose(seis.data[:, 3], [0.5, -0.5, 0.707107]))
    seis.data[:, 3] = [0, 0, 1]

    nu = [np.sqrt(3.0) / 3.0, np.sqrt(3.0) / 3.0, np.sqrt(3.0) / 3.0]
    seis.rotate(nu)
    assert (np.isclose(
        seis.tmatrix,
        np.array([
            [0.70710678, -0.70710678, 0.0],
            [0.40824829, 0.40824829, -0.81649658],
            [0.57735027, 0.57735027, 0.57735027],
        ]),
    )).all()
    assert all(np.isclose(seis.data[:, 0], [0.707107, 0.408248, 0.57735]))
    assert all(np.isclose(seis.data[:, 1], [0, 0, 1.73205]))
    seis.rotate_to_standard()
    assert all(np.isclose(seis.data[:, 0], [1, 0, 0]))
    assert all(np.isclose(seis.data[:, 1], [1, 1, 1]))

    nu = [np.sqrt(3.0) / 3.0, np.sqrt(3.0) / 3.0, np.sqrt(3.0) / 3.0]
    seis.rotate(SphericalCoordinate(nu))
    assert (np.isclose(
        seis.tmatrix,
        np.array([
            [0.70710678, -0.70710678, 0.0],
            [0.40824829, 0.40824829, -0.81649658],
            [0.57735027, 0.57735027, 0.57735027],
        ]),
    )).all()
    assert all(np.isclose(seis.data[:, 0], [0.707107, 0.408248, 0.57735]))
    assert all(np.isclose(seis.data[:, 1], [0, 0, 1.73205]))
    seis.rotate_to_standard()
    assert all(np.isclose(seis.data[:, 0], [1, 0, 0]))
    assert all(np.isclose(seis.data[:, 1], [1, 1, 1]))

    sc.phi = np.pi / 4
    sc.theta = 0.0
    seis.rotate(sc)
    assert (np.isclose(
        seis.tmatrix,
        np.array([
            [0.70710678, -0.70710678, 0.0],
            [0.70710678, 0.70710678, 0.0],
            [0.0, 0.0, 1.0],
        ]),
    )).all()
    assert all(np.isclose(seis.data[:, 0], [0.707107, 0.707107, 0]))
    assert all(np.isclose(seis.data[:, 1], [0, 1.41421, 1]))
    assert all(np.isclose(seis.data[:, 2], [0, 1.41421, 0]))
    assert all(np.isclose(seis.data[:, 3], [0, 0, 1]))
    seis.rotate_to_standard()

    # test for serialization of SphericalCoordinate
    sc_copy = pickle.loads(pickle.dumps(sc))
    assert sc_copy.radius == sc.radius
    assert sc_copy.theta == sc.theta
    assert sc_copy.phi == sc.phi

    a = np.zeros((3, 3))
    a[0][0] = 1.0
    a[0][1] = 1.0
    a[0][2] = 1.0
    a[1][0] = -1.0
    a[1][1] = 1.0
    a[1][2] = 1.0
    a[2][0] = 0.0
    a[2][1] = -1.0
    a[2][2] = 0.0
    seis.transform(a)
    assert all(np.isclose(seis.data[:, 0], [1, -1, 0]))
    assert all(np.isclose(seis.data[:, 1], [3, 1, -1]))
    assert all(np.isclose(seis.data[:, 2], [2, 0, -1]))
    assert all(np.isclose(seis.data[:, 3], [1, 1, 0]))
    seis_copy = pickle.loads(pickle.dumps(seis))
    seis_copy.rotate_to_standard()
    assert all(np.isclose(seis_copy.data[:, 0], [1, 0, 0]))
    assert all(np.isclose(seis_copy.data[:, 1], [1, 1, 1]))
    assert all(np.isclose(seis_copy.data[:, 2], [1, 1, 0]))
    assert all(np.isclose(seis_copy.data[:, 3], [0, 0, 1]))
    seis.rotate_to_standard()

    seis.rotate(np.pi / 4)
    seis.transform(a)
    assert (np.isclose(
        seis.tmatrix,
        np.array([[1.41421, 0.0, 1], [0.0, 1.41421, 1],
                  [-0.707107, -0.707107, 0]]),
    )).all()
    assert all(np.isclose(seis.data[:, 0], [1.41421, 0, -0.707107]))
    assert all(np.isclose(seis.data[:, 1], [2.41421, 2.41421, -1.41421]))
    assert all(np.isclose(seis.data[:, 2], [1.41421, 1.41421, -1.41421]))
    assert all(np.isclose(seis.data[:, 3], [1, 1, 0]))
    seis.rotate_to_standard()
    assert all(np.isclose(seis.data[:, 0], [1, 0, 0]))
    assert all(np.isclose(seis.data[:, 1], [1, 1, 1]))
    assert all(np.isclose(seis.data[:, 2], [1, 1, 0]))
    assert all(np.isclose(seis.data[:, 3], [0, 0, 1]))

    uvec = SlownessVector()
    uvec.ux = 0.17085  # cos(-20deg)/5.5
    uvec.uy = -0.062185  # sin(-20deg)/5.5
    seis.free_surface_transformation(uvec, 5.0, 3.5)
    assert (np.isclose(
        seis.tmatrix,
        np.array([
            [-0.171012, -0.469846, 0],
            [0.115793, -0.0421458, 0.445447],
            [-0.597975, 0.217647, 0.228152],
        ]),
    )).all()

    seis.tmatrix = a
    assert (seis.tmatrix == a).all()

    # test for serialization of SlownessVector
    uvec_copy = pickle.loads(pickle.dumps(uvec))
    assert uvec_copy.ux == uvec.ux
    assert uvec_copy.uy == uvec.uy
    assert uvec_copy.azimuth() == uvec.azimuth()