def test_get_obs_from_obs():
    """StreamConverter_test.test_get_obs_from_obs()

    The observatory stream can contain either ''d'' or ''e'' depending
    on it's source. get_obs_from_obs will return either or both as part
    of the obs Stream.
    """

    # 1) Call get_obs_from_obs using a decbas of 15, a H stream of
    #   [cos(15), cos(30)], and a E stream of [sin(15), sin(30)].
    #   Expect a D stream of [15 degrees, 30 degrees]
    obs_e = obspy.core.Stream()
    DECBAS = 15 * D2I
    obs_e += __create_trace('H', [cos(15 * D2R), cos(30 * D2R)], DECBAS)
    obs_e += __create_trace('E', [sin(15 * D2R), sin(30 * D2R)], DECBAS)
    obs_e += __create_trace('Z', [1, 1], DECBAS)
    obs_e += __create_trace('F', [1, 1], DECBAS)
    obs_D = StreamConverter.get_obs_from_obs(obs_e, False, True)
    d = obs_D.select(channel='D')[0].data
    assert_almost_equal(d, [15 * D2R, 30 * D2R], 9,
        'Expect D to equal [15 degrees, 30 degrees]', True)

    # 2) Call get_obs_from_obs using a decbase of 15 degrees, a H stream of
    #   [cos(15), cos(30)], and a D stream of [15, 30].
    #   Expect a D stream of [sin(15), sin(30)]
    obs_d = obspy.core.Stream()
    obs_d += __create_trace('H', [cos(15 * D2R), cos(30 * D2R)], DECBAS)
    obs_d += __create_trace('D', [15 * D2R, 30 * D2R], DECBAS)
    obs_d += __create_trace('Z', [1, 1], DECBAS)
    obs_d += __create_trace('F', [1, 1], DECBAS)
    obs_E = StreamConverter.get_obs_from_obs(obs_d, True, False)
    e = obs_E.select(channel='E')[0].data
    assert_almost_equal(e, [sin(15 * D2R), sin(30 * D2R)], 9,
        'Expect E to equal [sin(15), sin(30)', True)
Пример #2
0
def test_get_obs_from_obs():
    """StreamConverter_test.test_get_obs_from_obs()

    The observatory stream can contain either ''d'' or ''e'' depending
    on it's source. get_obs_from_obs will return either or both as part
    of the obs Stream.
    """

    # 1) Call get_obs_from_obs using a decbas of 15, a H stream of
    #   [cos(15), cos(30)], and a E stream of [sin(15), sin(30)].
    #   Expect a D stream of [15 degrees, 30 degrees]
    obs_e = obspy.core.Stream()
    DECBAS = 15 * D2I
    obs_e += __create_trace('H', [cos(15 * D2R), cos(30 * D2R)], DECBAS)
    obs_e += __create_trace('E', [sin(15 * D2R), sin(30 * D2R)], DECBAS)
    obs_e += __create_trace('Z', [1, 1], DECBAS)
    obs_e += __create_trace('F', [1, 1], DECBAS)
    obs_D = StreamConverter.get_obs_from_obs(obs_e, False, True)
    d = obs_D.select(channel='D')[0].data
    assert_almost_equal(d, [15 * D2R, 30 * D2R], 9,
                        'Expect D to equal [15 degrees, 30 degrees]', True)

    # 2) Call get_obs_from_obs using a decbase of 15 degrees, a H stream of
    #   [cos(15), cos(30)], and a D stream of [15, 30].
    #   Expect a D stream of [sin(15), sin(30)]
    obs_d = obspy.core.Stream()
    obs_d += __create_trace('H', [cos(15 * D2R), cos(30 * D2R)], DECBAS)
    obs_d += __create_trace('D', [15 * D2R, 30 * D2R], DECBAS)
    obs_d += __create_trace('Z', [1, 1], DECBAS)
    obs_d += __create_trace('F', [1, 1], DECBAS)
    obs_E = StreamConverter.get_obs_from_obs(obs_d, True, False)
    e = obs_E.select(channel='E')[0].data
    assert_almost_equal(e, [sin(15 * D2R), sin(30 * D2R)], 9,
                        'Expect E to equal [sin(15), sin(30)', True)
def test_verification_data():
    """StreamConverter_test.test_verification_data()

    This is a verification test of data done with different
    converters,  to see if the same result is returned.
    Since the small angle approximation was used in the other
    converters, AND round off was done differently,  we can't
    get the exact results.
    Change the precision in assert_almost_equal to larger precision
    (ie 2 to 8) to see how off the data is. Most are well within
    expectations.
    """
    DECBAS = 552.7
    obs_v = obspy.core.Stream()
    obs_v += __create_trace(
        "H", [20889.55, 20889.57, 20889.74, 20889.86, 20889.91, 20889.81],
        DECBAS)
    obs_v += __create_trace("E",
                            [-21.10, -20.89, -20.72, -20.57, -20.39, -20.12],
                            DECBAS)
    obs_v += __create_trace(
        "Z", [47565.29, 47565.34, 47565.39, 47565.45, 47565.51, 47565.54],
        DECBAS)
    obs_v += __create_trace(
        "F", [52485.77, 52485.84, 52485.94, 52486.06, 52486.11, 52486.10],
        DECBAS)
    obs_V = StreamConverter.get_obs_from_obs(obs_v, True, True)
    d = obs_V.select(channel="D")[0].data
    d = ChannelConverter.get_minutes_from_radians(d)
    # Using d values calculated using small angle approximation.
    assert_almost_equal(
        d,
        [-3.47, -3.43, -3.40, -3.38, -3.35, -3.31],
        2,
        "Expect d to equal [-3.47, -3.43, -3.40, -3.38, -3.35, -3.31]",
        True,
    )

    mag = obspy.core.Stream()
    DECBAS = 552.7
    mag += __create_trace(
        "H", [20884.04, 20883.45, 20883.38, 20883.43, 20883.07, 20882.76],
        DECBAS)
    d = ChannelConverter.get_radians_from_minutes(
        [556.51, 556.52, 556.56, 556.61, 556.65, 556.64])
    mag += __create_trace("D", d, DECBAS)
    mag += __create_trace(
        "Z", [48546.90, 48546.80, 48546.80, 48546.70, 48546.80, 48546.90],
        DECBAS)
    mag += __create_trace("F", [0.10, 0.00, 0.10, 0.00, 0.00, 0.00, 0.00],
                          DECBAS)
    geo = StreamConverter.get_geo_from_mag(mag)
    X = geo.select(channel="X")[0].data
    Y = geo.select(channel="Y")[0].data
    assert_almost_equal(
        X, [20611.00, 20610.40, 20610.30, 20610.30, 20609.90, 20609.60], 2)
    assert_almost_equal(Y,
                        [3366.00, 3366.00, 3366.20, 3366.50, 3366.70, 3366.60],
                        1)
def test_verification_data():
    """StreamConverter_test.test_verification_data()

    This is a verification test of data done with different
    converters,  to see if the same result is returned.
    Since the small angle approximation was used in the other
    converters, AND round off was done differently,  we can't
    get the exact results.
    Change the precision in assert_almost_equal to larger precision
    (ie 2 to 8) to see how off the data is. Most are well within
    expectations.
    """
    DECBAS = 552.7
    obs_v = obspy.core.Stream()
    obs_v += __create_trace('H',
        [20889.55, 20889.57, 20889.74, 20889.86, 20889.91, 20889.81], DECBAS)
    obs_v += __create_trace('E',
        [-21.10, -20.89, -20.72, -20.57, -20.39, -20.12], DECBAS)
    obs_v += __create_trace('Z',
        [47565.29, 47565.34, 47565.39, 47565.45, 47565.51, 47565.54], DECBAS)
    obs_v += __create_trace('F',
        [52485.77, 52485.84, 52485.94, 52486.06, 52486.11, 52486.10], DECBAS)
    obs_V = StreamConverter.get_obs_from_obs(obs_v, True, True)
    d = obs_V.select(channel='D')[0].data
    d = ChannelConverter.get_minutes_from_radians(d)
    # Using d values calculated using small angle approximation.
    assert_almost_equal(d,
        [-3.47, -3.43, -3.40, -3.38, -3.35, -3.31], 2,
        'Expect d to equal [-3.47, -3.43, -3.40, -3.38, -3.35, -3.31]', True)

    mag = obspy.core.Stream()
    DECBAS = 552.7
    mag += __create_trace('H',
        [20884.04, 20883.45, 20883.38, 20883.43, 20883.07, 20882.76], DECBAS)
    d = ChannelConverter.get_radians_from_minutes(
        [556.51, 556.52, 556.56, 556.61, 556.65, 556.64])
    mag += __create_trace('D', d, DECBAS)
    mag += __create_trace('Z',
        [48546.90, 48546.80, 48546.80, 48546.70, 48546.80, 48546.90], DECBAS)
    mag += __create_trace('F',
        [0.10, 0.00, 0.10, 0.00, 0.00, 0.00, 0.00], DECBAS)
    geo = StreamConverter.get_geo_from_mag(mag)
    X = geo.select(channel='X')[0].data
    Y = geo.select(channel='Y')[0].data
    assert_almost_equal(X,
        [20611.00, 20610.40, 20610.30, 20610.30, 20609.90, 20609.60], 2)
    assert_almost_equal(Y,
        [3366.00, 3366.00, 3366.20, 3366.50, 3366.70, 3366.60], 1)