예제 #1
0
class ClientTestCase(unittest.TestCase):
    def setUp(self):
        self.client = Client("rtserver.ipgp.fr")

    def test_get_waveform(self):
        def _test_offset_from_realtime(offset):
            t = UTCDateTime() - offset
            for request in [["G", "FDF", "00", "LHN", t, t + 20],
                            ["G", "CLF", "00", "BHZ", t, t + 10]]:
                st = self.client.get_waveforms(*request)
                self.assertGreater(len(st), 0)
                for tr in st:
                    self.assertEqual(tr.id, ".".join(request[:4]))
                self.assertTrue(any([len(tr) > 0 for tr in st]))
                st.merge(1)
                self.assertTrue(abs(tr.stats.starttime - request[4]) < 1)
                self.assertTrue(abs(tr.stats.endtime - request[5]) < 1)
                for tr in st:
                    self.assertEqual(tr.stats.network, request[0])
                    self.assertEqual(tr.stats.station, request[1])
                    self.assertEqual(tr.stats.location, request[2])
                    self.assertEqual(tr.stats.channel, request[3])

        # getting a result depends on two things.. how long backwards the ring
        # buffer stores data and how close to realtime the data is available,
        # so check some different offsets and see if we get some data
        for offset in (3600, 2000, 1000, 500):
            try:
                _test_offset_from_realtime(offset)
            except:
                continue
            break
        else:
            raise
예제 #2
0
class SeedLinkLocation(WaveformLocation):
    def __init__(self, name, priority, server_name):
        WaveformLocation.__init__(self, name, priority)

        self.__server_name = server_name
        self.client = Client(self.__server_name)
        self.__station_info = []

    def requestWaveformTraces(self, requests):
        """
        Method for requesting data from WaveformLocation. Implement this to get waveform data.
        """
        streams = Stream()
        if self.__checkStatus():
            for request in requests:
                if not request.fulfilled():
                    #check if station_info contains a station the request is trying to access and its data starts soon enough to contain the stream
                    if [
                            e for e in self.__station_info.findall('station')
                            if e.attrib['name'] == request.station() and
                            UTCDateTime(e.find("stream").attrib['begin_time'])
                            < request.start_time()
                    ]:
                        for channel in request.channels():
                            new_stream = self.client.get_waveforms(
                                request.network(), request.station(), '??',
                                'HH' + channel, request.start_time(),
                                request.end_time())
                            streams += new_stream
                            request.fulfilRequest()

        return streams

    def __checkStatus(self):
        """
        Function for checking the status of the seedlink location and fetching all station related information from the seedlink server and saving it to station_info.
        """
        try:
            cl = create_client(self.__server_name)
        except:
            return False
        self.__station_info = ET.fromstring(cl.get_info('STREAMS'))
        cl.close()
        return True

    def getWaveformLocationStatus(self):
        """
        Ask if the seedlink location is listening and return the information to the user.
        """
        return {self.getName(): self.__checkStatus()}
예제 #3
0
class ClientTestCase(unittest.TestCase):
    def setUp(self):
        self.client = Client("rtserver.ipgp.fr")

    def test_get_waveform(self):
        t = UTCDateTime() - 3600
        for request in [["G", "FDF", "00", "LHN", t, t + 20],
                        ["G", "CLF", "00", "BHZ", t, t + 10]]:
            st = self.client.get_waveforms(*request)
            self.assertGreater(len(st), 0)
            for tr in st:
                self.assertEqual(tr.id, ".".join(request[:4]))
            self.assertTrue(any([len(tr) > 0 for tr in st]))
            st.merge(1)
            self.assertTrue(abs(tr.stats.starttime - request[4]) < 1)
            self.assertTrue(abs(tr.stats.endtime - request[5]) < 1)
예제 #4
0
 def setUp(self):
     self.client = Client("rtserver.ipgp.fr")
예제 #5
0
class ClientTestCase(unittest.TestCase):
    def setUp(self):
        self.client = Client("rtserver.ipgp.fr")

    def test_get_waveform(self):
        def _test_offset_from_realtime(offset):
            t = UTCDateTime() - offset
            for request in [["G", "FDFM", "00", "LHN", t, t + 20],
                            ["G", "CLF", "00", "BHZ", t, t + 10]]:
                st = self.client.get_waveforms(*request)
                self.assertGreater(len(st), 0)
                for tr in st:
                    self.assertEqual(tr.id, ".".join(request[:4]))
                self.assertTrue(any([len(tr) > 0 for tr in st]))
                st.merge(1)
                self.assertTrue(abs(tr.stats.starttime - request[4]) < 1)
                self.assertTrue(abs(tr.stats.endtime - request[5]) < 1)
                for tr in st:
                    self.assertEqual(tr.stats.network, request[0])
                    self.assertEqual(tr.stats.station, request[1])
                    self.assertEqual(tr.stats.location, request[2])
                    self.assertEqual(tr.stats.channel, request[3])

        # getting a result depends on two things.. how long backwards the ring
        # buffer stores data and how close to realtime the data is available,
        # so check some different offsets and see if we get some data
        for offset in (3600, 2000, 1000, 500):
            try:
                _test_offset_from_realtime(offset)
            except AssertionError:
                continue
            else:
                break
        else:
            raise

    def test_get_info(self):
        """
        Test fetching station information
        """
        client = self.client

        info = client.get_info(station='F*')
        self.assertIn(('G', 'FDFM'), info)
        # should have at least 7 stations
        self.assertTrue(len(info) > 2)
        # only fetch one station
        info = client.get_info(network='G', station='FDFM')
        self.assertEqual([('G', 'FDFM')], info)
        # check that we have a cache on station level
        self.assertIn(('G', 'FDFM'), client._station_cache)
        self.assertTrue(len(client._station_cache) > 20)
        self.assertEqual(client._station_cache_level, "station")

    def test_multiple_waveform_requests_with_multiple_info_requests(self):
        """
        This test a combination of waveform requests that internally do
        multiple info requests on increasing detail levels
        """
        def _test_offset_from_realtime(offset):
            # need to reinit to clean out any caches
            self.setUp()
            t = UTCDateTime() - offset
            # first do a request that needs an info request on station level
            # only
            st = self.client.get_waveforms("*", "F?FM", "??", "B??", t, t + 5)
            self.assertGreater(len(st), 2)
            self.assertTrue(len(self.client._station_cache) > 20)
            station_cache_size = len(self.client._station_cache)
            self.assertIn(("G", "FDFM"), self.client._station_cache)
            self.assertEqual(self.client._station_cache_level, "station")
            for tr in st:
                self.assertEqual(tr.stats.network, "G")
                self.assertEqual(tr.stats.station, "FDFM")
                self.assertEqual(tr.stats.channel[0], "B")
            # now make a subsequent request that needs an info request on
            # channel level
            st = self.client.get_waveforms("*", "F?FM", "*", "B*", t, t + 5)
            self.assertGreater(len(st), 2)
            self.assertTrue(
                len(self.client._station_cache) > station_cache_size)
            self.assertIn(("G", "FDFM", "00", "BHZ"),
                          self.client._station_cache)
            self.assertEqual(self.client._station_cache_level, "channel")
            for tr in st:
                self.assertEqual(tr.stats.network, "G")
                self.assertEqual(tr.stats.station, "FDFM")
                self.assertEqual(tr.stats.channel[0], "B")

        # getting a result depends on two things.. how long backwards the ring
        # buffer stores data and how close to realtime the data is available,
        # so check some different offsets and see if we get some data
        for offset in (3600, 2000, 1000, 500):
            try:
                _test_offset_from_realtime(offset)
            except AssertionError:
                continue
            else:
                break
        else:
            raise
예제 #6
0
 def setUp(self):
     self.client = Client("rtserver.ipgp.fr")
예제 #7
0
    def __init__(self, name, priority, server_name):
        WaveformLocation.__init__(self, name, priority)

        self.__server_name = server_name
        self.client = Client(self.__server_name)
        self.__station_info = []