def get_mag_from_obs(obs): """Convert a stream to magnetic coordinate system. Parameters ---------- obs : obspy.core.Stream stream containing observatory components H, D or E, Z, and F. Returns ------- obspy.core.Stream new stream object containing magnetic components H, D, Z, and F. """ h = obs.select(channel='H')[0] e = __get_obs_e_from_obs(obs) z = obs.select(channel='Z')[0] f = obs.select(channel='F')[0] obs_h = h.data obs_e = e.data d0 = ChannelConverter.get_radians_from_minutes( numpy.float64(e.stats.declination_base) / 10) (mag_h, mag_d) = ChannelConverter.get_mag_from_obs(obs_h, obs_e, d0) return obspy.core.Stream( (__get_trace('H', h.stats, mag_h), __get_trace('D', e.stats, mag_d), z, f))
def get_mag_from_obs(obs): """Convert a stream to magnetic coordinate system. Parameters ---------- obs : obspy.core.Stream stream containing observatory components H, D or E, Z, and F. Returns ------- obspy.core.Stream new stream object containing magnetic components H, D, Z, and F. """ h = obs.select(channel='H')[0] e = __get_obs_e_from_obs(obs) z = obs.select(channel='Z')[0] f = obs.select(channel='F')[0] obs_h = h.data obs_e = e.data d0 = ChannelConverter.get_radians_from_minutes( numpy.float64(e.stats.declination_base) / 10) (mag_h, mag_d) = ChannelConverter.get_mag_from_obs(obs_h, obs_e, d0) return obspy.core.Stream(( __get_trace('H', h.stats, mag_h), __get_trace('D', e.stats, mag_d), z, f))
def test_get_mag_from_obs(self): """geomag.ChannelConverterTest.test_get_geo_y_from_obs() ``h``, ``e`` are the primary and secondary axis of the ``H`` vector in the horizontal plane of the magnetic field. ``d0`` is the declination baseline of the observatory frame of reference. ``D`` comes from the combination of ``d0`` and the angle produced from the ``h`` and ``e`` components. """ # Call get_mag_from_obs using h,d of cos(30), sin(30) and # d0 of 15 degrees. Expect H,D to equal 1, 45. h = cos(30 * D2R) e = sin(30 * D2R) d0 = 15 * D2R H, D = channel.get_mag_from_obs(h, e, d0) assert_almost_equal(H, 1, 8, 'Expect H to be 1.', True) assert_almost_equal(D, 45 * D2R, 8, 'Expect D to be 45.', True)