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)
def test_get_obs_from_mag(self): """geomag.ChannelConverterTest.test_get_obs_from_mag() Call the get_obs_from_mag function, using trig identities too test correctness, including d0. Which should test most of the d0 calls. """ H = 1 D = -22.5 * D2R (h, e) = channel.get_obs_from_mag(H, D, 22.5 * D2R) assert_almost_equal(h, cos(45 * D2R), 8, 'Expect h to be cos(45)', True) assert_almost_equal(e, -cos(45 * D2R), 8, 'Expect e to be -cos(45).', True)