本文整理汇总了Python中obspy.core.event.Event.resource_id方法的典型用法代码示例。如果您正苦于以下问题:Python Event.resource_id方法的具体用法?Python Event.resource_id怎么用?Python Event.resource_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类obspy.core.event.Event
的用法示例。
在下文中一共展示了Event.resource_id方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _parse_record_hy
# 需要导入模块: from obspy.core.event import Event [as 别名]
# 或者: from obspy.core.event.Event import resource_id [as 别名]
def _parse_record_hy(self, line):
"""
Parses the 'hypocenter' record HY
"""
date = line[2:10]
time = line[11:20]
# unused: location_quality = line[20]
latitude = self._float(line[21:27])
lat_type = line[27]
longitude = self._float(line[29:36])
lon_type = line[36]
depth = self._float(line[38:43])
# unused: depth_quality = line[43]
standard_dev = self._float(line[44:48])
station_number = self._int(line[48:51])
# unused: version_flag = line[51]
fe_region_number = line[52:55]
fe_region_name = self._decode_fe_region_number(fe_region_number)
source_code = line[55:60].strip()
event = Event()
# FIXME: a smarter way to define evid?
evid = date + time
res_id = '/'.join((res_id_prefix, 'event', evid))
event.resource_id = ResourceIdentifier(id=res_id)
description = EventDescription(
type='region name',
text=fe_region_name)
event.event_descriptions.append(description)
description = EventDescription(
type='Flinn-Engdahl region',
text=fe_region_number)
event.event_descriptions.append(description)
origin = Origin()
res_id = '/'.join((res_id_prefix, 'origin', evid))
origin.resource_id = ResourceIdentifier(id=res_id)
origin.creation_info = CreationInfo()
if source_code:
origin.creation_info.agency_id = source_code
else:
origin.creation_info.agency_id = 'USGS-NEIC'
res_id = '/'.join((res_id_prefix, 'earthmodel/ak135'))
origin.earth_model_id = ResourceIdentifier(id=res_id)
origin.time = UTCDateTime(date + time)
origin.latitude = latitude * self._coordinate_sign(lat_type)
origin.longitude = longitude * self._coordinate_sign(lon_type)
origin.depth = depth * 1000
origin.depth_type = 'from location'
origin.quality = OriginQuality()
origin.quality.associated_station_count = station_number
origin.quality.standard_error = standard_dev
# associated_phase_count can be incremented in records 'P ' and 'S '
origin.quality.associated_phase_count = 0
# depth_phase_count can be incremented in record 'S '
origin.quality.depth_phase_count = 0
origin.origin_type = 'hypocenter'
origin.region = fe_region_name
event.origins.append(origin)
return event
示例2: _parse_event
# 需要导入模块: from obspy.core.event import Event [as 别名]
# 或者: from obspy.core.event.Event import resource_id [as 别名]
def _parse_event(self, first_line):
"""
Parse an event.
:type first_line: str
:param first_line: First line of an event block, which contains
the event id.
:rtype: :class:`~obspy.core.event.event.Event`
:return: The parsed event or None.
"""
event_id = first_line[5:].strip()
# Skip event without id
if not event_id:
self._warn('Missing event id')
return None
event = Event()
origin, origin_res_id = self._parse_origin(event)
# Skip event without origin
if not origin:
return None
line = self._skip_empty_lines()
self._parse_region_name(line, event)
self._parse_arrivals(event, origin, origin_res_id)
# Origin ResourceIdentifier should be set at the end, when
# Arrivals are already set.
origin.resource_id = origin_res_id
event.origins.append(origin)
event.preferred_origin_id = origin.resource_id.id
# Must be done after the origin parsing
event.creation_info = self._get_creation_info()
public_id = "event/%s" % event_id
event.resource_id = self._get_res_id(public_id)
event.scope_resource_ids()
return event
示例3: event_to_quakeml
# 需要导入模块: from obspy.core.event import Event [as 别名]
# 或者: from obspy.core.event.Event import resource_id [as 别名]
def event_to_quakeml(event, filename):
"""
Write one of those events to QuakeML.
"""
# Create all objects.
cat = Catalog()
ev = Event()
org = Origin()
mag = Magnitude()
fm = FocalMechanism()
mt = MomentTensor()
t = Tensor()
# Link them together.
cat.append(ev)
ev.origins.append(org)
ev.magnitudes.append(mag)
ev.focal_mechanisms.append(fm)
fm.moment_tensor = mt
mt.tensor = t
# Fill values
ev.resource_id = "smi:inversion/%s" % str(event["identifier"])
org.time = event["time"]
org.longitude = event["longitude"]
org.latitude = event["latitude"]
org.depth = event["depth_in_km"] * 1000
mag.mag = event["Mw"]
mag.magnitude_type = "Mw"
t.m_rr = event["Mrr"]
t.m_tt = event["Mpp"]
t.m_pp = event["Mtt"]
t.m_rt = event["Mrt"]
t.m_rp = event["Mrp"]
t.m_tp = event["Mtp"]
cat.write(filename, format="quakeml")
示例4: _read_ndk
# 需要导入模块: from obspy.core.event import Event [as 别名]
# 或者: from obspy.core.event.Event import resource_id [as 别名]
def _read_ndk(filename, *args, **kwargs): # @UnusedVariable
"""
Reads an NDK file to a :class:`~obspy.core.event.Catalog` object.
:param filename: File or file-like object in text mode.
"""
# Read the whole file at once. While an iterator would be more efficient
# the largest NDK file out in the wild is 13.7 MB so it does not matter
# much.
if not hasattr(filename, "read"):
# Check if it exists, otherwise assume its a string.
try:
with open(filename, "rt") as fh:
data = fh.read()
except:
try:
data = filename.decode()
except:
data = str(filename)
data = data.strip()
else:
data = filename.read()
if hasattr(data, "decode"):
data = data.decode()
# Create iterator that yields lines.
def lines_iter():
prev_line = -1
while True:
next_line = data.find("\n", prev_line + 1)
if next_line < 0:
break
yield data[prev_line + 1: next_line]
prev_line = next_line
if len(data) > prev_line + 1:
yield data[prev_line + 1:]
# Use one Flinn Engdahl object for all region determinations.
fe = FlinnEngdahl()
cat = Catalog(resource_id=_get_resource_id("catalog", str(uuid.uuid4())))
# Loop over 5 lines at once.
for _i, lines in enumerate(itertools.zip_longest(*[lines_iter()] * 5)):
if None in lines:
msg = "Skipped last %i lines. Not a multiple of 5 lines." % (
lines.count(None))
warnings.warn(msg, ObsPyNDKWarning)
continue
# Parse the lines to a human readable dictionary.
try:
record = _read_lines(*lines)
except (ValueError, ObsPyNDKException):
exc = traceback.format_exc()
msg = (
"Could not parse event %i (faulty file?). Will be "
"skipped. Lines of the event:\n"
"\t%s\n"
"%s") % (_i + 1, "\n\t".join(lines), exc)
warnings.warn(msg, ObsPyNDKWarning)
continue
# Use one creation info for essentially every item.
creation_info = CreationInfo(
agency_id="GCMT",
version=record["version_code"]
)
# Use the ObsPy Flinn Engdahl region determiner as the region in the
# NDK files is oftentimes trimmed.
region = fe.get_region(record["centroid_longitude"],
record["centroid_latitude"])
# Create an event object.
event = Event(
force_resource_id=False,
event_type="earthquake",
event_type_certainty="known",
event_descriptions=[
EventDescription(text=region, type="Flinn-Engdahl region"),
EventDescription(text=record["cmt_event_name"],
type="earthquake name")
]
)
# Assemble the time for the reference origin.
try:
time = _parse_date_time(record["date"], record["time"])
except ObsPyNDKException:
msg = ("Invalid time in event %i. '%s' and '%s' cannot be "
"assembled to a valid time. Event will be skipped.") % \
(_i + 1, record["date"], record["time"])
warnings.warn(msg, ObsPyNDKWarning)
continue
# Create two origins, one with the reference latitude/longitude and
# one with the centroidal values.
ref_origin = Origin(
force_resource_id=False,
time=time,
#.........这里部分代码省略.........
示例5: __read_single_fnetmt_entry
# 需要导入模块: from obspy.core.event import Event [as 别名]
# 或者: from obspy.core.event.Event import resource_id [as 别名]
def __read_single_fnetmt_entry(line, **kwargs):
"""
Reads a single F-net moment tensor solution to a
:class:`~obspy.core.event.Event` object.
:param line: String containing moment tensor information.
:type line: str.
"""
a = line.split()
try:
ot = UTCDateTime().strptime(a[0], '%Y/%m/%d,%H:%M:%S.%f')
except ValueError:
ot = UTCDateTime().strptime(a[0], '%Y/%m/%d,%H:%M:%S')
lat, lon, depjma, magjma = map(float, a[1:5])
depjma *= 1000
region = a[5]
strike = tuple(map(int, a[6].split(';')))
dip = tuple(map(int, a[7].split(';')))
rake = tuple(map(int, a[8].split(';')))
mo = float(a[9])
depmt = float(a[10]) * 1000
magmt = float(a[11])
var_red = float(a[12])
mxx, mxy, mxz, myy, myz, mzz, unit = map(float, a[13:20])
event_name = util.gen_sc3_id(ot)
e = Event(event_type="earthquake")
e.resource_id = _get_resource_id(event_name, 'event')
# Standard JMA solution
o_jma = Origin(time=ot, latitude=lat, longitude=lon,
depth=depjma, depth_type="from location",
region=region)
o_jma.resource_id = _get_resource_id(event_name,
'origin', 'JMA')
m_jma = Magnitude(mag=magjma, magnitude_type='ML',
origin_id=o_jma.resource_id)
m_jma.resource_id = _get_resource_id(event_name,
'magnitude', 'JMA')
# MT solution
o_mt = Origin(time=ot, latitude=lat, longitude=lon,
depth=depmt, region=region,
depth_type="from moment tensor inversion")
o_mt.resource_id = _get_resource_id(event_name,
'origin', 'MT')
m_mt = Magnitude(mag=magmt, magnitude_type='Mw',
origin_id=o_mt.resource_id)
m_mt.resource_id = _get_resource_id(event_name,
'magnitude', 'MT')
foc_mec = FocalMechanism(triggering_origin_id=o_jma.resource_id)
foc_mec.resource_id = _get_resource_id(event_name,
"focal_mechanism")
nod1 = NodalPlane(strike=strike[0], dip=dip[0], rake=rake[0])
nod2 = NodalPlane(strike=strike[1], dip=dip[1], rake=rake[1])
nod = NodalPlanes(nodal_plane_1=nod1, nodal_plane_2=nod2)
foc_mec.nodal_planes = nod
tensor = Tensor(m_rr=mxx, m_tt=myy, m_pp=mzz, m_rt=mxy, m_rp=mxz, m_tp=myz)
cm = Comment(text="Basis system: North,East,Down (Jost and \
Herrmann 1989")
cm.resource_id = _get_resource_id(event_name, 'comment', 'mt')
mt = MomentTensor(derived_origin_id=o_mt.resource_id,
moment_magnitude_id=m_mt.resource_id,
scalar_moment=mo, comments=[cm],
tensor=tensor, variance_reduction=var_red)
mt.resource_id = _get_resource_id(event_name,
'moment_tensor')
foc_mec.moment_tensor = mt
e.origins = [o_jma, o_mt]
e.magnitudes = [m_jma, m_mt]
e.focal_mechanisms = [foc_mec]
e.preferred_magnitude_id = m_mt.resource_id.id
e.preferred_origin_id = o_mt.resource_id.id
e.preferred_focal_mechanism_id = foc_mec.resource_id.id
return e
示例6: build
# 需要导入模块: from obspy.core.event import Event [as 别名]
# 或者: from obspy.core.event.Event import resource_id [as 别名]
def build(self):
"""
Build an obspy moment tensor focal mech event
This makes the tensor output into an Event containing:
1) a FocalMechanism with a MomentTensor, NodalPlanes, and PrincipalAxes
2) a Magnitude of the Mw from the Tensor
Which is what we want for outputting QuakeML using
the (slightly modified) obspy code.
Input
-----
filehandle => open file OR str from filehandle.read()
Output
------
event => instance of Event() class as described above
"""
p = self.parser
event = Event(event_type='earthquake')
origin = Origin()
focal_mech = FocalMechanism()
nodal_planes = NodalPlanes()
moment_tensor = MomentTensor()
principal_ax = PrincipalAxes()
magnitude = Magnitude()
data_used = DataUsed()
creation_info = CreationInfo(agency_id='NN')
ev_mode = 'automatic'
ev_stat = 'preliminary'
evid = None
orid = None
# Parse the entire file line by line.
for n,l in enumerate(p.line):
if 'REVIEWED BY NSL STAFF' in l:
ev_mode = 'manual'
ev_stat = 'reviewed'
if 'Event ID' in l:
evid = p._id(n)
if 'Origin ID' in l:
orid = p._id(n)
if 'Ichinose' in l:
moment_tensor.category = 'regional'
if re.match(r'^\d{4}\/\d{2}\/\d{2}', l):
ev = p._event_info(n)
if 'Depth' in l:
derived_depth = p._depth(n)
if 'Mw' in l:
magnitude.mag = p._mw(n)
magnitude.magnitude_type = 'Mw'
if 'Mo' in l and 'dyne' in l:
moment_tensor.scalar_moment = p._mo(n)
if 'Percent Double Couple' in l:
moment_tensor.double_couple = p._percent(n)
if 'Percent CLVD' in l:
moment_tensor.clvd = p._percent(n)
if 'Epsilon' in l:
moment_tensor.variance = p._epsilon(n)
if 'Percent Variance Reduction' in l:
moment_tensor.variance_reduction = p._percent(n)
if 'Major Double Couple' in l and 'strike' in p.line[n+1]:
np = p._double_couple(n)
nodal_planes.nodal_plane_1 = NodalPlane(*np[0])
nodal_planes.nodal_plane_2 = NodalPlane(*np[1])
nodal_planes.preferred_plane = 1
if 'Spherical Coordinates' in l:
mt = p._mt_sphere(n)
moment_tensor.tensor = Tensor(
m_rr = mt['Mrr'],
m_tt = mt['Mtt'],
m_pp = mt['Mff'],
m_rt = mt['Mrt'],
m_rp = mt['Mrf'],
m_tp = mt['Mtf'],
)
if 'Eigenvalues and eigenvectors of the Major Double Couple' in l:
ax = p._vectors(n)
principal_ax.t_axis = Axis(ax['T']['trend'], ax['T']['plunge'], ax['T']['ev'])
principal_ax.p_axis = Axis(ax['P']['trend'], ax['P']['plunge'], ax['P']['ev'])
principal_ax.n_axis = Axis(ax['N']['trend'], ax['N']['plunge'], ax['N']['ev'])
if 'Number of Stations' in l:
data_used.station_count = p._number_of_stations(n)
if 'Maximum' in l and 'Gap' in l:
focal_mech.azimuthal_gap = p._gap(n)
if re.match(r'^Date', l):
creation_info.creation_time = p._creation_time(n)
# Creation Time
creation_info.version = orid
# Fill in magnitude values
magnitude.evaluation_mode = ev_mode
magnitude.evaluation_status = ev_stat
magnitude.creation_info = creation_info.copy()
magnitude.resource_id = self._rid(magnitude)
# Stub origin
origin.time = ev.get('time')
origin.latitude = ev.get('lat')
origin.longitude = ev.get('lon')
origin.depth = derived_depth * 1000.
origin.depth_type = "from moment tensor inversion"
#.........这里部分代码省略.........