本文整理汇总了Python中obspy.core.event.Event.scope_resource_ids方法的典型用法代码示例。如果您正苦于以下问题:Python Event.scope_resource_ids方法的具体用法?Python Event.scope_resource_ids怎么用?Python Event.scope_resource_ids使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类obspy.core.event.Event
的用法示例。
在下文中一共展示了Event.scope_resource_ids方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _deserialize
# 需要导入模块: from obspy.core.event import Event [as 别名]
# 或者: from obspy.core.event.Event import scope_resource_ids [as 别名]
def _deserialize(self, zmap_str):
catalog = Catalog()
for row in zmap_str.split('\n'):
if len(row) == 0:
continue
origin = Origin()
event = Event(origins=[origin])
event.preferred_origin_id = origin.resource_id.id
# Begin value extraction
columns = row.split('\t', 13)[:13] # ignore extra columns
values = dict(zip(_STD_ZMAP_COLUMNS + _EXT_ZMAP_COLUMNS, columns))
# Extract origin
origin.longitude = self._str2num(values.get('lon'))
origin.latitude = self._str2num(values.get('lat'))
depth = self._str2num(values.get('depth'))
if depth is not None:
origin.depth = depth * 1000.0
z_err = self._str2num(values.get('z_err'))
if z_err is not None:
origin.depth_errors.uncertainty = z_err * 1000.0
h_err = self._str2num(values.get('h_err'))
if h_err is not None:
ou = OriginUncertainty()
ou.horizontal_uncertainty = h_err
ou.preferred_description = 'horizontal uncertainty'
origin.origin_uncertainty = ou
year = self._str2num(values.get('year'))
if year is not None:
t_fields = ['year', 'month', 'day', 'hour', 'minute', 'second']
comps = [self._str2num(values.get(f)) for f in t_fields]
if year % 1 != 0:
origin.time = self._decyear2utc(year)
elif any(v > 0 for v in comps[1:]):
# no seconds involved
if len(comps) < 6:
utc_args = [int(v) for v in comps if v is not None]
# we also have to handle seconds
else:
utc_args = [int(v) if v is not None else 0
for v in comps[:-1]]
# just leave float seconds as is
utc_args.append(comps[-1])
origin.time = UTCDateTime(*utc_args)
mag = self._str2num(values.get('mag'))
# Extract magnitude
if mag is not None:
magnitude = Magnitude(mag=mag)
m_err = self._str2num(values.get('m_err'))
magnitude.mag_errors.uncertainty = m_err
event.magnitudes.append(magnitude)
event.preferred_magnitude_id = magnitude.resource_id.id
event.scope_resource_ids()
catalog.append(event)
return catalog
示例2: _parse_event
# 需要导入模块: from obspy.core.event import Event [as 别名]
# 或者: from obspy.core.event.Event import scope_resource_ids [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: _read_single_hypocenter
# 需要导入模块: from obspy.core.event import Event [as 别名]
# 或者: from obspy.core.event.Event import scope_resource_ids [as 别名]
#.........这里部分代码省略.........
msg = ("Negative value in XX value of covariance matrix, not "
"setting longitude error (epicentral uncertainties will "
"still be set in origin uncertainty).")
warnings.warn(msg)
else:
raise
o.latitude = y
try:
o.latitude_errors.uncertainty = kilometer2degrees(sqrt(covariance_yy))
except ValueError:
if covariance_yy < 0:
msg = ("Negative value in YY value of covariance matrix, not "
"setting longitude error (epicentral uncertainties will "
"still be set in origin uncertainty).")
warnings.warn(msg)
else:
raise
o.depth = z * 1e3 # meters!
o.depth_errors.uncertainty = sqrt(covariance_zz) * 1e3 # meters!
o.depth_errors.confidence_level = 68
o.depth_type = str("from location")
o.time = time
ou.horizontal_uncertainty = hor_unc
ou.min_horizontal_uncertainty = min_hor_unc
ou.max_horizontal_uncertainty = max_hor_unc
# values of -1 seem to be used for unset values, set to None
for field in ("horizontal_uncertainty", "min_horizontal_uncertainty",
"max_horizontal_uncertainty"):
if ou.get(field, -1) == -1:
ou[field] = None
else:
ou[field] *= 1e3 # meters!
ou.azimuth_max_horizontal_uncertainty = hor_unc_azim
ou.preferred_description = str("uncertainty ellipse")
ou.confidence_level = 68 # NonLinLoc in general uses 1-sigma (68%) level
oq.standard_error = stderr
oq.azimuthal_gap = az_gap
oq.secondary_azimuthal_gap = sec_az_gap
oq.used_phase_count = used_phase_count
oq.used_station_count = used_station_count
oq.associated_phase_count = assoc_phase_count
oq.associated_station_count = assoc_station_count
oq.depth_phase_count = depth_phase_count
oq.ground_truth_level = gt_level
oq.minimum_distance = kilometer2degrees(min_dist)
oq.maximum_distance = kilometer2degrees(max_dist)
oq.median_distance = kilometer2degrees(med_dist)
# go through all phase info lines
for line in phases_lines:
line = line.split()
arrival = Arrival()
o.arrivals.append(arrival)
station = str(line[0])
phase = str(line[4])
arrival.phase = phase
arrival.distance = kilometer2degrees(float(line[21]))
arrival.azimuth = float(line[23])
arrival.takeoff_angle = float(line[24])
arrival.time_residual = float(line[16])
arrival.time_weight = float(line[17])
pick = Pick()
# network codes are not used by NonLinLoc, so they can not be known
# when reading the .hyp file.. to conform with QuakeML standard set an
# empty network code
wid = WaveformStreamID(network_code="", station_code=station)
# have to split this into ints for overflow to work correctly
date, hourmin, sec = map(str, line[6:9])
ymd = [int(date[:4]), int(date[4:6]), int(date[6:8])]
hm = [int(hourmin[:2]), int(hourmin[2:4])]
t = UTCDateTime(*(ymd + hm), strict=False) + float(sec)
pick.waveform_id = wid
pick.time = t
pick.time_errors.uncertainty = float(line[10])
pick.phase_hint = phase
pick.onset = ONSETS.get(line[3].lower(), None)
pick.polarity = POLARITIES.get(line[5].lower(), None)
# try to determine original pick for each arrival
for pick_ in original_picks:
wid = pick_.waveform_id
if station == wid.station_code and phase == pick_.phase_hint:
pick = pick_
break
else:
# warn if original picks were specified and we could not associate
# the arrival correctly
if original_picks:
msg = ("Could not determine corresponding original pick for "
"arrival. "
"Falling back to pick information in NonLinLoc "
"hypocenter-phase file.")
warnings.warn(msg)
event.picks.append(pick)
arrival.pick_id = pick.resource_id
event.scope_resource_ids()
return event
示例4: _internal_read_single_fnetmt_entry
# 需要导入模块: from obspy.core.event import Event [as 别名]
# 或者: from obspy.core.event.Event import scope_resource_ids [as 别名]
def _internal_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
e.scope_resource_ids()
return e
示例5: _internal_read_single_cmtsolution
# 需要导入模块: from obspy.core.event import Event [as 别名]
# 或者: from obspy.core.event.Event import scope_resource_ids [as 别名]
#.........这里部分代码省略.........
for _i in values}
# Moment magnitude calculation in dyne * cm.
m_0 = 1.0 / math.sqrt(2.0) * math.sqrt(
cmt_values["m_rr"] ** 2 +
cmt_values["m_tt"] ** 2 +
cmt_values["m_pp"] ** 2 +
2.0 * cmt_values["m_rt"] ** 2 +
2.0 * cmt_values["m_rp"] ** 2 +
2.0 * cmt_values["m_tp"] ** 2)
m_w = 2.0 / 3.0 * (math.log10(m_0) - 16.1)
# Convert to meters.
cmt_values["depth"] *= 1000.0
# Convert to Newton meter.
values = ["m_rr", "m_tt", "m_pp", "m_rt", "m_rp", "m_tp"]
for value in values:
cmt_values[value] /= 1E7
cmt_origin = Origin(
resource_id=_get_resource_id(event_name, "origin", tag="cmt"),
time=origin_time + cmt_values["time_shift"],
longitude=cmt_values["longitude"],
latitude=cmt_values["latitude"],
depth=cmt_values["depth"],
origin_type="centroid",
# Could rarely be different than the epicentral region.
region=_fe.get_region(longitude=cmt_values["longitude"],
latitude=cmt_values["latitude"])
# No evaluation status as it could be any of several and the file
# format does not provide that information.
)
cmt_mag = Magnitude(
resource_id=_get_resource_id(event_name, "magnitude", tag="mw"),
# Round to 2 digits.
mag=round(m_w, 2),
magnitude_type="mw",
origin_id=cmt_origin.resource_id
)
foc_mec = FocalMechanism(
resource_id=_get_resource_id(event_name, "focal_mechanism"),
# The preliminary origin most likely triggered the focal mechanism
# determination.
triggering_origin_id=preliminary_origin.resource_id
)
tensor = Tensor(
m_rr=cmt_values["m_rr"],
m_pp=cmt_values["m_pp"],
m_tt=cmt_values["m_tt"],
m_rt=cmt_values["m_rt"],
m_rp=cmt_values["m_rp"],
m_tp=cmt_values["m_tp"]
)
# Source time function is a triangle, according to the SPECFEM manual.
stf = SourceTimeFunction(
type="triangle",
# The duration is twice the half duration.
duration=2.0 * cmt_values["half_duration"]
)
mt = MomentTensor(
resource_id=_get_resource_id(event_name, "moment_tensor"),
derived_origin_id=cmt_origin.resource_id,
moment_magnitude_id=cmt_mag.resource_id,
# Convert to Nm.
scalar_moment=m_0 / 1E7,
tensor=tensor,
source_time_function=stf
)
# Assemble everything.
foc_mec.moment_tensor = mt
ev = Event(resource_id=_get_resource_id(event_name, "event"),
event_type="earthquake")
ev.event_descriptions.append(EventDescription(text=event_name,
type="earthquake name"))
ev.comments.append(Comment(
text="Hypocenter catalog: %s" % hypocenter_catalog,
force_resource_id=False))
ev.origins.append(cmt_origin)
ev.origins.append(preliminary_origin)
ev.magnitudes.append(cmt_mag)
ev.magnitudes.append(preliminary_bw_magnitude)
ev.magnitudes.append(preliminary_sw_magnitude)
ev.focal_mechanisms.append(foc_mec)
# Set the preferred items.
ev.preferred_origin_id = cmt_origin.resource_id.id
ev.preferred_magnitude_id = cmt_mag.resource_id.id
ev.preferred_focal_mechanism_id = foc_mec.resource_id.id
ev.scope_resource_ids()
return ev
示例6: _internal_read_single_scardec
# 需要导入模块: from obspy.core.event import Event [as 别名]
# 或者: from obspy.core.event.Event import scope_resource_ids [as 别名]
#.........这里部分代码省略.........
latitude=latitude)
)
cmt_mag = Magnitude(
resource_id=_get_resource_id(event_name, "magnitude", tag="mw"),
mag=moment_mag,
magnitude_type="mw",
origin_id=cmt_origin.resource_id
)
nod1 = NodalPlane(strike=strike1, dip=dip1, rake=rake1)
nod2 = NodalPlane(strike=strike2, dip=dip2, rake=rake2)
nod = NodalPlanes(nodal_plane_1=nod1, nodal_plane_2=nod2)
foc_mec = FocalMechanism(
resource_id=_get_resource_id(event_name, "focal_mechanism"),
nodal_planes=nod
)
dip1 *= np.pi / 180.
rake1 *= np.pi / 180.
strike1 *= np.pi / 180.
mxx = - scalar_moment * ((np.sin(dip1) * np.cos(rake1) *
np.sin(2 * strike1)) +
(np.sin(2 * dip1) * np.sin(rake1) *
np.sin(2 * strike1)))
mxy = scalar_moment * ((np.sin(dip1) * np.cos(rake1) *
np.cos(2 * strike1)) +
(np.sin(2 * dip1) * np.sin(rake1) *
np.sin(2 * strike1) * 0.5))
myy = scalar_moment * ((np.sin(dip1) * np.cos(rake1) *
np.sin(2 * strike1)) -
(np.sin(2 * dip1) * np.sin(rake1) *
np.cos(2 * strike1)))
mxz = - scalar_moment * ((np.cos(dip1) * np.cos(rake1) *
np.cos(strike1)) +
(np.cos(2 * dip1) * np.sin(rake1) *
np.sin(strike1)))
myz = - scalar_moment * ((np.cos(dip1) * np.cos(rake1) *
np.sin(strike1)) -
(np.cos(2 * dip1) * np.sin(rake1) *
np.cos(strike1)))
mzz = scalar_moment * (np.sin(2 * dip1) * np.sin(rake1))
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[0].resource_id = _get_resource_id(event_name, 'comment', 'mt')
cm.append(Comment(text="MT derived from focal mechanism, therefore \
constrained to pure double couple.",
force_resource_id=False))
# Write moment rate function
extra = {'moment_rate': {'value': stf_mr,
'namespace': r"http://test.org/xmlns/0.1"},
'dt': {'value': dt,
'namespace': r"http://test.org/xmlns/0.1"},
'offset': {'value': offset,
'namespace': r"http://test.org/xmlns/0.1"}
}
# Source time function
stf = SourceTimeFunction(type="unknown")
stf.extra = extra
mt = MomentTensor(
resource_id=_get_resource_id(event_name, "moment_tensor"),
derived_origin_id=cmt_origin.resource_id,
moment_magnitude_id=cmt_mag.resource_id,
scalar_moment=scalar_moment,
tensor=tensor,
source_time_function=stf,
comments=cm
)
# Assemble everything.
foc_mec.moment_tensor = mt
ev = Event(resource_id=_get_resource_id(event_name, "event"),
event_type="earthquake")
ev.event_descriptions.append(EventDescription(text=event_name,
type="earthquake name"))
ev.comments.append(Comment(
text="Hypocenter catalog: SCARDEC",
force_resource_id=False))
ev.origins.append(cmt_origin)
ev.magnitudes.append(cmt_mag)
ev.focal_mechanisms.append(foc_mec)
# Set the preferred items.
ev.preferred_origin_id = cmt_origin.resource_id.id
ev.preferred_magnitude_id = cmt_mag.resource_id.id
ev.preferred_focal_mechanism_id = foc_mec.resource_id.id
ev.scope_resource_ids()
return ev