コード例 #1
0
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)
コード例 #2
0
    def test_get_minutes_from_radians(self):
        """ChannelConverter_test.test_get_decimal_from_radian()

        Call get_decimal_from_radian using pi/4, expect d to be 45
        """
        radians = math.pi / 4.0
        minutes = channel.get_minutes_from_radians(radians)
        assert_almost_equal(minutes, 45 * 60, 8,
                            "Expect minutes to be equal to 45 degrees", True)
コード例 #3
0
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)
コード例 #4
0
    def _format_data(self, timeseries, channels):
        """Format all data lines.

        Parameters
        ----------
            timeseries : obspy.core.Stream
                Stream containing traces with channel listed in channels
            channels : sequence
                List and order of channel values to output.

        Returns
        -------
        str
            A string formatted to be the data lines in a PCDCP file.
        """
        buf = []

        # create new stream
        timeseriesLocal = Stream()
        # Use a copy of the trace so that we don't modify the original.
        for trace in timeseries:
            traceLocal = trace.copy()
            if traceLocal.stats.channel == 'D':
                traceLocal.data = \
                    ChannelConverter.get_minutes_from_radians(traceLocal.data)

            # TODO - we should look into multiplying the trace all at once
            # like this, but this gives an error on Windows at the moment.
            # traceLocal.data = \
            #     numpy.round(numpy.multiply(traceLocal.data, 100)).astype(int)

            timeseriesLocal.append(traceLocal)

        traces = [timeseriesLocal.select(channel=c)[0] for c in channels]
        starttime = float(traces[0].stats.starttime)
        delta = traces[0].stats.delta

        for i in xrange(len(traces[0].data)):
            buf.append(
                self._format_values(
                    datetime.utcfromtimestamp(starttime + i * delta),
                    (t.data[i] for t in traces)))

        return ''.join(buf)