本文整理汇总了Python中obspy.core.event.Event.preferred_origin方法的典型用法代码示例。如果您正苦于以下问题:Python Event.preferred_origin方法的具体用法?Python Event.preferred_origin怎么用?Python Event.preferred_origin使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类obspy.core.event.Event
的用法示例。
在下文中一共展示了Event.preferred_origin方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_preferred_tags
# 需要导入模块: from obspy.core.event import Event [as 别名]
# 或者: from obspy.core.event.Event import preferred_origin [as 别名]
def test_preferred_tags(self):
"""
Testing preferred magnitude, origin and focal mechanism tags
"""
# testing empty event
ev = Event()
self.assertEqual(ev.preferred_origin(), None)
self.assertEqual(ev.preferred_magnitude(), None)
self.assertEqual(ev.preferred_focal_mechanism(), None)
# testing existing event
filename = os.path.join(self.path, 'preferred.xml')
catalog = read_events(filename)
self.assertEqual(len(catalog), 1)
ev_str = "Event:\t2012-12-12T05:46:24.120000Z | +38.297, +142.373 " + \
"| 2.0 MW"
self.assertIn(ev_str, str(catalog.events[0]))
# testing ids
ev = catalog.events[0]
self.assertEqual('smi:orig2', ev.preferred_origin_id)
self.assertEqual('smi:mag2', ev.preferred_magnitude_id)
self.assertEqual('smi:fm2', ev.preferred_focal_mechanism_id)
# testing objects
self.assertEqual(ev.preferred_origin(), ev.origins[1])
self.assertEqual(ev.preferred_magnitude(), ev.magnitudes[1])
self.assertEqual(
ev.preferred_focal_mechanism(), ev.focal_mechanisms[1])
示例2: outputOBSPY
# 需要导入模块: from obspy.core.event import Event [as 别名]
# 或者: from obspy.core.event.Event import preferred_origin [as 别名]
def outputOBSPY(hp, event=None, only_fm_picks=False):
"""
Make an Event which includes the current focal mechanism information from HASH
Use the 'only_fm_picks' flag to only include the picks HASH used for the FocalMechanism.
This flag will replace the 'picks' and 'arrivals' lists of existing events with new ones.
Inputs
-------
hp : hashpy.HashPype instance
event : obspy.core.event.Event
only_fm_picks : bool of whether to overwrite the picks/arrivals lists
Returns
-------
obspy.core.event.Event
Event will be new if no event was input, FocalMech added to existing event
"""
# Returns new (or updates existing) Event with HASH solution
n = hp.npol
if event is None:
event = Event(focal_mechanisms=[], picks=[], origins=[])
origin = Origin(arrivals=[])
origin.time = UTCDateTime(hp.tstamp)
origin.latitude = hp.qlat
origin.longitude = hp.qlon
origin.depth = hp.qdep
origin.creation_info = CreationInfo(version=hp.icusp)
origin.resource_id = ResourceIdentifier('smi:hash/Origin/{0}'.format(hp.icusp))
for _i in range(n):
p = Pick()
p.creation_info = CreationInfo(version=hp.arid[_i])
p.resource_id = ResourceIdentifier('smi:hash/Pick/{0}'.format(p.creation_info.version))
p.waveform_id = WaveformStreamID(network_code=hp.snet[_i], station_code=hp.sname[_i], channel_code=hp.scomp[_i])
if hp.p_pol[_i] > 0:
p.polarity = 'positive'
else:
p.polarity = 'negative'
a = Arrival()
a.creation_info = CreationInfo(version=hp.arid[_i])
a.resource_id = ResourceIdentifier('smi:hash/Arrival/{0}'.format(p.creation_info.version))
a.azimuth = hp.p_azi_mc[_i,0]
a.takeoff_angle = 180. - hp.p_the_mc[_i,0]
a.pick_id = p.resource_id
origin.arrivals.append(a)
event.picks.append(p)
event.origins.append(origin)
event.preferred_origin_id = str(origin.resource_id)
else: # just update the changes
origin = event.preferred_origin()
picks = []
arrivals = []
for _i in range(n):
ind = hp.p_index[_i]
a = origin.arrivals[ind]
p = a.pick_id.getReferredObject()
a.takeoff_angle = hp.p_the_mc[_i,0]
picks.append(p)
arrivals.append(a)
if only_fm_picks:
origin.arrivals = arrivals
event.picks = picks
# Use me double couple calculator and populate planes/axes etc
x = hp._best_quality_index
# Put all the mechanisms into the 'focal_mechanisms' list, mark "best" as preferred
for s in range(hp.nmult):
dc = DoubleCouple([hp.str_avg[s], hp.dip_avg[s], hp.rak_avg[s]])
ax = dc.axis
focal_mech = FocalMechanism()
focal_mech.creation_info = CreationInfo(creation_time=UTCDateTime(), author=hp.author)
focal_mech.triggering_origin_id = origin.resource_id
focal_mech.resource_id = ResourceIdentifier('smi:hash/FocalMechanism/{0}/{1}'.format(hp.icusp, s+1))
focal_mech.method_id = ResourceIdentifier('HASH')
focal_mech.nodal_planes = NodalPlanes()
focal_mech.nodal_planes.nodal_plane_1 = NodalPlane(*dc.plane1)
focal_mech.nodal_planes.nodal_plane_2 = NodalPlane(*dc.plane2)
focal_mech.principal_axes = PrincipalAxes()
focal_mech.principal_axes.t_axis = Axis(azimuth=ax['T']['azimuth'], plunge=ax['T']['dip'])
focal_mech.principal_axes.p_axis = Axis(azimuth=ax['P']['azimuth'], plunge=ax['P']['dip'])
focal_mech.station_polarity_count = n
focal_mech.azimuthal_gap = hp.magap
focal_mech.misfit = hp.mfrac[s]
focal_mech.station_distribution_ratio = hp.stdr[s]
focal_mech.comments.append(
Comment(hp.qual[s], resource_id=ResourceIdentifier(str(focal_mech.resource_id) + '/comment/quality'))
)
#----------------------------------------
event.focal_mechanisms.append(focal_mech)
if s == x:
event.preferred_focal_mechanism_id = str(focal_mech.resource_id)
return event
示例3: DBToQuakemlConverter
# 需要导入模块: from obspy.core.event import Event [as 别名]
# 或者: from obspy.core.event.Event import preferred_origin [as 别名]
class DBToQuakemlConverter(AntelopeToEventConverter):
"""
Antelope -> Event converter with customizations for writing QuakeML files
Methods
-------
build(self, evid=None, orid=None, delete=False, phase_data=False, focal_data=False):
Build up an Event using various parameters
quakeml_str(): Return QuakeML string of the current Event object
quakeml_anss_attrib(self, evid=None): Construct dict of ANSS attributes
quakeml_filename(self, product): Try to construct a meaningful XML filename
"""
rid_factory = rid_function
def quakeml_anss_attrib(self, evid=None):
"""
Returns stuff necessary for quakeml files
These things are specific to a datacenter, in an effort to generalize
the actual writer function as much as possible.
Input
-----
evid : int of some event identifier to name the file
agency : str of name or code of agency creating file (netcode)
Returns : dict of the 4 ANSS 'catalog' attributes with meaningful values.
"""
agency_code = self.agency.lower()
if evid:
anss_id = '{0:08d}'.format(evid)
else:
anss_id = '00000000'
return {'datasource' : agency_code, 'dataid' : agency_code + anss_id, 'eventsource' : agency_code, 'eventid' : anss_id}
def quakeml_filename(self, product):
return self.event.extra['dataid']['value'] + '_' + product + '.xml'
def extra_anss(self, **kwargs):
"""
Create an dictionary for ANSS vars for use by event classes 'extra' attribute
Inputs
------
kwargs SHOULD be one of ('datasource','dataid','eventsource','eventid')
Returns : dict of obspy 'extra' format
"""
# in new "extra" patch, use both for now
# NOTE: Obspy 0.9.3+ should support this natively, NO PATCH!!
# - '_namespace' renamed to 'namespace'
# - '_type renamed' to 'type'
extra_attrib = {}
ns_anss = 'http://anss.org/xmlns/catalog/0.1'
self.nsmap.update({'catalog': ns_anss})
for a in kwargs:
extra_attrib[a] = {'value': kwargs[a],
'namespace': ns_anss,
'type': 'attribute'}
return extra_attrib
def build(self, evid=None, orid=None, delete=False, phase_data=False, focal_data=False):
"""
Build up an Event object
Inputs
------
evid : int of EVID
orid : int of ORID
delete : bool of whether to mark event deleted (False)
phase_data : bool of whether to include phase arrivals for event (False)
focal_data : bool of whether to look for focal mechanisms (False)
"""
#--- Build an Event based on params --------------------------------------
if evid is None and orid:
try:
evid = self._evid(orid)
except:
pass
# 1. Build a stub Event to send a delete
if delete:
self.event = Event(event_type="not existing")
self.event.creation_info = CreationInfo(version=evid, creation_time=UTCDateTime())
self.event.resource_id = self._rid(self.event)
else:
self._build(orid=orid, phases=phase_data, focals=focal_data, event_type="not reported")
# if no EVID reported, try to get it from the db (version attribute)
if not evid:
evid = int(self.event.creation_info.version)
# Add a nearest event string, try to set event type with custom etype additions
prefor = self.event.preferred_origin()
if prefor is not None:
self.event.event_type = self.origin_event_type(prefor, emap=self.emap)
ed = self.get_nearest_event_description(prefor.latitude, prefor.longitude)
self.event.event_descriptions = [ed]
# Generate NSL namespace attributes
extra_attributes = self.quakeml_anss_attrib(evid)
#.........这里部分代码省略.........
示例4: Converter
# 需要导入模块: from obspy.core.event import Event [as 别名]
# 或者: from obspy.core.event.Event import preferred_origin [as 别名]
class Converter(DBToQuakemlConverter):
"""
Custom overrides on QuakemlConverter for NSL
1) rid_factory : if RID is for an Event, use the web
URL which resolves to an actual page.
2) build : check for an 'mt' string, and run the special
converter to get an Event/FocalMech/Mag/MomentTensor out
of it...
"""
rid_factory = CustomRIDFunction()
automatic_authors = ['orbassoc', 'orbmag', 'HYPOI:rt']
def build(self, evid=None, orid=None, delete=False, phase_data=False, focal_data=False, mt=None):
"""
Build up an Event object
Inputs
------
evid : int of EVID
orid : int of ORID
delete : bool of whether to mark event deleted (False)
phase_data : bool of whether to include phase arrivals for event (False)
focal_data : bool of whether to look for focal mechanisms (False)
mt : file/contents of NSL moment tensor (Ichinose)
Returns : obspy.core.event.Event
"""
#--- Build an Event based on params --------------------------------------
if evid is None and orid:
try:
evid = self._evid(orid)
except:
pass
# 1. Build a stub Event to send a delete
if delete:
self.event = Event(event_type="not existing")
self.event.creation_info = CreationInfo(version=evid, creation_time=UTCDateTime())
self.event.resource_id = self._rid(self.event)
elif mt:
# 2. Make a custom event (mt is a special-formatted text file)
#_RIDFactory = type('RIDFactory', (CustomRIDFunction,), {'authority': self.auth_id})
self.event = mt2event(mt, rid_factory=CustomRIDFunction(self.auth_id))
# 3. Use EventBuilder to get Event from the db
else:
self._build(orid=orid, phases=phase_data, focals=focal_data, event_type="not reported")
# if no EVID reported, try to get it from the db (version attribute)
if not evid:
evid = int(self.event.creation_info.version)
# Add a nearest event string, try to set event type with custom etype additions
prefor = self.event.preferred_origin()
if prefor is not None:
event_type = self.origin_event_type(prefor, emap=self.emap)
if event_type is None:
event_type = "earthquake"
self.event.event_type = event_type
ed = self.get_nearest_event_description(prefor.latitude, prefor.longitude)
self.event.event_descriptions = [ed]
# get rid of preferred if sending focalmech, so it doesn't clobber a
# better origin (This is a hack to deal with USGS splitting QuakeML
# into different products, In theory, one should be able to have a
# QuakeML file with everything, but alas)
if focal_data:
self.event.preferred_origin_id = None
self.event.preferred_magnitude_id = None
# Generate NSL namespace attributes
extra_attributes = self.quakeml_anss_attrib(evid)
self.event.extra = self.extra_anss(**extra_attributes)