Exemplo n.º 1
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.assertEqual(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.assertEqual(results, expected)
Exemplo n.º 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'))
Exemplo n.º 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)
Exemplo n.º 4
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'))
 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
Exemplo n.º 6
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)
Exemplo n.º 7
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')
Exemplo n.º 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)
Exemplo n.º 9
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
Exemplo n.º 10
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')
Exemplo n.º 11
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)
Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 14
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)