def test_get_geo_from_mag():
    """StreamConverter_test.test_get_geo_from_mag()

    The magnetic north stream containing the traces ''h'', ''d'', ''z'', and
    ''f'' converts to the geographics stream containing the traces ''x'',
    ''y'', ''z'' and ''f''
    """
    mag = obspy.core.Stream()

    # Call get_geo_from_magusing a decbas of 15 degrees, and streams with
    #   H = [1, 1], and D = [15 degrees, 30 degrees], expect streams of
    #   X = [cos(15), cos(30)] and Y = [sin(15), sin(30)]
    # stats.DECBAS = 15 * D2I
    mag += __create_trace("H", [1, 1])
    mag += __create_trace("D", [15 * D2R, 30 * D2R])
    mag += __create_trace("Z", [1, 1])
    mag += __create_trace("F", [1, 1])
    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,
        [cos(15 * D2R), cos(30 * D2R)],
        9,
        "Expect X to equal [cos(15), cos(30)]",
        True,
    )
    assert_almost_equal(
        Y,
        [sin(15 * D2R), sin(30 * D2R)],
        9,
        "Expect Y 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)
def test_get_geo_from_mag():
    """StreamConverter_test.test_get_geo_from_mag()

    The magnetic north stream containing the traces ''h'', ''d'', ''z'', and
    ''f'' converts to the geographics stream containing the traces ''x'',
    ''y'', ''z'' and ''f''
    """
    mag = obspy.core.Stream()

    # Call get_geo_from_magusing a decbas of 15 degrees, and streams with
    #   H = [1, 1], and D = [15 degrees, 30 degrees], expect streams of
    #   X = [cos(15), cos(30)] and Y = [sin(15), sin(30)]
    # stats.DECBAS = 15 * D2I
    mag += __create_trace('H', [1, 1])
    mag += __create_trace('D', [15 * D2R, 30 * D2R])
    mag += __create_trace('Z', [1, 1])
    mag += __create_trace('F', [1, 1])
    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, [cos(15 * D2R), cos(30 * D2R)], 9,
        'Expect X to equal [cos(15), cos(30)]', True)
    assert_almost_equal(Y, [sin(15 * D2R), sin(30 * D2R)], 9,
        'Expect Y to equal [sin(15), sin(30)]', True)