def test_get_geo_from_obs(): """geomag.StreamConverter_test.test_get_geo_from_obs() The observatory stream containing the observatory traces ''h'', ''d'' or ''e'', ''z'', and ''f'' converts to the geographic stream containing the traces ''x'', ''y'', ''z'', and ''f'' """ obs = obspy.core.Stream() # 1) Call get_geo_from_obs using equal h, e streams with a decbas of 0 # the geographic stream values X, Y will be the same. obs += __create_trace('H', [1]) obs += __create_trace('E', [1]) obs += __create_trace('Z', [1]) obs += __create_trace('F', [1]) geo = StreamConverter.get_geo_from_obs(obs) X = geo.select(channel='X')[0].data Y = geo.select(channel='Y')[0].data assert_almost_equal(X[0], 1, 9, 'Expect X to almost equal 1', True) assert_almost_equal(Y[0], 1, 9, 'Expect Y to almost equal 1', True) # 2) Call get_geo_from_obs using a decbas of 15 degrees, and streams # with H = [cos(15), cos(30)], and E = [sin(15), sin(30)]. # Expect streams of X = [cos(30), cos(45)] and Y = sin(30), sin(45) obs = obspy.core.Stream() DECBAS = 15 * D2I obs += __create_trace('H', [cos(15 * D2R), cos(30 * D2R)], DECBAS) obs += __create_trace('E', [sin(15 * D2R), sin(30 * D2R)], DECBAS) obs += __create_trace('Z', [1, 1], DECBAS) obs += __create_trace('F', [1, 1], DECBAS) geo = StreamConverter.get_geo_from_obs(obs) X = geo.select(channel='X')[0].data Y = geo.select(channel='Y')[0].data assert_almost_equal(X, [cos(30 * D2R), cos(45 * D2R)], 9, 'Expect X to equal [cos(30), cos(45)]', True) assert_almost_equal(Y, [sin(30 * D2R), sin(45 * D2R)], 9, 'Expect Y to equal [sin(30), sin(45)]', True)
def test_get_geo_from_obs(): """geomag.StreamConverter_test.test_get_geo_from_obs() The observatory stream containing the observatory traces ''h'', ''d'' or ''e'', ''z'', and ''f'' converts to the geographic stream containing the traces ''x'', ''y'', ''z'', and ''f'' """ obs = obspy.core.Stream() # 1) Call get_geo_from_obs using equal h, e streams with a decbas of 0 # the geographic stream values X, Y will be the same. obs += __create_trace('H', [1]) obs += __create_trace('E', [1]) obs += __create_trace('Z', [1]) obs += __create_trace('F', [1]) geo = StreamConverter.get_geo_from_obs(obs) X = geo.select(channel='X')[0].data Y = geo.select(channel='Y')[0].data assert_almost_equal(X[0], 1, 9, 'Expect X to almost equal 1', True) assert_almost_equal(Y[0], 1, 9, 'Expect Y to almost equal 1', True) # 2) Call get_geo_from_obs using a decbas of 15 degrees, and streams # with H = [cos(15), cos(30)], and E = [sin(15), sin(30)]. # Expect streams of X = [cos(30), cos(45)] and Y = sin(30), sin(45) obs = obspy.core.Stream() DECBAS = 15 * D2I obs += __create_trace('H', [cos(15 * D2R), cos(30 * D2R)], DECBAS) obs += __create_trace('E', [sin(15 * D2R), sin(30 * D2R)], DECBAS) obs += __create_trace('Z', [1, 1], DECBAS) obs += __create_trace('F', [1, 1], DECBAS) geo = StreamConverter.get_geo_from_obs(obs) X = geo.select(channel='X')[0].data Y = geo.select(channel='Y')[0].data assert_almost_equal(X, [cos(30 * D2R), cos(45 * D2R)], 9, 'Expect X to equal [cos(30), cos(45)]', True) assert_almost_equal(Y, [sin(30 * D2R), sin(45 * D2R)], 9, 'Expect Y to equal [sin(30), sin(45)]', True)
def process(self, timeseries): """converts a timeseries stream into a different coordinate system Parameters ---------- informat: string indicates the input coordinate system. outformat: string indicates the output coordinate system. out_stream: obspy.core.Stream new stream object containing the converted coordinates. """ self.check_stream(timeseries) out_stream = None if self.outformat == 'geo': if self.informat == 'geo': out_stream = timeseries elif self.informat == 'mag': out_stream = StreamConverter.get_geo_from_mag(timeseries) elif self.informat == 'obs' or self.informat == 'obsd': out_stream = StreamConverter.get_geo_from_obs(timeseries) elif self.outformat == 'mag': if self.informat == 'geo': out_stream = StreamConverter.get_mag_from_geo(timeseries) elif self.informat == 'mag': out_stream = timeseries elif self.informat == 'obs' or self.informat == 'obsd': out_stream = StreamConverter.get_mag_from_obs(timeseries) elif self.outformat == 'obs': if self.informat == 'geo': out_stream = StreamConverter.get_obs_from_geo(timeseries) elif self.informat == 'mag': out_stream = StreamConverter.get_obs_from_mag(timeseries) elif self.informat == 'obs' or self.informat == 'obsd': out_stream = StreamConverter.get_obs_from_obs(timeseries, include_e=True) elif self.outformat == 'obsd': if self.informat == 'geo': out_stream = StreamConverter.get_obs_from_geo(timeseries, include_d=True) elif self.informat == 'mag': out_stream = StreamConverter.get_obs_from_mag(timeseries, include_d=True) elif self.informat == 'obs' or self.informat == 'obsd': out_stream = StreamConverter.get_obs_from_obs(timeseries, include_d=True) return out_stream