def _parse_qml(qml_file, evid=None): if qml_file is None: return None, None hypo = AttribDict() hypo.latitude = None hypo.longitude = None hypo.depth = None hypo.origin_time = None hypo.evid = None try: cat = read_events(qml_file) except Exception as err: logger.error(err) ssp_exit(1) if evid is not None: ev = [e for e in cat if evid in str(e.resource_id)][0] else: # just take the first event ev = cat[0] # See if there is a preferred origin... origin = ev.preferred_origin() # ...or just use the first one if origin is None: origin = ev.origins[0] hypo.origin_time = origin.time hypo.latitude = origin.latitude hypo.longitude = origin.longitude hypo.depth = origin.depth/1000. hypo.evid = ev.resource_id.id.split('/')[-1].split('=')[-1] # See if there is a focal mechanism with nodal planes try: fm = ev.focal_mechanisms[0] nodal_plane = fm.nodal_planes.nodal_plane_1 hypo.strike = nodal_plane.strike hypo.dip = nodal_plane.dip hypo.rake = nodal_plane.rake logger.info('Found focal mechanism in QuakeML file') except Exception: pass picks = [] for pck in ev.picks: pick = Pick() pick.station = pck.waveform_id.station_code pick.network = pck.waveform_id.network_code pick.channel = pck.waveform_id.channel_code if pck.waveform_id.location_code is not None: pick.location = pck.waveform_id.location_code else: pick.location = '' if pck.onset == 'emergent': pick.flag = 'E' elif pck.onset == 'impulsive': pick.flag = 'I' try: pick.phase = pck.phase_hint[0:1] except Exception: # ignore picks with no phase hint continue if pck.polarity == 'positive': pick.polarity = 'U' elif pck.polarity == 'negative': pick.polarity = 'D' pick.time = pck.time picks.append(pick) return hypo, picks