def test_origin(self): """ Test Origin object. """ filename = os.path.join(self.path, 'gse_2.0_standard.txt') catalog = _read_gse2(filename) self.assertEqual(len(catalog), 1) self.assertEqual(len(catalog[0].origins), 1) origin = catalog[0].origins[0] self.assertEqual(origin.resource_id, 'smi:local/origin/282672') self.assertEqual(origin.time, UTCDateTime('1995-01-16T07:26:52.4')) self.assertEqual(origin.time_errors.uncertainty, 12.69) self.assertEqual(origin.latitude, 39.45) self.assertEqual(origin.latitude_errors.uncertainty, None) self.assertEqual(origin.longitude, 20.44) self.assertEqual(origin.longitude_errors.uncertainty, None) self.assertEqual(origin.depth, 66800) self.assertEqual(origin.depth_errors.uncertainty, 83800) self.assertEqual(origin.depth_type, OriginDepthType('from location')) self.assertEqual(origin.time_fixed, False) self.assertEqual(origin.epicenter_fixed, False) self.assertEqual(origin.reference_system_id, None) self.assertEqual(origin.method_id, 'smi:local/method/inversion') self.assertEqual(origin.earth_model_id, None) self.assertEqual(origin.origin_type, None) self.assertEqual(origin.region, None) self.assertEqual(origin.evaluation_mode, "manual") self.assertEqual(origin.evaluation_status, None) # quality self.assertEqual(origin.quality.associated_phase_count, 9) self.assertEqual(origin.quality.used_phase_count, 9) self.assertEqual(origin.quality.associated_station_count, 8) self.assertEqual(origin.quality.used_station_count, 8) self.assertEqual(origin.quality.depth_phase_count, None) self.assertEqual(origin.quality.standard_error, 0.53) self.assertEqual(origin.quality.azimuthal_gap, 322) self.assertEqual(origin.quality.secondary_azimuthal_gap, None) self.assertEqual(origin.quality.ground_truth_level, None) self.assertEqual(origin.quality.minimum_distance, 10.56) self.assertEqual(origin.quality.maximum_distance, 78.21) self.assertEqual(origin.quality.median_distance, None) # origin uncertainty u = origin.origin_uncertainty self.assertEqual(u.horizontal_uncertainty, None) self.assertEqual(u.min_horizontal_uncertainty, 83700) self.assertEqual(u.max_horizontal_uncertainty, 93600) self.assertEqual(u.azimuth_max_horizontal_uncertainty, 27) self.assertEqual(u.confidence_ellipsoid, None) self.assertEqual(u.preferred_description, 'uncertainty ellipse') self.assertEqual(u.confidence_level, None) # creation info self.assertEqual(origin.creation_info.author, 'GSE_IDC') # comments self.assertEqual(len(origin.comments), 0) # composite times self.assertEqual(len(origin.composite_times), 0)
def _parse_first_line_origin(self, line, event, magnitudes): """ Parse the first line of origin data. :type line: str :param line: Line to parse. :type event: :class:`~obspy.core.event.event.Event` :param event: Event of the origin. :type magnitudes: list of :class:`~obspy.core.event.magnitude.Magnitude` :param magnitudes: Store magnitudes in a list to keep their positions. :rtype: :class:`~obspy.core.event.origin.Origin`, :class:`~obspy.core.event.resourceid.ResourceIdentifier` :returns: Parsed origin or None, resource identifier of the origin. """ magnitude_types = [] magnitude_values = [] magnitude_station_counts = [] fields = self.fields['line_1'] time_origin = line[fields['time']].strip() time_fixed_flag = line[fields['time_fixf']].strip() latitude = line[fields['lat']].strip() longitude = line[fields['lon']].strip() epicenter_fixed_flag = line[fields['epicenter_fixf']].strip() depth = line[fields['depth']].strip() depth_fixed_flag = line[fields['depth_fixf']].strip() phase_count = line[fields['n_def']].strip() station_count = line[fields['n_sta']].strip() azimuthal_gap = line[fields['gap']].strip() magnitude_types.append(line[fields['mag_type_1']].strip()) magnitude_values.append(line[fields['mag_1']].strip()) magnitude_station_counts.append(line[fields['mag_n_sta_1']].strip()) magnitude_types.append(line[fields['mag_type_2']].strip()) magnitude_values.append(line[fields['mag_2']].strip()) magnitude_station_counts.append(line[fields['mag_n_sta_2']].strip()) magnitude_types.append(line[fields['mag_type_3']].strip()) magnitude_values.append(line[fields['mag_3']].strip()) magnitude_station_counts.append(line[fields['mag_n_sta_3']].strip()) author = line[fields['author']].strip() origin_id = line[fields['id']].strip() origin = Origin() origin.quality = OriginQuality() try: origin.time = UTCDateTime(time_origin.replace('/', '-')) origin.latitude = float(latitude) origin.longitude = float(longitude) except (TypeError, ValueError): self._warn('Missing origin data, skipping event') return None, None origin.time_fixed = time_fixed_flag.lower() == 'f' origin.epicenter_fixed = epicenter_fixed_flag.lower() == 'f' try: # Convert value from km to m origin.depth = float(depth) * 1000 except ValueError: pass try: origin.depth_type = DEPTH_TYPES[depth_fixed_flag] except KeyError: origin.depth_type = OriginDepthType('from location') try: origin.quality.used_phase_count = int(phase_count) origin.quality.associated_phase_count = int(phase_count) except ValueError: pass try: origin.quality.used_station_count = int(station_count) origin.quality.associated_station_count = int(station_count) except ValueError: pass try: origin.quality.azimuthal_gap = float(azimuthal_gap) except ValueError: pass self.author = author origin.creation_info = self._get_creation_info() public_id = "origin/%s" % origin_id origin_res_id = self._get_res_id(public_id) for i in range(3): try: magnitude = Magnitude() magnitude.creation_info = self._get_creation_info() magnitude.magnitude_type = magnitude_types[i] magnitude.mag = float(magnitude_values[i]) magnitude.station_count = int(magnitude_station_counts[i]) magnitude.origin_id = origin_res_id magnitudes.append(magnitude) event.magnitudes.append(magnitude) except ValueError: # Magnitude can be empty but we need to keep the # position between mag1, mag2 or mag3. magnitudes.append(None) return origin, origin_res_id
from obspy.core.event import (Amplitude, Arrival, Catalog, Comment, CreationInfo, Event, EventDescription, Magnitude, Origin, OriginQuality, OriginUncertainty, Pick, ResourceIdentifier, StationMagnitude, StationMagnitudeContribution, WaveformStreamID) from obspy.core.event.header import (EvaluationMode, EventDescriptionType, EventType, EventTypeCertainty, OriginDepthType, OriginUncertaintyDescription, PickOnset, PickPolarity) from obspy.core.utcdatetime import UTCDateTime # Convert GSE2 depth flag to ObsPy depth type DEPTH_TYPES = { 'f': OriginDepthType('operator assigned'), 'd': OriginDepthType('constrained by depth phases'), } # Convert GSE2 analysis type to ObsPy evaluation modes EVALUATION_MODES = { 'm': EvaluationMode.MANUAL, 'a': EvaluationMode.AUTOMATIC, 'g': EvaluationMode.MANUAL, } # Convert GSE2 to ObsPy location methods LOCATION_METHODS = { 'i': 'inversion', 'p': 'pattern recognition', 'g': 'ground truth',