repository_name stringlengths 5 67 | func_path_in_repository stringlengths 4 234 | func_name stringlengths 0 314 | whole_func_string stringlengths 52 3.87M | language stringclasses 6
values | func_code_string stringlengths 39 1.84M | func_code_tokens listlengths 15 672k | func_documentation_string stringlengths 1 47.2k | func_documentation_tokens listlengths 1 3.92k | split_name stringclasses 1
value | func_code_url stringlengths 85 339 |
|---|---|---|---|---|---|---|---|---|---|---|
gem/oq-engine | openquake/hmtk/sources/complex_fault_source.py | mtkComplexFaultSource._get_minmax_edges | def _get_minmax_edges(self, edge):
'''
Updates the upper and lower depths based on the input edges
'''
if isinstance(edge, Line):
# For instance of line class need to loop over values
depth_vals = np.array([node.depth for node in edge.points])
else:
... | python | def _get_minmax_edges(self, edge):
if isinstance(edge, Line):
depth_vals = np.array([node.depth for node in edge.points])
else:
depth_vals = edge[:, 2]
temp_upper_depth = np.min(depth_vals)
if not self.upper_depth:
self.upper_dep... | [
"def",
"_get_minmax_edges",
"(",
"self",
",",
"edge",
")",
":",
"if",
"isinstance",
"(",
"edge",
",",
"Line",
")",
":",
"# For instance of line class need to loop over values",
"depth_vals",
"=",
"np",
".",
"array",
"(",
"[",
"node",
".",
"depth",
"for",
"node... | Updates the upper and lower depths based on the input edges | [
"Updates",
"the",
"upper",
"and",
"lower",
"depths",
"based",
"on",
"the",
"input",
"edges"
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hmtk/sources/complex_fault_source.py#L153-L175 |
gem/oq-engine | openquake/hmtk/sources/complex_fault_source.py | mtkComplexFaultSource.create_oqhazardlib_source | def create_oqhazardlib_source(self, tom, mesh_spacing, use_defaults=False):
"""
Creates an instance of the source model as :class:
openquake.hazardlib.source.complex_fault.ComplexFaultSource
"""
if not self.mfd:
raise ValueError("Cannot write to hazardlib without MFD"... | python | def create_oqhazardlib_source(self, tom, mesh_spacing, use_defaults=False):
if not self.mfd:
raise ValueError("Cannot write to hazardlib without MFD")
return ComplexFaultSource(
self.id,
self.name,
self.trt,
self.mfd,
mesh_... | [
"def",
"create_oqhazardlib_source",
"(",
"self",
",",
"tom",
",",
"mesh_spacing",
",",
"use_defaults",
"=",
"False",
")",
":",
"if",
"not",
"self",
".",
"mfd",
":",
"raise",
"ValueError",
"(",
"\"Cannot write to hazardlib without MFD\"",
")",
"return",
"ComplexFau... | Creates an instance of the source model as :class:
openquake.hazardlib.source.complex_fault.ComplexFaultSource | [
"Creates",
"an",
"instance",
"of",
"the",
"source",
"model",
"as",
":",
"class",
":",
"openquake",
".",
"hazardlib",
".",
"source",
".",
"complex_fault",
".",
"ComplexFaultSource"
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hmtk/sources/complex_fault_source.py#L225-L242 |
gem/oq-engine | openquake/hazardlib/gsim/kotha_2016.py | KothaEtAl2016.get_mean_and_stddevs | def get_mean_and_stddevs(self, sites, rup, dists, imt, stddev_types):
"""
See :meth:`superclass method
<.base.GroundShakingIntensityModel.get_mean_and_stddevs>`
for spec of input and result values.
"""
# extracting dictionary of coefficients specific to required
#... | python | def get_mean_and_stddevs(self, sites, rup, dists, imt, stddev_types):
C = self.COEFFS[imt]
mean = (self._get_magnitude_term(C, rup.mag) +
self._get_distance_term(C, dists.rjb, rup.mag) +
self._get_site_term(C, sites.vs30))
... | [
"def",
"get_mean_and_stddevs",
"(",
"self",
",",
"sites",
",",
"rup",
",",
"dists",
",",
"imt",
",",
"stddev_types",
")",
":",
"# extracting dictionary of coefficients specific to required",
"# intensity measure type.",
"C",
"=",
"self",
".",
"COEFFS",
"[",
"imt",
"... | See :meth:`superclass method
<.base.GroundShakingIntensityModel.get_mean_and_stddevs>`
for spec of input and result values. | [
"See",
":",
"meth",
":",
"superclass",
"method",
"<",
".",
"base",
".",
"GroundShakingIntensityModel",
".",
"get_mean_and_stddevs",
">",
"for",
"spec",
"of",
"input",
"and",
"result",
"values",
"."
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/gsim/kotha_2016.py#L74-L99 |
gem/oq-engine | openquake/hazardlib/gsim/kotha_2016.py | KothaEtAl2016._get_magnitude_term | def _get_magnitude_term(self, C, mag):
"""
Returns the magnitude scaling term - equation 3
"""
if mag >= self.CONSTS["Mh"]:
return C["e1"] + C["b3"] * (mag - self.CONSTS["Mh"])
else:
return C["e1"] + (C["b1"] * (mag - self.CONSTS["Mh"])) +\
... | python | def _get_magnitude_term(self, C, mag):
if mag >= self.CONSTS["Mh"]:
return C["e1"] + C["b3"] * (mag - self.CONSTS["Mh"])
else:
return C["e1"] + (C["b1"] * (mag - self.CONSTS["Mh"])) +\
(C["b2"] * (mag - self.CONSTS["Mh"]) ** 2.) | [
"def",
"_get_magnitude_term",
"(",
"self",
",",
"C",
",",
"mag",
")",
":",
"if",
"mag",
">=",
"self",
".",
"CONSTS",
"[",
"\"Mh\"",
"]",
":",
"return",
"C",
"[",
"\"e1\"",
"]",
"+",
"C",
"[",
"\"b3\"",
"]",
"*",
"(",
"mag",
"-",
"self",
".",
"C... | Returns the magnitude scaling term - equation 3 | [
"Returns",
"the",
"magnitude",
"scaling",
"term",
"-",
"equation",
"3"
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/gsim/kotha_2016.py#L101-L109 |
gem/oq-engine | openquake/hazardlib/gsim/kotha_2016.py | KothaEtAl2016._get_distance_term | def _get_distance_term(self, C, rjb, mag):
"""
Returns the general distance scaling term - equation 2
"""
c_3 = self._get_anelastic_coeff(C)
rval = np.sqrt(rjb ** 2. + C["h"] ** 2.)
return (C["c1"] + C["c2"] * (mag - self.CONSTS["Mref"])) *\
np.log(rval / self... | python | def _get_distance_term(self, C, rjb, mag):
c_3 = self._get_anelastic_coeff(C)
rval = np.sqrt(rjb ** 2. + C["h"] ** 2.)
return (C["c1"] + C["c2"] * (mag - self.CONSTS["Mref"])) *\
np.log(rval / self.CONSTS["Rref"]) +\
c_3 * (rval - self.CONSTS["Rref"]) | [
"def",
"_get_distance_term",
"(",
"self",
",",
"C",
",",
"rjb",
",",
"mag",
")",
":",
"c_3",
"=",
"self",
".",
"_get_anelastic_coeff",
"(",
"C",
")",
"rval",
"=",
"np",
".",
"sqrt",
"(",
"rjb",
"**",
"2.",
"+",
"C",
"[",
"\"h\"",
"]",
"**",
"2.",... | Returns the general distance scaling term - equation 2 | [
"Returns",
"the",
"general",
"distance",
"scaling",
"term",
"-",
"equation",
"2"
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/gsim/kotha_2016.py#L111-L119 |
gem/oq-engine | openquake/hazardlib/gsim/kotha_2016.py | KothaEtAl2016._get_site_term | def _get_site_term(self, C, vs30):
"""
Returns only a linear site amplification term
"""
dg1, dg2 = self._get_regional_site_term(C)
return (C["g1"] + dg1) + (C["g2"] + dg2) * np.log(vs30) | python | def _get_site_term(self, C, vs30):
dg1, dg2 = self._get_regional_site_term(C)
return (C["g1"] + dg1) + (C["g2"] + dg2) * np.log(vs30) | [
"def",
"_get_site_term",
"(",
"self",
",",
"C",
",",
"vs30",
")",
":",
"dg1",
",",
"dg2",
"=",
"self",
".",
"_get_regional_site_term",
"(",
"C",
")",
"return",
"(",
"C",
"[",
"\"g1\"",
"]",
"+",
"dg1",
")",
"+",
"(",
"C",
"[",
"\"g2\"",
"]",
"+",... | Returns only a linear site amplification term | [
"Returns",
"only",
"a",
"linear",
"site",
"amplification",
"term"
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/gsim/kotha_2016.py#L128-L133 |
gem/oq-engine | openquake/hazardlib/gsim/tusa_langer_2016.py | TusaLanger2016RepiBA08SE._get_stddevs | def _get_stddevs(self, C, stddev_types, num_sites):
"""
Return standard deviations as defined in tables below
"""
assert all(stddev_type in self.DEFINED_FOR_STANDARD_DEVIATION_TYPES
for stddev_type in stddev_types)
stddevs = [np.zeros(num_sites) + C['SigmaTot'] for _ ... | python | def _get_stddevs(self, C, stddev_types, num_sites):
assert all(stddev_type in self.DEFINED_FOR_STANDARD_DEVIATION_TYPES
for stddev_type in stddev_types)
stddevs = [np.zeros(num_sites) + C['SigmaTot'] for _ in stddev_types]
return stddevs | [
"def",
"_get_stddevs",
"(",
"self",
",",
"C",
",",
"stddev_types",
",",
"num_sites",
")",
":",
"assert",
"all",
"(",
"stddev_type",
"in",
"self",
".",
"DEFINED_FOR_STANDARD_DEVIATION_TYPES",
"for",
"stddev_type",
"in",
"stddev_types",
")",
"stddevs",
"=",
"[",
... | Return standard deviations as defined in tables below | [
"Return",
"standard",
"deviations",
"as",
"defined",
"in",
"tables",
"below"
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/gsim/tusa_langer_2016.py#L112-L119 |
gem/oq-engine | openquake/hazardlib/gsim/tusa_langer_2016.py | TusaLanger2016RepiBA08SE._get_site_type_dummy_variables | def _get_site_type_dummy_variables(self, sites):
"""
Get site type dummy variables, which classified the sites into
different site classes based on the shear wave velocity in the
upper 30 m (Vs30) according to the EC8 (CEN 2003):
class A: Vs30 > 800 m/s
class B: Vs30 = 36... | python | def _get_site_type_dummy_variables(self, sites):
ssa = np.zeros(len(sites.vs30))
ssb = np.zeros(len(sites.vs30))
ssd = np.zeros(len(sites.vs30))
idx = (sites.vs30 < 180.0)
ssd[idx] = 1.0
idx = (sites.vs30 >= 360.0) & (sites.vs30 < 800.0)
... | [
"def",
"_get_site_type_dummy_variables",
"(",
"self",
",",
"sites",
")",
":",
"ssa",
"=",
"np",
".",
"zeros",
"(",
"len",
"(",
"sites",
".",
"vs30",
")",
")",
"ssb",
"=",
"np",
".",
"zeros",
"(",
"len",
"(",
"sites",
".",
"vs30",
")",
")",
"ssd",
... | Get site type dummy variables, which classified the sites into
different site classes based on the shear wave velocity in the
upper 30 m (Vs30) according to the EC8 (CEN 2003):
class A: Vs30 > 800 m/s
class B: Vs30 = 360 - 800 m/s
class C*: Vs30 = 180 - 360 m/s
class D: V... | [
"Get",
"site",
"type",
"dummy",
"variables",
"which",
"classified",
"the",
"sites",
"into",
"different",
"site",
"classes",
"based",
"on",
"the",
"shear",
"wave",
"velocity",
"in",
"the",
"upper",
"30",
"m",
"(",
"Vs30",
")",
"according",
"to",
"the",
"EC8... | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/gsim/tusa_langer_2016.py#L148-L177 |
gem/oq-engine | openquake/hazardlib/gsim/tusa_langer_2016.py | TusaLanger2016RepiSP87SE._compute_distance | def _compute_distance(self, rup, dists, C):
"""
Compute the distance function, equation (5).
"""
rval = np.sqrt(dists.repi ** 2 + C['h'] ** 2)
return C['c1'] * np.log10(rval) | python | def _compute_distance(self, rup, dists, C):
rval = np.sqrt(dists.repi ** 2 + C['h'] ** 2)
return C['c1'] * np.log10(rval) | [
"def",
"_compute_distance",
"(",
"self",
",",
"rup",
",",
"dists",
",",
"C",
")",
":",
"rval",
"=",
"np",
".",
"sqrt",
"(",
"dists",
".",
"repi",
"**",
"2",
"+",
"C",
"[",
"'h'",
"]",
"**",
"2",
")",
"return",
"C",
"[",
"'c1'",
"]",
"*",
"np"... | Compute the distance function, equation (5). | [
"Compute",
"the",
"distance",
"function",
"equation",
"(",
"5",
")",
"."
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/gsim/tusa_langer_2016.py#L256-L261 |
gem/oq-engine | openquake/hazardlib/gsim/tusa_langer_2016.py | TusaLanger2016Rhypo._compute_distance | def _compute_distance(self, rup, dists, C):
"""
Compute the distance function, equation (9):
"""
mref = 3.6
rref = 1.0
rval = np.sqrt(dists.rhypo ** 2 + C['h'] ** 2)
return (C['c1'] + C['c2'] * (rup.mag - mref)) *\
np.log10(rval / rref) + C['c3'] * (rv... | python | def _compute_distance(self, rup, dists, C):
mref = 3.6
rref = 1.0
rval = np.sqrt(dists.rhypo ** 2 + C['h'] ** 2)
return (C['c1'] + C['c2'] * (rup.mag - mref)) *\
np.log10(rval / rref) + C['c3'] * (rval - rref) | [
"def",
"_compute_distance",
"(",
"self",
",",
"rup",
",",
"dists",
",",
"C",
")",
":",
"mref",
"=",
"3.6",
"rref",
"=",
"1.0",
"rval",
"=",
"np",
".",
"sqrt",
"(",
"dists",
".",
"rhypo",
"**",
"2",
"+",
"C",
"[",
"'h'",
"]",
"**",
"2",
")",
"... | Compute the distance function, equation (9): | [
"Compute",
"the",
"distance",
"function",
"equation",
"(",
"9",
")",
":"
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/gsim/tusa_langer_2016.py#L353-L361 |
gem/oq-engine | openquake/hazardlib/gsim/dowrickrhoades_2005.py | DowrickRhoades2005Asc.get_mean_and_stddevs | def get_mean_and_stddevs(self, sites, rup, dists, imt, stddev_types):
"""
See :meth:`superclass method
<.base.GroundShakingIntensityModel.get_mean_and_stddevs>`
for spec of input and result values.
"""
assert all(stddev_type in self.DEFINED_FOR_STANDARD_DEVIATION_TYPES
... | python | def get_mean_and_stddevs(self, sites, rup, dists, imt, stddev_types):
assert all(stddev_type in self.DEFINED_FOR_STANDARD_DEVIATION_TYPES
for stddev_type in stddev_types)
C = self.COEFFS[imt]
delta_R, delta_S, delta_V, delta_I = self._get_... | [
"def",
"get_mean_and_stddevs",
"(",
"self",
",",
"sites",
",",
"rup",
",",
"dists",
",",
"imt",
",",
"stddev_types",
")",
":",
"assert",
"all",
"(",
"stddev_type",
"in",
"self",
".",
"DEFINED_FOR_STANDARD_DEVIATION_TYPES",
"for",
"stddev_type",
"in",
"stddev_typ... | See :meth:`superclass method
<.base.GroundShakingIntensityModel.get_mean_and_stddevs>`
for spec of input and result values. | [
"See",
":",
"meth",
":",
"superclass",
"method",
"<",
".",
"base",
".",
"GroundShakingIntensityModel",
".",
"get_mean_and_stddevs",
">",
"for",
"spec",
"of",
"input",
"and",
"result",
"values",
"."
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/gsim/dowrickrhoades_2005.py#L74-L96 |
gem/oq-engine | openquake/hazardlib/gsim/dowrickrhoades_2005.py | DowrickRhoades2005Asc._compute_mean | def _compute_mean(self, C, mag, rrup, hypo_depth, delta_R, delta_S,
delta_V, delta_I, vs30):
"""
Compute MMI Intensity Value as per Equation in Table 5 and
Table 7 pag 198.
"""
# mean is calculated for all the 4 classes using the same equation.
# Fo... | python | def _compute_mean(self, C, mag, rrup, hypo_depth, delta_R, delta_S,
delta_V, delta_I, vs30):
mean = (C['A1'] + (C['A2'] + C['A2R'] * delta_R + C['A2V'] * delta_V) *
mag + (C['A3'] + C['A3S'] * delta_S + C['A3V'] * delta_V) *
... | [
"def",
"_compute_mean",
"(",
"self",
",",
"C",
",",
"mag",
",",
"rrup",
",",
"hypo_depth",
",",
"delta_R",
",",
"delta_S",
",",
"delta_V",
",",
"delta_I",
",",
"vs30",
")",
":",
"# mean is calculated for all the 4 classes using the same equation.",
"# For DowrickRho... | Compute MMI Intensity Value as per Equation in Table 5 and
Table 7 pag 198. | [
"Compute",
"MMI",
"Intensity",
"Value",
"as",
"per",
"Equation",
"in",
"Table",
"5",
"and",
"Table",
"7",
"pag",
"198",
"."
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/gsim/dowrickrhoades_2005.py#L98-L120 |
gem/oq-engine | openquake/hazardlib/gsim/dowrickrhoades_2005.py | DowrickRhoades2005Asc._get_stddevs | def _get_stddevs(self, C, stddev_types, num_sites):
"""
Return total standard deviation as described in paragraph 5.2 pag 200.
"""
# interevent stddev
sigma_inter = C['tau'] + np.zeros(num_sites)
# intraevent std
sigma_intra = C['sigma'] + np.zeros(num_sites)
... | python | def _get_stddevs(self, C, stddev_types, num_sites):
sigma_inter = C['tau'] + np.zeros(num_sites)
sigma_intra = C['sigma'] + np.zeros(num_sites)
std = []
for stddev_type in stddev_types:
if stddev_type == const.StdDev.TOTAL:
... | [
"def",
"_get_stddevs",
"(",
"self",
",",
"C",
",",
"stddev_types",
",",
"num_sites",
")",
":",
"# interevent stddev",
"sigma_inter",
"=",
"C",
"[",
"'tau'",
"]",
"+",
"np",
".",
"zeros",
"(",
"num_sites",
")",
"# intraevent std",
"sigma_intra",
"=",
"C",
"... | Return total standard deviation as described in paragraph 5.2 pag 200. | [
"Return",
"total",
"standard",
"deviation",
"as",
"described",
"in",
"paragraph",
"5",
".",
"2",
"pag",
"200",
"."
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/gsim/dowrickrhoades_2005.py#L122-L143 |
gem/oq-engine | openquake/hazardlib/gsim/dowrickrhoades_2005.py | DowrickRhoades2005Asc._get_site_class | def _get_site_class(self, vs30, mmi_mean):
"""
Return site class flag for:
Class E - Very Soft Soil vs30 < 180
Class D - Deep or Soft Soil vs30 >= 180 and vs30 <= 360
Class C - Shallow Soil vs30 > 360 and vs30 <= 760
Class B - Rock vs3... | python | def _get_site_class(self, vs30, mmi_mean):
if vs30[0] < 180:
c1 = 1.0
c2 = -0.25
d = 0.5
elif vs30[0] >= 180 and vs30[0] <= 360:
c1 = 0.5
c2 = -0.125
d = 0.25
elif vs30[0] > 360 and vs30[0] <= 760:
c1 =... | [
"def",
"_get_site_class",
"(",
"self",
",",
"vs30",
",",
"mmi_mean",
")",
":",
"if",
"vs30",
"[",
"0",
"]",
"<",
"180",
":",
"c1",
"=",
"1.0",
"c2",
"=",
"-",
"0.25",
"d",
"=",
"0.5",
"elif",
"vs30",
"[",
"0",
"]",
">=",
"180",
"and",
"vs30",
... | Return site class flag for:
Class E - Very Soft Soil vs30 < 180
Class D - Deep or Soft Soil vs30 >= 180 and vs30 <= 360
Class C - Shallow Soil vs30 > 360 and vs30 <= 760
Class B - Rock vs30 > 760 and vs30 <= 1500
Class A - Strong Rock ... | [
"Return",
"site",
"class",
"flag",
"for",
":",
"Class",
"E",
"-",
"Very",
"Soft",
"Soil",
"vs30",
"<",
"180",
"Class",
"D",
"-",
"Deep",
"or",
"Soft",
"Soil",
"vs30",
">",
"=",
"180",
"and",
"vs30",
"<",
"=",
"360",
"Class",
"C",
"-",
"Shallow",
... | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/gsim/dowrickrhoades_2005.py#L145-L190 |
gem/oq-engine | openquake/hazardlib/gsim/dowrickrhoades_2005.py | DowrickRhoades2005Asc._get_deltas | def _get_deltas(self, rake):
"""
Return the value of deltas (delta_R, delta_S, delta_V, delta_I),
as defined in "Table 5: Model 1" pag 198
"""
# delta_R = 1 for reverse focal mechanism (45<rake<135)
# and for interface events, 0 for all other events
# delta_S = 1 ... | python | def _get_deltas(self, rake):
delta_R, delta_S = 0, 0
delta_V, delta_I = 0, 0
if rake > 45.0 and rake < 135.0:
delta_R = 1
if (rake >= 0.0 and rake <= 45.0) or \
(rake >= 135 and rake <= 180... | [
"def",
"_get_deltas",
"(",
"self",
",",
"rake",
")",
":",
"# delta_R = 1 for reverse focal mechanism (45<rake<135)",
"# and for interface events, 0 for all other events",
"# delta_S = 1 for Strike-slip focal mechanisms (0<=rake<=45) or",
"# (135<=rake<=180) or (-45<=rake<=0), 0 for all other e... | Return the value of deltas (delta_R, delta_S, delta_V, delta_I),
as defined in "Table 5: Model 1" pag 198 | [
"Return",
"the",
"value",
"of",
"deltas",
"(",
"delta_R",
"delta_S",
"delta_V",
"delta_I",
")",
"as",
"defined",
"in",
"Table",
"5",
":",
"Model",
"1",
"pag",
"198"
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/gsim/dowrickrhoades_2005.py#L192-L218 |
gem/oq-engine | openquake/hazardlib/gsim/dowrickrhoades_2005.py | DowrickRhoades2005SSlab._get_deltas | def _get_deltas(self, rake):
"""
Return the value of deltas (delta_R, delta_S, delta_V, delta_I),
as defined in "Table 5: Model 1" pag 198
"""
# All deltas = 0 for DowrickRhoades2005SSlab Model 3: Deep Region,
# pag 198
delta_R, delta_S = 0, 0
delta_V, de... | python | def _get_deltas(self, rake):
delta_R, delta_S = 0, 0
delta_V, delta_I = 0, 0
return delta_R, delta_S, delta_V, delta_I | [
"def",
"_get_deltas",
"(",
"self",
",",
"rake",
")",
":",
"# All deltas = 0 for DowrickRhoades2005SSlab Model 3: Deep Region,",
"# pag 198",
"delta_R",
",",
"delta_S",
"=",
"0",
",",
"0",
"delta_V",
",",
"delta_I",
"=",
"0",
",",
"0",
"return",
"delta_R",
",",
"... | Return the value of deltas (delta_R, delta_S, delta_V, delta_I),
as defined in "Table 5: Model 1" pag 198 | [
"Return",
"the",
"value",
"of",
"deltas",
"(",
"delta_R",
"delta_S",
"delta_V",
"delta_I",
")",
"as",
"defined",
"in",
"Table",
"5",
":",
"Model",
"1",
"pag",
"198"
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/gsim/dowrickrhoades_2005.py#L273-L284 |
gem/oq-engine | openquake/commands/plot_assets.py | plot_assets | def plot_assets(calc_id=-1, site_model=False):
"""
Plot the sites and the assets
"""
# NB: matplotlib is imported inside since it is a costly import
import matplotlib.pyplot as p
from openquake.hmtk.plotting.patch import PolygonPatch
dstore = util.read(calc_id)
try:
region = dsto... | python | def plot_assets(calc_id=-1, site_model=False):
import matplotlib.pyplot as p
from openquake.hmtk.plotting.patch import PolygonPatch
dstore = util.read(calc_id)
try:
region = dstore['oqparam'].region
except KeyError:
region = None
sitecol = dstore['sitecol']
try:
... | [
"def",
"plot_assets",
"(",
"calc_id",
"=",
"-",
"1",
",",
"site_model",
"=",
"False",
")",
":",
"# NB: matplotlib is imported inside since it is a costly import",
"import",
"matplotlib",
".",
"pyplot",
"as",
"p",
"from",
"openquake",
".",
"hmtk",
".",
"plotting",
... | Plot the sites and the assets | [
"Plot",
"the",
"sites",
"and",
"the",
"assets"
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/commands/plot_assets.py#L26-L62 |
gem/oq-engine | openquake/hmtk/seismicity/smoothing/smoothed_seismicity.py | _get_adjustment | def _get_adjustment(mag, year, mmin, completeness_year, t_f, mag_inc=0.1):
'''
If the magnitude is greater than the minimum in the completeness table
and the year is greater than the corresponding completeness year then
return the Weichert factor
:param float mag:
Magnitude of an earthquake... | python | def _get_adjustment(mag, year, mmin, completeness_year, t_f, mag_inc=0.1):
if len(completeness_year) == 1:
if (mag >= mmin) and (year >= completeness_year[0]):
return 1.0
else:
return False
kval = int(((mag - mmin) / mag_inc)) + 1
if (... | [
"def",
"_get_adjustment",
"(",
"mag",
",",
"year",
",",
"mmin",
",",
"completeness_year",
",",
"t_f",
",",
"mag_inc",
"=",
"0.1",
")",
":",
"if",
"len",
"(",
"completeness_year",
")",
"==",
"1",
":",
"if",
"(",
"mag",
">=",
"mmin",
")",
"and",
"(",
... | If the magnitude is greater than the minimum in the completeness table
and the year is greater than the corresponding completeness year then
return the Weichert factor
:param float mag:
Magnitude of an earthquake
:param float year:
Year of earthquake
:param np.ndarray completeness... | [
"If",
"the",
"magnitude",
"is",
"greater",
"than",
"the",
"minimum",
"in",
"the",
"completeness",
"table",
"and",
"the",
"year",
"is",
"greater",
"than",
"the",
"corresponding",
"completeness",
"year",
"then",
"return",
"the",
"Weichert",
"factor"
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hmtk/seismicity/smoothing/smoothed_seismicity.py#L129-L167 |
gem/oq-engine | openquake/hmtk/seismicity/smoothing/smoothed_seismicity.py | get_catalogue_bounding_polygon | def get_catalogue_bounding_polygon(catalogue):
'''
Returns a polygon containing the bounding box of the catalogue
'''
upper_lon = np.max(catalogue.data['longitude'])
upper_lat = np.max(catalogue.data['latitude'])
lower_lon = np.min(catalogue.data['longitude'])
lower_lat = np.min(catalogue.da... | python | def get_catalogue_bounding_polygon(catalogue):
upper_lon = np.max(catalogue.data['longitude'])
upper_lat = np.max(catalogue.data['latitude'])
lower_lon = np.min(catalogue.data['longitude'])
lower_lat = np.min(catalogue.data['latitude'])
return Polygon([Point(lower_lon, upper_lat), Point(upper_... | [
"def",
"get_catalogue_bounding_polygon",
"(",
"catalogue",
")",
":",
"upper_lon",
"=",
"np",
".",
"max",
"(",
"catalogue",
".",
"data",
"[",
"'longitude'",
"]",
")",
"upper_lat",
"=",
"np",
".",
"max",
"(",
"catalogue",
".",
"data",
"[",
"'latitude'",
"]",... | Returns a polygon containing the bounding box of the catalogue | [
"Returns",
"a",
"polygon",
"containing",
"the",
"bounding",
"box",
"of",
"the",
"catalogue"
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hmtk/seismicity/smoothing/smoothed_seismicity.py#L170-L180 |
gem/oq-engine | openquake/hmtk/seismicity/smoothing/smoothed_seismicity.py | Grid.make_from_catalogue | def make_from_catalogue(cls, catalogue, spacing, dilate):
'''
Defines the grid on the basis of the catalogue
'''
new = cls()
cat_bbox = get_catalogue_bounding_polygon(catalogue)
if dilate > 0:
cat_bbox = cat_bbox.dilate(dilate)
# Define Grid spacing
... | python | def make_from_catalogue(cls, catalogue, spacing, dilate):
new = cls()
cat_bbox = get_catalogue_bounding_polygon(catalogue)
if dilate > 0:
cat_bbox = cat_bbox.dilate(dilate)
new.update({'xmin': np.min(cat_bbox.lons),
'xmax': np.max(cat_b... | [
"def",
"make_from_catalogue",
"(",
"cls",
",",
"catalogue",
",",
"spacing",
",",
"dilate",
")",
":",
"new",
"=",
"cls",
"(",
")",
"cat_bbox",
"=",
"get_catalogue_bounding_polygon",
"(",
"catalogue",
")",
"if",
"dilate",
">",
"0",
":",
"cat_bbox",
"=",
"cat... | Defines the grid on the basis of the catalogue | [
"Defines",
"the",
"grid",
"on",
"the",
"basis",
"of",
"the",
"catalogue"
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hmtk/seismicity/smoothing/smoothed_seismicity.py#L81-L105 |
gem/oq-engine | openquake/hmtk/seismicity/smoothing/smoothed_seismicity.py | SmoothedSeismicity.run_analysis | def run_analysis(self, catalogue, config, completeness_table=None,
smoothing_kernel=None):
'''
Runs an analysis of smoothed seismicity in the manner
originally implemented by Frankel (1995)
:param catalogue:
Instance of the openquake.hmtk.seismicity.cata... | python | def run_analysis(self, catalogue, config, completeness_table=None,
smoothing_kernel=None):
self.catalogue = catalogue
if smoothing_kernel:
self.kernel = smoothing_kernel
else:
self.kernel = IsotropicGaussian()
if isinstance... | [
"def",
"run_analysis",
"(",
"self",
",",
"catalogue",
",",
"config",
",",
"completeness_table",
"=",
"None",
",",
"smoothing_kernel",
"=",
"None",
")",
":",
"self",
".",
"catalogue",
"=",
"catalogue",
"if",
"smoothing_kernel",
":",
"self",
".",
"kernel",
"="... | Runs an analysis of smoothed seismicity in the manner
originally implemented by Frankel (1995)
:param catalogue:
Instance of the openquake.hmtk.seismicity.catalogue.Catalogue class
catalogue.data dictionary containing the following -
'year' - numpy.ndarray vector of ... | [
"Runs",
"an",
"analysis",
"of",
"smoothed",
"seismicity",
"in",
"the",
"manner",
"originally",
"implemented",
"by",
"Frankel",
"(",
"1995",
")"
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hmtk/seismicity/smoothing/smoothed_seismicity.py#L242-L321 |
gem/oq-engine | openquake/hmtk/seismicity/smoothing/smoothed_seismicity.py | SmoothedSeismicity.create_2D_grid_simple | def create_2D_grid_simple(self, longitude, latitude, year, magnitude,
completeness_table, t_f=1., mag_inc=0.1):
'''
Generates the grid from the limits using an approach closer to that of
Frankel (1995)
:param numpy.ndarray longitude:
Vector of e... | python | def create_2D_grid_simple(self, longitude, latitude, year, magnitude,
completeness_table, t_f=1., mag_inc=0.1):
assert mag_inc > 0.
xlim = np.ceil(
(self.grid_limits['xmax'] - self.grid_limits['xmin']) /
self.grid_limits['xspc'])
yl... | [
"def",
"create_2D_grid_simple",
"(",
"self",
",",
"longitude",
",",
"latitude",
",",
"year",
",",
"magnitude",
",",
"completeness_table",
",",
"t_f",
"=",
"1.",
",",
"mag_inc",
"=",
"0.1",
")",
":",
"assert",
"mag_inc",
">",
"0.",
"xlim",
"=",
"np",
".",... | Generates the grid from the limits using an approach closer to that of
Frankel (1995)
:param numpy.ndarray longitude:
Vector of earthquake longitudes
:param numpy.ndarray latitude:
Vector of earthquake latitudes
:param numpy.ndarray year:
Vector of ... | [
"Generates",
"the",
"grid",
"from",
"the",
"limits",
"using",
"an",
"approach",
"closer",
"to",
"that",
"of",
"Frankel",
"(",
"1995",
")"
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hmtk/seismicity/smoothing/smoothed_seismicity.py#L323-L390 |
gem/oq-engine | openquake/hmtk/seismicity/smoothing/smoothed_seismicity.py | SmoothedSeismicity.create_3D_grid | def create_3D_grid(self, catalogue, completeness_table, t_f=1.0,
mag_inc=0.1):
'''
Counts the earthquakes observed in a three dimensional grid
:param catalogue:
Instance of the openquake.hmtk.seismicity.catalogue.Catalogue class
catalogue.data dic... | python | def create_3D_grid(self, catalogue, completeness_table, t_f=1.0,
mag_inc=0.1):
x_bins = np.arange(self.grid_limits['xmin'],
self.grid_limits['xmax'],
self.grid_limits['xspc'])
if x_bins[-1] < self.grid_limits['xmax']:
... | [
"def",
"create_3D_grid",
"(",
"self",
",",
"catalogue",
",",
"completeness_table",
",",
"t_f",
"=",
"1.0",
",",
"mag_inc",
"=",
"0.1",
")",
":",
"x_bins",
"=",
"np",
".",
"arange",
"(",
"self",
".",
"grid_limits",
"[",
"'xmin'",
"]",
",",
"self",
".",
... | Counts the earthquakes observed in a three dimensional grid
:param catalogue:
Instance of the openquake.hmtk.seismicity.catalogue.Catalogue class
catalogue.data dictionary containing the following -
'year' - numpy.ndarray vector of years
'longitude' - numpy.ndar... | [
"Counts",
"the",
"earthquakes",
"observed",
"in",
"a",
"three",
"dimensional",
"grid"
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hmtk/seismicity/smoothing/smoothed_seismicity.py#L392-L489 |
gem/oq-engine | openquake/hmtk/seismicity/smoothing/smoothed_seismicity.py | SmoothedSeismicity.write_to_csv | def write_to_csv(self, filename):
'''
Exports to simple csv
:param str filename:
Path to file for export
'''
fid = open(filename, 'wt')
# Create header list
header_info = ['Longitude', 'Latitude', 'Depth', 'Observed Count',
'Smo... | python | def write_to_csv(self, filename):
fid = open(filename, 'wt')
header_info = ['Longitude', 'Latitude', 'Depth', 'Observed Count',
'Smoothed Rate', 'b-value']
writer = csv.DictWriter(fid, fieldnames=header_info)
headers = dict((name0, name0) for name... | [
"def",
"write_to_csv",
"(",
"self",
",",
"filename",
")",
":",
"fid",
"=",
"open",
"(",
"filename",
",",
"'wt'",
")",
"# Create header list",
"header_info",
"=",
"[",
"'Longitude'",
",",
"'Latitude'",
",",
"'Depth'",
",",
"'Observed Count'",
",",
"'Smoothed Ra... | Exports to simple csv
:param str filename:
Path to file for export | [
"Exports",
"to",
"simple",
"csv"
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hmtk/seismicity/smoothing/smoothed_seismicity.py#L491-L518 |
gem/oq-engine | openquake/commonlib/hazard_writers.py | _validate_hazard_metadata | def _validate_hazard_metadata(md):
"""
Validate metadata `dict` of attributes, which are more or less the same for
hazard curves, hazard maps, and disaggregation histograms.
:param dict md:
`dict` which can contain the following keys:
* statistics
* gsimlt_path
* smlt_p... | python | def _validate_hazard_metadata(md):
if (md.get('statistics') is not None and (
md.get('smlt_path') is not None or
md.get('gsimlt_path') is not None)):
raise ValueError('Cannot specify both `statistics` and logic tree '
'paths')
if md.get('statistics'... | [
"def",
"_validate_hazard_metadata",
"(",
"md",
")",
":",
"if",
"(",
"md",
".",
"get",
"(",
"'statistics'",
")",
"is",
"not",
"None",
"and",
"(",
"md",
".",
"get",
"(",
"'smlt_path'",
")",
"is",
"not",
"None",
"or",
"md",
".",
"get",
"(",
"'gsimlt_pat... | Validate metadata `dict` of attributes, which are more or less the same for
hazard curves, hazard maps, and disaggregation histograms.
:param dict md:
`dict` which can contain the following keys:
* statistics
* gsimlt_path
* smlt_path
* imt
* sa_period
*... | [
"Validate",
"metadata",
"dict",
"of",
"attributes",
"which",
"are",
"more",
"or",
"less",
"the",
"same",
"for",
"hazard",
"curves",
"hazard",
"maps",
"and",
"disaggregation",
"histograms",
"."
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/commonlib/hazard_writers.py#L54-L103 |
gem/oq-engine | openquake/commonlib/hazard_writers.py | _set_metadata | def _set_metadata(element, metadata, attr_map, transform=str):
"""
Set metadata attributes on a given ``element``.
:param element:
:class:`xml.etree.ElementTree.Element` instance
:param metadata:
Dictionary of metadata items containing attribute data for ``element``.
:param attr_map... | python | def _set_metadata(element, metadata, attr_map, transform=str):
for kw, attr in attr_map.items():
value = metadata.get(kw)
if value is not None:
element.set(attr, transform(value)) | [
"def",
"_set_metadata",
"(",
"element",
",",
"metadata",
",",
"attr_map",
",",
"transform",
"=",
"str",
")",
":",
"for",
"kw",
",",
"attr",
"in",
"attr_map",
".",
"items",
"(",
")",
":",
"value",
"=",
"metadata",
".",
"get",
"(",
"kw",
")",
"if",
"... | Set metadata attributes on a given ``element``.
:param element:
:class:`xml.etree.ElementTree.Element` instance
:param metadata:
Dictionary of metadata items containing attribute data for ``element``.
:param attr_map:
Dictionary mapping of metadata key->attribute name.
:param tr... | [
"Set",
"metadata",
"attributes",
"on",
"a",
"given",
"element",
"."
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/commonlib/hazard_writers.py#L106-L123 |
gem/oq-engine | openquake/commonlib/hazard_writers.py | gen_gmfs | def gen_gmfs(gmf_set):
"""
Generate GMF nodes from a gmf_set
:param gmf_set: a sequence of GMF objects with attributes
imt, sa_period, sa_damping, event_id and containing a list
of GMF nodes with attributes gmv and location. The nodes
are sorted by lon/lat.
"""
for gmf in gmf_set:
... | python | def gen_gmfs(gmf_set):
for gmf in gmf_set:
gmf_node = Node('gmf')
gmf_node['IMT'] = gmf.imt
if gmf.imt == 'SA':
gmf_node['saPeriod'] = str(gmf.sa_period)
gmf_node['saDamping'] = str(gmf.sa_damping)
gmf_node['ruptureId'] = gmf.event_id
sorted_nodes... | [
"def",
"gen_gmfs",
"(",
"gmf_set",
")",
":",
"for",
"gmf",
"in",
"gmf_set",
":",
"gmf_node",
"=",
"Node",
"(",
"'gmf'",
")",
"gmf_node",
"[",
"'IMT'",
"]",
"=",
"gmf",
".",
"imt",
"if",
"gmf",
".",
"imt",
"==",
"'SA'",
":",
"gmf_node",
"[",
"'saPer... | Generate GMF nodes from a gmf_set
:param gmf_set: a sequence of GMF objects with attributes
imt, sa_period, sa_damping, event_id and containing a list
of GMF nodes with attributes gmv and location. The nodes
are sorted by lon/lat. | [
"Generate",
"GMF",
"nodes",
"from",
"a",
"gmf_set",
":",
"param",
"gmf_set",
":",
"a",
"sequence",
"of",
"GMF",
"objects",
"with",
"attributes",
"imt",
"sa_period",
"sa_damping",
"event_id",
"and",
"containing",
"a",
"list",
"of",
"GMF",
"nodes",
"with",
"at... | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/commonlib/hazard_writers.py#L218-L237 |
gem/oq-engine | openquake/commonlib/hazard_writers.py | rupture_to_element | def rupture_to_element(rup, parent=None):
"""
Convert a rupture object into an Element object.
:param rup:
must have attributes .rupid, .events_by_ses and .seed
:param parent:
parent of the returned element, or None
"""
if parent is None:
parent = et.Element('root')
... | python | def rupture_to_element(rup, parent=None):
if parent is None:
parent = et.Element('root')
rup_elem = et.SubElement(parent, rup.typology)
elem = et.SubElement(rup_elem, 'stochasticEventSets')
n = 0
for ses in rup.events_by_ses:
eids = rup.events_by_ses[ses]['eid']
n += len... | [
"def",
"rupture_to_element",
"(",
"rup",
",",
"parent",
"=",
"None",
")",
":",
"if",
"parent",
"is",
"None",
":",
"parent",
"=",
"et",
".",
"Element",
"(",
"'root'",
")",
"rup_elem",
"=",
"et",
".",
"SubElement",
"(",
"parent",
",",
"rup",
".",
"typo... | Convert a rupture object into an Element object.
:param rup:
must have attributes .rupid, .events_by_ses and .seed
:param parent:
parent of the returned element, or None | [
"Convert",
"a",
"rupture",
"object",
"into",
"an",
"Element",
"object",
"."
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/commonlib/hazard_writers.py#L311-L422 |
gem/oq-engine | openquake/commonlib/hazard_writers.py | HazardCurveXMLWriter.serialize | def serialize(self, data):
"""
Write a sequence of hazard curves to the specified file.
:param data:
Iterable of hazard curve data. Each datum must be an object with
the following attributes:
* poes: A list of probability of exceedence values (floats).
... | python | def serialize(self, data):
with open(self.dest, 'wb') as fh:
root = et.Element('nrml')
self.add_hazard_curves(root, self.metadata, data)
nrml.write(list(root), fh) | [
"def",
"serialize",
"(",
"self",
",",
"data",
")",
":",
"with",
"open",
"(",
"self",
".",
"dest",
",",
"'wb'",
")",
"as",
"fh",
":",
"root",
"=",
"et",
".",
"Element",
"(",
"'nrml'",
")",
"self",
".",
"add_hazard_curves",
"(",
"root",
",",
"self",
... | Write a sequence of hazard curves to the specified file.
:param data:
Iterable of hazard curve data. Each datum must be an object with
the following attributes:
* poes: A list of probability of exceedence values (floats).
* location: An object representing the l... | [
"Write",
"a",
"sequence",
"of",
"hazard",
"curves",
"to",
"the",
"specified",
"file",
"."
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/commonlib/hazard_writers.py#L177-L192 |
gem/oq-engine | openquake/commonlib/hazard_writers.py | HazardCurveXMLWriter.add_hazard_curves | def add_hazard_curves(self, root, metadata, data):
"""
Add hazard curves stored into `data` as child of the `root`
element with `metadata`. See the documentation of the method
`serialize` and the constructor for a description of `data`
and `metadata`, respectively.
"""
... | python | def add_hazard_curves(self, root, metadata, data):
hazard_curves = et.SubElement(root, 'hazardCurves')
_set_metadata(hazard_curves, metadata, _ATTR_MAP)
imls_elem = et.SubElement(hazard_curves, 'IMLs')
imls_elem.text = ' '.join(map(scientificformat, metadata['imls']))
... | [
"def",
"add_hazard_curves",
"(",
"self",
",",
"root",
",",
"metadata",
",",
"data",
")",
":",
"hazard_curves",
"=",
"et",
".",
"SubElement",
"(",
"root",
",",
"'hazardCurves'",
")",
"_set_metadata",
"(",
"hazard_curves",
",",
"metadata",
",",
"_ATTR_MAP",
")... | Add hazard curves stored into `data` as child of the `root`
element with `metadata`. See the documentation of the method
`serialize` and the constructor for a description of `data`
and `metadata`, respectively. | [
"Add",
"hazard",
"curves",
"stored",
"into",
"data",
"as",
"child",
"of",
"the",
"root",
"element",
"with",
"metadata",
".",
"See",
"the",
"documentation",
"of",
"the",
"method",
"serialize",
"and",
"the",
"constructor",
"for",
"a",
"description",
"of",
"dat... | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/commonlib/hazard_writers.py#L194-L215 |
gem/oq-engine | openquake/commonlib/hazard_writers.py | EventBasedGMFXMLWriter.serialize | def serialize(self, data, fmt='%10.7E'):
"""
Serialize a collection of ground motion fields to XML.
:param data:
An iterable of "GMF set" objects.
Each "GMF set" object should:
* have an `investigation_time` attribute
* have an `stochastic_event_... | python | def serialize(self, data, fmt='%10.7E'):
gmf_set_nodes = []
for gmf_set in data:
gmf_set_node = Node('gmfSet')
if gmf_set.investigation_time:
gmf_set_node['investigationTime'] = str(
gmf_set.investigation_time)
gmf_set_node... | [
"def",
"serialize",
"(",
"self",
",",
"data",
",",
"fmt",
"=",
"'%10.7E'",
")",
":",
"gmf_set_nodes",
"=",
"[",
"]",
"for",
"gmf_set",
"in",
"data",
":",
"gmf_set_node",
"=",
"Node",
"(",
"'gmfSet'",
")",
"if",
"gmf_set",
".",
"investigation_time",
":",
... | Serialize a collection of ground motion fields to XML.
:param data:
An iterable of "GMF set" objects.
Each "GMF set" object should:
* have an `investigation_time` attribute
* have an `stochastic_event_set_id` attribute
* be iterable, yielding a seque... | [
"Serialize",
"a",
"collection",
"of",
"ground",
"motion",
"fields",
"to",
"XML",
"."
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/commonlib/hazard_writers.py#L259-L303 |
gem/oq-engine | openquake/commonlib/hazard_writers.py | SESXMLWriter.serialize | def serialize(self, data, investigation_time):
"""
Serialize a collection of stochastic event sets to XML.
:param data:
A dictionary src_group_id -> list of
:class:`openquake.commonlib.calc.Rupture` objects.
Each Rupture should have the following attributes:
... | python | def serialize(self, data, investigation_time):
with open(self.dest, 'wb') as fh:
root = et.Element('nrml')
ses_container = et.SubElement(root, 'ruptureCollection')
ses_container.set('investigationTime', str(investigation_time))
for grp_id in sorted(data):... | [
"def",
"serialize",
"(",
"self",
",",
"data",
",",
"investigation_time",
")",
":",
"with",
"open",
"(",
"self",
".",
"dest",
",",
"'wb'",
")",
"as",
"fh",
":",
"root",
"=",
"et",
".",
"Element",
"(",
"'nrml'",
")",
"ses_container",
"=",
"et",
".",
... | Serialize a collection of stochastic event sets to XML.
:param data:
A dictionary src_group_id -> list of
:class:`openquake.commonlib.calc.Rupture` objects.
Each Rupture should have the following attributes:
* `rupid`
* `events_by_ses`
* ... | [
"Serialize",
"a",
"collection",
"of",
"stochastic",
"event",
"sets",
"to",
"XML",
"."
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/commonlib/hazard_writers.py#L440-L507 |
gem/oq-engine | openquake/commonlib/hazard_writers.py | HazardMapXMLWriter.serialize | def serialize(self, data):
"""
Serialize hazard map data to XML.
See :meth:`HazardMapWriter.serialize` for details about the expected
input.
"""
with open(self.dest, 'wb') as fh:
root = et.Element('nrml')
hazard_map = et.SubElement(root, 'hazardMa... | python | def serialize(self, data):
with open(self.dest, 'wb') as fh:
root = et.Element('nrml')
hazard_map = et.SubElement(root, 'hazardMap')
_set_metadata(hazard_map, self.metadata, _ATTR_MAP)
for lon, lat, iml in data:
node = et.SubElement(hazar... | [
"def",
"serialize",
"(",
"self",
",",
"data",
")",
":",
"with",
"open",
"(",
"self",
".",
"dest",
",",
"'wb'",
")",
"as",
"fh",
":",
"root",
"=",
"et",
".",
"Element",
"(",
"'nrml'",
")",
"hazard_map",
"=",
"et",
".",
"SubElement",
"(",
"root",
"... | Serialize hazard map data to XML.
See :meth:`HazardMapWriter.serialize` for details about the expected
input. | [
"Serialize",
"hazard",
"map",
"data",
"to",
"XML",
"."
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/commonlib/hazard_writers.py#L560-L578 |
gem/oq-engine | openquake/commonlib/hazard_writers.py | DisaggXMLWriter.serialize | def serialize(self, data):
"""
:param data:
A sequence of data where each datum has the following attributes:
* matrix: N-dimensional numpy array containing the disaggregation
histogram.
* dim_labels: A list of strings which label the dimensions of a
... | python | def serialize(self, data):
with open(self.dest, 'wb') as fh, floatformat('%.6E'):
root = et.Element('nrml')
diss_matrices = et.SubElement(root, 'disaggMatrices')
_set_metadata(diss_matrices, self.metadata, _ATTR_MAP)
transform = lambda val: ', '.join(... | [
"def",
"serialize",
"(",
"self",
",",
"data",
")",
":",
"with",
"open",
"(",
"self",
".",
"dest",
",",
"'wb'",
")",
"as",
"fh",
",",
"floatformat",
"(",
"'%.6E'",
")",
":",
"root",
"=",
"et",
".",
"Element",
"(",
"'nrml'",
")",
"diss_matrices",
"="... | :param data:
A sequence of data where each datum has the following attributes:
* matrix: N-dimensional numpy array containing the disaggregation
histogram.
* dim_labels: A list of strings which label the dimensions of a
given histogram. For example, for ... | [
":",
"param",
"data",
":"
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/commonlib/hazard_writers.py#L639-L695 |
gem/oq-engine | openquake/commonlib/hazard_writers.py | UHSXMLWriter.serialize | def serialize(self, data):
"""
Write a sequence of uniform hazard spectra to the specified file.
:param data:
Iterable of UHS data. Each datum must be an object with the
following attributes:
* imls: A sequence of Intensity Measure Levels
* locat... | python | def serialize(self, data):
gml_ns = nrml.SERIALIZE_NS_MAP['gml']
with open(self.dest, 'wb') as fh:
root = et.Element('nrml')
uh_spectra = et.SubElement(root, 'uniformHazardSpectra')
_set_metadata(uh_spectra, self.metadata, _ATTR_MAP)
periods_e... | [
"def",
"serialize",
"(",
"self",
",",
"data",
")",
":",
"gml_ns",
"=",
"nrml",
".",
"SERIALIZE_NS_MAP",
"[",
"'gml'",
"]",
"with",
"open",
"(",
"self",
".",
"dest",
",",
"'wb'",
")",
"as",
"fh",
":",
"root",
"=",
"et",
".",
"Element",
"(",
"'nrml'"... | Write a sequence of uniform hazard spectra to the specified file.
:param data:
Iterable of UHS data. Each datum must be an object with the
following attributes:
* imls: A sequence of Intensity Measure Levels
* location: An object representing the location of the... | [
"Write",
"a",
"sequence",
"of",
"uniform",
"hazard",
"spectra",
"to",
"the",
"specified",
"file",
"."
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/commonlib/hazard_writers.py#L728-L761 |
gem/oq-engine | openquake/hmtk/plotting/seismicity/max_magnitude/cumulative_moment.py | plot_cumulative_moment | def plot_cumulative_moment(year, mag, figure_size=(8, 6),
filename=None, filetype='png', dpi=300, ax=None):
'''Calculation of Mmax using aCumulative Moment approach, adapted from
the cumulative strain energy method of Makropoulos & Burton (1983)
:param year: Year of Earthquake
... | python | def plot_cumulative_moment(year, mag, figure_size=(8, 6),
filename=None, filetype='png', dpi=300, ax=None):
m_o = 10. ** (9.05 + 1.5 * mag)
year_range = np.arange(np.min(year), np.max(year) + 1, 1)
nyr = np.int(np.shape(year_range)[0])
morate = np.zeros(nyr, dtype=fl... | [
"def",
"plot_cumulative_moment",
"(",
"year",
",",
"mag",
",",
"figure_size",
"=",
"(",
"8",
",",
"6",
")",
",",
"filename",
"=",
"None",
",",
"filetype",
"=",
"'png'",
",",
"dpi",
"=",
"300",
",",
"ax",
"=",
"None",
")",
":",
"# Calculate seismic mome... | Calculation of Mmax using aCumulative Moment approach, adapted from
the cumulative strain energy method of Makropoulos & Burton (1983)
:param year: Year of Earthquake
:type year: numpy.ndarray
:param mag: Magnitude of Earthquake
:type mag: numpy.ndarray
:keyword iplot: Include cumulative moment ... | [
"Calculation",
"of",
"Mmax",
"using",
"aCumulative",
"Moment",
"approach",
"adapted",
"from",
"the",
"cumulative",
"strain",
"energy",
"method",
"of",
"Makropoulos",
"&",
"Burton",
"(",
"1983",
")",
":",
"param",
"year",
":",
"Year",
"of",
"Earthquake",
":",
... | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hmtk/plotting/seismicity/max_magnitude/cumulative_moment.py#L58-L100 |
gem/oq-engine | openquake/hmtk/seismicity/max_magnitude/kijko_sellevol_bayes.py | check_config | def check_config(config, data):
'''Check config file inputs
:param dict config:
Configuration settings for the function
'''
essential_keys = ['input_mmin', 'b-value', 'sigma-b']
for key in essential_keys:
if not key in config.keys():
raise ValueError('For KijkoSellevol... | python | def check_config(config, data):
essential_keys = ['input_mmin', 'b-value', 'sigma-b']
for key in essential_keys:
if not key in config.keys():
raise ValueError('For KijkoSellevolBayes the key %s needs to '
'be set in the configuation' % key)
if 'tolerance... | [
"def",
"check_config",
"(",
"config",
",",
"data",
")",
":",
"essential_keys",
"=",
"[",
"'input_mmin'",
",",
"'b-value'",
",",
"'sigma-b'",
"]",
"for",
"key",
"in",
"essential_keys",
":",
"if",
"not",
"key",
"in",
"config",
".",
"keys",
"(",
")",
":",
... | Check config file inputs
:param dict config:
Configuration settings for the function | [
"Check",
"config",
"file",
"inputs"
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hmtk/seismicity/max_magnitude/kijko_sellevol_bayes.py#L60-L84 |
gem/oq-engine | openquake/hazardlib/gsim/toro_1997.py | ToroEtAl1997MblgNSHMP2008._compute_mean | def _compute_mean(self, C, mag, rjb):
"""
Compute ground motion mean value.
"""
# line 1686 in hazgridXnga2.f
ffc = self._compute_finite_fault_correction(mag)
d = np.sqrt(rjb ** 2 + (C['c7'] ** 2) * (ffc ** 2))
# lines 1663, 1694-1696 in hazgridXnga2.f
me... | python | def _compute_mean(self, C, mag, rjb):
ffc = self._compute_finite_fault_correction(mag)
d = np.sqrt(rjb ** 2 + (C['c7'] ** 2) * (ffc ** 2))
mean = (
C['c1'] + C['c2'] * (mag - 6.) +
C['c3'] * ((mag - 6.) ** 2) -
C['c4'] * np.log(d) -... | [
"def",
"_compute_mean",
"(",
"self",
",",
"C",
",",
"mag",
",",
"rjb",
")",
":",
"# line 1686 in hazgridXnga2.f",
"ffc",
"=",
"self",
".",
"_compute_finite_fault_correction",
"(",
"mag",
")",
"d",
"=",
"np",
".",
"sqrt",
"(",
"rjb",
"**",
"2",
"+",
"(",
... | Compute ground motion mean value. | [
"Compute",
"ground",
"motion",
"mean",
"value",
"."
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/gsim/toro_1997.py#L110-L129 |
gem/oq-engine | openquake/hazardlib/gsim/toro_1997.py | ToroEtAl1997MblgNSHMP2008._compute_finite_fault_correction | def _compute_finite_fault_correction(self, mag):
"""
Compute finite fault correction term as geometric mean of correction
terms obtained from Mw values calculated with Johnston 1996 and
Atkinson and Boore 1987 conversion equations.
Implement equations as in lines 1653 - 1658 in ... | python | def _compute_finite_fault_correction(self, mag):
mw_j96 = mblg_to_mw_johnston_96(mag)
mw_ab87 = mblg_to_mw_atkinson_boore_87(mag)
t1 = np.exp(-1.25 + 0.227 * mw_j96)
t2 = np.exp(-1.25 + 0.227 * mw_ab87)
return np.sqrt(t1 * t2) | [
"def",
"_compute_finite_fault_correction",
"(",
"self",
",",
"mag",
")",
":",
"mw_j96",
"=",
"mblg_to_mw_johnston_96",
"(",
"mag",
")",
"mw_ab87",
"=",
"mblg_to_mw_atkinson_boore_87",
"(",
"mag",
")",
"t1",
"=",
"np",
".",
"exp",
"(",
"-",
"1.25",
"+",
"0.22... | Compute finite fault correction term as geometric mean of correction
terms obtained from Mw values calculated with Johnston 1996 and
Atkinson and Boore 1987 conversion equations.
Implement equations as in lines 1653 - 1658 in hazgridXnga2.f | [
"Compute",
"finite",
"fault",
"correction",
"term",
"as",
"geometric",
"mean",
"of",
"correction",
"terms",
"obtained",
"from",
"Mw",
"values",
"calculated",
"with",
"Johnston",
"1996",
"and",
"Atkinson",
"and",
"Boore",
"1987",
"conversion",
"equations",
"."
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/gsim/toro_1997.py#L131-L145 |
gem/oq-engine | openquake/commands/upgrade_nrml.py | get_vulnerability_functions_04 | def get_vulnerability_functions_04(fname):
"""
Parse the vulnerability model in NRML 0.4 format.
:param fname:
path of the vulnerability file
:returns:
a dictionary imt, taxonomy -> vulnerability function + vset
"""
categories = dict(assetCategory=set(), lossCategory=set(),
... | python | def get_vulnerability_functions_04(fname):
categories = dict(assetCategory=set(), lossCategory=set(),
vulnerabilitySetID=set())
imts = set()
taxonomies = set()
vf_dict = {}
for vset in nrml.read(fname).vulnerabilityModel:
categories['assetCategory'].add(vset['ass... | [
"def",
"get_vulnerability_functions_04",
"(",
"fname",
")",
":",
"categories",
"=",
"dict",
"(",
"assetCategory",
"=",
"set",
"(",
")",
",",
"lossCategory",
"=",
"set",
"(",
")",
",",
"vulnerabilitySetID",
"=",
"set",
"(",
")",
")",
"imts",
"=",
"set",
"... | Parse the vulnerability model in NRML 0.4 format.
:param fname:
path of the vulnerability file
:returns:
a dictionary imt, taxonomy -> vulnerability function + vset | [
"Parse",
"the",
"vulnerability",
"model",
"in",
"NRML",
"0",
".",
"4",
"format",
"."
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/commands/upgrade_nrml.py#L32-L80 |
gem/oq-engine | openquake/commands/upgrade_nrml.py | upgrade_file | def upgrade_file(path, multipoint):
"""Upgrade to the latest NRML version"""
node0 = nrml.read(path, chatty=False)[0]
shutil.copy(path, path + '.bak') # make a backup of the original file
tag = striptag(node0.tag)
gml = True
if tag == 'vulnerabilityModel':
vf_dict, cat_dict = get_vulner... | python | def upgrade_file(path, multipoint):
node0 = nrml.read(path, chatty=False)[0]
shutil.copy(path, path + '.bak')
tag = striptag(node0.tag)
gml = True
if tag == 'vulnerabilityModel':
vf_dict, cat_dict = get_vulnerability_functions_04(path)
node0 = Node(
'vulne... | [
"def",
"upgrade_file",
"(",
"path",
",",
"multipoint",
")",
":",
"node0",
"=",
"nrml",
".",
"read",
"(",
"path",
",",
"chatty",
"=",
"False",
")",
"[",
"0",
"]",
"shutil",
".",
"copy",
"(",
"path",
",",
"path",
"+",
"'.bak'",
")",
"# make a backup of... | Upgrade to the latest NRML version | [
"Upgrade",
"to",
"the",
"latest",
"NRML",
"version"
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/commands/upgrade_nrml.py#L83-L110 |
gem/oq-engine | openquake/commands/upgrade_nrml.py | upgrade_nrml | def upgrade_nrml(directory, dry_run, multipoint):
"""
Upgrade all the NRML files contained in the given directory to the latest
NRML version. Works by walking all subdirectories.
WARNING: there is no downgrade!
"""
for cwd, dirs, files in os.walk(directory):
for f in files:
p... | python | def upgrade_nrml(directory, dry_run, multipoint):
for cwd, dirs, files in os.walk(directory):
for f in files:
path = os.path.join(cwd, f)
if f.endswith('.xml'):
ip = iterparse(path, events=('start',))
next(ip)
try:
... | [
"def",
"upgrade_nrml",
"(",
"directory",
",",
"dry_run",
",",
"multipoint",
")",
":",
"for",
"cwd",
",",
"dirs",
",",
"files",
"in",
"os",
".",
"walk",
"(",
"directory",
")",
":",
"for",
"f",
"in",
"files",
":",
"path",
"=",
"os",
".",
"path",
".",... | Upgrade all the NRML files contained in the given directory to the latest
NRML version. Works by walking all subdirectories.
WARNING: there is no downgrade! | [
"Upgrade",
"all",
"the",
"NRML",
"files",
"contained",
"in",
"the",
"given",
"directory",
"to",
"the",
"latest",
"NRML",
"version",
".",
"Works",
"by",
"walking",
"all",
"subdirectories",
".",
"WARNING",
":",
"there",
"is",
"no",
"downgrade!"
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/commands/upgrade_nrml.py#L117-L152 |
gem/oq-engine | openquake/hazardlib/gsim/faccioli_2010.py | FaccioliEtAl2010._compute_term_3 | def _compute_term_3(self, C, rrup, mag):
"""
This computes the third term in equation 2, page 2.
"""
return (C['a3'] *
np.log10(rrup + C['a4'] * np.power(10, C['a5'] * mag))) | python | def _compute_term_3(self, C, rrup, mag):
return (C['a3'] *
np.log10(rrup + C['a4'] * np.power(10, C['a5'] * mag))) | [
"def",
"_compute_term_3",
"(",
"self",
",",
"C",
",",
"rrup",
",",
"mag",
")",
":",
"return",
"(",
"C",
"[",
"'a3'",
"]",
"*",
"np",
".",
"log10",
"(",
"rrup",
"+",
"C",
"[",
"'a4'",
"]",
"*",
"np",
".",
"power",
"(",
"10",
",",
"C",
"[",
"... | This computes the third term in equation 2, page 2. | [
"This",
"computes",
"the",
"third",
"term",
"in",
"equation",
"2",
"page",
"2",
"."
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/gsim/faccioli_2010.py#L85-L90 |
gem/oq-engine | openquake/hmtk/sources/source_conversion_utils.py | mag_scale_rel_to_hazardlib | def mag_scale_rel_to_hazardlib(mag_scale_rel, use_default=False):
"""
Returns the magnitude scaling relation in a format readable by
openquake.hazardlib
"""
if isinstance(mag_scale_rel, BaseMSR):
return mag_scale_rel
elif isinstance(mag_scale_rel, str):
if not mag_scale_rel in SC... | python | def mag_scale_rel_to_hazardlib(mag_scale_rel, use_default=False):
if isinstance(mag_scale_rel, BaseMSR):
return mag_scale_rel
elif isinstance(mag_scale_rel, str):
if not mag_scale_rel in SCALE_RELS.keys():
raise ValueError('Magnitude scaling relation %s not supported!'
... | [
"def",
"mag_scale_rel_to_hazardlib",
"(",
"mag_scale_rel",
",",
"use_default",
"=",
"False",
")",
":",
"if",
"isinstance",
"(",
"mag_scale_rel",
",",
"BaseMSR",
")",
":",
"return",
"mag_scale_rel",
"elif",
"isinstance",
"(",
"mag_scale_rel",
",",
"str",
")",
":"... | Returns the magnitude scaling relation in a format readable by
openquake.hazardlib | [
"Returns",
"the",
"magnitude",
"scaling",
"relation",
"in",
"a",
"format",
"readable",
"by",
"openquake",
".",
"hazardlib"
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hmtk/sources/source_conversion_utils.py#L79-L97 |
gem/oq-engine | openquake/hmtk/sources/source_conversion_utils.py | npd_to_pmf | def npd_to_pmf(nodal_plane_dist, use_default=False):
"""
Returns the nodal plane distribution as an instance of the PMF class
"""
if isinstance(nodal_plane_dist, PMF):
# Aready in PMF format - return
return nodal_plane_dist
else:
if use_default:
return PMF([(1.0, ... | python | def npd_to_pmf(nodal_plane_dist, use_default=False):
if isinstance(nodal_plane_dist, PMF):
return nodal_plane_dist
else:
if use_default:
return PMF([(1.0, NodalPlane(0.0, 90.0, 0.0))])
else:
raise ValueError('Nodal Plane distribution not defined') | [
"def",
"npd_to_pmf",
"(",
"nodal_plane_dist",
",",
"use_default",
"=",
"False",
")",
":",
"if",
"isinstance",
"(",
"nodal_plane_dist",
",",
"PMF",
")",
":",
"# Aready in PMF format - return",
"return",
"nodal_plane_dist",
"else",
":",
"if",
"use_default",
":",
"re... | Returns the nodal plane distribution as an instance of the PMF class | [
"Returns",
"the",
"nodal",
"plane",
"distribution",
"as",
"an",
"instance",
"of",
"the",
"PMF",
"class"
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hmtk/sources/source_conversion_utils.py#L100-L111 |
gem/oq-engine | openquake/hmtk/sources/source_conversion_utils.py | hdd_to_pmf | def hdd_to_pmf(hypo_depth_dist, use_default=False):
"""
Returns the hypocentral depth distribtuion as an instance of the :class:
openquake.hazardlib.pmf.
"""
if isinstance(hypo_depth_dist, PMF):
# Is already instance of PMF
return hypo_depth_dist
else:
if use_default:
... | python | def hdd_to_pmf(hypo_depth_dist, use_default=False):
if isinstance(hypo_depth_dist, PMF):
return hypo_depth_dist
else:
if use_default:
return PMF([(1.0, 10.0)])
else:
raise ValueError('Hypocentral depth distribution not defin... | [
"def",
"hdd_to_pmf",
"(",
"hypo_depth_dist",
",",
"use_default",
"=",
"False",
")",
":",
"if",
"isinstance",
"(",
"hypo_depth_dist",
",",
"PMF",
")",
":",
"# Is already instance of PMF",
"return",
"hypo_depth_dist",
"else",
":",
"if",
"use_default",
":",
"# Defaul... | Returns the hypocentral depth distribtuion as an instance of the :class:
openquake.hazardlib.pmf. | [
"Returns",
"the",
"hypocentral",
"depth",
"distribtuion",
"as",
"an",
"instance",
"of",
"the",
":",
"class",
":",
"openquake",
".",
"hazardlib",
".",
"pmf",
"."
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hmtk/sources/source_conversion_utils.py#L114-L128 |
gem/oq-engine | openquake/hmtk/sources/source_conversion_utils.py | simple_trace_to_wkt_linestring | def simple_trace_to_wkt_linestring(trace):
'''
Coverts a simple fault trace to well-known text format
:param trace:
Fault trace as instance of :class: openquake.hazardlib.geo.line.Line
:returns:
Well-known text (WKT) Linstring representation of the trace
'''
trace_str = ""
... | python | def simple_trace_to_wkt_linestring(trace):
trace_str = ""
for point in trace:
trace_str += ' %s %s,' % (point.longitude, point.latitude)
trace_str = trace_str.lstrip(' ')
return 'LINESTRING (' + trace_str.rstrip(',') + ')' | [
"def",
"simple_trace_to_wkt_linestring",
"(",
"trace",
")",
":",
"trace_str",
"=",
"\"\"",
"for",
"point",
"in",
"trace",
":",
"trace_str",
"+=",
"' %s %s,'",
"%",
"(",
"point",
".",
"longitude",
",",
"point",
".",
"latitude",
")",
"trace_str",
"=",
"trace_s... | Coverts a simple fault trace to well-known text format
:param trace:
Fault trace as instance of :class: openquake.hazardlib.geo.line.Line
:returns:
Well-known text (WKT) Linstring representation of the trace | [
"Coverts",
"a",
"simple",
"fault",
"trace",
"to",
"well",
"-",
"known",
"text",
"format"
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hmtk/sources/source_conversion_utils.py#L131-L145 |
gem/oq-engine | openquake/hmtk/sources/source_conversion_utils.py | simple_edge_to_wkt_linestring | def simple_edge_to_wkt_linestring(edge):
'''
Coverts a simple fault trace to well-known text format
:param trace:
Fault trace as instance of :class: openquake.hazardlib.geo.line.Line
:returns:
Well-known text (WKT) Linstring representation of the trace
'''
trace_str = ""
fo... | python | def simple_edge_to_wkt_linestring(edge):
trace_str = ""
for point in edge:
trace_str += ' %s %s %s,' % (point.longitude, point.latitude,
point.depth)
trace_str = trace_str.lstrip(' ')
return 'LINESTRING (' + trace_str.rstrip(',') + ')' | [
"def",
"simple_edge_to_wkt_linestring",
"(",
"edge",
")",
":",
"trace_str",
"=",
"\"\"",
"for",
"point",
"in",
"edge",
":",
"trace_str",
"+=",
"' %s %s %s,'",
"%",
"(",
"point",
".",
"longitude",
",",
"point",
".",
"latitude",
",",
"point",
".",
"depth",
"... | Coverts a simple fault trace to well-known text format
:param trace:
Fault trace as instance of :class: openquake.hazardlib.geo.line.Line
:returns:
Well-known text (WKT) Linstring representation of the trace | [
"Coverts",
"a",
"simple",
"fault",
"trace",
"to",
"well",
"-",
"known",
"text",
"format"
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hmtk/sources/source_conversion_utils.py#L148-L163 |
gem/oq-engine | openquake/commands/checksum.py | checksum | def checksum(thing):
"""
Get the checksum of a calculation from the calculation ID (if already
done) or from the job.ini/job.zip file (if not done yet). If `thing`
is a source model logic tree file, get the checksum of the model by
ignoring the job.ini, the gmpe logic tree file and possibly other fi... | python | def checksum(thing):
try:
job_id = int(thing)
job_file = None
except ValueError:
job_id = None
job_file = thing
if not os.path.exists(job_file):
sys.exit('%s does not correspond to an existing file' % job_file)
if job_id:
dstore = util.read(jo... | [
"def",
"checksum",
"(",
"thing",
")",
":",
"try",
":",
"job_id",
"=",
"int",
"(",
"thing",
")",
"job_file",
"=",
"None",
"except",
"ValueError",
":",
"job_id",
"=",
"None",
"job_file",
"=",
"thing",
"if",
"not",
"os",
".",
"path",
".",
"exists",
"(",... | Get the checksum of a calculation from the calculation ID (if already
done) or from the job.ini/job.zip file (if not done yet). If `thing`
is a source model logic tree file, get the checksum of the model by
ignoring the job.ini, the gmpe logic tree file and possibly other files. | [
"Get",
"the",
"checksum",
"of",
"a",
"calculation",
"from",
"the",
"calculation",
"ID",
"(",
"if",
"already",
"done",
")",
"or",
"from",
"the",
"job",
".",
"ini",
"/",
"job",
".",
"zip",
"file",
"(",
"if",
"not",
"done",
"yet",
")",
".",
"If",
"thi... | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/commands/checksum.py#L27-L51 |
gem/oq-engine | openquake/commands/engine.py | run_job | def run_job(job_ini, log_level='info', log_file=None, exports='',
username=getpass.getuser(), **kw):
"""
Run a job using the specified config file and other options.
:param str job_ini:
Path to calculation config (INI-style) files.
:param str log_level:
'debug', 'info', 'war... | python | def run_job(job_ini, log_level='info', log_file=None, exports='',
username=getpass.getuser(), **kw):
job_id = logs.init('job', getattr(logging, log_level.upper()))
with logs.handle(job_id, log_level, log_file):
job_ini = os.path.abspath(job_ini)
oqparam = eng.job_from_file(job_i... | [
"def",
"run_job",
"(",
"job_ini",
",",
"log_level",
"=",
"'info'",
",",
"log_file",
"=",
"None",
",",
"exports",
"=",
"''",
",",
"username",
"=",
"getpass",
".",
"getuser",
"(",
")",
",",
"*",
"*",
"kw",
")",
":",
"job_id",
"=",
"logs",
".",
"init"... | Run a job using the specified config file and other options.
:param str job_ini:
Path to calculation config (INI-style) files.
:param str log_level:
'debug', 'info', 'warn', 'error', or 'critical'
:param str log_file:
Path to log file.
:param exports:
A comma-separated s... | [
"Run",
"a",
"job",
"using",
"the",
"specified",
"config",
"file",
"and",
"other",
"options",
"."
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/commands/engine.py#L45-L71 |
gem/oq-engine | openquake/commands/engine.py | run_tile | def run_tile(job_ini, sites_slice):
"""
Used in tiling calculations
"""
return run_job(job_ini, sites_slice=(sites_slice.start, sites_slice.stop)) | python | def run_tile(job_ini, sites_slice):
return run_job(job_ini, sites_slice=(sites_slice.start, sites_slice.stop)) | [
"def",
"run_tile",
"(",
"job_ini",
",",
"sites_slice",
")",
":",
"return",
"run_job",
"(",
"job_ini",
",",
"sites_slice",
"=",
"(",
"sites_slice",
".",
"start",
",",
"sites_slice",
".",
"stop",
")",
")"
] | Used in tiling calculations | [
"Used",
"in",
"tiling",
"calculations"
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/commands/engine.py#L74-L78 |
gem/oq-engine | openquake/commands/engine.py | del_calculation | def del_calculation(job_id, confirmed=False):
"""
Delete a calculation and all associated outputs.
"""
if logs.dbcmd('get_job', job_id) is None:
print('There is no job %d' % job_id)
return
if confirmed or confirm(
'Are you sure you want to (abort and) delete this calcula... | python | def del_calculation(job_id, confirmed=False):
if logs.dbcmd('get_job', job_id) is None:
print('There is no job %d' % job_id)
return
if confirmed or confirm(
'Are you sure you want to (abort and) delete this calculation and '
'all associated outputs?\nThis action can... | [
"def",
"del_calculation",
"(",
"job_id",
",",
"confirmed",
"=",
"False",
")",
":",
"if",
"logs",
".",
"dbcmd",
"(",
"'get_job'",
",",
"job_id",
")",
"is",
"None",
":",
"print",
"(",
"'There is no job %d'",
"%",
"job_id",
")",
"return",
"if",
"confirmed",
... | Delete a calculation and all associated outputs. | [
"Delete",
"a",
"calculation",
"and",
"all",
"associated",
"outputs",
"."
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/commands/engine.py#L81-L101 |
gem/oq-engine | openquake/commands/engine.py | smart_run | def smart_run(job_ini, oqparam, log_level, log_file, exports, reuse_hazard):
"""
Run calculations by storing their hazard checksum and reusing previous
calculations if requested.
"""
haz_checksum = readinput.get_checksum32(oqparam, hazard=True)
# retrieve an old calculation with the right checks... | python | def smart_run(job_ini, oqparam, log_level, log_file, exports, reuse_hazard):
haz_checksum = readinput.get_checksum32(oqparam, hazard=True)
job = logs.dbcmd('get_job_from_checksum', haz_checksum)
reuse = reuse_hazard and job and os.path.exists(job.ds_calc_dir + '.hdf5')
ebr = (oqparam.calc... | [
"def",
"smart_run",
"(",
"job_ini",
",",
"oqparam",
",",
"log_level",
",",
"log_file",
",",
"exports",
",",
"reuse_hazard",
")",
":",
"haz_checksum",
"=",
"readinput",
".",
"get_checksum32",
"(",
"oqparam",
",",
"hazard",
"=",
"True",
")",
"# retrieve an old c... | Run calculations by storing their hazard checksum and reusing previous
calculations if requested. | [
"Run",
"calculations",
"by",
"storing",
"their",
"hazard",
"checksum",
"and",
"reusing",
"previous",
"calculations",
"if",
"requested",
"."
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/commands/engine.py#L104-L137 |
gem/oq-engine | openquake/commands/engine.py | engine | def engine(log_file, no_distribute, yes, config_file, make_html_report,
upgrade_db, db_version, what_if_I_upgrade, run,
list_hazard_calculations, list_risk_calculations,
delete_calculation, delete_uncompleted_calculations,
hazard_calculation_id, list_outputs, show_log,
... | python | def engine(log_file, no_distribute, yes, config_file, make_html_report,
upgrade_db, db_version, what_if_I_upgrade, run,
list_hazard_calculations, list_risk_calculations,
delete_calculation, delete_uncompleted_calculations,
hazard_calculation_id, list_outputs, show_log,
... | [
"def",
"engine",
"(",
"log_file",
",",
"no_distribute",
",",
"yes",
",",
"config_file",
",",
"make_html_report",
",",
"upgrade_db",
",",
"db_version",
",",
"what_if_I_upgrade",
",",
"run",
",",
"list_hazard_calculations",
",",
"list_risk_calculations",
",",
"delete_... | Run a calculation using the traditional command line API | [
"Run",
"a",
"calculation",
"using",
"the",
"traditional",
"command",
"line",
"API"
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/commands/engine.py#L141-L268 |
gem/oq-engine | openquake/hazardlib/gsim/campbell_bozorgnia_2008.py | CampbellBozorgnia2008.get_mean_and_stddevs | def get_mean_and_stddevs(self, sites, rup, dists, imt, stddev_types):
"""
See :meth:`superclass method
<.base.GroundShakingIntensityModel.get_mean_and_stddevs>`
for spec of input and result values.
"""
# extract dictionaries of coefficients specific to required
# ... | python | def get_mean_and_stddevs(self, sites, rup, dists, imt, stddev_types):
C = self.COEFFS[imt]
C_PGA = self.COEFFS[PGA()]
if imt.name == 'SA' and imt.period > 0.0 and imt.period < 0.25:
get_pga_site = True
e... | [
"def",
"get_mean_and_stddevs",
"(",
"self",
",",
"sites",
",",
"rup",
",",
"dists",
",",
"imt",
",",
"stddev_types",
")",
":",
"# extract dictionaries of coefficients specific to required",
"# intensity measure type and for PGA",
"C",
"=",
"self",
".",
"COEFFS",
"[",
... | See :meth:`superclass method
<.base.GroundShakingIntensityModel.get_mean_and_stddevs>`
for spec of input and result values. | [
"See",
":",
"meth",
":",
"superclass",
"method",
"<",
".",
"base",
".",
"GroundShakingIntensityModel",
".",
"get_mean_and_stddevs",
">",
"for",
"spec",
"of",
"input",
"and",
"result",
"values",
"."
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/gsim/campbell_bozorgnia_2008.py#L83-L127 |
gem/oq-engine | openquake/hazardlib/gsim/campbell_bozorgnia_2008.py | CampbellBozorgnia2008._compute_imt1100 | def _compute_imt1100(self, C, sites, rup, dists, get_pga_site=False):
"""
Computes the PGA on reference (Vs30 = 1100 m/s) rock.
"""
# Calculates simple site response term assuming all sites 1100 m/s
fsite = (C['c10'] + (C['k2'] * C['n'])) * log(1100. / C['k1'])
# Calculat... | python | def _compute_imt1100(self, C, sites, rup, dists, get_pga_site=False):
fsite = (C['c10'] + (C['k2'] * C['n'])) * log(1100. / C['k1'])
pga1100 = np.exp(self._compute_magnitude_term(C, rup.mag) +
self._compute_distance_term(C, rup, dists) +
... | [
"def",
"_compute_imt1100",
"(",
"self",
",",
"C",
",",
"sites",
",",
"rup",
",",
"dists",
",",
"get_pga_site",
"=",
"False",
")",
":",
"# Calculates simple site response term assuming all sites 1100 m/s",
"fsite",
"=",
"(",
"C",
"[",
"'c10'",
"]",
"+",
"(",
"C... | Computes the PGA on reference (Vs30 = 1100 m/s) rock. | [
"Computes",
"the",
"PGA",
"on",
"reference",
"(",
"Vs30",
"=",
"1100",
"m",
"/",
"s",
")",
"rock",
"."
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/gsim/campbell_bozorgnia_2008.py#L129-L150 |
gem/oq-engine | openquake/hazardlib/gsim/campbell_bozorgnia_2008.py | CampbellBozorgnia2008._compute_magnitude_term | def _compute_magnitude_term(self, C, mag):
"""
Returns the magnitude scaling factor (equation (2), page 144)
"""
fmag = C['c0'] + C['c1'] * mag
if mag <= 5.5:
return fmag
elif mag > 6.5:
return fmag + (C['c2'] * (mag - 5.5)) + (C['c3'] * (mag - 6.5... | python | def _compute_magnitude_term(self, C, mag):
fmag = C['c0'] + C['c1'] * mag
if mag <= 5.5:
return fmag
elif mag > 6.5:
return fmag + (C['c2'] * (mag - 5.5)) + (C['c3'] * (mag - 6.5))
else:
return fmag + (C['c2'] * (mag - 5.5)) | [
"def",
"_compute_magnitude_term",
"(",
"self",
",",
"C",
",",
"mag",
")",
":",
"fmag",
"=",
"C",
"[",
"'c0'",
"]",
"+",
"C",
"[",
"'c1'",
"]",
"*",
"mag",
"if",
"mag",
"<=",
"5.5",
":",
"return",
"fmag",
"elif",
"mag",
">",
"6.5",
":",
"return",
... | Returns the magnitude scaling factor (equation (2), page 144) | [
"Returns",
"the",
"magnitude",
"scaling",
"factor",
"(",
"equation",
"(",
"2",
")",
"page",
"144",
")"
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/gsim/campbell_bozorgnia_2008.py#L152-L162 |
gem/oq-engine | openquake/hazardlib/gsim/campbell_bozorgnia_2008.py | CampbellBozorgnia2008._compute_distance_term | def _compute_distance_term(self, C, rup, dists):
"""
Returns the distance scaling factor (equation (3), page 145)
"""
return (C['c4'] + C['c5'] * rup.mag) * \
np.log(np.sqrt(dists.rrup ** 2. + C['c6'] ** 2.)) | python | def _compute_distance_term(self, C, rup, dists):
return (C['c4'] + C['c5'] * rup.mag) * \
np.log(np.sqrt(dists.rrup ** 2. + C['c6'] ** 2.)) | [
"def",
"_compute_distance_term",
"(",
"self",
",",
"C",
",",
"rup",
",",
"dists",
")",
":",
"return",
"(",
"C",
"[",
"'c4'",
"]",
"+",
"C",
"[",
"'c5'",
"]",
"*",
"rup",
".",
"mag",
")",
"*",
"np",
".",
"log",
"(",
"np",
".",
"sqrt",
"(",
"di... | Returns the distance scaling factor (equation (3), page 145) | [
"Returns",
"the",
"distance",
"scaling",
"factor",
"(",
"equation",
"(",
"3",
")",
"page",
"145",
")"
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/gsim/campbell_bozorgnia_2008.py#L164-L169 |
gem/oq-engine | openquake/hazardlib/gsim/campbell_bozorgnia_2008.py | CampbellBozorgnia2008._compute_style_of_faulting_term | def _compute_style_of_faulting_term(self, C, rup):
"""
Returns the style of faulting factor, depending on the mechanism (rake)
and top of rupture depth (equations (4) and (5), pages 145 - 146)
"""
frv, fnm = self._get_fault_type_dummy_variables(rup.rake)
if frv > 0.:
... | python | def _compute_style_of_faulting_term(self, C, rup):
frv, fnm = self._get_fault_type_dummy_variables(rup.rake)
if frv > 0.:
if rup.ztor < 1.:
ffltz = rup.ztor
else:
ffltz = 1.
else:
ffltz = 0.
return... | [
"def",
"_compute_style_of_faulting_term",
"(",
"self",
",",
"C",
",",
"rup",
")",
":",
"frv",
",",
"fnm",
"=",
"self",
".",
"_get_fault_type_dummy_variables",
"(",
"rup",
".",
"rake",
")",
"if",
"frv",
">",
"0.",
":",
"# Top of rupture depth term only applies to... | Returns the style of faulting factor, depending on the mechanism (rake)
and top of rupture depth (equations (4) and (5), pages 145 - 146) | [
"Returns",
"the",
"style",
"of",
"faulting",
"factor",
"depending",
"on",
"the",
"mechanism",
"(",
"rake",
")",
"and",
"top",
"of",
"rupture",
"depth",
"(",
"equations",
"(",
"4",
")",
"and",
"(",
"5",
")",
"pages",
"145",
"-",
"146",
")"
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/gsim/campbell_bozorgnia_2008.py#L171-L186 |
gem/oq-engine | openquake/hazardlib/gsim/campbell_bozorgnia_2008.py | CampbellBozorgnia2008._compute_hanging_wall_term | def _compute_hanging_wall_term(self, C, rup, dists):
"""
Returns the hanging wall scaling term, the product of the scaling
coefficient and four separate scaling terms for distance, magnitude,
rupture depth and dip (equations 6 - 10, page 146). Individual
scaling terms defined in ... | python | def _compute_hanging_wall_term(self, C, rup, dists):
return (C['c9'] *
self._get_hanging_wall_distance_term(dists, rup.ztor) *
self._get_hanging_wall_magnitude_term(rup.mag) *
self._get_hanging_wall_depth_term(rup.ztor) *
self._get_hanging... | [
"def",
"_compute_hanging_wall_term",
"(",
"self",
",",
"C",
",",
"rup",
",",
"dists",
")",
":",
"return",
"(",
"C",
"[",
"'c9'",
"]",
"*",
"self",
".",
"_get_hanging_wall_distance_term",
"(",
"dists",
",",
"rup",
".",
"ztor",
")",
"*",
"self",
".",
"_g... | Returns the hanging wall scaling term, the product of the scaling
coefficient and four separate scaling terms for distance, magnitude,
rupture depth and dip (equations 6 - 10, page 146). Individual
scaling terms defined in separate functions | [
"Returns",
"the",
"hanging",
"wall",
"scaling",
"term",
"the",
"product",
"of",
"the",
"scaling",
"coefficient",
"and",
"four",
"separate",
"scaling",
"terms",
"for",
"distance",
"magnitude",
"rupture",
"depth",
"and",
"dip",
"(",
"equations",
"6",
"-",
"10",
... | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/gsim/campbell_bozorgnia_2008.py#L205-L216 |
gem/oq-engine | openquake/hazardlib/gsim/campbell_bozorgnia_2008.py | CampbellBozorgnia2008._get_hanging_wall_distance_term | def _get_hanging_wall_distance_term(self, dists, ztor):
"""
Returns the hanging wall distance scaling term (equation 7, page 146)
"""
fhngr = np.ones_like(dists.rjb, dtype=float)
idx = dists.rjb > 0.
if ztor < 1.:
temp_rjb = np.sqrt(dists.rjb[idx] ** 2. + 1.)
... | python | def _get_hanging_wall_distance_term(self, dists, ztor):
fhngr = np.ones_like(dists.rjb, dtype=float)
idx = dists.rjb > 0.
if ztor < 1.:
temp_rjb = np.sqrt(dists.rjb[idx] ** 2. + 1.)
r_max = np.max(np.column_stack([dists.rrup[idx], temp_rjb]),
... | [
"def",
"_get_hanging_wall_distance_term",
"(",
"self",
",",
"dists",
",",
"ztor",
")",
":",
"fhngr",
"=",
"np",
".",
"ones_like",
"(",
"dists",
".",
"rjb",
",",
"dtype",
"=",
"float",
")",
"idx",
"=",
"dists",
".",
"rjb",
">",
"0.",
"if",
"ztor",
"<"... | Returns the hanging wall distance scaling term (equation 7, page 146) | [
"Returns",
"the",
"hanging",
"wall",
"distance",
"scaling",
"term",
"(",
"equation",
"7",
"page",
"146",
")"
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/gsim/campbell_bozorgnia_2008.py#L218-L231 |
gem/oq-engine | openquake/hazardlib/gsim/campbell_bozorgnia_2008.py | CampbellBozorgnia2008._compute_shallow_site_response | def _compute_shallow_site_response(self, C, sites, pga1100):
"""
Returns the shallow site response term (equation 11, page 146)
"""
stiff_factor = C['c10'] + (C['k2'] * C['n'])
# Initially default all sites to intermediate rock value
fsite = stiff_factor * np.log(sites.vs... | python | def _compute_shallow_site_response(self, C, sites, pga1100):
stiff_factor = C['c10'] + (C['k2'] * C['n'])
fsite = stiff_factor * np.log(sites.vs30 / C['k1'])
idx = sites.vs30 < C['k1']
if np.any(idx):
pga_scale = np.log(pga1100[idx] +
... | [
"def",
"_compute_shallow_site_response",
"(",
"self",
",",
"C",
",",
"sites",
",",
"pga1100",
")",
":",
"stiff_factor",
"=",
"C",
"[",
"'c10'",
"]",
"+",
"(",
"C",
"[",
"'k2'",
"]",
"*",
"C",
"[",
"'n'",
"]",
")",
"# Initially default all sites to intermed... | Returns the shallow site response term (equation 11, page 146) | [
"Returns",
"the",
"shallow",
"site",
"response",
"term",
"(",
"equation",
"11",
"page",
"146",
")"
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/gsim/campbell_bozorgnia_2008.py#L262-L283 |
gem/oq-engine | openquake/hazardlib/gsim/campbell_bozorgnia_2008.py | CampbellBozorgnia2008._compute_basin_response_term | def _compute_basin_response_term(self, C, z2pt5):
"""
Returns the basin response term (equation 12, page 146)
"""
fsed = np.zeros_like(z2pt5, dtype=float)
idx = z2pt5 < 1.0
if np.any(idx):
fsed[idx] = C['c11'] * (z2pt5[idx] - 1.0)
idx = z2pt5 > 3.0
... | python | def _compute_basin_response_term(self, C, z2pt5):
fsed = np.zeros_like(z2pt5, dtype=float)
idx = z2pt5 < 1.0
if np.any(idx):
fsed[idx] = C['c11'] * (z2pt5[idx] - 1.0)
idx = z2pt5 > 3.0
if np.any(idx):
fsed[idx] = (C['c12'] * C['k3'] * exp(-0.75))... | [
"def",
"_compute_basin_response_term",
"(",
"self",
",",
"C",
",",
"z2pt5",
")",
":",
"fsed",
"=",
"np",
".",
"zeros_like",
"(",
"z2pt5",
",",
"dtype",
"=",
"float",
")",
"idx",
"=",
"z2pt5",
"<",
"1.0",
"if",
"np",
".",
"any",
"(",
"idx",
")",
":"... | Returns the basin response term (equation 12, page 146) | [
"Returns",
"the",
"basin",
"response",
"term",
"(",
"equation",
"12",
"page",
"146",
")"
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/gsim/campbell_bozorgnia_2008.py#L285-L298 |
gem/oq-engine | openquake/hazardlib/gsim/campbell_bozorgnia_2008.py | CampbellBozorgnia2008._get_stddevs | def _get_stddevs(self, C, sites, pga1100, sigma_pga, stddev_types):
"""
Returns the standard deviations as described in the "ALEATORY
UNCERTAINTY MODEL" section of the paper. Equations 13 to 19, pages 147
to 151
"""
std_intra = self._compute_intra_event_std(C,
... | python | def _get_stddevs(self, C, sites, pga1100, sigma_pga, stddev_types):
std_intra = self._compute_intra_event_std(C,
sites.vs30,
pga1100,
sigma_pga)
... | [
"def",
"_get_stddevs",
"(",
"self",
",",
"C",
",",
"sites",
",",
"pga1100",
",",
"sigma_pga",
",",
"stddev_types",
")",
":",
"std_intra",
"=",
"self",
".",
"_compute_intra_event_std",
"(",
"C",
",",
"sites",
".",
"vs30",
",",
"pga1100",
",",
"sigma_pga",
... | Returns the standard deviations as described in the "ALEATORY
UNCERTAINTY MODEL" section of the paper. Equations 13 to 19, pages 147
to 151 | [
"Returns",
"the",
"standard",
"deviations",
"as",
"described",
"in",
"the",
"ALEATORY",
"UNCERTAINTY",
"MODEL",
"section",
"of",
"the",
"paper",
".",
"Equations",
"13",
"to",
"19",
"pages",
"147",
"to",
"151"
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/gsim/campbell_bozorgnia_2008.py#L300-L321 |
gem/oq-engine | openquake/hazardlib/gsim/campbell_bozorgnia_2008.py | CampbellBozorgnia2008._compute_intra_event_std | def _compute_intra_event_std(self, C, vs30, pga1100, sigma_pga):
"""
Returns the intra-event standard deviation at the site, as defined in
equation 15, page 147
"""
# Get intra-event standard deviation at the base of the site profile
sig_lnyb = np.sqrt(C['s_lny'] ** 2. - ... | python | def _compute_intra_event_std(self, C, vs30, pga1100, sigma_pga):
sig_lnyb = np.sqrt(C['s_lny'] ** 2. - C['s_lnAF'] ** 2.)
sig_lnab = np.sqrt(sigma_pga ** 2. - C['s_lnAF'] ** 2.)
alpha = self._compute_intra_event_alpha(C, vs30, pga1100)
return np.sqrt(
... | [
"def",
"_compute_intra_event_std",
"(",
"self",
",",
"C",
",",
"vs30",
",",
"pga1100",
",",
"sigma_pga",
")",
":",
"# Get intra-event standard deviation at the base of the site profile",
"sig_lnyb",
"=",
"np",
".",
"sqrt",
"(",
"C",
"[",
"'s_lny'",
"]",
"**",
"2."... | Returns the intra-event standard deviation at the site, as defined in
equation 15, page 147 | [
"Returns",
"the",
"intra",
"-",
"event",
"standard",
"deviation",
"at",
"the",
"site",
"as",
"defined",
"in",
"equation",
"15",
"page",
"147"
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/gsim/campbell_bozorgnia_2008.py#L323-L338 |
gem/oq-engine | openquake/hazardlib/gsim/campbell_bozorgnia_2008.py | CampbellBozorgnia2008._compute_intra_event_alpha | def _compute_intra_event_alpha(self, C, vs30, pga1100):
"""
Returns the linearised functional relationship between fsite and
pga1100, determined from the partial derivative defined on equation 17
on page 148
"""
alpha = np.zeros_like(vs30, dtype=float)
idx = vs30 ... | python | def _compute_intra_event_alpha(self, C, vs30, pga1100):
alpha = np.zeros_like(vs30, dtype=float)
idx = vs30 < C['k1']
if np.any(idx):
temp1 = (pga1100[idx] +
C['c'] * (vs30[idx] / C['k1']) ** C['n']) ** -1.
temp1 = temp1 - ((pga1100[idx] + C[... | [
"def",
"_compute_intra_event_alpha",
"(",
"self",
",",
"C",
",",
"vs30",
",",
"pga1100",
")",
":",
"alpha",
"=",
"np",
".",
"zeros_like",
"(",
"vs30",
",",
"dtype",
"=",
"float",
")",
"idx",
"=",
"vs30",
"<",
"C",
"[",
"'k1'",
"]",
"if",
"np",
".",... | Returns the linearised functional relationship between fsite and
pga1100, determined from the partial derivative defined on equation 17
on page 148 | [
"Returns",
"the",
"linearised",
"functional",
"relationship",
"between",
"fsite",
"and",
"pga1100",
"determined",
"from",
"the",
"partial",
"derivative",
"defined",
"on",
"equation",
"17",
"on",
"page",
"148"
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/gsim/campbell_bozorgnia_2008.py#L340-L354 |
gem/oq-engine | openquake/hazardlib/gsim/campbell_bozorgnia_2008.py | CampbellBozorgnia2008Arbitrary._get_total_sigma | def _get_total_sigma(self, C, std_intra, std_inter):
"""
Returns the total sigma term for the arbitrary horizontal component of
ground motion defined by equation 18, page 150
"""
return np.sqrt(std_intra ** 2. + std_inter ** 2. + C['c_lny'] ** 2.) | python | def _get_total_sigma(self, C, std_intra, std_inter):
return np.sqrt(std_intra ** 2. + std_inter ** 2. + C['c_lny'] ** 2.) | [
"def",
"_get_total_sigma",
"(",
"self",
",",
"C",
",",
"std_intra",
",",
"std_inter",
")",
":",
"return",
"np",
".",
"sqrt",
"(",
"std_intra",
"**",
"2.",
"+",
"std_inter",
"**",
"2.",
"+",
"C",
"[",
"'c_lny'",
"]",
"**",
"2.",
")"
] | Returns the total sigma term for the arbitrary horizontal component of
ground motion defined by equation 18, page 150 | [
"Returns",
"the",
"total",
"sigma",
"term",
"for",
"the",
"arbitrary",
"horizontal",
"component",
"of",
"ground",
"motion",
"defined",
"by",
"equation",
"18",
"page",
"150"
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/gsim/campbell_bozorgnia_2008.py#L407-L412 |
gem/oq-engine | openquake/calculators/ucerf_event_based.py | generate_event_set | def generate_event_set(ucerf, background_sids, src_filter, ses_idx, seed):
"""
Generates the event set corresponding to a particular branch
"""
serial = seed + ses_idx * TWO16
# get rates from file
with h5py.File(ucerf.source_file, 'r') as hdf5:
occurrences = ucerf.tom.sample_number_of_o... | python | def generate_event_set(ucerf, background_sids, src_filter, ses_idx, seed):
serial = seed + ses_idx * TWO16
with h5py.File(ucerf.source_file, 'r') as hdf5:
occurrences = ucerf.tom.sample_number_of_occurrences(ucerf.rate, seed)
indices, = numpy.where(occurrences)
logging.debug(
... | [
"def",
"generate_event_set",
"(",
"ucerf",
",",
"background_sids",
",",
"src_filter",
",",
"ses_idx",
",",
"seed",
")",
":",
"serial",
"=",
"seed",
"+",
"ses_idx",
"*",
"TWO16",
"# get rates from file",
"with",
"h5py",
".",
"File",
"(",
"ucerf",
".",
"source... | Generates the event set corresponding to a particular branch | [
"Generates",
"the",
"event",
"set",
"corresponding",
"to",
"a",
"particular",
"branch"
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/calculators/ucerf_event_based.py#L41-L76 |
gem/oq-engine | openquake/calculators/ucerf_event_based.py | sample_background_model | def sample_background_model(
hdf5, branch_key, tom, seed, filter_idx, min_mag, npd, hdd,
upper_seismogenic_depth, lower_seismogenic_depth, msr=WC1994(),
aspect=1.5, trt=DEFAULT_TRT):
"""
Generates a rupture set from a sample of the background model
:param branch_key:
Key to ... | python | def sample_background_model(
hdf5, branch_key, tom, seed, filter_idx, min_mag, npd, hdd,
upper_seismogenic_depth, lower_seismogenic_depth, msr=WC1994(),
aspect=1.5, trt=DEFAULT_TRT):
bg_magnitudes = hdf5["/".join(["Grid", branch_key, "Magnitude"])].value
mag_idx = bg_magnitudes... | [
"def",
"sample_background_model",
"(",
"hdf5",
",",
"branch_key",
",",
"tom",
",",
"seed",
",",
"filter_idx",
",",
"min_mag",
",",
"npd",
",",
"hdd",
",",
"upper_seismogenic_depth",
",",
"lower_seismogenic_depth",
",",
"msr",
"=",
"WC1994",
"(",
")",
",",
"a... | Generates a rupture set from a sample of the background model
:param branch_key:
Key to indicate the branch for selecting the background model
:param tom:
Temporal occurrence model as instance of :class:
openquake.hazardlib.tom.TOM
:param seed:
Random seed to use in the call... | [
"Generates",
"a",
"rupture",
"set",
"from",
"a",
"sample",
"of",
"the",
"background",
"model"
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/calculators/ucerf_event_based.py#L79-L136 |
gem/oq-engine | openquake/calculators/ucerf_event_based.py | build_ruptures | def build_ruptures(sources, src_filter, param, monitor):
"""
:param sources: a list with a single UCERF source
:param param: extra parameters
:param monitor: a Monitor instance
:returns: an AccumDict grp_id -> EBRuptures
"""
[src] = sources
res = AccumDict()
res.calc_times = []
s... | python | def build_ruptures(sources, src_filter, param, monitor):
[src] = sources
res = AccumDict()
res.calc_times = []
sampl_mon = monitor('sampling ruptures', measuremem=True)
res.trt = DEFAULT_TRT
background_sids = src.get_background_sids(src_filter)
sitecol = src_filter.sitecol
samples =... | [
"def",
"build_ruptures",
"(",
"sources",
",",
"src_filter",
",",
"param",
",",
"monitor",
")",
":",
"[",
"src",
"]",
"=",
"sources",
"res",
"=",
"AccumDict",
"(",
")",
"res",
".",
"calc_times",
"=",
"[",
"]",
"sampl_mon",
"=",
"monitor",
"(",
"'samplin... | :param sources: a list with a single UCERF source
:param param: extra parameters
:param monitor: a Monitor instance
:returns: an AccumDict grp_id -> EBRuptures | [
":",
"param",
"sources",
":",
"a",
"list",
"with",
"a",
"single",
"UCERF",
"source",
":",
"param",
"param",
":",
"extra",
"parameters",
":",
"param",
"monitor",
":",
"a",
"Monitor",
"instance",
":",
"returns",
":",
"an",
"AccumDict",
"grp_id",
"-",
">",
... | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/calculators/ucerf_event_based.py#L141-L173 |
gem/oq-engine | openquake/hazardlib/scalerel/wc1994.py | WC1994.get_median_area | def get_median_area(self, mag, rake):
"""
The values are a function of both magnitude and rake.
Setting the rake to ``None`` causes their "All" rupture-types
to be applied.
"""
assert rake is None or -180 <= rake <= 180
if rake is None:
# their "All" ... | python | def get_median_area(self, mag, rake):
assert rake is None or -180 <= rake <= 180
if rake is None:
return 10.0 ** (-3.49 + 0.91 * mag)
elif (-45 <= rake <= 45) or (rake >= 135) or (rake <= -135):
return 10.0 ** (-3.42 + 0.90 * mag)
... | [
"def",
"get_median_area",
"(",
"self",
",",
"mag",
",",
"rake",
")",
":",
"assert",
"rake",
"is",
"None",
"or",
"-",
"180",
"<=",
"rake",
"<=",
"180",
"if",
"rake",
"is",
"None",
":",
"# their \"All\" case",
"return",
"10.0",
"**",
"(",
"-",
"3.49",
... | The values are a function of both magnitude and rake.
Setting the rake to ``None`` causes their "All" rupture-types
to be applied. | [
"The",
"values",
"are",
"a",
"function",
"of",
"both",
"magnitude",
"and",
"rake",
"."
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/scalerel/wc1994.py#L33-L52 |
gem/oq-engine | openquake/hazardlib/scalerel/wc1994.py | WC1994.get_std_dev_area | def get_std_dev_area(self, mag, rake):
"""
Standard deviation for WC1994. Magnitude is ignored.
"""
assert rake is None or -180 <= rake <= 180
if rake is None:
# their "All" case
return 0.24
elif (-45 <= rake <= 45) or (rake >= 135) or (rake <= -13... | python | def get_std_dev_area(self, mag, rake):
assert rake is None or -180 <= rake <= 180
if rake is None:
return 0.24
elif (-45 <= rake <= 45) or (rake >= 135) or (rake <= -135):
return 0.22
elif rake > 0:
retur... | [
"def",
"get_std_dev_area",
"(",
"self",
",",
"mag",
",",
"rake",
")",
":",
"assert",
"rake",
"is",
"None",
"or",
"-",
"180",
"<=",
"rake",
"<=",
"180",
"if",
"rake",
"is",
"None",
":",
"# their \"All\" case",
"return",
"0.24",
"elif",
"(",
"-",
"45",
... | Standard deviation for WC1994. Magnitude is ignored. | [
"Standard",
"deviation",
"for",
"WC1994",
".",
"Magnitude",
"is",
"ignored",
"."
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/scalerel/wc1994.py#L54-L70 |
gem/oq-engine | openquake/hazardlib/scalerel/wc1994.py | WC1994.get_std_dev_mag | def get_std_dev_mag(self, rake):
"""
Standard deviation on the magnitude for the WC1994 area relation.
"""
assert rake is None or -180 <= rake <= 180
if rake is None:
# their "All" case
return 0.24
elif (-45 <= rake <= 45) or (rake >= 135) or (rake... | python | def get_std_dev_mag(self, rake):
assert rake is None or -180 <= rake <= 180
if rake is None:
return 0.24
elif (-45 <= rake <= 45) or (rake >= 135) or (rake <= -135):
return 0.23
elif rake > 0:
return 0.25... | [
"def",
"get_std_dev_mag",
"(",
"self",
",",
"rake",
")",
":",
"assert",
"rake",
"is",
"None",
"or",
"-",
"180",
"<=",
"rake",
"<=",
"180",
"if",
"rake",
"is",
"None",
":",
"# their \"All\" case",
"return",
"0.24",
"elif",
"(",
"-",
"45",
"<=",
"rake",
... | Standard deviation on the magnitude for the WC1994 area relation. | [
"Standard",
"deviation",
"on",
"the",
"magnitude",
"for",
"the",
"WC1994",
"area",
"relation",
"."
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/scalerel/wc1994.py#L72-L88 |
gem/oq-engine | openquake/hazardlib/scalerel/wc1994.py | WC1994.get_median_mag | def get_median_mag(self, area, rake):
"""
Return magnitude (Mw) given the area and rake.
Setting the rake to ``None`` causes their "All" rupture-types
to be applied.
:param area:
Area in square km.
:param rake:
Rake angle (the rupture propagation... | python | def get_median_mag(self, area, rake):
assert rake is None or -180 <= rake <= 180
if rake is None:
return 4.07 + 0.98 * log10(area)
elif (-45 <= rake <= 45) or (rake > 135) or (rake < -135):
return 3.98 + 1.02 * log10(area)
elif r... | [
"def",
"get_median_mag",
"(",
"self",
",",
"area",
",",
"rake",
")",
":",
"assert",
"rake",
"is",
"None",
"or",
"-",
"180",
"<=",
"rake",
"<=",
"180",
"if",
"rake",
"is",
"None",
":",
"# their \"All\" case",
"return",
"4.07",
"+",
"0.98",
"*",
"log10",... | Return magnitude (Mw) given the area and rake.
Setting the rake to ``None`` causes their "All" rupture-types
to be applied.
:param area:
Area in square km.
:param rake:
Rake angle (the rupture propagation direction) in degrees,
from -180 to 180. | [
"Return",
"magnitude",
"(",
"Mw",
")",
"given",
"the",
"area",
"and",
"rake",
"."
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/scalerel/wc1994.py#L90-L115 |
gem/oq-engine | openquake/hazardlib/gsim/mgmpe/generic_gmpe_avgsa.py | GenericGmpeAvgSA.set_parameters | def set_parameters(self):
"""
Combines the parameters of the GMPE provided at the construction
level with the ones assigned to the average GMPE.
"""
for key in dir(self):
if key.startswith('REQUIRES_'):
setattr(self, key, getattr(self.gmpe, key))
... | python | def set_parameters(self):
for key in dir(self):
if key.startswith('REQUIRES_'):
setattr(self, key, getattr(self.gmpe, key))
if key.startswith('DEFINED_'):
if not key.endswith('FOR_INTENSITY_MEASURE_TYPES'):
setattr(self, key, g... | [
"def",
"set_parameters",
"(",
"self",
")",
":",
"for",
"key",
"in",
"dir",
"(",
"self",
")",
":",
"if",
"key",
".",
"startswith",
"(",
"'REQUIRES_'",
")",
":",
"setattr",
"(",
"self",
",",
"key",
",",
"getattr",
"(",
"self",
".",
"gmpe",
",",
"key"... | Combines the parameters of the GMPE provided at the construction
level with the ones assigned to the average GMPE. | [
"Combines",
"the",
"parameters",
"of",
"the",
"GMPE",
"provided",
"at",
"the",
"construction",
"level",
"with",
"the",
"ones",
"assigned",
"to",
"the",
"average",
"GMPE",
"."
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/gsim/mgmpe/generic_gmpe_avgsa.py#L87-L97 |
gem/oq-engine | openquake/hazardlib/gsim/mgmpe/generic_gmpe_avgsa.py | GenericGmpeAvgSA.get_mean_and_stddevs | def get_mean_and_stddevs(self, sites, rup, dists, imt, stds_types):
"""
See :meth:`superclass method
<.base.GroundShakingIntensityModel.get_mean_and_stddevs>`
for spec of input and result values.
"""
mean_list = []
stddvs_list = []
# Loop over averaging ... | python | def get_mean_and_stddevs(self, sites, rup, dists, imt, stds_types):
mean_list = []
stddvs_list = []
for period in self.avg_periods:
imt_local = SA(float(period))
mean, stddvs = self.gmpe.get_mean_and_stddevs(sites, rup, dists,
... | [
"def",
"get_mean_and_stddevs",
"(",
"self",
",",
"sites",
",",
"rup",
",",
"dists",
",",
"imt",
",",
"stds_types",
")",
":",
"mean_list",
"=",
"[",
"]",
"stddvs_list",
"=",
"[",
"]",
"# Loop over averaging periods",
"for",
"period",
"in",
"self",
".",
"avg... | See :meth:`superclass method
<.base.GroundShakingIntensityModel.get_mean_and_stddevs>`
for spec of input and result values. | [
"See",
":",
"meth",
":",
"superclass",
"method",
"<",
".",
"base",
".",
"GroundShakingIntensityModel",
".",
"get_mean_and_stddevs",
">",
"for",
"spec",
"of",
"input",
"and",
"result",
"values",
"."
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/gsim/mgmpe/generic_gmpe_avgsa.py#L99-L132 |
gem/oq-engine | openquake/hazardlib/gsim/mgmpe/generic_gmpe_avgsa.py | BakerJayaramCorrelationModel.get_correlation | def get_correlation(self, t1, t2):
"""
Computes the correlation coefficient for the specified periods.
:param float t1:
First period of interest.
:param float t2:
Second period of interest.
:return float rho:
The predicted correlation coeffi... | python | def get_correlation(self, t1, t2):
t_min = min(t1, t2)
t_max = max(t1, t2)
c1 = 1.0
c1 -= np.cos(np.pi / 2.0 - np.log(t_max / max(t_min, 0.109)) * 0.366)
if t_max < 0.2:
c2 = 0.105 * (1.0 - 1.0 / (1.0 + np.exp(100.0 * t_max - 5.0)))
c2 = 1.0 - ... | [
"def",
"get_correlation",
"(",
"self",
",",
"t1",
",",
"t2",
")",
":",
"t_min",
"=",
"min",
"(",
"t1",
",",
"t2",
")",
"t_max",
"=",
"max",
"(",
"t1",
",",
"t2",
")",
"c1",
"=",
"1.0",
"c1",
"-=",
"np",
".",
"cos",
"(",
"np",
".",
"pi",
"/"... | Computes the correlation coefficient for the specified periods.
:param float t1:
First period of interest.
:param float t2:
Second period of interest.
:return float rho:
The predicted correlation coefficient. | [
"Computes",
"the",
"correlation",
"coefficient",
"for",
"the",
"specified",
"periods",
"."
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/gsim/mgmpe/generic_gmpe_avgsa.py#L165-L208 |
gem/oq-engine | openquake/hazardlib/gsim/mgmpe/generic_gmpe_avgsa.py | AkkarCorrelationModel.get_correlation | def get_correlation(self, t1, t2):
"""
Computes the correlation coefficient for the specified periods.
:param float t1:
First period of interest.
:param float t2:
Second period of interest.
:return float:
The predicted correlation coefficien... | python | def get_correlation(self, t1, t2):
if t1 not in act.periods:
raise ValueError('t1 not a valid period')
if t2 not in act.periods:
raise ValueError('t2 not a valid period')
return act.coeff_table[act.periods.index(t1)][act.periods.index(t2)] | [
"def",
"get_correlation",
"(",
"self",
",",
"t1",
",",
"t2",
")",
":",
"if",
"t1",
"not",
"in",
"act",
".",
"periods",
":",
"raise",
"ValueError",
"(",
"'t1 not a valid period'",
")",
"if",
"t2",
"not",
"in",
"act",
".",
"periods",
":",
"raise",
"Value... | Computes the correlation coefficient for the specified periods.
:param float t1:
First period of interest.
:param float t2:
Second period of interest.
:return float:
The predicted correlation coefficient. | [
"Computes",
"the",
"correlation",
"coefficient",
"for",
"the",
"specified",
"periods",
"."
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/gsim/mgmpe/generic_gmpe_avgsa.py#L220-L240 |
gem/oq-engine | openquake/hazardlib/geo/mesh.py | surface_to_array | def surface_to_array(surface):
"""
:param surface: a Surface object
:returns: a 3D array of shape (3, N, M)
"""
if hasattr(surface, 'surfaces'): # multiplanar surfaces
n = len(surface.surfaces)
arr = numpy.zeros((3, n, 4), F32)
for i, surf in enumerate(surface.surfaces):
... | python | def surface_to_array(surface):
if hasattr(surface, 'surfaces'):
n = len(surface.surfaces)
arr = numpy.zeros((3, n, 4), F32)
for i, surf in enumerate(surface.surfaces):
arr[:, i] = surf.mesh.array
return arr
mesh = surface.mesh
if len(mesh.lons.shape) == 1: ... | [
"def",
"surface_to_array",
"(",
"surface",
")",
":",
"if",
"hasattr",
"(",
"surface",
",",
"'surfaces'",
")",
":",
"# multiplanar surfaces",
"n",
"=",
"len",
"(",
"surface",
".",
"surfaces",
")",
"arr",
"=",
"numpy",
".",
"zeros",
"(",
"(",
"3",
",",
"... | :param surface: a Surface object
:returns: a 3D array of shape (3, N, M) | [
":",
"param",
"surface",
":",
"a",
"Surface",
"object",
":",
"returns",
":",
"a",
"3D",
"array",
"of",
"shape",
"(",
"3",
"N",
"M",
")"
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/geo/mesh.py#L46-L62 |
gem/oq-engine | openquake/hazardlib/geo/mesh.py | Mesh.from_coords | def from_coords(cls, coords, sort=True):
"""
Create a mesh object from a list of 3D coordinates (by sorting them)
:params coords: list of coordinates
:param sort: flag (default True)
:returns: a :class:`Mesh` instance
"""
coords = list(coords)
if sort:
... | python | def from_coords(cls, coords, sort=True):
coords = list(coords)
if sort:
coords.sort()
if len(coords[0]) == 2:
lons, lats = zip(*coords)
depths = None
else:
lons, lats, depths = zip(*coords)
depths = numpy.array(dept... | [
"def",
"from_coords",
"(",
"cls",
",",
"coords",
",",
"sort",
"=",
"True",
")",
":",
"coords",
"=",
"list",
"(",
"coords",
")",
"if",
"sort",
":",
"coords",
".",
"sort",
"(",
")",
"if",
"len",
"(",
"coords",
"[",
"0",
"]",
")",
"==",
"2",
":",
... | Create a mesh object from a list of 3D coordinates (by sorting them)
:params coords: list of coordinates
:param sort: flag (default True)
:returns: a :class:`Mesh` instance | [
"Create",
"a",
"mesh",
"object",
"from",
"a",
"list",
"of",
"3D",
"coordinates",
"(",
"by",
"sorting",
"them",
")"
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/geo/mesh.py#L114-L131 |
gem/oq-engine | openquake/hazardlib/geo/mesh.py | Mesh.from_points_list | def from_points_list(cls, points):
"""
Create a mesh object from a collection of points.
:param point:
List of :class:`~openquake.hazardlib.geo.point.Point` objects.
:returns:
An instance of :class:`Mesh` with one-dimensional arrays
of coordinates fro... | python | def from_points_list(cls, points):
lons = numpy.zeros(len(points), dtype=float)
lats = lons.copy()
depths = lons.copy()
for i in range(len(points)):
lons[i] = points[i].longitude
lats[i] = points[i].latitude
depths[i] = points[i].depth
... | [
"def",
"from_points_list",
"(",
"cls",
",",
"points",
")",
":",
"lons",
"=",
"numpy",
".",
"zeros",
"(",
"len",
"(",
"points",
")",
",",
"dtype",
"=",
"float",
")",
"lats",
"=",
"lons",
".",
"copy",
"(",
")",
"depths",
"=",
"lons",
".",
"copy",
"... | Create a mesh object from a collection of points.
:param point:
List of :class:`~openquake.hazardlib.geo.point.Point` objects.
:returns:
An instance of :class:`Mesh` with one-dimensional arrays
of coordinates from ``points``. | [
"Create",
"a",
"mesh",
"object",
"from",
"a",
"collection",
"of",
"points",
"."
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/geo/mesh.py#L134-L154 |
gem/oq-engine | openquake/hazardlib/geo/mesh.py | Mesh.xyz | def xyz(self):
"""
:returns: an array of shape (N, 3) with the cartesian coordinates
"""
return geo_utils.spherical_to_cartesian(
self.lons.flat, self.lats.flat, self.depths.flat) | python | def xyz(self):
return geo_utils.spherical_to_cartesian(
self.lons.flat, self.lats.flat, self.depths.flat) | [
"def",
"xyz",
"(",
"self",
")",
":",
"return",
"geo_utils",
".",
"spherical_to_cartesian",
"(",
"self",
".",
"lons",
".",
"flat",
",",
"self",
".",
"lats",
".",
"flat",
",",
"self",
".",
"depths",
".",
"flat",
")"
] | :returns: an array of shape (N, 3) with the cartesian coordinates | [
":",
"returns",
":",
"an",
"array",
"of",
"shape",
"(",
"N",
"3",
")",
"with",
"the",
"cartesian",
"coordinates"
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/geo/mesh.py#L167-L172 |
gem/oq-engine | openquake/hazardlib/geo/mesh.py | Mesh.get_min_distance | def get_min_distance(self, mesh):
"""
Compute and return the minimum distance from the mesh to each point
in another mesh.
:returns:
numpy array of distances in km of shape (self.size, mesh.size)
Method doesn't make any assumptions on arrangement of the points
... | python | def get_min_distance(self, mesh):
return cdist(self.xyz, mesh.xyz).min(axis=0) | [
"def",
"get_min_distance",
"(",
"self",
",",
"mesh",
")",
":",
"return",
"cdist",
"(",
"self",
".",
"xyz",
",",
"mesh",
".",
"xyz",
")",
".",
"min",
"(",
"axis",
"=",
"0",
")"
] | Compute and return the minimum distance from the mesh to each point
in another mesh.
:returns:
numpy array of distances in km of shape (self.size, mesh.size)
Method doesn't make any assumptions on arrangement of the points
in either mesh and instead calculates the distance ... | [
"Compute",
"and",
"return",
"the",
"minimum",
"distance",
"from",
"the",
"mesh",
"to",
"each",
"point",
"in",
"another",
"mesh",
"."
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/geo/mesh.py#L236-L249 |
gem/oq-engine | openquake/hazardlib/geo/mesh.py | Mesh.get_closest_points | def get_closest_points(self, mesh):
"""
Find closest point of this mesh for each point in the other mesh
:returns:
:class:`Mesh` object of the same shape as `mesh` with closest
points from this one at respective indices.
"""
min_idx = cdist(self.xyz, mesh... | python | def get_closest_points(self, mesh):
min_idx = cdist(self.xyz, mesh.xyz).argmin(axis=0)
if hasattr(mesh, 'shape'):
min_idx = min_idx.reshape(mesh.shape)
lons = self.lons.take(min_idx)
lats = self.lats.take(min_idx)
deps = self.depths.take(min_idx)
re... | [
"def",
"get_closest_points",
"(",
"self",
",",
"mesh",
")",
":",
"min_idx",
"=",
"cdist",
"(",
"self",
".",
"xyz",
",",
"mesh",
".",
"xyz",
")",
".",
"argmin",
"(",
"axis",
"=",
"0",
")",
"# lose shape",
"if",
"hasattr",
"(",
"mesh",
",",
"'shape'",
... | Find closest point of this mesh for each point in the other mesh
:returns:
:class:`Mesh` object of the same shape as `mesh` with closest
points from this one at respective indices. | [
"Find",
"closest",
"point",
"of",
"this",
"mesh",
"for",
"each",
"point",
"in",
"the",
"other",
"mesh"
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/geo/mesh.py#L251-L265 |
gem/oq-engine | openquake/hazardlib/geo/mesh.py | Mesh.get_distance_matrix | def get_distance_matrix(self):
"""
Compute and return distances between each pairs of points in the mesh.
This method requires that the coordinate arrays are one-dimensional.
NB: the depth of the points is ignored
.. warning::
Because of its quadratic space and time... | python | def get_distance_matrix(self):
assert self.lons.ndim == 1
distances = geodetic.geodetic_distance(
self.lons.reshape(self.lons.shape + (1, )),
self.lats.reshape(self.lats.shape + (1, )),
self.lons,
self.lats)
return numpy.matrix(distances, ... | [
"def",
"get_distance_matrix",
"(",
"self",
")",
":",
"assert",
"self",
".",
"lons",
".",
"ndim",
"==",
"1",
"distances",
"=",
"geodetic",
".",
"geodetic_distance",
"(",
"self",
".",
"lons",
".",
"reshape",
"(",
"self",
".",
"lons",
".",
"shape",
"+",
"... | Compute and return distances between each pairs of points in the mesh.
This method requires that the coordinate arrays are one-dimensional.
NB: the depth of the points is ignored
.. warning::
Because of its quadratic space and time complexity this method
is safe to use ... | [
"Compute",
"and",
"return",
"distances",
"between",
"each",
"pairs",
"of",
"points",
"in",
"the",
"mesh",
"."
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/geo/mesh.py#L267-L295 |
gem/oq-engine | openquake/hazardlib/geo/mesh.py | Mesh._get_proj_convex_hull | def _get_proj_convex_hull(self):
"""
Create a projection centered in the center of this mesh and define
a convex polygon in that projection, enveloping all the points
of the mesh.
:returns:
Tuple of two items: projection function and shapely 2d polygon.
N... | python | def _get_proj_convex_hull(self):
proj = geo_utils.OrthographicProjection(
*geo_utils.get_spherical_bounding_box(self.lons, self.lats))
coords = numpy.transpose(proj(self.lons.flat, self.lats.flat)).copy()
multipoint = shapely.geometry.MultiPoint(c... | [
"def",
"_get_proj_convex_hull",
"(",
"self",
")",
":",
"# create a projection centered in the center of points collection",
"proj",
"=",
"geo_utils",
".",
"OrthographicProjection",
"(",
"*",
"geo_utils",
".",
"get_spherical_bounding_box",
"(",
"self",
".",
"lons",
",",
"s... | Create a projection centered in the center of this mesh and define
a convex polygon in that projection, enveloping all the points
of the mesh.
:returns:
Tuple of two items: projection function and shapely 2d polygon.
Note that the result geometry can be line or point dep... | [
"Create",
"a",
"projection",
"centered",
"in",
"the",
"center",
"of",
"this",
"mesh",
"and",
"define",
"a",
"convex",
"polygon",
"in",
"that",
"projection",
"enveloping",
"all",
"the",
"points",
"of",
"the",
"mesh",
"."
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/geo/mesh.py#L297-L317 |
gem/oq-engine | openquake/hazardlib/geo/mesh.py | Mesh.get_joyner_boore_distance | def get_joyner_boore_distance(self, mesh):
"""
Compute and return Joyner-Boore distance to each point of ``mesh``.
Point's depth is ignored.
See
:meth:`openquake.hazardlib.geo.surface.base.BaseSurface.get_joyner_boore_distance`
for definition of this distance.
:... | python | def get_joyner_boore_distance(self, mesh):
distances = geodetic.min_geodetic_distance(
(self.lons, self.lats), (mesh.lons, mesh.lats))
... | [
"def",
"get_joyner_boore_distance",
"(",
"self",
",",
"mesh",
")",
":",
"# we perform a hybrid calculation (geodetic mesh-to-mesh distance",
"# and distance on the projection plane for close points). first,",
"# we find the closest geodetic distance for each point of target",
"# mesh to this o... | Compute and return Joyner-Boore distance to each point of ``mesh``.
Point's depth is ignored.
See
:meth:`openquake.hazardlib.geo.surface.base.BaseSurface.get_joyner_boore_distance`
for definition of this distance.
:returns:
numpy array of distances in km of the same... | [
"Compute",
"and",
"return",
"Joyner",
"-",
"Boore",
"distance",
"to",
"each",
"point",
"of",
"mesh",
".",
"Point",
"s",
"depth",
"is",
"ignored",
"."
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/geo/mesh.py#L319-L393 |
gem/oq-engine | openquake/hazardlib/geo/mesh.py | Mesh._get_proj_enclosing_polygon | def _get_proj_enclosing_polygon(self):
"""
See :meth:`Mesh._get_proj_enclosing_polygon`.
:class:`RectangularMesh` contains an information about relative
positions of points, so it allows to define the minimum polygon,
containing the projection of the mesh, which doesn't necessar... | python | def _get_proj_enclosing_polygon(self):
if self.lons.size < 4:
return self._get_proj_convex_hull()
proj = geo_utils.OrthographicProjection(
*geo_utils.get_spherical_bounding_box(self.lons, self.lats))
if len(self.lons.shape) == 1:
lons ... | [
"def",
"_get_proj_enclosing_polygon",
"(",
"self",
")",
":",
"if",
"self",
".",
"lons",
".",
"size",
"<",
"4",
":",
"# the mesh doesn't contain even a single cell",
"return",
"self",
".",
"_get_proj_convex_hull",
"(",
")",
"proj",
"=",
"geo_utils",
".",
"Orthograp... | See :meth:`Mesh._get_proj_enclosing_polygon`.
:class:`RectangularMesh` contains an information about relative
positions of points, so it allows to define the minimum polygon,
containing the projection of the mesh, which doesn't necessarily
have to be convex (in contrast to :class:`Mesh`... | [
"See",
":",
"meth",
":",
"Mesh",
".",
"_get_proj_enclosing_polygon",
"."
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/geo/mesh.py#L395-L455 |
gem/oq-engine | openquake/hazardlib/geo/mesh.py | Mesh.get_convex_hull | def get_convex_hull(self):
"""
Get a convex polygon object that contains projections of all the points
of the mesh.
:returns:
Instance of :class:`openquake.hazardlib.geo.polygon.Polygon` that
is a convex hull around all the points in this mesh. If the
... | python | def get_convex_hull(self):
proj, polygon2d = self._get_proj_convex_hull()
if isinstance(polygon2d, (shapely.geometry.LineString,
shapely.geometry.Point)):
polygon2d = polygon2d.buffer(self.DIST_TOLERANCE, 1)
... | [
"def",
"get_convex_hull",
"(",
"self",
")",
":",
"proj",
",",
"polygon2d",
"=",
"self",
".",
"_get_proj_convex_hull",
"(",
")",
"# if mesh had only one point, the convex hull is a point. if there",
"# were two, it is a line string. we need to return a convex polygon",
"# object, so... | Get a convex polygon object that contains projections of all the points
of the mesh.
:returns:
Instance of :class:`openquake.hazardlib.geo.polygon.Polygon` that
is a convex hull around all the points in this mesh. If the
original mesh had only one point, the resultin... | [
"Get",
"a",
"convex",
"polygon",
"object",
"that",
"contains",
"projections",
"of",
"all",
"the",
"points",
"of",
"the",
"mesh",
"."
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/geo/mesh.py#L457-L480 |
gem/oq-engine | openquake/hazardlib/geo/mesh.py | RectangularMesh.from_points_list | def from_points_list(cls, points):
"""
Create a rectangular mesh object from a list of lists of points.
Lists in a list are supposed to have the same length.
:param point:
List of lists of :class:`~openquake.hazardlib.geo.point.Point`
objects.
"""
... | python | def from_points_list(cls, points):
assert points is not None and len(points) > 0 and len(points[0]) > 0, \
'list of at least one non-empty list of points is required'
lons = numpy.zeros((len(points), len(points[0])), dtype=float)
lats = lons.copy()
depths = lons.copy... | [
"def",
"from_points_list",
"(",
"cls",
",",
"points",
")",
":",
"assert",
"points",
"is",
"not",
"None",
"and",
"len",
"(",
"points",
")",
">",
"0",
"and",
"len",
"(",
"points",
"[",
"0",
"]",
")",
">",
"0",
",",
"'list of at least one non-empty list of ... | Create a rectangular mesh object from a list of lists of points.
Lists in a list are supposed to have the same length.
:param point:
List of lists of :class:`~openquake.hazardlib.geo.point.Point`
objects. | [
"Create",
"a",
"rectangular",
"mesh",
"object",
"from",
"a",
"list",
"of",
"lists",
"of",
"points",
".",
"Lists",
"in",
"a",
"list",
"are",
"supposed",
"to",
"have",
"the",
"same",
"length",
"."
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/geo/mesh.py#L497-L521 |
gem/oq-engine | openquake/hazardlib/geo/mesh.py | RectangularMesh.get_middle_point | def get_middle_point(self):
"""
Return the middle point of the mesh.
:returns:
An instance of :class:`~openquake.hazardlib.geo.point.Point`.
The middle point is taken from the middle row and a middle column
of the mesh if there are odd number of both. Otherwise the ... | python | def get_middle_point(self):
num_rows, num_cols = self.lons.shape
mid_row = num_rows // 2
depth = 0
if num_rows & 1 == 1:
mid_col = num_cols // 2
if num_cols & 1 == 1:
depth = self.depths[mid_r... | [
"def",
"get_middle_point",
"(",
"self",
")",
":",
"num_rows",
",",
"num_cols",
"=",
"self",
".",
"lons",
".",
"shape",
"mid_row",
"=",
"num_rows",
"//",
"2",
"depth",
"=",
"0",
"if",
"num_rows",
"&",
"1",
"==",
"1",
":",
"# there are odd number of rows",
... | Return the middle point of the mesh.
:returns:
An instance of :class:`~openquake.hazardlib.geo.point.Point`.
The middle point is taken from the middle row and a middle column
of the mesh if there are odd number of both. Otherwise the geometric
mean point of two or four midd... | [
"Return",
"the",
"middle",
"point",
"of",
"the",
"mesh",
"."
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/geo/mesh.py#L523-L566 |
gem/oq-engine | openquake/hazardlib/geo/mesh.py | RectangularMesh.get_mean_inclination_and_azimuth | def get_mean_inclination_and_azimuth(self):
"""
Calculate weighted average inclination and azimuth of the mesh surface.
:returns:
Tuple of two float numbers: inclination angle in a range [0, 90]
and azimuth in range [0, 360) (in decimal degrees).
The mesh is tri... | python | def get_mean_inclination_and_azimuth(self):
assert 1 not in self.lons.shape, (
"inclination and azimuth are only defined for mesh of more than "
"one row and more than one column of points")
assert ((self.depths[1:] - self.depths[:-1]) >= 0).all(), (
"get_mea... | [
"def",
"get_mean_inclination_and_azimuth",
"(",
"self",
")",
":",
"assert",
"1",
"not",
"in",
"self",
".",
"lons",
".",
"shape",
",",
"(",
"\"inclination and azimuth are only defined for mesh of more than \"",
"\"one row and more than one column of points\"",
")",
"assert",
... | Calculate weighted average inclination and azimuth of the mesh surface.
:returns:
Tuple of two float numbers: inclination angle in a range [0, 90]
and azimuth in range [0, 360) (in decimal degrees).
The mesh is triangulated, the inclination and azimuth for each triangle
... | [
"Calculate",
"weighted",
"average",
"inclination",
"and",
"azimuth",
"of",
"the",
"mesh",
"surface",
"."
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/geo/mesh.py#L568-L702 |
gem/oq-engine | openquake/hazardlib/geo/mesh.py | RectangularMesh.get_cell_dimensions | def get_cell_dimensions(self):
"""
Calculate centroid, width, length and area of each mesh cell.
:returns:
Tuple of four elements, each being 2d numpy array.
Each array has both dimensions less by one the dimensions
of the mesh, since they represent cells, no... | python | def get_cell_dimensions(self):
points, along_azimuth, updip, diag = self.triangulate()
top = along_azimuth[:-1]
left = updip[:, :-1]
tl_area = geo_utils.triangle_area(top, left, diag)
top_length = numpy.sqrt(numpy.sum(top * top, axis=-1))
left_length = numpy.sqrt... | [
"def",
"get_cell_dimensions",
"(",
"self",
")",
":",
"points",
",",
"along_azimuth",
",",
"updip",
",",
"diag",
"=",
"self",
".",
"triangulate",
"(",
")",
"top",
"=",
"along_azimuth",
"[",
":",
"-",
"1",
"]",
"left",
"=",
"updip",
"[",
":",
",",
":",... | Calculate centroid, width, length and area of each mesh cell.
:returns:
Tuple of four elements, each being 2d numpy array.
Each array has both dimensions less by one the dimensions
of the mesh, since they represent cells, not vertices.
Arrays contain the followin... | [
"Calculate",
"centroid",
"width",
"length",
"and",
"area",
"of",
"each",
"mesh",
"cell",
"."
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/geo/mesh.py#L704-L746 |
gem/oq-engine | openquake/hazardlib/geo/mesh.py | RectangularMesh.triangulate | def triangulate(self):
"""
Convert mesh points to vectors in Cartesian space.
:returns:
Tuple of four elements, each being 2d numpy array of 3d vectors
(the same structure and shape as the mesh itself). Those arrays
are:
#. points vectors,
... | python | def triangulate(self):
points = geo_utils.spherical_to_cartesian(self.lons, self.lats,
self.depths)
along_azimuth = points[:, 1:] - points[:, :-1]
updip = points[:-1] - points[1:]
diag = points... | [
"def",
"triangulate",
"(",
"self",
")",
":",
"points",
"=",
"geo_utils",
".",
"spherical_to_cartesian",
"(",
"self",
".",
"lons",
",",
"self",
".",
"lats",
",",
"self",
".",
"depths",
")",
"# triangulate the mesh by defining vectors of triangles edges:",
"# →",
"a... | Convert mesh points to vectors in Cartesian space.
:returns:
Tuple of four elements, each being 2d numpy array of 3d vectors
(the same structure and shape as the mesh itself). Those arrays
are:
#. points vectors,
#. vectors directed from each point (... | [
"Convert",
"mesh",
"points",
"to",
"vectors",
"in",
"Cartesian",
"space",
"."
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/geo/mesh.py#L748-L778 |
gem/oq-engine | openquake/hazardlib/geo/mesh.py | RectangularMesh.get_mean_width | def get_mean_width(self):
"""
Calculate and return (weighted) mean width (km) of a mesh surface.
The length of each mesh column is computed (summing up the cell widths
in a same column), and the mean value (weighted by the mean cell
length in each column) is returned.
""... | python | def get_mean_width(self):
assert 1 not in self.lons.shape, (
"mean width is only defined for mesh of more than "
"one row and more than one column of points")
_, cell_length, cell_width, cell_area = self.get_cell_dimensions()
widths = numpy.sum(cell_wi... | [
"def",
"get_mean_width",
"(",
"self",
")",
":",
"assert",
"1",
"not",
"in",
"self",
".",
"lons",
".",
"shape",
",",
"(",
"\"mean width is only defined for mesh of more than \"",
"\"one row and more than one column of points\"",
")",
"_",
",",
"cell_length",
",",
"cell... | Calculate and return (weighted) mean width (km) of a mesh surface.
The length of each mesh column is computed (summing up the cell widths
in a same column), and the mean value (weighted by the mean cell
length in each column) is returned. | [
"Calculate",
"and",
"return",
"(",
"weighted",
")",
"mean",
"width",
"(",
"km",
")",
"of",
"a",
"mesh",
"surface",
"."
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/geo/mesh.py#L780-L804 |
gem/oq-engine | openquake/hmtk/seismicity/smoothing/kernels/isotropic_gaussian.py | IsotropicGaussian.smooth_data | def smooth_data(self, data, config, is_3d=False):
'''
Applies the smoothing kernel to the data
:param np.ndarray data:
Raw earthquake count in the form [Longitude, Latitude, Depth,
Count]
:param dict config:
Configuration parameters must contain:
... | python | def smooth_data(self, data, config, is_3d=False):
max_dist = config['Length_Limit'] * config['BandWidth']
smoothed_value = np.zeros(len(data), dtype=float)
for iloc in range(0, len(data)):
dist_val = haversine(data[:, 0], data[:, 1],
data[ilo... | [
"def",
"smooth_data",
"(",
"self",
",",
"data",
",",
"config",
",",
"is_3d",
"=",
"False",
")",
":",
"max_dist",
"=",
"config",
"[",
"'Length_Limit'",
"]",
"*",
"config",
"[",
"'BandWidth'",
"]",
"smoothed_value",
"=",
"np",
".",
"zeros",
"(",
"len",
"... | Applies the smoothing kernel to the data
:param np.ndarray data:
Raw earthquake count in the form [Longitude, Latitude, Depth,
Count]
:param dict config:
Configuration parameters must contain:
* BandWidth: The bandwidth of the kernel (in km) (float)
... | [
"Applies",
"the",
"smoothing",
"kernel",
"to",
"the",
"data"
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hmtk/seismicity/smoothing/kernels/isotropic_gaussian.py#L69-L99 |
gem/oq-engine | openquake/hazardlib/gsim/atkinson_macias_2009.py | AtkinsonMacias2009._get_magnitude_term | def _get_magnitude_term(self, C, mag):
"""
Returns the magnitude scaling term provided in Equation (5)
"""
dmag = mag - 8.0
return C["c0"] + C["c3"] * dmag + C["c4"] * (dmag ** 2.) | python | def _get_magnitude_term(self, C, mag):
dmag = mag - 8.0
return C["c0"] + C["c3"] * dmag + C["c4"] * (dmag ** 2.) | [
"def",
"_get_magnitude_term",
"(",
"self",
",",
"C",
",",
"mag",
")",
":",
"dmag",
"=",
"mag",
"-",
"8.0",
"return",
"C",
"[",
"\"c0\"",
"]",
"+",
"C",
"[",
"\"c3\"",
"]",
"*",
"dmag",
"+",
"C",
"[",
"\"c4\"",
"]",
"*",
"(",
"dmag",
"**",
"2.",... | Returns the magnitude scaling term provided in Equation (5) | [
"Returns",
"the",
"magnitude",
"scaling",
"term",
"provided",
"in",
"Equation",
"(",
"5",
")"
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/gsim/atkinson_macias_2009.py#L85-L90 |
gem/oq-engine | openquake/hazardlib/gsim/atkinson_macias_2009.py | AtkinsonMacias2009._get_distance_term | def _get_distance_term(self, C, rrup, mag):
"""
Returns the distance scaling given in Equation (4), page 1569,
with distance adjusted by the magnitude-dependent depth scaling
factor given in Equation (6)
"""
r_adj = np.sqrt(rrup ** 2.0 + (mag ** 2.0 - 3.1 * mag - 14.55) *... | python | def _get_distance_term(self, C, rrup, mag):
r_adj = np.sqrt(rrup ** 2.0 + (mag ** 2.0 - 3.1 * mag - 14.55) ** 2.)
return C["c1"] * np.log10(r_adj) + C["c2"] * r_adj | [
"def",
"_get_distance_term",
"(",
"self",
",",
"C",
",",
"rrup",
",",
"mag",
")",
":",
"r_adj",
"=",
"np",
".",
"sqrt",
"(",
"rrup",
"**",
"2.0",
"+",
"(",
"mag",
"**",
"2.0",
"-",
"3.1",
"*",
"mag",
"-",
"14.55",
")",
"**",
"2.",
")",
"return"... | Returns the distance scaling given in Equation (4), page 1569,
with distance adjusted by the magnitude-dependent depth scaling
factor given in Equation (6) | [
"Returns",
"the",
"distance",
"scaling",
"given",
"in",
"Equation",
"(",
"4",
")",
"page",
"1569",
"with",
"distance",
"adjusted",
"by",
"the",
"magnitude",
"-",
"dependent",
"depth",
"scaling",
"factor",
"given",
"in",
"Equation",
"(",
"6",
")"
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/gsim/atkinson_macias_2009.py#L92-L99 |
gem/oq-engine | openquake/commands/purge.py | purge_one | def purge_one(calc_id, user):
"""
Remove one calculation ID from the database and remove its datastore
"""
filename = os.path.join(datadir, 'calc_%s.hdf5' % calc_id)
err = dbcmd('del_calc', calc_id, user)
if err:
print(err)
elif os.path.exists(filename): # not removed yet
os... | python | def purge_one(calc_id, user):
filename = os.path.join(datadir, 'calc_%s.hdf5' % calc_id)
err = dbcmd('del_calc', calc_id, user)
if err:
print(err)
elif os.path.exists(filename):
os.remove(filename)
print('Removed %s' % filename) | [
"def",
"purge_one",
"(",
"calc_id",
",",
"user",
")",
":",
"filename",
"=",
"os",
".",
"path",
".",
"join",
"(",
"datadir",
",",
"'calc_%s.hdf5'",
"%",
"calc_id",
")",
"err",
"=",
"dbcmd",
"(",
"'del_calc'",
",",
"calc_id",
",",
"user",
")",
"if",
"e... | Remove one calculation ID from the database and remove its datastore | [
"Remove",
"one",
"calculation",
"ID",
"from",
"the",
"database",
"and",
"remove",
"its",
"datastore"
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/commands/purge.py#L28-L38 |
gem/oq-engine | openquake/commands/purge.py | purge_all | def purge_all(user=None, fast=False):
"""
Remove all calculations of the given user
"""
user = user or getpass.getuser()
if os.path.exists(datadir):
if fast:
shutil.rmtree(datadir)
print('Removed %s' % datadir)
else:
for fname in os.listdir(datadir... | python | def purge_all(user=None, fast=False):
user = user or getpass.getuser()
if os.path.exists(datadir):
if fast:
shutil.rmtree(datadir)
print('Removed %s' % datadir)
else:
for fname in os.listdir(datadir):
mo = re.match('calc_(\d+)\.hdf5', fnam... | [
"def",
"purge_all",
"(",
"user",
"=",
"None",
",",
"fast",
"=",
"False",
")",
":",
"user",
"=",
"user",
"or",
"getpass",
".",
"getuser",
"(",
")",
"if",
"os",
".",
"path",
".",
"exists",
"(",
"datadir",
")",
":",
"if",
"fast",
":",
"shutil",
".",... | Remove all calculations of the given user | [
"Remove",
"all",
"calculations",
"of",
"the",
"given",
"user"
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/commands/purge.py#L42-L56 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.