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
def test_get_mag_from_geo(): """geomag.StreamConverter_test.test_get_mag_from_geo() The geographic stream containing the traces ''x'', ''y'', ''z'', and ''f'' converts to the magnetic stream containing the traces ''h'', ''d'', ''z'' and ''f''. """ geo = obspy.core.Stream() # Call get_mag_from_geo using a decbas of 15, a X stream of # [cos(15), cos(30)], and a Y stream of [sin(15), sin(30)]. # Expect a H stream of [1,1] and a D strem of [15 degrees, 30 degrees] DECBAS = 15 * D2I geo += __create_trace('X', [cos(15 * D2R), cos(30 * D2R)], DECBAS) geo += __create_trace('Y', [sin(15 * D2R), sin(30 * D2R)], DECBAS) geo += __create_trace('Z', [1, 1], DECBAS) geo += __create_trace('F', [1, 1], DECBAS) mag = StreamConverter.get_mag_from_geo(geo) H = mag.select(channel='H')[0].data D = mag.select(channel='D')[0].data assert_almost_equal(H, [1, 1], 9, 'Expect H to equal [1,1]', True) assert_almost_equal(D, [15 * D2R, 30 * D2R], 9, 'Expect D to equal [15 degrees, 30 degrees]', True)