예제 #1
0
 def test_getEventDetail(self):
     """
     Testing event detail request method.
     """
     client = Client()
     # EMSC identifier
     # xml
     data = client.getEventDetail("19990817_0000001", format='xml')
     self.assertTrue(isinstance(data, basestring))
     self.assertTrue(data.startswith('<?xml'))
     # list
     data = client.getEventDetail("19990817_0000001", format='list')
     self.assertTrue(isinstance(data, list))
     # catalog
     data = client.getEventDetail("19990817_0000001", format='catalog')
     self.assertTrue(isinstance(data, Catalog))
     # QuakeML identifier
     # xml
     data = client.getEventDetail("quakeml:eu.emsc/event#19990817_0000001",
                                  format='xml')
     self.assertTrue(data.startswith('<?xml'))
     # list
     data = client.getEventDetail("quakeml:eu.emsc/event#19990817_0000001",
                                  format='list')
     self.assertTrue(isinstance(data, list))
     # catalog
     data = client.getEventDetail("quakeml:eu.emsc/event#19990817_0000001",
                                  format='catalog')
     self.assertTrue(isinstance(data, Catalog))
예제 #2
0
 def test_getEventsAsCatalog(self):
     """
     Testing event request with Catalog as output format.
     """
     client = Client()
     cat = client.getEvents(format="catalog",
                            min_depth=-700,
                            max_datetime=UTCDateTime("2005-01-01"))
     self.assertTrue(isinstance(cat, Catalog))
     # check for origin id
     self.assertTrue(cat[0].preferred_origin_id.endswith('1347097'))
예제 #3
0
 def test_getEventsAsQuakeML(self):
     """
     Testing event request with QuakeML as output format.
     """
     client = Client()
     results = client.getEvents(format="xml",
                                min_depth=-700,
                                max_datetime=UTCDateTime("2005-01-01"))
     self.assertTrue(isinstance(results, basestring))
     # check for origin id
     self.assertTrue('1347097' in results)
예제 #4
0
 def get_events(self):
     """
     Method to fetch updated list of events to use in plot.
     """
     with self.lock:
         start, end = self.stream[0].stats.starttime, self.stream[
             0].stats.endtime
     c = Client()
     events = c.getEvents(min_datetime=start,
                          max_datetime=end,
                          format="catalog",
                          min_magnitude=self.args.events)
     return events
예제 #5
0
 def test_issue531(self):
     """
     Event_type "other" has been replaced by "other event" in recent
     QuakeML version
     """
     client = Client(user='******')
     events = client.getEvents(
         minlon=-30,
         maxlon=40,
         minlat=30,
         maxlat=90,
         min_datetime=UTCDateTime(2000, 4, 11, 11, 24, 31),
         max_datetime=UTCDateTime(2000, 4, 11, 11, 24, 32),
         minmag=5.5,
         format='catalog')
     self.assertEquals(len(events), 1)
     self.assertEquals(events[0].event_type, 'other event')
예제 #6
0
 def test_saveWaveform(self):
     """
     """
     # initialize client
     client = Client(user='******')
     start = UTCDateTime(2012, 1, 1)
     end = start + 10
     with NamedTemporaryFile() as tf:
         mseedfile = tf.name
         # MiniSEED
         client.saveWaveform(mseedfile, 'BW', 'MANZ', '', 'EHZ', start, end)
         st = read(mseedfile)
         # MiniSEED may not start with Volume Index Control Headers (V)
         with open(mseedfile, 'rb') as fp:
             self.assertNotEqual(fp.read(8)[6:7], b"V")
     # ArcLink cuts on record base
     self.assertTrue(st[0].stats.starttime <= start)
     self.assertTrue(st[0].stats.endtime >= end)
     self.assertEqual(st[0].stats.network, 'BW')
     self.assertEqual(st[0].stats.station, 'MANZ')
     self.assertEqual(st[0].stats.location, '')
     self.assertEqual(st[0].stats.channel, 'EHZ')
     # Full SEED
     with NamedTemporaryFile() as tf:
         fseedfile = tf.name
         client.saveWaveform(fseedfile,
                             'BW',
                             'MANZ',
                             '',
                             'EHZ',
                             start,
                             end,
                             format='FSEED')
         st = read(fseedfile)
         # Full SEED must start with Volume Index Control Headers (V)
         with open(fseedfile, 'rb') as fp:
             self.assertEqual(fp.read(8)[6:7], b"V")
     # ArcLink cuts on record base
     self.assertTrue(st[0].stats.starttime <= start)
     self.assertTrue(st[0].stats.endtime >= end)
     self.assertEqual(st[0].stats.network, 'BW')
     self.assertEqual(st[0].stats.station, 'MANZ')
     self.assertEqual(st[0].stats.location, '')
     self.assertEqual(st[0].stats.channel, 'EHZ')
예제 #7
0
 def test_getTravelTimes(self):
     """
     Testing request method for calculating travel times.
     """
     client = Client()
     # 1
     result = client.getTravelTimes(20, 20, 10, [(48, 12)], 'ak135')
     self.assertEqual(len(result), 1)
     self.assertAlmostEqual(result[0]['P'], 356988.24732429383)
     self.assertAlmostEqual(result[0]['S'], 645775.5623471631)
     # 2
     result = client.getTravelTimes(0, 0, 10, [(120, 0), (150, 0),
                                               (180, 0)])
     self.assertEqual(len(result), 3)
     self.assertAlmostEqual(result[0]['P'], 605519.0321213702)
     self.assertAlmostEqual(result[0]['S'], 1097834.6352750373)
     self.assertAlmostEqual(result[1]['P'], 367256.0587305712)
     self.assertAlmostEqual(result[1]['S'], 665027.0583152708)
     self.assertEqual(result[2], {})
예제 #8
0
 def test_getEventsWithUTCDateTimes(self):
     """
     Testing event request method with UTCDateTimes as input parameters.
     """
     client = Client()
     # 1
     results = client.getEvents(format="list",
                                min_depth=-700,
                                max_datetime=UTCDateTime("2005-01-01"))
     expected = [{
         'author': u'EMSC',
         'event_id': u'20040312_0000026',
         'origin_id': 1347097,
         'longitude': 57.143,
         'datetime': UTCDateTime('2004-03-12T22:48:05Z'),
         'depth': -700.0,
         'magnitude': 4.4,
         'magnitude_type': u'mb',
         'latitude': 26.303,
         'flynn_region': u'SOUTHERN IRAN'
     }]
     self.assertEquals(results, expected)
     # 2
     results = client.getEvents(format="list",
                                min_depth=-700,
                                min_datetime=UTCDateTime("2004-01-01"),
                                max_datetime=UTCDateTime("2005-01-01"))
     expected = [{
         'author': u'EMSC',
         'event_id': u'20040312_0000026',
         'origin_id': 1347097,
         'longitude': 57.143,
         'datetime': UTCDateTime('2004-03-12T22:48:05Z'),
         'depth': -700.0,
         'magnitude': 4.4,
         'magnitude_type': u'mb',
         'latitude': 26.303,
         'flynn_region': u'SOUTHERN IRAN'
     }]
     self.assertEquals(results, expected)
예제 #9
0
 def test_getLatestEvents(self):
     """
     Testing request method for latest events.
     """
     client = Client()
     # xml
     data = client.getLatestEvents(5, format='xml')
     self.assertTrue(isinstance(data, basestring))
     self.assertTrue(data.startswith('<?xml'))
     # list
     data = client.getLatestEvents(5, format='list')
     self.assertTrue(isinstance(data, list))
     self.assertEquals(len(data), 5)
     # catalog
     data = client.getLatestEvents(5, format='catalog')
     self.assertTrue(isinstance(data, Catalog))
     # no given number of events should default to 10
     data = client.getLatestEvents(format='list')
     self.assertEquals(len(data), 10)
     # invalid number of events should default to 10
     data = client.getLatestEvents(num='blah', format='list')
     self.assertEquals(len(data), 10)
예제 #10
0
    def test_getLatestEvents(self):
        """
        Testing request method for latest events.

        XXX: Currently we can not rely on the length of the returned list due
            to a bug in Web Service implementation.
        """
        client = Client()
        # xml
        data = client.getLatestEvents(5, format='xml')
        self.assertTrue(isinstance(data, bytes))
        self.assertTrue(data.startswith(b'<?xml'))
        # list
        data = client.getLatestEvents(5, format='list')
        self.assertTrue(isinstance(data, list))
        # catalog
        data = client.getLatestEvents(5, format='catalog')
        self.assertTrue(isinstance(data, Catalog))
        # no given number of events should default to 10
        data = client.getLatestEvents(format='list')
        self.assertTrue(isinstance(data, list))
        # invalid number of events should default to 10
        data = client.getLatestEvents(num='blah', format='list')
        self.assertTrue(isinstance(data, list))
예제 #11
0
 def test_getInventory(self):
     """
     Testing inventory requests.
     """
     client = Client(user='******')
     dt1 = UTCDateTime("1974-01-01T00:00:00")
     dt2 = UTCDateTime("2011-01-01T00:00:00")
     # 1 - XML w/ instruments
     result = client.getInventory('GE',
                                  'SNAA',
                                  '',
                                  'BHZ',
                                  dt1,
                                  dt2,
                                  format='XML')
     self.assertTrue(result.startswith(b'<?xml'))
     self.assertTrue(b'code="GE"' in result)
     # 2 - SUDS object w/o instruments
     result = client.getInventory('GE',
                                  'SNAA',
                                  '',
                                  'BHZ',
                                  dt1,
                                  dt2,
                                  instruments=False)
     self.assertTrue(isinstance(result, object))
     self.assertEqual(result.ArclinkInventory.inventory.network._code, 'GE')
     # 3 - SUDS object w/ instruments
     result = client.getInventory('GE',
                                  'SNAA',
                                  '',
                                  'BHZ',
                                  dt1,
                                  dt2,
                                  instruments=True)
     self.assertTrue(isinstance(result, object))
     self.assertEqual(result.ArclinkInventory.inventory.network._code, 'GE')
     self.assertTrue('sensor' in result.ArclinkInventory.inventory)
     self.assertTrue('responsePAZ' in result.ArclinkInventory.inventory)
     # 4 - SUDS object with spatial filters
     client = Client(user='******')
     result = client.getInventory('GE',
                                  'SNAA',
                                  '',
                                  'BHZ',
                                  dt1,
                                  dt2,
                                  min_latitude=-72.0,
                                  max_latitude=-71.0,
                                  min_longitude=-3,
                                  max_longitude=-2)
     self.assertTrue(isinstance(result, object))
     self.assertEqual(result.ArclinkInventory.inventory.network._code, 'GE')
     # 5 - SUDS object with spatial filters with incorrect coordinates
     client = Client(user='******')
     result = client.getInventory('GE',
                                  'SNAA',
                                  '',
                                  'BHZ',
                                  dt1,
                                  dt2,
                                  min_latitude=-71.0,
                                  max_latitude=-72.0,
                                  min_longitude=-2,
                                  max_longitude=-3)
     self.assertTrue(isinstance(result, object))
     self.assertEqual(result.ArclinkInventory.inventory.network._code, 'GE')
예제 #12
0
 def test_getEventsList(self):
     """
     Testing event request method.
     """
     client = Client()
     # 1
     results = client.getEvents(format="list",
                                min_depth=-700,
                                max_datetime="2005-01-01")
     expected = [{
         'author': u'EMSC',
         'event_id': u'20040312_0000026',
         'origin_id': 1347097,
         'longitude': 57.143,
         'datetime': UTCDateTime('2004-03-12T22:48:05Z'),
         'depth': -700.0,
         'magnitude': 4.4,
         'magnitude_type': u'mb',
         'latitude': 26.303,
         'flynn_region': u'SOUTHERN IRAN'
     }]
     self.assertEquals(results, expected)
     # 2
     results = client.getEvents(format="list",
                                min_latitude=-95,
                                max_latitude=-1,
                                min_longitude=20,
                                max_longitude=90,
                                max_datetime="2005-01-01")
     expected = [{
         'author': u'NEIR',
         'event_id': u'20041016_0000009',
         'origin_id': 120690,
         'longitude': 33.682,
         'datetime': UTCDateTime('2004-10-16T01:29:14Z'),
         'depth': -10.0,
         'magnitude': 5.0,
         'magnitude_type': u'm ',
         'latitude': -46.394,
         'flynn_region': u'PRINCE EDWARD ISLANDS REGION'
     }]
     self.assertEquals(results, expected)
     # 3
     results = client.getEvents(format="list",
                                min_depth=-11,
                                max_depth=-22.33,
                                min_magnitude=6.6,
                                max_magnitude=7,
                                max_datetime="2005-01-01")
     expected = [{
         'author': u'EMSC',
         'event_id': u'20001206_0000014',
         'origin_id': 1441886,
         'longitude': 54.843,
         'datetime': UTCDateTime('2000-12-06T17:11:05Z'),
         'depth': -11.4,
         'magnitude': 6.7,
         'magnitude_type': u'mb',
         'latitude': 39.604
     }, {
         'author': u'EMSC',
         'event_id': u'20010210_0000010',
         'origin_id': 1438991,
         'longitude': 43.784,
         'datetime': UTCDateTime('2001-02-10T18:21:57Z'),
         'depth': -17.0,
         'magnitude': 6.6,
         'magnitude_type': u'mb',
         'latitude': 12.045,
         'flynn_region': u'NEAR THE COAST OF YEMEN'
     }]
     self.assertEquals(results, expected)
     # 4
     results = client.getEvents(format="list",
                                author="EMSC",
                                max_results=3,
                                magnitude_type="mw",
                                min_magnitude=4,
                                max_datetime="2005-01-01")
     expected = [{
         'author': u'EMSC',
         'event_id': u'19980110_0000006',
         'origin_id': 1500183,
         'longitude': 20.816,
         'datetime': UTCDateTime('1998-01-10T19:21:55Z'),
         'depth': -10.0,
         'magnitude': 5.5,
         'magnitude_type': u'mw',
         'latitude': 37.243,
         'flynn_region': u'IONIAN SEA'
     }, {
         'author': u'EMSC',
         'event_id': u'19980128_0000006',
         'origin_id': 1500249,
         'longitude': 32.204,
         'datetime': UTCDateTime('1998-01-28T22:38:57Z'),
         'depth': -41.6,
         'magnitude': 4.3,
         'magnitude_type': u'mw',
         'latitude': 34.429
     }, {
         'author': u'EMSC',
         'event_id': u'19980213_0000004',
         'origin_id': 1500135,
         'longitude': 28.459,
         'datetime': UTCDateTime('1998-02-13T07:18:50Z'),
         'depth': -69.2,
         'magnitude': 4.8,
         'magnitude_type': u'mw',
         'latitude': 36.284
     }]
     self.assertEquals(results, expected)
예제 #13
0
 def plotDay(self, *args, **kwargs):
     """
     Extend the seismogram.
     """
     # Merge and trim to pad.
     self.stream.merge()
     if len(self.stream) != 1:
         msg = "All traces need to be of the same id for a dayplot"
         raise ValueError(msg)
     self.stream.trim(self.starttime, self.endtime, pad=True)
     # Get minmax array.
     self.__dayplotGetMinMaxValues(self, *args, **kwargs)
     # Normalize array
     self.__dayplotNormalizeValues(self, *args, **kwargs)
     # Get timezone information. If none is  given, use local time.
     self.time_offset = kwargs.get(
         'time_offset',
         round((UTCDateTime(datetime.now()) - UTCDateTime()) / 3600.0, 2))
     self.timezone = kwargs.get('timezone', 'local time')
     # Try to guess how many steps are needed to advance one full time unit.
     self.repeat = None
     intervals = self.extreme_values.shape[0]
     if self.interval < 60 and 60 % self.interval == 0:
         self.repeat = 60 / self.interval
     elif self.interval < 1800 and 3600 % self.interval == 0:
         self.repeat = 3600 / self.interval
     # Otherwise use a maximum value of 10.
     else:
         if intervals >= 10:
             self.repeat = 10
         else:
             self.repeat = intervals
     # Create axis to plot on.
     if self.background_color:
         ax = self.fig.add_subplot(1, 1, 1, axisbg=self.background_color)
     else:
         ax = self.fig.add_subplot(1, 1, 1)
     # Adjust the subplots
     self.fig.subplots_adjust(left=self.subplots_adjust_left,
                              right=self.subplots_adjust_right,
                              top=self.subplots_adjust_top,
                              bottom=self.subplots_adjust_bottom)
     # Create x_value_array.
     aranged_array = np.arange(self.width)
     x_values = np.empty(2 * self.width)
     x_values[0::2] = aranged_array
     x_values[1::2] = aranged_array
     intervals = self.extreme_values.shape[0]
     # Loop over each step.
     for _i in xrange(intervals):
         # Create offset array.
         y_values = np.ma.empty(self.width * 2)
         y_values.fill(intervals - (_i + 1))
         # Add min and max values.
         y_values[0::2] += self.extreme_values[_i, :, 0]
         y_values[1::2] += self.extreme_values[_i, :, 1]
         # Plot the values.
         ax.plot(x_values,
                 y_values,
                 color=self.color[_i % len(self.color)],
                 linewidth=self.linewidth,
                 linestyle=self.linestyle)
     # Plot the scale, if required.
     scale_unit = kwargs.get("data_unit", None)
     if scale_unit is not None:
         self._plotDayplotScale(unit=scale_unit)
     # Set ranges.
     ax.set_xlim(0, self.width - 1)
     ax.set_ylim(-0.3, intervals + 0.3)
     self.axis = [ax]
     # Set ticks.
     self.__dayplotSetYTicks(*args, **kwargs)
     self.__dayplotSetXTicks(*args, **kwargs)
     # Choose to show grid but only on the x axis.
     self.fig.axes[0].grid(color=self.grid_color,
                           linestyle=self.grid_linestyle,
                           linewidth=self.grid_linewidth)
     self.fig.axes[0].yaxis.grid(False)
     # Set the title of the plot.
     self.fig.suptitle(self.title, fontsize=self.title_size)
     # Now try to plot some events.
     events = kwargs.get("events", [])
     # Potentially download some events with the help of obspy.neries.
     if "min_magnitude" in events:
         try:
             from obspy.neries import Client
             c = Client()
             events = c.getEvents(min_datetime=self.starttime,
                                  max_datetime=self.endtime,
                                  format="catalog",
                                  min_magnitude=events["min_magnitude"])
         except Exception, e:
             msg = "Could not download the events because of '%s: %s'." % \
                 (e.__class__.__name__, e.message)
             warnings.warn(msg)