Beispiel #1
0
    def test_get_obs_from_geo(self):
        """geomag.io.channelTest.test_get_obs_from_geo()

        The geographic north and east components ``X`` and ``Y`` of the
        magnetic field vector H, combined with the declination baseline angle
        ``d0`` can be used to produce the observatory components ``h`` and
        ```e``
        """

        # 1) Call get_obs_from_geo using equal X,Y values with a d0 of 0
        #   the observatory values h,e will be the same.
        X = 1
        Y = 1
        (h, e) = channel.get_obs_from_geo(X, Y)
        assert_almost_equal(h, 1.0, 8, 'Expect h to be 1.', True)
        assert_almost_equal(e, 1.0, 8, 'Expect e to be 1.', True)
        # 2) Call get_obs_from_geo using equal X,Y values to create a 45
        #   degree angle (D), with a d0 of 45/2. The observatory declination
        #   (d) will be 45/2, the difference between the total field angle,
        #   and d0.
        X = 1
        Y = 1
        d0 = 22.5 * D2R
        (h, e) = channel.get_obs_from_geo(X, Y, d0)
        d = channel.get_obs_d_from_obs(h, e)
        assert_almost_equal(d, 22.5 * D2R, 8,
                'Expect d to be 22.5 degrees.', True)
        # 3) Call get_obs_from_geo using equal X,Y values to create a 45
        #   degree angle (D), with a d0 of 315 degrees. The observatory
        #   declination (d) will be 90 degrees.
        X = 1
        Y = 1
        d0 = 315 * D2R
        (h, e) = channel.get_obs_from_geo(X, Y, d0)
        d = channel.get_obs_d_from_obs(h, e)
        assert_almost_equal(d, 90 * D2R, 8, 'Expect d to be 90 degrees.', True)
        # 4) Call get_obs_from_geo using X,Y values of cos(60), sin(60), and
        #   d0 of 30 degrees. The observatory values h,e will be cos(30)
        #   and sin(30), and the observatory declination will be 30 degrees.
        #   The observatory angle of 30 degrees + the d0 of 30 degrees produces
        #   the total declination (D) of 60 degrees.
        X = cos(60 * D2R)
        Y = sin(60 * D2R)
        d0 = 30 * D2R
        (h, e) = channel.get_obs_from_geo(X, Y, d0)
        assert_almost_equal(h, cos(30 * D2R), 8,
                'Expect h to be cos(30).', True)
        assert_almost_equal(e, sin(30 * D2R), 8,
                'Expect e to be sin(30).', True)
        d = channel.get_obs_d_from_obs(h, e)
        assert_almost_equal(d, 30 * D2R, 8, 'Expect d to be 30 degrees.', True)
def get_obs_from_mag(mag, include_d=False):
    """Convert a stream to magnetic observatory coordinate system.

    Parameters
    ----------
    stream: obspy.core.Stream
        stream containing magnetic components H, D, Z, and F.
    include_d: boolean
        whether to also include the observatory D component
    Returns
    -------
    obspy.core.Stream
        new stream object containing observatory components H, D, E, Z, and F
    """
    h = mag.select(channel='H')[0]
    d = mag.select(channel='D')[0]
    z = mag.select(channel='Z')[0]
    f = mag.select(channel='F')[0]
    mag_h = h.data
    mag_d = d.data
    d0 = ChannelConverter.get_radians_from_minutes(
        numpy.float64(d.stats.declination_base) / 10)
    (obs_h, obs_e) = ChannelConverter.get_obs_from_mag(mag_h, mag_d, d0)

    traces = (
        __get_trace('H', h.stats, obs_h),
        __get_trace('E', d.stats, obs_e),
        z, f)
    if include_d:
        obs_d = ChannelConverter.get_obs_d_from_obs(obs_h, obs_e)
        traces = traces + (__get_trace('D', d.stats, obs_d),)
    return obspy.core.Stream(traces)
def get_obs_from_mag(mag, include_d=False):
    """Convert a stream to magnetic observatory coordinate system.

    Parameters
    ----------
    stream: obspy.core.Stream
        stream containing magnetic components H, D, Z, and F.
    include_d: boolean
        whether to also include the observatory D component
    Returns
    -------
    obspy.core.Stream
        new stream object containing observatory components H, D, E, Z, and F
    """
    h = mag.select(channel='H')[0]
    d = mag.select(channel='D')[0]
    z = mag.select(channel='Z')[0]
    f = mag.select(channel='F')[0]
    mag_h = h.data
    mag_d = d.data
    d0 = ChannelConverter.get_radians_from_minutes(
        numpy.float64(d.stats.declination_base) / 10)
    (obs_h, obs_e) = ChannelConverter.get_obs_from_mag(mag_h, mag_d, d0)

    traces = (__get_trace('H', h.stats,
                          obs_h), __get_trace('E', d.stats, obs_e), z, f)
    if include_d:
        obs_d = ChannelConverter.get_obs_d_from_obs(obs_h, obs_e)
        traces = traces + (__get_trace('D', d.stats, obs_d), )
    return obspy.core.Stream(traces)
Beispiel #4
0
    def test_get_obs_d_from_obs(self):
        """geomag.ChannelConverterTest.test_get_obs_d_from_obs()

        ``d`` is the angle formed by the observatory components ``h`` and
        ``e`` the primary and secondary axis of the horizontal magnetic
        field vector in the observatories frame of reference.
        """
        # 1) Call get_obs_d_from_obs usine h,e equal to cos(30), sin(30).
        #   Expect d to be 30.
        h = cos(30 * D2R)
        e = sin(30 * D2R)
        d = channel.get_obs_d_from_obs(h, e)
        assert_almost_equal(d, 30 * D2R, 8, 'Expect d to be 30 degrees.', True)
        # 2) Call get_obs_d_from_obs using h,e cos(30), -sin(30). Expect
        #   d to be 30.
        h = cos(30 * D2R)
        e = sin(-30 * D2R)
        d = channel.get_obs_d_from_obs(h, e)
        assert_almost_equal(d, -30 * D2R, 8,
                'Expect d to be 30 degrees.', True)
def __get_obs_d_from_obs(obs):
    """Get trace containing observatory D component.

    Returns D if found, otherwise computes D from H, E, D0.

    Parameters
    ----------
    obs : obspy.core.Stream
        observatory components (D) or (H, E).

    Returns
    -------
    obspy.core.Trace
        observatory component D.
    """
    try:
        d = obs.select(channel='D')[0]
    except:
        h = obs.select(channel='H')[0]
        e = obs.select(channel='E')[0]
        d = __get_trace('D', e.stats,
                ChannelConverter.get_obs_d_from_obs(h.data, e.data))
    return d
def __get_obs_d_from_obs(obs):
    """Get trace containing observatory D component.

    Returns D if found, otherwise computes D from H, E, D0.

    Parameters
    ----------
    obs : obspy.core.Stream
        observatory components (D) or (H, E).

    Returns
    -------
    obspy.core.Trace
        observatory component D.
    """
    try:
        d = obs.select(channel='D')[0]
    except:
        h = obs.select(channel='H')[0]
        e = obs.select(channel='E')[0]
        d = __get_trace('D', e.stats,
                        ChannelConverter.get_obs_d_from_obs(h.data, e.data))
    return d