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/hazardlib/gsim/bindi_2017.py | BindiEtAl2017Rjb._get_distance_scaling | def _get_distance_scaling(self, C, dists, mag):
"""
Implements the distance scaling function F(M, R) presented in equations
2 and 3. In the case of Joyner-Boore distance then the fixed-depth
term h is required
"""
r_h = self._get_rh(C, dists)
return (C["c1"] + C["... | python | def _get_distance_scaling(self, C, dists, mag):
r_h = self._get_rh(C, dists)
return (C["c1"] + C["c2"] * (mag - self.CONSTANTS["mref"])) *\
np.log(r_h / self.CONSTANTS["rref"]) +\
C["c3"] * (r_h - self.CONSTANTS["rref"]) | [
"def",
"_get_distance_scaling",
"(",
"self",
",",
"C",
",",
"dists",
",",
"mag",
")",
":",
"r_h",
"=",
"self",
".",
"_get_rh",
"(",
"C",
",",
"dists",
")",
"return",
"(",
"C",
"[",
"\"c1\"",
"]",
"+",
"C",
"[",
"\"c2\"",
"]",
"*",
"(",
"mag",
"... | Implements the distance scaling function F(M, R) presented in equations
2 and 3. In the case of Joyner-Boore distance then the fixed-depth
term h is required | [
"Implements",
"the",
"distance",
"scaling",
"function",
"F",
"(",
"M",
"R",
")",
"presented",
"in",
"equations",
"2",
"and",
"3",
".",
"In",
"the",
"case",
"of",
"Joyner",
"-",
"Boore",
"distance",
"then",
"the",
"fixed",
"-",
"depth",
"term",
"h",
"is... | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/gsim/bindi_2017.py#L110-L119 |
gem/oq-engine | openquake/hazardlib/gsim/munson_thurber_1997.py | MunsonThurber1997.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.
"""
# Distance term
R = np.sqrt(dists.rjb ** 2 + 11.29 ** 2)
... | python | def get_mean_and_stddevs(self, sites, rup, dists, imt, stddev_types):
R = np.sqrt(dists.rjb ** 2 + 11.29 ** 2)
M = rup.mag - 6
S = np.zeros(R.shape)
S[sites.vs30 <= 200] = 1
mean = (0.518 + 0.387*M - np.log10(R) -... | [
"def",
"get_mean_and_stddevs",
"(",
"self",
",",
"sites",
",",
"rup",
",",
"dists",
",",
"imt",
",",
"stddev_types",
")",
":",
"# Distance term",
"R",
"=",
"np",
".",
"sqrt",
"(",
"dists",
".",
"rjb",
"**",
"2",
"+",
"11.29",
"**",
"2",
")",
"# Magni... | 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/munson_thurber_1997.py#L67-L99 |
gem/oq-engine | openquake/hazardlib/gsim/munson_thurber_1997.py | MunsonThurber1997Hawaii.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.
"""
# assign constant
log10e = np.log10(np.e)
# Distance... | python | def get_mean_and_stddevs(self, sites, rup, dists, imt, stddev_types):
log10e = np.log10(np.e)
R = np.sqrt(dists.rjb ** 2 + 11.29 ** 2)
M = rup.mag - 6
S = np.zeros(R.shape)
S[sites.vs30 <= 200] = 1
... | [
"def",
"get_mean_and_stddevs",
"(",
"self",
",",
"sites",
",",
"rup",
",",
"dists",
",",
"imt",
",",
"stddev_types",
")",
":",
"# assign constant",
"log10e",
"=",
"np",
".",
"log10",
"(",
"np",
".",
"e",
")",
"# Distance term",
"R",
"=",
"np",
".",
"sq... | 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/munson_thurber_1997.py#L111-L151 |
gem/oq-engine | openquake/hazardlib/gsim/skarlatoudis_2013.py | SkarlatoudisEtAlSSlab2013.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]
imean = (self._compute_magnitude(rup, C) +
self._compute_distance(rup, dists, C) +
self._get_site_amplification(sites, C) +
self._comp... | [
"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/skarlatoudis_2013.py#L76-L105 |
gem/oq-engine | openquake/hazardlib/gsim/skarlatoudis_2013.py | SkarlatoudisEtAlSSlab2013._compute_distance | def _compute_distance(self, rup, dists, C):
"""
equation 3 pag 1960:
``c31 * logR + c32 * (R-Rref)``
"""
rref = 1.0
c31 = -1.7
return (c31 * np.log10(dists.rhypo) + C['c32'] * (dists.rhypo - rref)) | python | def _compute_distance(self, rup, dists, C):
rref = 1.0
c31 = -1.7
return (c31 * np.log10(dists.rhypo) + C['c32'] * (dists.rhypo - rref)) | [
"def",
"_compute_distance",
"(",
"self",
",",
"rup",
",",
"dists",
",",
"C",
")",
":",
"rref",
"=",
"1.0",
"c31",
"=",
"-",
"1.7",
"return",
"(",
"c31",
"*",
"np",
".",
"log10",
"(",
"dists",
".",
"rhypo",
")",
"+",
"C",
"[",
"'c32'",
"]",
"*",... | equation 3 pag 1960:
``c31 * logR + c32 * (R-Rref)`` | [
"equation",
"3",
"pag",
"1960",
":"
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/gsim/skarlatoudis_2013.py#L122-L130 |
gem/oq-engine | openquake/hazardlib/gsim/skarlatoudis_2013.py | SkarlatoudisEtAlSSlab2013._compute_magnitude | def _compute_magnitude(self, rup, C):
"""
equation 3 pag 1960:
c1 + c2(M-5.5)
"""
m_h = 5.5
return C['c1'] + (C['c2'] * (rup.mag - m_h)) | python | def _compute_magnitude(self, rup, C):
m_h = 5.5
return C['c1'] + (C['c2'] * (rup.mag - m_h)) | [
"def",
"_compute_magnitude",
"(",
"self",
",",
"rup",
",",
"C",
")",
":",
"m_h",
"=",
"5.5",
"return",
"C",
"[",
"'c1'",
"]",
"+",
"(",
"C",
"[",
"'c2'",
"]",
"*",
"(",
"rup",
".",
"mag",
"-",
"m_h",
")",
")"
] | equation 3 pag 1960:
c1 + c2(M-5.5) | [
"equation",
"3",
"pag",
"1960",
":"
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/gsim/skarlatoudis_2013.py#L132-L139 |
gem/oq-engine | openquake/hazardlib/gsim/skarlatoudis_2013.py | SkarlatoudisEtAlSSlab2013._get_site_amplification | def _get_site_amplification(self, sites, C):
"""
Compute the fourth term of the equation 3:
The functional form Fs in Eq. (1) represents the site amplification and
it is given by FS = c61*S + c62*SS , where c61 and c62 are the
coefficients to be determined through the regression ... | python | def _get_site_amplification(self, sites, C):
S, SS = self._get_site_type_dummy_variables(sites)
return (C['c61'] * S) + (C['c62'] * SS) | [
"def",
"_get_site_amplification",
"(",
"self",
",",
"sites",
",",
"C",
")",
":",
"S",
",",
"SS",
"=",
"self",
".",
"_get_site_type_dummy_variables",
"(",
"sites",
")",
"return",
"(",
"C",
"[",
"'c61'",
"]",
"*",
"S",
")",
"+",
"(",
"C",
"[",
"'c62'",... | Compute the fourth term of the equation 3:
The functional form Fs in Eq. (1) represents the site amplification and
it is given by FS = c61*S + c62*SS , where c61 and c62 are the
coefficients to be determined through the regression analysis,
while S and SS are dummy variables used to deno... | [
"Compute",
"the",
"fourth",
"term",
"of",
"the",
"equation",
"3",
":",
"The",
"functional",
"form",
"Fs",
"in",
"Eq",
".",
"(",
"1",
")",
"represents",
"the",
"site",
"amplification",
"and",
"it",
"is",
"given",
"by",
"FS",
"=",
"c61",
"*",
"S",
"+",... | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/gsim/skarlatoudis_2013.py#L141-L153 |
gem/oq-engine | openquake/hazardlib/gsim/skarlatoudis_2013.py | SkarlatoudisEtAlSSlab2013._get_site_type_dummy_variables | def _get_site_type_dummy_variables(self, sites):
"""
Get site type dummy variables, three different site classes,
based on the shear wave velocity intervals in the uppermost 30 m, Vs30,
according to the NEHRP:
class A-B: Vs30 > 760 m/s
class C: Vs30 = 360 − 760 m/s
... | python | def _get_site_type_dummy_variables(self, sites):
S = np.zeros(len(sites.vs30))
SS = np.zeros(len(sites.vs30))
idx = (sites.vs30 < 360.0)
SS[idx] = 1.0
idx = (sites.vs30 >= 360.0) & (sites.vs30 < 760)
S[idx] = 1.0
return S, SS | [
"def",
"_get_site_type_dummy_variables",
"(",
"self",
",",
"sites",
")",
":",
"S",
"=",
"np",
".",
"zeros",
"(",
"len",
"(",
"sites",
".",
"vs30",
")",
")",
"SS",
"=",
"np",
".",
"zeros",
"(",
"len",
"(",
"sites",
".",
"vs30",
")",
")",
"# Class C;... | Get site type dummy variables, three different site classes,
based on the shear wave velocity intervals in the uppermost 30 m, Vs30,
according to the NEHRP:
class A-B: Vs30 > 760 m/s
class C: Vs30 = 360 − 760 m/s
class D: Vs30 < 360 m/s | [
"Get",
"site",
"type",
"dummy",
"variables",
"three",
"different",
"site",
"classes",
"based",
"on",
"the",
"shear",
"wave",
"velocity",
"intervals",
"in",
"the",
"uppermost",
"30",
"m",
"Vs30",
"according",
"to",
"the",
"NEHRP",
":",
"class",
"A",
"-",
"B... | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/gsim/skarlatoudis_2013.py#L155-L175 |
gem/oq-engine | openquake/hazardlib/gsim/skarlatoudis_2013.py | SkarlatoudisEtAlSSlab2013._compute_forearc_backarc_term | def _compute_forearc_backarc_term(self, C, sites, dists, rup):
"""
Compute back-arc term of Equation 3
"""
# flag 1 (R < 335 & R >= 205)
flag1 = np.zeros(len(dists.rhypo))
ind1 = np.logical_and((dists.rhypo < 335), (dists.rhypo >= 205))
flag1[ind1] = 1.0
... | python | def _compute_forearc_backarc_term(self, C, sites, dists, rup):
flag1 = np.zeros(len(dists.rhypo))
ind1 = np.logical_and((dists.rhypo < 335), (dists.rhypo >= 205))
flag1[ind1] = 1.0
flag2 = np.zeros(len(dists.rhypo))
ind2 = (dists.rhypo >= 335)
f... | [
"def",
"_compute_forearc_backarc_term",
"(",
"self",
",",
"C",
",",
"sites",
",",
"dists",
",",
"rup",
")",
":",
"# flag 1 (R < 335 & R >= 205)",
"flag1",
"=",
"np",
".",
"zeros",
"(",
"len",
"(",
"dists",
".",
"rhypo",
")",
")",
"ind1",
"=",
"np",
".",
... | Compute back-arc term of Equation 3 | [
"Compute",
"back",
"-",
"arc",
"term",
"of",
"Equation",
"3"
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/gsim/skarlatoudis_2013.py#L177-L219 |
gem/oq-engine | openquake/hazardlib/gsim/gmpe_table.py | AmplificationTable._build_data | def _build_data(self, amplification_group):
"""
Creates the numpy array tables from the hdf5 tables
"""
# Determine shape of the tables
n_levels = len(amplification_group)
# Checks the first group in the amplification group and returns the
# shape of the SA array ... | python | def _build_data(self, amplification_group):
n_levels = len(amplification_group)
level = next(iter(amplification_group))
n_d, n_p, n_m = amplification_group[level]["IMLs/SA"].shape
assert n_d == len(self.distances), (n_d, len(self.distances))
... | [
"def",
"_build_data",
"(",
"self",
",",
"amplification_group",
")",
":",
"# Determine shape of the tables",
"n_levels",
"=",
"len",
"(",
"amplification_group",
")",
"# Checks the first group in the amplification group and returns the",
"# shape of the SA array - implicitly assumes th... | Creates the numpy array tables from the hdf5 tables | [
"Creates",
"the",
"numpy",
"array",
"tables",
"from",
"the",
"hdf5",
"tables"
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/gsim/gmpe_table.py#L112-L150 |
gem/oq-engine | openquake/hazardlib/gsim/gmpe_table.py | AmplificationTable.get_amplification_factors | def get_amplification_factors(self, imt, sctx, rctx, dists, stddev_types):
"""
Returns the amplification factors for the given rupture and site
conditions.
:param imt:
Intensity measure type as an instance of the :class:
`openquake.hazardlib.imt`
:param s... | python | def get_amplification_factors(self, imt, sctx, rctx, dists, stddev_types):
dist_level_table = self.get_mean_table(imt, rctx)
sigma_tables = self.get_sigma_tables(imt, rctx, stddev_types)
mean_interpolator = interp1d(self.values,
numpy.log10(dist_leve... | [
"def",
"get_amplification_factors",
"(",
"self",
",",
"imt",
",",
"sctx",
",",
"rctx",
",",
"dists",
",",
"stddev_types",
")",
":",
"dist_level_table",
"=",
"self",
".",
"get_mean_table",
"(",
"imt",
",",
"rctx",
")",
"sigma_tables",
"=",
"self",
".",
"get... | Returns the amplification factors for the given rupture and site
conditions.
:param imt:
Intensity measure type as an instance of the :class:
`openquake.hazardlib.imt`
:param sctx:
SiteCollection instance
:param rctx:
Rupture instance
... | [
"Returns",
"the",
"amplification",
"factors",
"for",
"the",
"given",
"rupture",
"and",
"site",
"conditions",
"."
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/gsim/gmpe_table.py#L158-L202 |
gem/oq-engine | openquake/hazardlib/gsim/gmpe_table.py | AmplificationTable.get_mean_table | def get_mean_table(self, imt, rctx):
"""
Returns amplification factors for the mean, given the rupture and
intensity measure type.
:returns:
amplification table as an array of [Number Distances,
Number Levels]
"""
# Levels by Distances
if ... | python | def get_mean_table(self, imt, rctx):
if imt.name in 'PGA PGV':
interpolator = interp1d(self.magnitudes,
numpy.log10(self.mean[imt.name]), axis=2)
output_table = 10.0 ** (
interpolator(rctx.mag).reshape(self.shape[0], s... | [
"def",
"get_mean_table",
"(",
"self",
",",
"imt",
",",
"rctx",
")",
":",
"# Levels by Distances",
"if",
"imt",
".",
"name",
"in",
"'PGA PGV'",
":",
"interpolator",
"=",
"interp1d",
"(",
"self",
".",
"magnitudes",
",",
"numpy",
".",
"log10",
"(",
"self",
... | Returns amplification factors for the mean, given the rupture and
intensity measure type.
:returns:
amplification table as an array of [Number Distances,
Number Levels] | [
"Returns",
"amplification",
"factors",
"for",
"the",
"mean",
"given",
"the",
"rupture",
"and",
"intensity",
"measure",
"type",
"."
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/gsim/gmpe_table.py#L204-L229 |
gem/oq-engine | openquake/hazardlib/gsim/gmpe_table.py | AmplificationTable.get_sigma_tables | def get_sigma_tables(self, imt, rctx, stddev_types):
"""
Returns modification factors for the standard deviations, given the
rupture and intensity measure type.
:returns:
List of standard deviation modification tables, each as an array
of [Number Distances, Numbe... | python | def get_sigma_tables(self, imt, rctx, stddev_types):
output_tables = []
for stddev_type in stddev_types:
if imt.name in 'PGA PGV':
interpolator = interp1d(self.magnitudes,
self.sigma[stddev_type][imt.name],
... | [
"def",
"get_sigma_tables",
"(",
"self",
",",
"imt",
",",
"rctx",
",",
"stddev_types",
")",
":",
"output_tables",
"=",
"[",
"]",
"for",
"stddev_type",
"in",
"stddev_types",
":",
"# For PGA and PGV only needs to apply magnitude interpolation",
"if",
"imt",
".",
"name"... | Returns modification factors for the standard deviations, given the
rupture and intensity measure type.
:returns:
List of standard deviation modification tables, each as an array
of [Number Distances, Number Levels] | [
"Returns",
"modification",
"factors",
"for",
"the",
"standard",
"deviations",
"given",
"the",
"rupture",
"and",
"intensity",
"measure",
"type",
"."
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/gsim/gmpe_table.py#L231-L263 |
gem/oq-engine | openquake/hazardlib/gsim/gmpe_table.py | GMPETable.init | def init(self, fle=None):
"""
Executes the preprocessing steps at the instantiation stage to read in
the tables from hdf5 and hold them in memory.
"""
if fle is None:
fname = self.kwargs.get('gmpe_table', self.GMPE_TABLE)
if fname is None:
... | python | def init(self, fle=None):
if fle is None:
fname = self.kwargs.get('gmpe_table', self.GMPE_TABLE)
if fname is None:
raise ValueError('You forgot to set GMPETable.GMPE_TABLE!')
elif os.path.isabs(fname):
self.GMPE_TABLE = fname
... | [
"def",
"init",
"(",
"self",
",",
"fle",
"=",
"None",
")",
":",
"if",
"fle",
"is",
"None",
":",
"fname",
"=",
"self",
".",
"kwargs",
".",
"get",
"(",
"'gmpe_table'",
",",
"self",
".",
"GMPE_TABLE",
")",
"if",
"fname",
"is",
"None",
":",
"raise",
"... | Executes the preprocessing steps at the instantiation stage to read in
the tables from hdf5 and hold them in memory. | [
"Executes",
"the",
"preprocessing",
"steps",
"at",
"the",
"instantiation",
"stage",
"to",
"read",
"in",
"the",
"tables",
"from",
"hdf5",
"and",
"hold",
"them",
"in",
"memory",
"."
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/gsim/gmpe_table.py#L306-L342 |
gem/oq-engine | openquake/hazardlib/gsim/gmpe_table.py | GMPETable._setup_standard_deviations | def _setup_standard_deviations(self, fle):
"""
Reads the standard deviation tables from hdf5 and stores them in
memory
:param fle:
HDF5 Tables as instance of :class:`h5py.File`
"""
# Load in total standard deviation
self.stddevs = {}
self.stdde... | python | def _setup_standard_deviations(self, fle):
self.stddevs = {}
self.stddevs[const.StdDev.TOTAL] = hdf_arrays_to_dict(fle["Total"])
self.DEFINED_FOR_STANDARD_DEVIATION_TYPES = set(
self.DEFINED_FOR_STANDARD_DEVIATION_TYPES)
for stddev_type in [const.St... | [
"def",
"_setup_standard_deviations",
"(",
"self",
",",
"fle",
")",
":",
"# Load in total standard deviation",
"self",
".",
"stddevs",
"=",
"{",
"}",
"self",
".",
"stddevs",
"[",
"const",
".",
"StdDev",
".",
"TOTAL",
"]",
"=",
"hdf_arrays_to_dict",
"(",
"fle",
... | Reads the standard deviation tables from hdf5 and stores them in
memory
:param fle:
HDF5 Tables as instance of :class:`h5py.File` | [
"Reads",
"the",
"standard",
"deviation",
"tables",
"from",
"hdf5",
"and",
"stores",
"them",
"in",
"memory",
":",
"param",
"fle",
":",
"HDF5",
"Tables",
"as",
"instance",
"of",
":",
"class",
":",
"h5py",
".",
"File"
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/gsim/gmpe_table.py#L344-L362 |
gem/oq-engine | openquake/hazardlib/gsim/gmpe_table.py | GMPETable._setup_amplification | def _setup_amplification(self, fle):
"""
If amplification data is specified then reads into memory and updates
the required rupture and site parameters
"""
self.amplification = AmplificationTable(fle["Amplification"],
self.m_w,
... | python | def _setup_amplification(self, fle):
self.amplification = AmplificationTable(fle["Amplification"],
self.m_w,
self.distances)
if self.amplification.element == "Sites":
self.REQUIRES_SITES_... | [
"def",
"_setup_amplification",
"(",
"self",
",",
"fle",
")",
":",
"self",
".",
"amplification",
"=",
"AmplificationTable",
"(",
"fle",
"[",
"\"Amplification\"",
"]",
",",
"self",
".",
"m_w",
",",
"self",
".",
"distances",
")",
"if",
"self",
".",
"amplifica... | If amplification data is specified then reads into memory and updates
the required rupture and site parameters | [
"If",
"amplification",
"data",
"is",
"specified",
"then",
"reads",
"into",
"memory",
"and",
"updates",
"the",
"required",
"rupture",
"and",
"site",
"parameters"
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/gsim/gmpe_table.py#L364-L380 |
gem/oq-engine | openquake/hazardlib/gsim/gmpe_table.py | GMPETable._supported_imts | def _supported_imts(self):
"""
Updates the list of supported IMTs from the tables
"""
imt_list = []
for key in self.imls:
if "SA" in key:
imt_list.append(imt_module.SA)
elif key == "T":
continue
else:
... | python | def _supported_imts(self):
imt_list = []
for key in self.imls:
if "SA" in key:
imt_list.append(imt_module.SA)
elif key == "T":
continue
else:
try:
factory = getattr(imt_module, key)
... | [
"def",
"_supported_imts",
"(",
"self",
")",
":",
"imt_list",
"=",
"[",
"]",
"for",
"key",
"in",
"self",
".",
"imls",
":",
"if",
"\"SA\"",
"in",
"key",
":",
"imt_list",
".",
"append",
"(",
"imt_module",
".",
"SA",
")",
"elif",
"key",
"==",
"\"T\"",
... | Updates the list of supported IMTs from the tables | [
"Updates",
"the",
"list",
"of",
"supported",
"IMTs",
"from",
"the",
"tables"
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/gsim/gmpe_table.py#L382-L398 |
gem/oq-engine | openquake/hazardlib/gsim/gmpe_table.py | GMPETable.get_mean_and_stddevs | def get_mean_and_stddevs(self, sctx, rctx, dctx, imt, stddev_types):
"""
Returns the mean and standard deviations
"""
# Return Distance Tables
imls = self._return_tables(rctx.mag, imt, "IMLs")
# Get distance vector for the given magnitude
idx = numpy.searchsorted(... | python | def get_mean_and_stddevs(self, sctx, rctx, dctx, imt, stddev_types):
imls = self._return_tables(rctx.mag, imt, "IMLs")
idx = numpy.searchsorted(self.m_w, rctx.mag)
dists = self.distances[:, 0, idx - 1]
mean = self._get_mean(imls, dctx, dists)
s... | [
"def",
"get_mean_and_stddevs",
"(",
"self",
",",
"sctx",
",",
"rctx",
",",
"dctx",
",",
"imt",
",",
"stddev_types",
")",
":",
"# Return Distance Tables",
"imls",
"=",
"self",
".",
"_return_tables",
"(",
"rctx",
".",
"mag",
",",
"imt",
",",
"\"IMLs\"",
")",... | Returns the mean and standard deviations | [
"Returns",
"the",
"mean",
"and",
"standard",
"deviations"
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/gsim/gmpe_table.py#L400-L425 |
gem/oq-engine | openquake/hazardlib/gsim/gmpe_table.py | GMPETable._get_mean | def _get_mean(self, data, dctx, dists):
"""
Returns the mean intensity measure level from the tables
:param data:
The intensity measure level vector for the given magnitude and IMT
:param key:
The distance type
:param distances:
The distance ve... | python | def _get_mean(self, data, dctx, dists):
interpolator_mean = interp1d(dists, data,
bounds_error=False,
fill_value=-999.)
mean = interpolator_mean(getattr(dctx, self.distance_type))
... | [
"def",
"_get_mean",
"(",
"self",
",",
"data",
",",
"dctx",
",",
"dists",
")",
":",
"# For values outside of the interpolation range use -999. to ensure",
"# value is identifiable and outside of potential real values",
"interpolator_mean",
"=",
"interp1d",
"(",
"dists",
",",
"... | Returns the mean intensity measure level from the tables
:param data:
The intensity measure level vector for the given magnitude and IMT
:param key:
The distance type
:param distances:
The distance vector for the given magnitude and IMT | [
"Returns",
"the",
"mean",
"intensity",
"measure",
"level",
"from",
"the",
"tables",
":",
"param",
"data",
":",
"The",
"intensity",
"measure",
"level",
"vector",
"for",
"the",
"given",
"magnitude",
"and",
"IMT",
":",
"param",
"key",
":",
"The",
"distance",
... | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/gsim/gmpe_table.py#L427-L452 |
gem/oq-engine | openquake/hazardlib/gsim/gmpe_table.py | GMPETable._get_stddevs | def _get_stddevs(self, dists, mag, dctx, imt, stddev_types):
"""
Returns the total standard deviation of the intensity measure level
from the tables.
:param fle:
HDF5 data stream as instance of :class:`h5py.File`
:param distances:
The distance vector for ... | python | def _get_stddevs(self, dists, mag, dctx, imt, stddev_types):
stddevs = []
for stddev_type in stddev_types:
if stddev_type not in self.DEFINED_FOR_STANDARD_DEVIATION_TYPES:
raise ValueError("Standard Deviation type %s not supported"
% ... | [
"def",
"_get_stddevs",
"(",
"self",
",",
"dists",
",",
"mag",
",",
"dctx",
",",
"imt",
",",
"stddev_types",
")",
":",
"stddevs",
"=",
"[",
"]",
"for",
"stddev_type",
"in",
"stddev_types",
":",
"if",
"stddev_type",
"not",
"in",
"self",
".",
"DEFINED_FOR_S... | Returns the total standard deviation of the intensity measure level
from the tables.
:param fle:
HDF5 data stream as instance of :class:`h5py.File`
:param distances:
The distance vector for the given magnitude and IMT
:param key:
The distance type
... | [
"Returns",
"the",
"total",
"standard",
"deviation",
"of",
"the",
"intensity",
"measure",
"level",
"from",
"the",
"tables",
"."
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/gsim/gmpe_table.py#L454-L480 |
gem/oq-engine | openquake/hazardlib/gsim/gmpe_table.py | GMPETable._return_tables | def _return_tables(self, mag, imt, val_type):
"""
Returns the vector of ground motions or standard deviations
corresponding to the specific magnitude and intensity measure type.
:param val_type:
String indicating the type of data {"IMLs", "Total", "Inter" etc}
"""
... | python | def _return_tables(self, mag, imt, val_type):
if imt.name in 'PGA PGV':
if val_type == "IMLs":
iml_table = self.imls[imt.name][:]
else:
iml_table = self.stddevs[val_type][imt.name][:]
n_d, n_s, n_m = iml_table.shape
... | [
"def",
"_return_tables",
"(",
"self",
",",
"mag",
",",
"imt",
",",
"val_type",
")",
":",
"if",
"imt",
".",
"name",
"in",
"'PGA PGV'",
":",
"# Get scalar imt",
"if",
"val_type",
"==",
"\"IMLs\"",
":",
"iml_table",
"=",
"self",
".",
"imls",
"[",
"imt",
"... | Returns the vector of ground motions or standard deviations
corresponding to the specific magnitude and intensity measure type.
:param val_type:
String indicating the type of data {"IMLs", "Total", "Inter" etc} | [
"Returns",
"the",
"vector",
"of",
"ground",
"motions",
"or",
"standard",
"deviations",
"corresponding",
"to",
"the",
"specific",
"magnitude",
"and",
"intensity",
"measure",
"type",
"."
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/gsim/gmpe_table.py#L482-L518 |
gem/oq-engine | openquake/hazardlib/gsim/gmpe_table.py | GMPETable.apply_magnitude_interpolation | def apply_magnitude_interpolation(self, mag, iml_table):
"""
Interpolates the tables to the required magnitude level
:param float mag:
Magnitude
:param iml_table:
Intensity measure level table
"""
# do not allow "mag" to exceed maximum table magni... | python | def apply_magnitude_interpolation(self, mag, iml_table):
if mag > self.m_w[-1]:
mag = self.m_w[-1]
if mag < self.m_w[0] or mag > self.m_w[-1]:
raise ValueError("Magnitude %.2f outside of supported range "
"(%.2f to %.2f)" %... | [
"def",
"apply_magnitude_interpolation",
"(",
"self",
",",
"mag",
",",
"iml_table",
")",
":",
"# do not allow \"mag\" to exceed maximum table magnitude",
"if",
"mag",
">",
"self",
".",
"m_w",
"[",
"-",
"1",
"]",
":",
"mag",
"=",
"self",
".",
"m_w",
"[",
"-",
... | Interpolates the tables to the required magnitude level
:param float mag:
Magnitude
:param iml_table:
Intensity measure level table | [
"Interpolates",
"the",
"tables",
"to",
"the",
"required",
"magnitude",
"level"
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/gsim/gmpe_table.py#L520-L542 |
gem/oq-engine | openquake/hazardlib/gsim/sadigh_1997.py | SadighEtAl1997.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)
is_reverse = (45 <= rup.rake <= 135)
stddevs = [numpy.zeros_like(sites.vs30) ... | [
"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/sadigh_1997.py#L76-L112 |
gem/oq-engine | openquake/hazardlib/gsim/sadigh_1997.py | SadighEtAl1997._get_mean_deep_soil | def _get_mean_deep_soil(self, mag, rake, rrup, is_reverse, imt):
"""
Calculate and return the mean intensity for deep soil sites.
Implements an equation from table 4.
"""
if mag <= self.NEAR_FIELD_SATURATION_MAG:
c4 = self.COEFFS_SOIL_IMT_INDEPENDENT['c4lowmag']
... | python | def _get_mean_deep_soil(self, mag, rake, rrup, is_reverse, imt):
if mag <= self.NEAR_FIELD_SATURATION_MAG:
c4 = self.COEFFS_SOIL_IMT_INDEPENDENT['c4lowmag']
c5 = self.COEFFS_SOIL_IMT_INDEPENDENT['c5lowmag']
else:
c4 = self.COEFFS_SOIL_IMT_INDEPENDENT['c4himag... | [
"def",
"_get_mean_deep_soil",
"(",
"self",
",",
"mag",
",",
"rake",
",",
"rrup",
",",
"is_reverse",
",",
"imt",
")",
":",
"if",
"mag",
"<=",
"self",
".",
"NEAR_FIELD_SATURATION_MAG",
":",
"c4",
"=",
"self",
".",
"COEFFS_SOIL_IMT_INDEPENDENT",
"[",
"'c4lowmag... | Calculate and return the mean intensity for deep soil sites.
Implements an equation from table 4. | [
"Calculate",
"and",
"return",
"the",
"mean",
"intensity",
"for",
"deep",
"soil",
"sites",
"."
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/gsim/sadigh_1997.py#L114-L139 |
gem/oq-engine | openquake/hazardlib/gsim/sadigh_1997.py | SadighEtAl1997._get_mean_rock | def _get_mean_rock(self, mag, _rake, rrup, is_reverse, imt):
"""
Calculate and return the mean intensity for rock sites.
Implements an equation from table 2.
"""
if mag <= self.NEAR_FIELD_SATURATION_MAG:
C = self.COEFFS_ROCK_LOWMAG[imt]
else:
C = ... | python | def _get_mean_rock(self, mag, _rake, rrup, is_reverse, imt):
if mag <= self.NEAR_FIELD_SATURATION_MAG:
C = self.COEFFS_ROCK_LOWMAG[imt]
else:
C = self.COEFFS_ROCK_HIMAG[imt]
mag = 8.5 if mag > 8.5 else mag
mean = (
C['c1'] + ... | [
"def",
"_get_mean_rock",
"(",
"self",
",",
"mag",
",",
"_rake",
",",
"rrup",
",",
"is_reverse",
",",
"imt",
")",
":",
"if",
"mag",
"<=",
"self",
".",
"NEAR_FIELD_SATURATION_MAG",
":",
"C",
"=",
"self",
".",
"COEFFS_ROCK_LOWMAG",
"[",
"imt",
"]",
"else",
... | Calculate and return the mean intensity for rock sites.
Implements an equation from table 2. | [
"Calculate",
"and",
"return",
"the",
"mean",
"intensity",
"for",
"rock",
"sites",
"."
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/gsim/sadigh_1997.py#L141-L163 |
gem/oq-engine | openquake/hazardlib/gsim/sadigh_1997.py | SadighEtAl1997._get_stddev_rock | def _get_stddev_rock(self, mag, imt):
"""
Calculate and return total standard deviation for rock sites.
Implements formulae from table 3.
"""
C = self.COEFFS_ROCK_STDDERR[imt]
if mag > C['maxmag']:
return C['maxsigma']
else:
return C['sigm... | python | def _get_stddev_rock(self, mag, imt):
C = self.COEFFS_ROCK_STDDERR[imt]
if mag > C['maxmag']:
return C['maxsigma']
else:
return C['sigma0'] + C['magfactor'] * mag | [
"def",
"_get_stddev_rock",
"(",
"self",
",",
"mag",
",",
"imt",
")",
":",
"C",
"=",
"self",
".",
"COEFFS_ROCK_STDDERR",
"[",
"imt",
"]",
"if",
"mag",
">",
"C",
"[",
"'maxmag'",
"]",
":",
"return",
"C",
"[",
"'maxsigma'",
"]",
"else",
":",
"return",
... | Calculate and return total standard deviation for rock sites.
Implements formulae from table 3. | [
"Calculate",
"and",
"return",
"total",
"standard",
"deviation",
"for",
"rock",
"sites",
"."
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/gsim/sadigh_1997.py#L165-L175 |
gem/oq-engine | openquake/hazardlib/gsim/sadigh_1997.py | SadighEtAl1997._get_stddev_deep_soil | def _get_stddev_deep_soil(self, mag, imt):
"""
Calculate and return total standard deviation for deep soil sites.
Implements formulae from the last column of table 4.
"""
# footnote from table 4 says that stderr for magnitudes over 7
# is equal to one of magnitude 7.
... | python | def _get_stddev_deep_soil(self, mag, imt):
if mag > 7:
mag = 7
C = self.COEFFS_SOIL[imt]
return C['sigma0'] + C['magfactor'] * mag | [
"def",
"_get_stddev_deep_soil",
"(",
"self",
",",
"mag",
",",
"imt",
")",
":",
"# footnote from table 4 says that stderr for magnitudes over 7",
"# is equal to one of magnitude 7.",
"if",
"mag",
">",
"7",
":",
"mag",
"=",
"7",
"C",
"=",
"self",
".",
"COEFFS_SOIL",
"... | Calculate and return total standard deviation for deep soil sites.
Implements formulae from the last column of table 4. | [
"Calculate",
"and",
"return",
"total",
"standard",
"deviation",
"for",
"deep",
"soil",
"sites",
"."
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/gsim/sadigh_1997.py#L177-L188 |
gem/oq-engine | openquake/commands/zip.py | zip | def zip(what, archive_zip='', risk_file=''):
"""
Zip into an archive one or two job.ini files with all related files
"""
if os.path.isdir(what):
oqzip.zip_all(what)
elif what.endswith('.xml') and '<logicTree' in open(what).read(512):
# hack to see if the NRML file is of kind logicTre... | python | def zip(what, archive_zip='', risk_file=''):
if os.path.isdir(what):
oqzip.zip_all(what)
elif what.endswith('.xml') and '<logicTree' in open(what).read(512):
oqzip.zip_source_model(what, archive_zip)
elif what.endswith('.xml') and '<exposureModel' in open(what).read(512):
... | [
"def",
"zip",
"(",
"what",
",",
"archive_zip",
"=",
"''",
",",
"risk_file",
"=",
"''",
")",
":",
"if",
"os",
".",
"path",
".",
"isdir",
"(",
"what",
")",
":",
"oqzip",
".",
"zip_all",
"(",
"what",
")",
"elif",
"what",
".",
"endswith",
"(",
"'.xml... | Zip into an archive one or two job.ini files with all related files | [
"Zip",
"into",
"an",
"archive",
"one",
"or",
"two",
"job",
".",
"ini",
"files",
"with",
"all",
"related",
"files"
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/commands/zip.py#L25-L40 |
gem/oq-engine | openquake/commands/reduce.py | reduce | def reduce(fname, reduction_factor):
"""
Produce a submodel from `fname` by sampling the nodes randomly.
Supports source models, site models and exposure models. As a special
case, it is also able to reduce .csv files by sampling the lines.
This is a debugging utility to reduce large computations to... | python | def reduce(fname, reduction_factor):
if fname.endswith('.csv'):
with open(fname) as f:
line = f.readline()
if csv.Sniffer().has_header(line):
header = line
all_lines = f.readlines()
else:
header = None
... | [
"def",
"reduce",
"(",
"fname",
",",
"reduction_factor",
")",
":",
"if",
"fname",
".",
"endswith",
"(",
"'.csv'",
")",
":",
"with",
"open",
"(",
"fname",
")",
"as",
"f",
":",
"line",
"=",
"f",
".",
"readline",
"(",
")",
"# read the first line",
"if",
... | Produce a submodel from `fname` by sampling the nodes randomly.
Supports source models, site models and exposure models. As a special
case, it is also able to reduce .csv files by sampling the lines.
This is a debugging utility to reduce large computations to small ones. | [
"Produce",
"a",
"submodel",
"from",
"fname",
"by",
"sampling",
"the",
"nodes",
"randomly",
".",
"Supports",
"source",
"models",
"site",
"models",
"and",
"exposure",
"models",
".",
"As",
"a",
"special",
"case",
"it",
"is",
"also",
"able",
"to",
"reduce",
".... | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/commands/reduce.py#L60-L111 |
gem/oq-engine | openquake/hmtk/faults/mfd/youngs_coppersmith.py | YoungsCoppersmithExponential.get_mfd | def get_mfd(self, slip, area, shear_modulus=30.0):
'''
Calculates activity rate on the fault
:param float slip:
Slip rate in mm/yr
:param area:
Width of the fault (km)
:param float shear_modulus:
Shear modulus of the fault (GPa)
:re... | python | def get_mfd(self, slip, area, shear_modulus=30.0):
moment_rate = (shear_modulus * 1.E9) * (area * 1.E6) * (slip / 1000.)
moment_mag = _scale_moment(self.mmax, in_nm=True)
beta = self.b_value * log(10.)
mag = np.arange(self.mmin - (self.bin_width / 2.),... | [
"def",
"get_mfd",
"(",
"self",
",",
"slip",
",",
"area",
",",
"shear_modulus",
"=",
"30.0",
")",
":",
"# Working in Nm so convert: shear_modulus - GPa -> Nm",
"# area - km ** 2. -> m ** 2.",
"# slip - mm/yr -> m/yr",
"moment_rate",
"=",
"(",
"shear_modulus",
"*",
"1.E9",... | Calculates activity rate on the fault
:param float slip:
Slip rate in mm/yr
:param area:
Width of the fault (km)
:param float shear_modulus:
Shear modulus of the fault (GPa)
:returns:
* Minimum Magnitude (float)
* Bin width ... | [
"Calculates",
"activity",
"rate",
"on",
"the",
"fault"
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hmtk/faults/mfd/youngs_coppersmith.py#L155-L195 |
gem/oq-engine | openquake/hmtk/faults/mfd/youngs_coppersmith.py | YoungsCoppersmithExponential.cumulative_value | def cumulative_value(self, mag_val, moment_rate, beta, moment_mag):
'''
Calculates the cumulative rate of events with M > m0 using
equation 11 of Youngs & Coppersmith (1985)
:param float mag_val:
Magnitude
:param float moment_rate:
Moment rate on fault (... | python | def cumulative_value(self, mag_val, moment_rate, beta, moment_mag):
exponent = exp(-beta * (self.mmax - mag_val))
return (moment_rate * (D_VALUE - self.b_value) * (1. - exponent)) /\
(self.b_value * moment_mag * exponent) | [
"def",
"cumulative_value",
"(",
"self",
",",
"mag_val",
",",
"moment_rate",
",",
"beta",
",",
"moment_mag",
")",
":",
"exponent",
"=",
"exp",
"(",
"-",
"beta",
"*",
"(",
"self",
".",
"mmax",
"-",
"mag_val",
")",
")",
"return",
"(",
"moment_rate",
"*",
... | Calculates the cumulative rate of events with M > m0 using
equation 11 of Youngs & Coppersmith (1985)
:param float mag_val:
Magnitude
:param float moment_rate:
Moment rate on fault (in Nm) from slip rate
:param float beta:
Exponent (b log(10)
... | [
"Calculates",
"the",
"cumulative",
"rate",
"of",
"events",
"with",
"M",
">",
"m0",
"using",
"equation",
"11",
"of",
"Youngs",
"&",
"Coppersmith",
"(",
"1985",
")"
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hmtk/faults/mfd/youngs_coppersmith.py#L197-L216 |
gem/oq-engine | openquake/hmtk/faults/mfd/youngs_coppersmith.py | YoungsCoppersmithCharacteristic.get_mfd | def get_mfd(self, slip, area, shear_modulus=30.0):
'''
Calculates activity rate on the fault
:param float slip:
Slip rate in mm/yr
:param area:
Area of the fault (km)
:param float shear_modulus:
Shear modulus of the fault (GPa)
:ret... | python | def get_mfd(self, slip, area, shear_modulus=30.0):
moment_rate = (shear_modulus * 1.E9) * (area * 1.E6) * (slip / 1000.)
self.model = YoungsCoppersmith1985MFD.from_total_moment_rate(
self.mmin - (self.bin_width / 2.),
self.b_value,
... | [
"def",
"get_mfd",
"(",
"self",
",",
"slip",
",",
"area",
",",
"shear_modulus",
"=",
"30.0",
")",
":",
"# Calculate moment rate in N-m / year",
"moment_rate",
"=",
"(",
"shear_modulus",
"*",
"1.E9",
")",
"*",
"(",
"area",
"*",
"1.E6",
")",
"*",
"(",
"slip",... | Calculates activity rate on the fault
:param float slip:
Slip rate in mm/yr
:param area:
Area of the fault (km)
:param float shear_modulus:
Shear modulus of the fault (GPa)
:returns:
* Minimum Magnitude (float)
* Bin width (... | [
"Calculates",
"activity",
"rate",
"on",
"the",
"fault"
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hmtk/faults/mfd/youngs_coppersmith.py#L309-L344 |
gem/oq-engine | openquake/hazardlib/gsim/can15/sinter.py | SInterCan15Mid.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.
"""
mean = self._get_mean(sites, rup, dists, imt, stddev_types)
st... | python | def get_mean_and_stddevs(self, sites, rup, dists, imt, stddev_types):
mean = self._get_mean(sites, rup, dists, imt, stddev_types)
stddevs = [np.ones(len(dists.rrup))*get_sigma(imt)]
return mean, stddevs | [
"def",
"get_mean_and_stddevs",
"(",
"self",
",",
"sites",
",",
"rup",
",",
"dists",
",",
"imt",
",",
"stddev_types",
")",
":",
"mean",
"=",
"self",
".",
"_get_mean",
"(",
"sites",
",",
"rup",
",",
"dists",
",",
"imt",
",",
"stddev_types",
")",
"stddevs... | 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/can15/sinter.py#L48-L56 |
gem/oq-engine | openquake/hazardlib/gsim/can15/sinter.py | SInterCan15Mid._get_mean | def _get_mean(self, sites, rup, dists, imt, stddev_types):
"""
See :meth:`superclass method
<.base.GroundShakingIntensityModel.get_mean_and_stddevs>`
for spec of input and result values.
"""
# Zhao et al. 2006 - Vs30 + Rrup
mean_zh06, stds1 = super().get_mean_and_... | python | def _get_mean(self, sites, rup, dists, imt, stddev_types):
mean_zh06, stds1 = super().get_mean_and_stddevs(sites, rup, dists, imt,
stddev_types)
gmpe = AtkinsonMacias2009()
mean_am09, stds2 = gmpe.get_mea... | [
"def",
"_get_mean",
"(",
"self",
",",
"sites",
",",
"rup",
",",
"dists",
",",
"imt",
",",
"stddev_types",
")",
":",
"# Zhao et al. 2006 - Vs30 + Rrup",
"mean_zh06",
",",
"stds1",
"=",
"super",
"(",
")",
".",
"get_mean_and_stddevs",
"(",
"sites",
",",
"rup",
... | 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/can15/sinter.py#L58-L87 |
gem/oq-engine | openquake/hazardlib/geo/surface/base.py | _find_turning_points | def _find_turning_points(mesh, tol=1.0):
"""
Identifies the turning points in a rectangular mesh based on the
deviation in the azimuth between successive points on the upper edge.
A turning point is flagged if the change in azimuth change is greater than
the specified tolerance (in degrees)
:pa... | python | def _find_turning_points(mesh, tol=1.0):
assert isinstance(mesh, RectangularMesh)
azimuths = geodetic.azimuth(mesh.lons[0, :-1], mesh.lats[0, :-1],
mesh.lons[0, 1:], mesh.lats[0, 1:])
naz = len(azimuths)
azim = azimuths[0]
idx = [0]
for i in range(1, naz... | [
"def",
"_find_turning_points",
"(",
"mesh",
",",
"tol",
"=",
"1.0",
")",
":",
"assert",
"isinstance",
"(",
"mesh",
",",
"RectangularMesh",
")",
"azimuths",
"=",
"geodetic",
".",
"azimuth",
"(",
"mesh",
".",
"lons",
"[",
"0",
",",
":",
"-",
"1",
"]",
... | Identifies the turning points in a rectangular mesh based on the
deviation in the azimuth between successive points on the upper edge.
A turning point is flagged if the change in azimuth change is greater than
the specified tolerance (in degrees)
:param mesh:
Mesh for downsampling as instance o... | [
"Identifies",
"the",
"turning",
"points",
"in",
"a",
"rectangular",
"mesh",
"based",
"on",
"the",
"deviation",
"in",
"the",
"azimuth",
"between",
"successive",
"points",
"on",
"the",
"upper",
"edge",
".",
"A",
"turning",
"point",
"is",
"flagged",
"if",
"the"... | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/geo/surface/base.py#L29-L61 |
gem/oq-engine | openquake/hazardlib/geo/surface/base.py | downsample_mesh | def downsample_mesh(mesh, tol=1.0):
"""
Returns a mesh sampled at a lower resolution - if the difference
in azimuth is larger than the specified tolerance a turn is assumed
:returns:
Downsampled mesh as instance of :class:
openquake.hazardlib.geo.mesh.RectangularMesh
"""
idx = _... | python | def downsample_mesh(mesh, tol=1.0):
idx = _find_turning_points(mesh, tol)
if mesh.depths is not None:
return RectangularMesh(lons=mesh.lons[:, idx],
lats=mesh.lats[:, idx],
depths=mesh.depths[:, idx])
else:
return Rectangular... | [
"def",
"downsample_mesh",
"(",
"mesh",
",",
"tol",
"=",
"1.0",
")",
":",
"idx",
"=",
"_find_turning_points",
"(",
"mesh",
",",
"tol",
")",
"if",
"mesh",
".",
"depths",
"is",
"not",
"None",
":",
"return",
"RectangularMesh",
"(",
"lons",
"=",
"mesh",
"."... | Returns a mesh sampled at a lower resolution - if the difference
in azimuth is larger than the specified tolerance a turn is assumed
:returns:
Downsampled mesh as instance of :class:
openquake.hazardlib.geo.mesh.RectangularMesh | [
"Returns",
"a",
"mesh",
"sampled",
"at",
"a",
"lower",
"resolution",
"-",
"if",
"the",
"difference",
"in",
"azimuth",
"is",
"larger",
"than",
"the",
"specified",
"tolerance",
"a",
"turn",
"is",
"assumed"
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/geo/surface/base.py#L64-L80 |
gem/oq-engine | openquake/hazardlib/geo/surface/base.py | downsample_trace | def downsample_trace(mesh, tol=1.0):
"""
Downsamples the upper edge of a fault within a rectangular mesh, retaining
node points only if changes in direction on the order of tol are found
:returns:
Downsampled edge as a numpy array of [long, lat, depth]
"""
idx = _find_turning_points(mes... | python | def downsample_trace(mesh, tol=1.0):
idx = _find_turning_points(mesh, tol)
if mesh.depths is not None:
return numpy.column_stack([mesh.lons[0, idx],
mesh.lats[0, idx],
mesh.depths[0, idx]])
else:
return numpy.column_s... | [
"def",
"downsample_trace",
"(",
"mesh",
",",
"tol",
"=",
"1.0",
")",
":",
"idx",
"=",
"_find_turning_points",
"(",
"mesh",
",",
"tol",
")",
"if",
"mesh",
".",
"depths",
"is",
"not",
"None",
":",
"return",
"numpy",
".",
"column_stack",
"(",
"[",
"mesh",... | Downsamples the upper edge of a fault within a rectangular mesh, retaining
node points only if changes in direction on the order of tol are found
:returns:
Downsampled edge as a numpy array of [long, lat, depth] | [
"Downsamples",
"the",
"upper",
"edge",
"of",
"a",
"fault",
"within",
"a",
"rectangular",
"mesh",
"retaining",
"node",
"points",
"only",
"if",
"changes",
"in",
"direction",
"on",
"the",
"order",
"of",
"tol",
"are",
"found"
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/geo/surface/base.py#L83-L97 |
gem/oq-engine | openquake/hazardlib/geo/surface/base.py | BaseSurface.get_ry0_distance | def get_ry0_distance(self, mesh):
"""
Compute the minimum distance between each point of a mesh and the great
circle arcs perpendicular to the average strike direction of the
fault trace and passing through the end-points of the trace.
:param mesh:
:class:`~openquake... | python | def get_ry0_distance(self, mesh):
top_edge = self.mesh[0:1]
mean_strike = self.get_strike()
dst1 = geodetic.distance_to_arc(top_edge.lons[0, 0],
top_edge.lats[0, 0],
(mean_strike + 90.) % 360,
... | [
"def",
"get_ry0_distance",
"(",
"self",
",",
"mesh",
")",
":",
"# This computes ry0 by using an average strike direction",
"top_edge",
"=",
"self",
".",
"mesh",
"[",
"0",
":",
"1",
"]",
"mean_strike",
"=",
"self",
".",
"get_strike",
"(",
")",
"dst1",
"=",
"geo... | Compute the minimum distance between each point of a mesh and the great
circle arcs perpendicular to the average strike direction of the
fault trace and passing through the end-points of the trace.
:param mesh:
:class:`~openquake.hazardlib.geo.mesh.Mesh` of points to calculate
... | [
"Compute",
"the",
"minimum",
"distance",
"between",
"each",
"point",
"of",
"a",
"mesh",
"and",
"the",
"great",
"circle",
"arcs",
"perpendicular",
"to",
"the",
"average",
"strike",
"direction",
"of",
"the",
"fault",
"trace",
"and",
"passing",
"through",
"the",
... | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/geo/surface/base.py#L148-L180 |
gem/oq-engine | openquake/hazardlib/geo/surface/base.py | BaseSurface.get_rx_distance | def get_rx_distance(self, mesh):
"""
Compute distance between each point of mesh and surface's great circle
arc.
Distance is measured perpendicular to the rupture strike, from
the surface projection of the updip edge of the rupture, with
the down dip direction being posi... | python | def get_rx_distance(self, mesh):
top_edge = self.mesh[0:1]
dists = []
if top_edge.lons.shape[1] < 3:
i = 0
p1 = Point(
top_edge.lons[0, i],
top_edge.lats[0, i],
top_edge.depths[0, i]
)
p2 =... | [
"def",
"get_rx_distance",
"(",
"self",
",",
"mesh",
")",
":",
"top_edge",
"=",
"self",
".",
"mesh",
"[",
"0",
":",
"1",
"]",
"dists",
"=",
"[",
"]",
"if",
"top_edge",
".",
"lons",
".",
"shape",
"[",
"1",
"]",
"<",
"3",
":",
"i",
"=",
"0",
"p1... | Compute distance between each point of mesh and surface's great circle
arc.
Distance is measured perpendicular to the rupture strike, from
the surface projection of the updip edge of the rupture, with
the down dip direction being positive (this distance is usually
called ``Rx``)... | [
"Compute",
"distance",
"between",
"each",
"point",
"of",
"mesh",
"and",
"surface",
"s",
"great",
"circle",
"arc",
"."
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/geo/surface/base.py#L182-L266 |
gem/oq-engine | openquake/hazardlib/geo/surface/base.py | BaseSurface.get_top_edge_depth | def get_top_edge_depth(self):
"""
Return minimum depth of surface's top edge.
:returns:
Float value, the vertical distance between the earth surface
and the shallowest point in surface's top edge in km.
"""
top_edge = self.mesh[0:1]
if top_edge.de... | python | def get_top_edge_depth(self):
top_edge = self.mesh[0:1]
if top_edge.depths is None:
return 0
else:
return numpy.min(top_edge.depths) | [
"def",
"get_top_edge_depth",
"(",
"self",
")",
":",
"top_edge",
"=",
"self",
".",
"mesh",
"[",
"0",
":",
"1",
"]",
"if",
"top_edge",
".",
"depths",
"is",
"None",
":",
"return",
"0",
"else",
":",
"return",
"numpy",
".",
"min",
"(",
"top_edge",
".",
... | Return minimum depth of surface's top edge.
:returns:
Float value, the vertical distance between the earth surface
and the shallowest point in surface's top edge in km. | [
"Return",
"minimum",
"depth",
"of",
"surface",
"s",
"top",
"edge",
"."
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/geo/surface/base.py#L268-L280 |
gem/oq-engine | openquake/hazardlib/geo/surface/base.py | BaseSurface.get_area | def get_area(self):
"""
Compute area as the sum of the mesh cells area values.
"""
mesh = self.mesh
_, _, _, area = mesh.get_cell_dimensions()
return numpy.sum(area) | python | def get_area(self):
mesh = self.mesh
_, _, _, area = mesh.get_cell_dimensions()
return numpy.sum(area) | [
"def",
"get_area",
"(",
"self",
")",
":",
"mesh",
"=",
"self",
".",
"mesh",
"_",
",",
"_",
",",
"_",
",",
"area",
"=",
"mesh",
".",
"get_cell_dimensions",
"(",
")",
"return",
"numpy",
".",
"sum",
"(",
"area",
")"
] | Compute area as the sum of the mesh cells area values. | [
"Compute",
"area",
"as",
"the",
"sum",
"of",
"the",
"mesh",
"cells",
"area",
"values",
"."
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/geo/surface/base.py#L290-L297 |
gem/oq-engine | openquake/hazardlib/geo/surface/base.py | BaseSurface.get_bounding_box | def get_bounding_box(self):
"""
Compute surface bounding box from surface mesh representation. That is
extract longitudes and latitudes of mesh points and calls:
:meth:`openquake.hazardlib.geo.utils.get_spherical_bounding_box`
:return:
A tuple of four items. These it... | python | def get_bounding_box(self):
mesh = self.mesh
return utils.get_spherical_bounding_box(mesh.lons, mesh.lats) | [
"def",
"get_bounding_box",
"(",
"self",
")",
":",
"mesh",
"=",
"self",
".",
"mesh",
"return",
"utils",
".",
"get_spherical_bounding_box",
"(",
"mesh",
".",
"lons",
",",
"mesh",
".",
"lats",
")"
] | Compute surface bounding box from surface mesh representation. That is
extract longitudes and latitudes of mesh points and calls:
:meth:`openquake.hazardlib.geo.utils.get_spherical_bounding_box`
:return:
A tuple of four items. These items represent western, eastern,
nort... | [
"Compute",
"surface",
"bounding",
"box",
"from",
"surface",
"mesh",
"representation",
".",
"That",
"is",
"extract",
"longitudes",
"and",
"latitudes",
"of",
"mesh",
"points",
"and",
"calls",
":",
":",
"meth",
":",
"openquake",
".",
"hazardlib",
".",
"geo",
".... | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/geo/surface/base.py#L299-L311 |
gem/oq-engine | openquake/hazardlib/geo/surface/base.py | BaseSurface.get_surface_boundaries | def get_surface_boundaries(self):
"""
Returns the boundaries in the same format as a multiplanar
surface, with two one-element lists of lons and lats
"""
mesh = self.mesh
lons = numpy.concatenate((mesh.lons[0, :],
mesh.lons[1:, -1],
... | python | def get_surface_boundaries(self):
mesh = self.mesh
lons = numpy.concatenate((mesh.lons[0, :],
mesh.lons[1:, -1],
mesh.lons[-1, :-1][::-1],
mesh.lons[:-1, 0][::-1]))
lats = numpy.concate... | [
"def",
"get_surface_boundaries",
"(",
"self",
")",
":",
"mesh",
"=",
"self",
".",
"mesh",
"lons",
"=",
"numpy",
".",
"concatenate",
"(",
"(",
"mesh",
".",
"lons",
"[",
"0",
",",
":",
"]",
",",
"mesh",
".",
"lons",
"[",
"1",
":",
",",
"-",
"1",
... | Returns the boundaries in the same format as a multiplanar
surface, with two one-element lists of lons and lats | [
"Returns",
"the",
"boundaries",
"in",
"the",
"same",
"format",
"as",
"a",
"multiplanar",
"surface",
"with",
"two",
"one",
"-",
"element",
"lists",
"of",
"lons",
"and",
"lats"
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/geo/surface/base.py#L326-L340 |
gem/oq-engine | openquake/hazardlib/geo/surface/base.py | BaseSurface.get_resampled_top_edge | def get_resampled_top_edge(self, angle_var=0.1):
"""
This methods computes a simplified representation of a fault top edge
by removing the points that are not describing a change of direction,
provided a certain tolerance angle.
:param float angle_var:
Number represe... | python | def get_resampled_top_edge(self, angle_var=0.1):
mesh = self.mesh
top_edge = [Point(mesh.lons[0][0], mesh.lats[0][0], mesh.depths[0][0])]
for i in range(len(mesh.triangulate()[1][0]) - 1):
v1 = numpy.asarray(mesh.triangulate()[1][0][i])
v2 = numpy.asarray(mesh.t... | [
"def",
"get_resampled_top_edge",
"(",
"self",
",",
"angle_var",
"=",
"0.1",
")",
":",
"mesh",
"=",
"self",
".",
"mesh",
"top_edge",
"=",
"[",
"Point",
"(",
"mesh",
".",
"lons",
"[",
"0",
"]",
"[",
"0",
"]",
",",
"mesh",
".",
"lats",
"[",
"0",
"]"... | This methods computes a simplified representation of a fault top edge
by removing the points that are not describing a change of direction,
provided a certain tolerance angle.
:param float angle_var:
Number representing the maximum deviation (in degrees) admitted
without... | [
"This",
"methods",
"computes",
"a",
"simplified",
"representation",
"of",
"a",
"fault",
"top",
"edge",
"by",
"removing",
"the",
"points",
"that",
"are",
"not",
"describing",
"a",
"change",
"of",
"direction",
"provided",
"a",
"certain",
"tolerance",
"angle",
".... | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/geo/surface/base.py#L342-L375 |
gem/oq-engine | openquake/hazardlib/geo/surface/base.py | BaseSurface.get_hypo_location | def get_hypo_location(self, mesh_spacing, hypo_loc=None):
"""
The method determines the location of the hypocentre within the rupture
:param mesh:
:class:`~openquake.hazardlib.geo.mesh.Mesh` of points
:param mesh_spacing:
The desired distance between two adjacent... | python | def get_hypo_location(self, mesh_spacing, hypo_loc=None):
mesh = self.mesh
centroid = mesh.get_middle_point()
if hypo_loc is None:
return centroid
total_len_y = (len(mesh.depths) - 1) * mesh_spacing
y_distance = hypo_loc[1] * total_len_y
y_node = int... | [
"def",
"get_hypo_location",
"(",
"self",
",",
"mesh_spacing",
",",
"hypo_loc",
"=",
"None",
")",
":",
"mesh",
"=",
"self",
".",
"mesh",
"centroid",
"=",
"mesh",
".",
"get_middle_point",
"(",
")",
"if",
"hypo_loc",
"is",
"None",
":",
"return",
"centroid",
... | The method determines the location of the hypocentre within the rupture
:param mesh:
:class:`~openquake.hazardlib.geo.mesh.Mesh` of points
:param mesh_spacing:
The desired distance between two adjacent points in source's
ruptures' mesh, in km. Mainly this parameter a... | [
"The",
"method",
"determines",
"the",
"location",
"of",
"the",
"hypocentre",
"within",
"the",
"rupture"
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/geo/surface/base.py#L377-L414 |
gem/oq-engine | openquake/hazardlib/geo/surface/base.py | BaseSurface.get_azimuth | def get_azimuth(self, mesh):
"""
This method computes the azimuth of a set of points in a
:class:`openquake.hazardlib.geo.mesh` instance. The reference used for
the calculation of azimuth is the middle point and the strike of the
rupture. The value of azimuth computed corresponds... | python | def get_azimuth(self, mesh):
strike = self.get_strike()
hypocenter = self.get_middle_point()
azim = geodetic.azimuth(hypocenter.longitude, hypocenter.latitude,
mesh.lons, mesh.lats)
rel_azi = (azim - strike) % 3... | [
"def",
"get_azimuth",
"(",
"self",
",",
"mesh",
")",
":",
"# Get info about the rupture",
"strike",
"=",
"self",
".",
"get_strike",
"(",
")",
"hypocenter",
"=",
"self",
".",
"get_middle_point",
"(",
")",
"# This is the azimuth from the north of each point Vs. the middle... | This method computes the azimuth of a set of points in a
:class:`openquake.hazardlib.geo.mesh` instance. The reference used for
the calculation of azimuth is the middle point and the strike of the
rupture. The value of azimuth computed corresponds to the angle
measured in a clockwise dir... | [
"This",
"method",
"computes",
"the",
"azimuth",
"of",
"a",
"set",
"of",
"points",
"in",
"a",
":",
"class",
":",
"openquake",
".",
"hazardlib",
".",
"geo",
".",
"mesh",
"instance",
".",
"The",
"reference",
"used",
"for",
"the",
"calculation",
"of",
"azimu... | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/geo/surface/base.py#L416-L438 |
gem/oq-engine | openquake/calculators/export/risk.py | export_avg_losses | def export_avg_losses(ekey, dstore):
"""
:param ekey: export key, i.e. a pair (datastore key, fmt)
:param dstore: datastore object
"""
dskey = ekey[0]
oq = dstore['oqparam']
dt = oq.loss_dt()
name, value, tags = _get_data(dstore, dskey, oq.hazard_stats().items())
writer = writers.Csv... | python | def export_avg_losses(ekey, dstore):
dskey = ekey[0]
oq = dstore['oqparam']
dt = oq.loss_dt()
name, value, tags = _get_data(dstore, dskey, oq.hazard_stats().items())
writer = writers.CsvWriter(fmt=writers.FIVEDIGITS)
assets = get_assets(dstore)
for tag, values in zip(tags, value.transpo... | [
"def",
"export_avg_losses",
"(",
"ekey",
",",
"dstore",
")",
":",
"dskey",
"=",
"ekey",
"[",
"0",
"]",
"oq",
"=",
"dstore",
"[",
"'oqparam'",
"]",
"dt",
"=",
"oq",
".",
"loss_dt",
"(",
")",
"name",
",",
"value",
",",
"tags",
"=",
"_get_data",
"(",
... | :param ekey: export key, i.e. a pair (datastore key, fmt)
:param dstore: datastore object | [
":",
"param",
"ekey",
":",
"export",
"key",
"i",
".",
"e",
".",
"a",
"pair",
"(",
"datastore",
"key",
"fmt",
")",
":",
"param",
"dstore",
":",
"datastore",
"object"
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/calculators/export/risk.py#L131-L148 |
gem/oq-engine | openquake/calculators/export/risk.py | export_agg_losses | def export_agg_losses(ekey, dstore):
"""
:param ekey: export key, i.e. a pair (datastore key, fmt)
:param dstore: datastore object
"""
dskey = ekey[0]
oq = dstore['oqparam']
dt = oq.loss_dt()
name, value, tags = _get_data(dstore, dskey, oq.hazard_stats().items())
writer = writers.Csv... | python | def export_agg_losses(ekey, dstore):
dskey = ekey[0]
oq = dstore['oqparam']
dt = oq.loss_dt()
name, value, tags = _get_data(dstore, dskey, oq.hazard_stats().items())
writer = writers.CsvWriter(fmt=writers.FIVEDIGITS)
expvalue = dstore['exposed_value'].value
tagcol = dstore['assetcol/t... | [
"def",
"export_agg_losses",
"(",
"ekey",
",",
"dstore",
")",
":",
"dskey",
"=",
"ekey",
"[",
"0",
"]",
"oq",
"=",
"dstore",
"[",
"'oqparam'",
"]",
"dt",
"=",
"oq",
".",
"loss_dt",
"(",
")",
"name",
",",
"value",
",",
"tags",
"=",
"_get_data",
"(",
... | :param ekey: export key, i.e. a pair (datastore key, fmt)
:param dstore: datastore object | [
":",
"param",
"ekey",
":",
"export",
"key",
"i",
".",
"e",
".",
"a",
"pair",
"(",
"datastore",
"key",
"fmt",
")",
":",
"param",
"dstore",
":",
"datastore",
"object"
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/calculators/export/risk.py#L153-L178 |
gem/oq-engine | openquake/calculators/export/risk.py | export_avg_losses_ebrisk | def export_avg_losses_ebrisk(ekey, dstore):
"""
:param ekey: export key, i.e. a pair (datastore key, fmt)
:param dstore: datastore object
"""
name = ekey[0]
oq = dstore['oqparam']
dt = oq.loss_dt()
value = dstore[name].value # shape (A, L)
writer = writers.CsvWriter(fmt=writers.FIVE... | python | def export_avg_losses_ebrisk(ekey, dstore):
name = ekey[0]
oq = dstore['oqparam']
dt = oq.loss_dt()
value = dstore[name].value
writer = writers.CsvWriter(fmt=writers.FIVEDIGITS)
assets = get_assets(dstore)
dest = dstore.build_fname(name, 'mean', 'csv')
array = numpy.zeros(len(valu... | [
"def",
"export_avg_losses_ebrisk",
"(",
"ekey",
",",
"dstore",
")",
":",
"name",
"=",
"ekey",
"[",
"0",
"]",
"oq",
"=",
"dstore",
"[",
"'oqparam'",
"]",
"dt",
"=",
"oq",
".",
"loss_dt",
"(",
")",
"value",
"=",
"dstore",
"[",
"name",
"]",
".",
"valu... | :param ekey: export key, i.e. a pair (datastore key, fmt)
:param dstore: datastore object | [
":",
"param",
"ekey",
":",
"export",
"key",
"i",
".",
"e",
".",
"a",
"pair",
"(",
"datastore",
"key",
"fmt",
")",
":",
"param",
"dstore",
":",
"datastore",
"object"
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/calculators/export/risk.py#L183-L199 |
gem/oq-engine | openquake/calculators/export/risk.py | export_losses_by_asset | def export_losses_by_asset(ekey, dstore):
"""
:param ekey: export key, i.e. a pair (datastore key, fmt)
:param dstore: datastore object
"""
loss_dt = dstore['oqparam'].loss_dt(stat_dt)
losses_by_asset = dstore[ekey[0]].value
rlzs = dstore['csm_info'].get_rlzs_assoc().realizations
assets ... | python | def export_losses_by_asset(ekey, dstore):
loss_dt = dstore['oqparam'].loss_dt(stat_dt)
losses_by_asset = dstore[ekey[0]].value
rlzs = dstore['csm_info'].get_rlzs_assoc().realizations
assets = get_assets(dstore)
writer = writers.CsvWriter(fmt=writers.FIVEDIGITS)
for rlz in rlzs:
loss... | [
"def",
"export_losses_by_asset",
"(",
"ekey",
",",
"dstore",
")",
":",
"loss_dt",
"=",
"dstore",
"[",
"'oqparam'",
"]",
".",
"loss_dt",
"(",
"stat_dt",
")",
"losses_by_asset",
"=",
"dstore",
"[",
"ekey",
"[",
"0",
"]",
"]",
".",
"value",
"rlzs",
"=",
"... | :param ekey: export key, i.e. a pair (datastore key, fmt)
:param dstore: datastore object | [
":",
"param",
"ekey",
":",
"export",
"key",
"i",
".",
"e",
".",
"a",
"pair",
"(",
"datastore",
"key",
"fmt",
")",
":",
"param",
"dstore",
":",
"datastore",
"object"
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/calculators/export/risk.py#L204-L219 |
gem/oq-engine | openquake/calculators/export/risk.py | export_losses_by_event | def export_losses_by_event(ekey, dstore):
"""
:param ekey: export key, i.e. a pair (datastore key, fmt)
:param dstore: datastore object
"""
oq = dstore['oqparam']
writer = writers.CsvWriter(fmt=writers.FIVEDIGITS)
dest = dstore.build_fname('losses_by_event', '', 'csv')
if oq.calculation_... | python | def export_losses_by_event(ekey, dstore):
oq = dstore['oqparam']
writer = writers.CsvWriter(fmt=writers.FIVEDIGITS)
dest = dstore.build_fname('losses_by_event', '', 'csv')
if oq.calculation_mode.startswith('scenario'):
dtlist = [('eid', U64)] + oq.loss_dt_list()
arr = dstore['losses... | [
"def",
"export_losses_by_event",
"(",
"ekey",
",",
"dstore",
")",
":",
"oq",
"=",
"dstore",
"[",
"'oqparam'",
"]",
"writer",
"=",
"writers",
".",
"CsvWriter",
"(",
"fmt",
"=",
"writers",
".",
"FIVEDIGITS",
")",
"dest",
"=",
"dstore",
".",
"build_fname",
... | :param ekey: export key, i.e. a pair (datastore key, fmt)
:param dstore: datastore object | [
":",
"param",
"ekey",
":",
"export",
"key",
"i",
".",
"e",
".",
"a",
"pair",
"(",
"datastore",
"key",
"fmt",
")",
":",
"param",
"dstore",
":",
"datastore",
"object"
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/calculators/export/risk.py#L224-L261 |
gem/oq-engine | openquake/calculators/export/risk.py | export_losses_by_asset_npz | def export_losses_by_asset_npz(ekey, dstore):
"""
:param ekey: export key, i.e. a pair (datastore key, fmt)
:param dstore: datastore object
"""
fname = dstore.export_path('%s.%s' % ekey)
savez(fname, **dict(extract(dstore, 'losses_by_asset')))
return [fname] | python | def export_losses_by_asset_npz(ekey, dstore):
fname = dstore.export_path('%s.%s' % ekey)
savez(fname, **dict(extract(dstore, 'losses_by_asset')))
return [fname] | [
"def",
"export_losses_by_asset_npz",
"(",
"ekey",
",",
"dstore",
")",
":",
"fname",
"=",
"dstore",
".",
"export_path",
"(",
"'%s.%s'",
"%",
"ekey",
")",
"savez",
"(",
"fname",
",",
"*",
"*",
"dict",
"(",
"extract",
"(",
"dstore",
",",
"'losses_by_asset'",
... | :param ekey: export key, i.e. a pair (datastore key, fmt)
:param dstore: datastore object | [
":",
"param",
"ekey",
":",
"export",
"key",
"i",
".",
"e",
".",
"a",
"pair",
"(",
"datastore",
"key",
"fmt",
")",
":",
"param",
"dstore",
":",
"datastore",
"object"
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/calculators/export/risk.py#L265-L272 |
gem/oq-engine | openquake/calculators/export/risk.py | export_maxloss_ruptures | def export_maxloss_ruptures(ekey, dstore):
"""
:param ekey: export key, i.e. a pair (datastore key, fmt)
:param dstore: datastore object
"""
oq = dstore['oqparam']
mesh = get_mesh(dstore['sitecol'])
rlzs_by_gsim = dstore['csm_info'].get_rlzs_by_gsim_grp()
num_ses = oq.ses_per_logic_tree_... | python | def export_maxloss_ruptures(ekey, dstore):
oq = dstore['oqparam']
mesh = get_mesh(dstore['sitecol'])
rlzs_by_gsim = dstore['csm_info'].get_rlzs_by_gsim_grp()
num_ses = oq.ses_per_logic_tree_path
fnames = []
for loss_type in oq.loss_dt().names:
ebr = getters.get_maxloss_rupture(dstor... | [
"def",
"export_maxloss_ruptures",
"(",
"ekey",
",",
"dstore",
")",
":",
"oq",
"=",
"dstore",
"[",
"'oqparam'",
"]",
"mesh",
"=",
"get_mesh",
"(",
"dstore",
"[",
"'sitecol'",
"]",
")",
"rlzs_by_gsim",
"=",
"dstore",
"[",
"'csm_info'",
"]",
".",
"get_rlzs_by... | :param ekey: export key, i.e. a pair (datastore key, fmt)
:param dstore: datastore object | [
":",
"param",
"ekey",
":",
"export",
"key",
"i",
".",
"e",
".",
"a",
"pair",
"(",
"datastore",
"key",
"fmt",
")",
":",
"param",
"dstore",
":",
"datastore",
"object"
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/calculators/export/risk.py#L286-L304 |
gem/oq-engine | openquake/calculators/export/risk.py | export_agg_losses_ebr | def export_agg_losses_ebr(ekey, dstore):
"""
:param ekey: export key, i.e. a pair (datastore key, fmt)
:param dstore: datastore object
"""
if 'ruptures' not in dstore:
logging.warning('There are no ruptures in the datastore')
return []
name, ext = export.keyfunc(ekey)
agg_los... | python | def export_agg_losses_ebr(ekey, dstore):
if 'ruptures' not in dstore:
logging.warning('There are no ruptures in the datastore')
return []
name, ext = export.keyfunc(ekey)
agg_losses = dstore['losses_by_event']
has_rup_data = 'ruptures' in dstore
extra_list = [('magnitude', F32),... | [
"def",
"export_agg_losses_ebr",
"(",
"ekey",
",",
"dstore",
")",
":",
"if",
"'ruptures'",
"not",
"in",
"dstore",
":",
"logging",
".",
"warning",
"(",
"'There are no ruptures in the datastore'",
")",
"return",
"[",
"]",
"name",
",",
"ext",
"=",
"export",
".",
... | :param ekey: export key, i.e. a pair (datastore key, fmt)
:param dstore: datastore object | [
":",
"param",
"ekey",
":",
"export",
"key",
"i",
".",
"e",
".",
"a",
"pair",
"(",
"datastore",
"key",
"fmt",
")",
":",
"param",
"dstore",
":",
"datastore",
"object"
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/calculators/export/risk.py#L316-L369 |
gem/oq-engine | openquake/calculators/export/risk.py | export_dmg_by_event | def export_dmg_by_event(ekey, dstore):
"""
:param ekey: export key, i.e. a pair (datastore key, fmt)
:param dstore: datastore object
"""
damage_dt = build_damage_dt(dstore, mean_std=False)
dt_list = [('event_id', numpy.uint64), ('rlzi', numpy.uint16)] + [
(f, damage_dt.fields[f][0]) for ... | python | def export_dmg_by_event(ekey, dstore):
damage_dt = build_damage_dt(dstore, mean_std=False)
dt_list = [('event_id', numpy.uint64), ('rlzi', numpy.uint16)] + [
(f, damage_dt.fields[f][0]) for f in damage_dt.names]
all_losses = dstore[ekey[0]].value
events_by_rlz = group_array(dstore['events... | [
"def",
"export_dmg_by_event",
"(",
"ekey",
",",
"dstore",
")",
":",
"damage_dt",
"=",
"build_damage_dt",
"(",
"dstore",
",",
"mean_std",
"=",
"False",
")",
"dt_list",
"=",
"[",
"(",
"'event_id'",
",",
"numpy",
".",
"uint64",
")",
",",
"(",
"'rlzi'",
",",... | :param ekey: export key, i.e. a pair (datastore key, fmt)
:param dstore: datastore object | [
":",
"param",
"ekey",
":",
"export",
"key",
"i",
".",
"e",
".",
"a",
"pair",
"(",
"datastore",
"key",
"fmt",
")",
":",
"param",
"dstore",
":",
"datastore",
"object"
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/calculators/export/risk.py#L479-L502 |
gem/oq-engine | openquake/calculators/export/risk.py | get_loss_maps | def get_loss_maps(dstore, kind):
"""
:param dstore: a DataStore instance
:param kind: 'rlzs' or 'stats'
"""
oq = dstore['oqparam']
name = 'loss_maps-%s' % kind
if name in dstore: # event_based risk
return _to_loss_maps(dstore[name].value, oq.loss_maps_dt())
name = 'loss_curves-%... | python | def get_loss_maps(dstore, kind):
oq = dstore['oqparam']
name = 'loss_maps-%s' % kind
if name in dstore:
return _to_loss_maps(dstore[name].value, oq.loss_maps_dt())
name = 'loss_curves-%s' % kind
if name in dstore:
loss_curves = dstore[name]
loss_maps = scien... | [
"def",
"get_loss_maps",
"(",
"dstore",
",",
"kind",
")",
":",
"oq",
"=",
"dstore",
"[",
"'oqparam'",
"]",
"name",
"=",
"'loss_maps-%s'",
"%",
"kind",
"if",
"name",
"in",
"dstore",
":",
"# event_based risk",
"return",
"_to_loss_maps",
"(",
"dstore",
"[",
"n... | :param dstore: a DataStore instance
:param kind: 'rlzs' or 'stats' | [
":",
"param",
"dstore",
":",
"a",
"DataStore",
"instance",
":",
"param",
"kind",
":",
"rlzs",
"or",
"stats"
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/calculators/export/risk.py#L526-L542 |
gem/oq-engine | openquake/calculators/export/risk.py | get_paths | def get_paths(rlz):
"""
:param rlz:
a logic tree realization (composite or simple)
:returns:
a dict {'source_model_tree_path': string, 'gsim_tree_path': string}
"""
dic = {}
if hasattr(rlz, 'sm_lt_path'): # composite realization
dic['source_model_tree_path'] = '_'.join(r... | python | def get_paths(rlz):
dic = {}
if hasattr(rlz, 'sm_lt_path'):
dic['source_model_tree_path'] = '_'.join(rlz.sm_lt_path)
dic['gsim_tree_path'] = '_'.join(rlz.gsim_lt_path)
else:
dic['source_model_tree_path'] = ''
dic['gsim_tree_path'] = '_'.join(rlz.lt_path)
return d... | [
"def",
"get_paths",
"(",
"rlz",
")",
":",
"dic",
"=",
"{",
"}",
"if",
"hasattr",
"(",
"rlz",
",",
"'sm_lt_path'",
")",
":",
"# composite realization",
"dic",
"[",
"'source_model_tree_path'",
"]",
"=",
"'_'",
".",
"join",
"(",
"rlz",
".",
"sm_lt_path",
")... | :param rlz:
a logic tree realization (composite or simple)
:returns:
a dict {'source_model_tree_path': string, 'gsim_tree_path': string} | [
":",
"param",
"rlz",
":",
"a",
"logic",
"tree",
"realization",
"(",
"composite",
"or",
"simple",
")",
":",
"returns",
":",
"a",
"dict",
"{",
"source_model_tree_path",
":",
"string",
"gsim_tree_path",
":",
"string",
"}"
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/calculators/export/risk.py#L573-L587 |
gem/oq-engine | openquake/calculators/export/risk.py | export_by_tag_csv | def export_by_tag_csv(ekey, dstore):
"""
:param ekey: export key, i.e. a pair (datastore key, fmt)
:param dstore: datastore object
"""
token, tag = ekey[0].split('/')
data = extract(dstore, token + '/' + tag)
fnames = []
writer = writers.CsvWriter(fmt=writers.FIVEDIGITS)
for stat, ar... | python | def export_by_tag_csv(ekey, dstore):
token, tag = ekey[0].split('/')
data = extract(dstore, token + '/' + tag)
fnames = []
writer = writers.CsvWriter(fmt=writers.FIVEDIGITS)
for stat, arr in data:
tup = (ekey[0].replace('/', '-'), stat, ekey[1])
path = '%s-%s.%s' % tup
f... | [
"def",
"export_by_tag_csv",
"(",
"ekey",
",",
"dstore",
")",
":",
"token",
",",
"tag",
"=",
"ekey",
"[",
"0",
"]",
".",
"split",
"(",
"'/'",
")",
"data",
"=",
"extract",
"(",
"dstore",
",",
"token",
"+",
"'/'",
"+",
"tag",
")",
"fnames",
"=",
"["... | :param ekey: export key, i.e. a pair (datastore key, fmt)
:param dstore: datastore object | [
":",
"param",
"ekey",
":",
"export",
"key",
"i",
".",
"e",
".",
"a",
"pair",
"(",
"datastore",
"key",
"fmt",
")",
":",
"param",
"dstore",
":",
"datastore",
"object"
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/calculators/export/risk.py#L611-L626 |
gem/oq-engine | openquake/calculators/export/risk.py | export_aggregate_by_csv | def export_aggregate_by_csv(ekey, dstore):
"""
:param ekey: export key, i.e. a pair (datastore key, fmt)
:param dstore: datastore object
"""
token, what = ekey[0].split('/', 1)
aw = extract(dstore, 'aggregate/' + what)
fnames = []
writer = writers.CsvWriter(fmt=writers.FIVEDIGITS)
pa... | python | def export_aggregate_by_csv(ekey, dstore):
token, what = ekey[0].split('/', 1)
aw = extract(dstore, 'aggregate/' + what)
fnames = []
writer = writers.CsvWriter(fmt=writers.FIVEDIGITS)
path = '%s.%s' % (sanitize(ekey[0]), ekey[1])
fname = dstore.export_path(path)
writer.save(aw.to_table(... | [
"def",
"export_aggregate_by_csv",
"(",
"ekey",
",",
"dstore",
")",
":",
"token",
",",
"what",
"=",
"ekey",
"[",
"0",
"]",
".",
"split",
"(",
"'/'",
",",
"1",
")",
"aw",
"=",
"extract",
"(",
"dstore",
",",
"'aggregate/'",
"+",
"what",
")",
"fnames",
... | :param ekey: export key, i.e. a pair (datastore key, fmt)
:param dstore: datastore object | [
":",
"param",
"ekey",
":",
"export",
"key",
"i",
".",
"e",
".",
"a",
"pair",
"(",
"datastore",
"key",
"fmt",
")",
":",
"param",
"dstore",
":",
"datastore",
"object"
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/calculators/export/risk.py#L630-L643 |
gem/oq-engine | openquake/calculators/export/risk.py | export_asset_risk_csv | def export_asset_risk_csv(ekey, dstore):
"""
:param ekey: export key, i.e. a pair (datastore key, fmt)
:param dstore: datastore object
"""
writer = writers.CsvWriter(fmt=writers.FIVEDIGITS)
path = '%s.%s' % (sanitize(ekey[0]), ekey[1])
fname = dstore.export_path(path)
md = extract(dstore... | python | def export_asset_risk_csv(ekey, dstore):
writer = writers.CsvWriter(fmt=writers.FIVEDIGITS)
path = '%s.%s' % (sanitize(ekey[0]), ekey[1])
fname = dstore.export_path(path)
md = extract(dstore, 'exposure_metadata')
tostr = {'taxonomy': md.taxonomy}
for tagname in md.tagnames:
tostr[ta... | [
"def",
"export_asset_risk_csv",
"(",
"ekey",
",",
"dstore",
")",
":",
"writer",
"=",
"writers",
".",
"CsvWriter",
"(",
"fmt",
"=",
"writers",
".",
"FIVEDIGITS",
")",
"path",
"=",
"'%s.%s'",
"%",
"(",
"sanitize",
"(",
"ekey",
"[",
"0",
"]",
")",
",",
... | :param ekey: export key, i.e. a pair (datastore key, fmt)
:param dstore: datastore object | [
":",
"param",
"ekey",
":",
"export",
"key",
"i",
".",
"e",
".",
"a",
"pair",
"(",
"datastore",
"key",
"fmt",
")",
":",
"param",
"dstore",
":",
"datastore",
"object"
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/calculators/export/risk.py#L647-L682 |
gem/oq-engine | openquake/calculators/export/risk.py | export_agg_risk_csv | def export_agg_risk_csv(ekey, dstore):
"""
:param ekey: export key, i.e. a pair (datastore key, fmt)
:param dstore: datastore object
"""
writer = writers.CsvWriter(fmt=writers.FIVEDIGITS)
path = '%s.%s' % (sanitize(ekey[0]), ekey[1])
fname = dstore.export_path(path)
writer.save(dstore['a... | python | def export_agg_risk_csv(ekey, dstore):
writer = writers.CsvWriter(fmt=writers.FIVEDIGITS)
path = '%s.%s' % (sanitize(ekey[0]), ekey[1])
fname = dstore.export_path(path)
writer.save(dstore['agg_risk'].value, fname)
return [fname] | [
"def",
"export_agg_risk_csv",
"(",
"ekey",
",",
"dstore",
")",
":",
"writer",
"=",
"writers",
".",
"CsvWriter",
"(",
"fmt",
"=",
"writers",
".",
"FIVEDIGITS",
")",
"path",
"=",
"'%s.%s'",
"%",
"(",
"sanitize",
"(",
"ekey",
"[",
"0",
"]",
")",
",",
"e... | :param ekey: export key, i.e. a pair (datastore key, fmt)
:param dstore: datastore object | [
":",
"param",
"ekey",
":",
"export",
"key",
"i",
".",
"e",
".",
"a",
"pair",
"(",
"datastore",
"key",
"fmt",
")",
":",
"param",
"dstore",
":",
"datastore",
"object"
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/calculators/export/risk.py#L686-L695 |
gem/oq-engine | openquake/engine/tools/viewlog.py | viewlog | def viewlog(calc_id, host='localhost', port=8000):
"""
Extract the log of the given calculation ID from the WebUI
"""
base_url = 'http://%s:%s/v1/calc/' % (host, port)
start = 0
psize = 10 # page size
try:
while True:
url = base_url + '%d/log/%d:%d' % (calc_id, start, st... | python | def viewlog(calc_id, host='localhost', port=8000):
base_url = 'http://%s:%s/v1/calc/' % (host, port)
start = 0
psize = 10
try:
while True:
url = base_url + '%d/log/%d:%d' % (calc_id, start, start + psize)
rows = json.load(urlopen(url))
for row in rows:
... | [
"def",
"viewlog",
"(",
"calc_id",
",",
"host",
"=",
"'localhost'",
",",
"port",
"=",
"8000",
")",
":",
"base_url",
"=",
"'http://%s:%s/v1/calc/'",
"%",
"(",
"host",
",",
"port",
")",
"start",
"=",
"0",
"psize",
"=",
"10",
"# page size",
"try",
":",
"wh... | Extract the log of the given calculation ID from the WebUI | [
"Extract",
"the",
"log",
"of",
"the",
"given",
"calculation",
"ID",
"from",
"the",
"WebUI"
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/engine/tools/viewlog.py#L33-L49 |
gem/oq-engine | openquake/hazardlib/gsim/megawati_2003.py | MegawatiEtAl2003.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.
"""
# Check that the GSIM supports the standard deviations requested
... | 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)
coe = self.COEFFS[imt]
mean = (self._get_magnitude_scaling(coe, rup.mag) +
... | [
"def",
"get_mean_and_stddevs",
"(",
"self",
",",
"sites",
",",
"rup",
",",
"dists",
",",
"imt",
",",
"stddev_types",
")",
":",
"# Check that the GSIM supports the standard deviations requested",
"assert",
"all",
"(",
"stddev_type",
"in",
"self",
".",
"DEFINED_FOR_STAN... | 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/megawati_2003.py#L68-L86 |
gem/oq-engine | openquake/hazardlib/gsim/megawati_2003.py | MegawatiEtAl2003._get_distance_scaling | def _get_distance_scaling(self, coe, rhypo):
"""
Returns the distance scaling term
"""
return coe["a3"] * np.log(rhypo) + coe["a4"] * rhypo | python | def _get_distance_scaling(self, coe, rhypo):
return coe["a3"] * np.log(rhypo) + coe["a4"] * rhypo | [
"def",
"_get_distance_scaling",
"(",
"self",
",",
"coe",
",",
"rhypo",
")",
":",
"return",
"coe",
"[",
"\"a3\"",
"]",
"*",
"np",
".",
"log",
"(",
"rhypo",
")",
"+",
"coe",
"[",
"\"a4\"",
"]",
"*",
"rhypo"
] | Returns the distance scaling term | [
"Returns",
"the",
"distance",
"scaling",
"term"
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/gsim/megawati_2003.py#L94-L98 |
gem/oq-engine | openquake/hazardlib/gsim/megawati_2003.py | MegawatiEtAl2003._get_azimuth_correction | def _get_azimuth_correction(self, coe, azimuth):
"""
This is the azimuth correction defined in the functional form (see
equation 3 at page 2256)
"""
term1 = abs(np.cos(np.radians(2.*azimuth)))
term2 = abs(np.sin(np.radians(2.*azimuth)))*coe['a5']
return np.log(np.... | python | def _get_azimuth_correction(self, coe, azimuth):
term1 = abs(np.cos(np.radians(2.*azimuth)))
term2 = abs(np.sin(np.radians(2.*azimuth)))*coe['a5']
return np.log(np.max(np.hstack((term1, term2)))) | [
"def",
"_get_azimuth_correction",
"(",
"self",
",",
"coe",
",",
"azimuth",
")",
":",
"term1",
"=",
"abs",
"(",
"np",
".",
"cos",
"(",
"np",
".",
"radians",
"(",
"2.",
"*",
"azimuth",
")",
")",
")",
"term2",
"=",
"abs",
"(",
"np",
".",
"sin",
"(",... | This is the azimuth correction defined in the functional form (see
equation 3 at page 2256) | [
"This",
"is",
"the",
"azimuth",
"correction",
"defined",
"in",
"the",
"functional",
"form",
"(",
"see",
"equation",
"3",
"at",
"page",
"2256",
")"
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/gsim/megawati_2003.py#L100-L107 |
gem/oq-engine | openquake/baselib/parallel.py | get_pickled_sizes | def get_pickled_sizes(obj):
"""
Return the pickled sizes of an object and its direct attributes,
ordered by decreasing size. Here is an example:
>> total_size, partial_sizes = get_pickled_sizes(Monitor(''))
>> total_size
345
>> partial_sizes
[('_procs', 214), ('exc', 4), ('mem', 4), ('s... | python | def get_pickled_sizes(obj):
sizes = []
attrs = getattr(obj, '__dict__', {})
for name, value in attrs.items():
sizes.append((name, len(Pickled(value))))
return len(Pickled(obj)), sorted(
sizes, key=lambda pair: pair[1], reverse=True) | [
"def",
"get_pickled_sizes",
"(",
"obj",
")",
":",
"sizes",
"=",
"[",
"]",
"attrs",
"=",
"getattr",
"(",
"obj",
",",
"'__dict__'",
",",
"{",
"}",
")",
"for",
"name",
",",
"value",
"in",
"attrs",
".",
"items",
"(",
")",
":",
"sizes",
".",
"append",
... | Return the pickled sizes of an object and its direct attributes,
ordered by decreasing size. Here is an example:
>> total_size, partial_sizes = get_pickled_sizes(Monitor(''))
>> total_size
345
>> partial_sizes
[('_procs', 214), ('exc', 4), ('mem', 4), ('start_time', 4),
('_start_time', 4), ... | [
"Return",
"the",
"pickled",
"sizes",
"of",
"an",
"object",
"and",
"its",
"direct",
"attributes",
"ordered",
"by",
"decreasing",
"size",
".",
"Here",
"is",
"an",
"example",
":"
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/baselib/parallel.py#L272-L291 |
gem/oq-engine | openquake/baselib/parallel.py | pickle_sequence | def pickle_sequence(objects):
"""
Convert an iterable of objects into a list of pickled objects.
If the iterable contains copies, the pickling will be done only once.
If the iterable contains objects already pickled, they will not be
pickled again.
:param objects: a sequence of objects to pickl... | python | def pickle_sequence(objects):
cache = {}
out = []
for obj in objects:
obj_id = id(obj)
if obj_id not in cache:
if isinstance(obj, Pickled):
cache[obj_id] = obj
else:
cache[obj_id] = Pickled(obj)
out.append(cache[obj_id]... | [
"def",
"pickle_sequence",
"(",
"objects",
")",
":",
"cache",
"=",
"{",
"}",
"out",
"=",
"[",
"]",
"for",
"obj",
"in",
"objects",
":",
"obj_id",
"=",
"id",
"(",
"obj",
")",
"if",
"obj_id",
"not",
"in",
"cache",
":",
"if",
"isinstance",
"(",
"obj",
... | Convert an iterable of objects into a list of pickled objects.
If the iterable contains copies, the pickling will be done only once.
If the iterable contains objects already pickled, they will not be
pickled again.
:param objects: a sequence of objects to pickle | [
"Convert",
"an",
"iterable",
"of",
"objects",
"into",
"a",
"list",
"of",
"pickled",
"objects",
".",
"If",
"the",
"iterable",
"contains",
"copies",
"the",
"pickling",
"will",
"be",
"done",
"only",
"once",
".",
"If",
"the",
"iterable",
"contains",
"objects",
... | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/baselib/parallel.py#L294-L313 |
gem/oq-engine | openquake/baselib/parallel.py | check_mem_usage | def check_mem_usage(soft_percent=None, hard_percent=None):
"""
Display a warning if we are running out of memory
"""
soft_percent = soft_percent or config.memory.soft_mem_limit
hard_percent = hard_percent or config.memory.hard_mem_limit
used_mem_percent = psutil.virtual_memory().percent
if u... | python | def check_mem_usage(soft_percent=None, hard_percent=None):
soft_percent = soft_percent or config.memory.soft_mem_limit
hard_percent = hard_percent or config.memory.hard_mem_limit
used_mem_percent = psutil.virtual_memory().percent
if used_mem_percent > hard_percent:
raise MemoryError('Using ... | [
"def",
"check_mem_usage",
"(",
"soft_percent",
"=",
"None",
",",
"hard_percent",
"=",
"None",
")",
":",
"soft_percent",
"=",
"soft_percent",
"or",
"config",
".",
"memory",
".",
"soft_mem_limit",
"hard_percent",
"=",
"hard_percent",
"or",
"config",
".",
"memory",... | Display a warning if we are running out of memory | [
"Display",
"a",
"warning",
"if",
"we",
"are",
"running",
"out",
"of",
"memory"
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/baselib/parallel.py#L370-L383 |
gem/oq-engine | openquake/baselib/parallel.py | safely_call | def safely_call(func, args, task_no=0, mon=dummy_mon):
"""
Call the given function with the given arguments safely, i.e.
by trapping the exceptions. Return a pair (result, exc_type)
where exc_type is None if no exceptions occur, otherwise it
is the exception class and the result is a string containi... | python | def safely_call(func, args, task_no=0, mon=dummy_mon):
isgenfunc = inspect.isgeneratorfunction(func)
if hasattr(args[0], 'unpickle'):
args = [a.unpickle() for a in args]
if mon is dummy_mon:
assert not isgenfunc, func
return Result.new(func, args, mon)
mon = mon.... | [
"def",
"safely_call",
"(",
"func",
",",
"args",
",",
"task_no",
"=",
"0",
",",
"mon",
"=",
"dummy_mon",
")",
":",
"isgenfunc",
"=",
"inspect",
".",
"isgeneratorfunction",
"(",
"func",
")",
"if",
"hasattr",
"(",
"args",
"[",
"0",
"]",
",",
"'unpickle'",... | Call the given function with the given arguments safely, i.e.
by trapping the exceptions. Return a pair (result, exc_type)
where exc_type is None if no exceptions occur, otherwise it
is the exception class and the result is a string containing
error message and traceback.
:param func: the function ... | [
"Call",
"the",
"given",
"function",
"with",
"the",
"given",
"arguments",
"safely",
"i",
".",
"e",
".",
"by",
"trapping",
"the",
"exceptions",
".",
"Return",
"a",
"pair",
"(",
"result",
"exc_type",
")",
"where",
"exc_type",
"is",
"None",
"if",
"no",
"exce... | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/baselib/parallel.py#L390-L440 |
gem/oq-engine | openquake/baselib/parallel.py | save_task_info | def save_task_info(self, res, mem_gb=0):
"""
:param self: an object with attributes .hdf5, .argnames, .sent
:parent res: a :class:`Result` object
:param mem_gb: memory consumption at the saving time (optional)
"""
mon = res.mon
name = mon.operation[6:] # strip 'total '
if self.hdf5:
... | python | def save_task_info(self, res, mem_gb=0):
mon = res.mon
name = mon.operation[6:]
if self.hdf5:
mon.hdf5 = self.hdf5
t = (mon.task_no, mon.weight, mon.duration, len(res.pik), mem_gb)
data = numpy.array([t], task_info_dt)
hdf5.extend3(self.hdf5.filename, 'task_info/' + ... | [
"def",
"save_task_info",
"(",
"self",
",",
"res",
",",
"mem_gb",
"=",
"0",
")",
":",
"mon",
"=",
"res",
".",
"mon",
"name",
"=",
"mon",
".",
"operation",
"[",
"6",
":",
"]",
"# strip 'total '",
"if",
"self",
".",
"hdf5",
":",
"mon",
".",
"hdf5",
... | :param self: an object with attributes .hdf5, .argnames, .sent
:parent res: a :class:`Result` object
:param mem_gb: memory consumption at the saving time (optional) | [
":",
"param",
"self",
":",
"an",
"object",
"with",
"attributes",
".",
"hdf5",
".",
"argnames",
".",
"sent",
":",
"parent",
"res",
":",
"a",
":",
"class",
":",
"Result",
"object",
":",
"param",
"mem_gb",
":",
"memory",
"consumption",
"at",
"the",
"savin... | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/baselib/parallel.py#L550-L564 |
gem/oq-engine | openquake/baselib/parallel.py | init_workers | def init_workers():
"""Waiting function, used to wake up the process pool"""
setproctitle('oq-worker')
# unregister raiseMasterKilled in oq-workers to avoid deadlock
# since processes are terminated via pool.terminate()
signal.signal(signal.SIGTERM, signal.SIG_DFL)
# prctl is still useful (on Li... | python | def init_workers():
setproctitle('oq-worker')
signal.signal(signal.SIGTERM, signal.SIG_DFL)
try:
import prctl
except ImportError:
pass
else:
prctl.set_pdeathsig(signal.SIGKILL) | [
"def",
"init_workers",
"(",
")",
":",
"setproctitle",
"(",
"'oq-worker'",
")",
"# unregister raiseMasterKilled in oq-workers to avoid deadlock",
"# since processes are terminated via pool.terminate()",
"signal",
".",
"signal",
"(",
"signal",
".",
"SIGTERM",
",",
"signal",
"."... | Waiting function, used to wake up the process pool | [
"Waiting",
"function",
"used",
"to",
"wake",
"up",
"the",
"process",
"pool"
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/baselib/parallel.py#L567-L581 |
gem/oq-engine | openquake/baselib/parallel.py | sequential_apply | def sequential_apply(task, args, concurrent_tasks=cpu_count * 3,
weight=lambda item: 1, key=lambda item: 'Unspecified'):
"""
Apply sequentially task to args by splitting args[0] in blocks
"""
chunks = split_in_blocks(args[0], concurrent_tasks or 1, weight, key)
task_args = [(ch,... | python | def sequential_apply(task, args, concurrent_tasks=cpu_count * 3,
weight=lambda item: 1, key=lambda item: 'Unspecified'):
chunks = split_in_blocks(args[0], concurrent_tasks or 1, weight, key)
task_args = [(ch,) + args[1:] for ch in chunks]
return itertools.starmap(task, task_args) | [
"def",
"sequential_apply",
"(",
"task",
",",
"args",
",",
"concurrent_tasks",
"=",
"cpu_count",
"*",
"3",
",",
"weight",
"=",
"lambda",
"item",
":",
"1",
",",
"key",
"=",
"lambda",
"item",
":",
"'Unspecified'",
")",
":",
"chunks",
"=",
"split_in_blocks",
... | Apply sequentially task to args by splitting args[0] in blocks | [
"Apply",
"sequentially",
"task",
"to",
"args",
"by",
"splitting",
"args",
"[",
"0",
"]",
"in",
"blocks"
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/baselib/parallel.py#L787-L794 |
gem/oq-engine | openquake/baselib/parallel.py | Result.get | def get(self):
"""
Returns the underlying value or raise the underlying exception
"""
val = self.pik.unpickle()
if self.tb_str:
etype = val.__class__
msg = '\n%s%s: %s' % (self.tb_str, etype.__name__, val)
if issubclass(etype, KeyError):
... | python | def get(self):
val = self.pik.unpickle()
if self.tb_str:
etype = val.__class__
msg = '\n%s%s: %s' % (self.tb_str, etype.__name__, val)
if issubclass(etype, KeyError):
raise RuntimeError(msg)
else:
raise etype(msg)... | [
"def",
"get",
"(",
"self",
")",
":",
"val",
"=",
"self",
".",
"pik",
".",
"unpickle",
"(",
")",
"if",
"self",
".",
"tb_str",
":",
"etype",
"=",
"val",
".",
"__class__",
"msg",
"=",
"'\\n%s%s: %s'",
"%",
"(",
"self",
".",
"tb_str",
",",
"etype",
"... | Returns the underlying value or raise the underlying exception | [
"Returns",
"the",
"underlying",
"value",
"or",
"raise",
"the",
"underlying",
"exception"
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/baselib/parallel.py#L337-L349 |
gem/oq-engine | openquake/baselib/parallel.py | Result.new | def new(cls, func, args, mon, count=0):
"""
:returns: a new Result instance
"""
try:
with mon:
val = func(*args)
except StopIteration:
res = Result(None, mon, msg='TASK_ENDED')
except Exception:
_etype, exc, tb = sys.exc... | python | def new(cls, func, args, mon, count=0):
try:
with mon:
val = func(*args)
except StopIteration:
res = Result(None, mon, msg='TASK_ENDED')
except Exception:
_etype, exc, tb = sys.exc_info()
res = Result(exc, mon, ''.join(trac... | [
"def",
"new",
"(",
"cls",
",",
"func",
",",
"args",
",",
"mon",
",",
"count",
"=",
"0",
")",
":",
"try",
":",
"with",
"mon",
":",
"val",
"=",
"func",
"(",
"*",
"args",
")",
"except",
"StopIteration",
":",
"res",
"=",
"Result",
"(",
"None",
",",... | :returns: a new Result instance | [
":",
"returns",
":",
"a",
"new",
"Result",
"instance"
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/baselib/parallel.py#L352-L367 |
gem/oq-engine | openquake/baselib/parallel.py | IterResult.sum | def sum(cls, iresults):
"""
Sum the data transfer information of a set of results
"""
res = object.__new__(cls)
res.received = []
res.sent = 0
for iresult in iresults:
res.received.extend(iresult.received)
res.sent += iresult.sent
... | python | def sum(cls, iresults):
res = object.__new__(cls)
res.received = []
res.sent = 0
for iresult in iresults:
res.received.extend(iresult.received)
res.sent += iresult.sent
name = iresult.name.split('
if hasattr(res, 'name'):
... | [
"def",
"sum",
"(",
"cls",
",",
"iresults",
")",
":",
"res",
"=",
"object",
".",
"__new__",
"(",
"cls",
")",
"res",
".",
"received",
"=",
"[",
"]",
"res",
".",
"sent",
"=",
"0",
"for",
"iresult",
"in",
"iresults",
":",
"res",
".",
"received",
".",... | Sum the data transfer information of a set of results | [
"Sum",
"the",
"data",
"transfer",
"information",
"of",
"a",
"set",
"of",
"results"
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/baselib/parallel.py#L532-L547 |
gem/oq-engine | openquake/baselib/parallel.py | Starmap.apply | def apply(cls, task, args, concurrent_tasks=cpu_count * 3,
maxweight=None, weight=lambda item: 1,
key=lambda item: 'Unspecified',
distribute=None, progress=logging.info):
r"""
Apply a task to a tuple of the form (sequence, \*other_args)
by first splittin... | python | def apply(cls, task, args, concurrent_tasks=cpu_count * 3,
maxweight=None, weight=lambda item: 1,
key=lambda item: 'Unspecified',
distribute=None, progress=logging.info):
r
arg0 = args[0]
mon = args[-1]
args = args[1:-1]
if maxweight: ... | [
"def",
"apply",
"(",
"cls",
",",
"task",
",",
"args",
",",
"concurrent_tasks",
"=",
"cpu_count",
"*",
"3",
",",
"maxweight",
"=",
"None",
",",
"weight",
"=",
"lambda",
"item",
":",
"1",
",",
"key",
"=",
"lambda",
"item",
":",
"'Unspecified'",
",",
"d... | r"""
Apply a task to a tuple of the form (sequence, \*other_args)
by first splitting the sequence in chunks, according to the weight
of the elements and possibly to a key (see :func:
`openquake.baselib.general.split_in_blocks`).
:param task: a task to run in parallel
:pa... | [
"r",
"Apply",
"a",
"task",
"to",
"a",
"tuple",
"of",
"the",
"form",
"(",
"sequence",
"\\",
"*",
"other_args",
")",
"by",
"first",
"splitting",
"the",
"sequence",
"in",
"chunks",
"according",
"to",
"the",
"weight",
"of",
"the",
"elements",
"and",
"possibl... | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/baselib/parallel.py#L620-L649 |
gem/oq-engine | openquake/baselib/parallel.py | Starmap.log_percent | def log_percent(self):
"""
Log the progress of the computation in percentage
"""
done = self.total - self.todo
percent = int(float(done) / self.total * 100)
if not hasattr(self, 'prev_percent'): # first time
self.prev_percent = 0
self.progress('Se... | python | def log_percent(self):
done = self.total - self.todo
percent = int(float(done) / self.total * 100)
if not hasattr(self, 'prev_percent'):
self.prev_percent = 0
self.progress('Sent %s of data in %d %s task(s)',
humansize(self.sent.sum())... | [
"def",
"log_percent",
"(",
"self",
")",
":",
"done",
"=",
"self",
".",
"total",
"-",
"self",
".",
"todo",
"percent",
"=",
"int",
"(",
"float",
"(",
"done",
")",
"/",
"self",
".",
"total",
"*",
"100",
")",
"if",
"not",
"hasattr",
"(",
"self",
",",... | Log the progress of the computation in percentage | [
"Log",
"the",
"progress",
"of",
"the",
"computation",
"in",
"percentage"
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/baselib/parallel.py#L691-L705 |
gem/oq-engine | openquake/baselib/parallel.py | Starmap.submit | def submit(self, *args, func=None, monitor=None):
"""
Submit the given arguments to the underlying task
"""
monitor = monitor or self.monitor
func = func or self.task_func
if not hasattr(self, 'socket'): # first time
self.__class__.running_tasks = self.tasks
... | python | def submit(self, *args, func=None, monitor=None):
monitor = monitor or self.monitor
func = func or self.task_func
if not hasattr(self, 'socket'):
self.__class__.running_tasks = self.tasks
self.socket = Socket(self.receiver, zmq.PULL, 'bind').__enter__()
... | [
"def",
"submit",
"(",
"self",
",",
"*",
"args",
",",
"func",
"=",
"None",
",",
"monitor",
"=",
"None",
")",
":",
"monitor",
"=",
"monitor",
"or",
"self",
".",
"monitor",
"func",
"=",
"func",
"or",
"self",
".",
"task_func",
"if",
"not",
"hasattr",
"... | Submit the given arguments to the underlying task | [
"Submit",
"the",
"given",
"arguments",
"to",
"the",
"underlying",
"task"
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/baselib/parallel.py#L707-L724 |
gem/oq-engine | openquake/baselib/parallel.py | Starmap.submit_all | def submit_all(self):
"""
:returns: an IterResult object
"""
for args in self.task_args:
self.submit(*args)
return self.get_results() | python | def submit_all(self):
for args in self.task_args:
self.submit(*args)
return self.get_results() | [
"def",
"submit_all",
"(",
"self",
")",
":",
"for",
"args",
"in",
"self",
".",
"task_args",
":",
"self",
".",
"submit",
"(",
"*",
"args",
")",
"return",
"self",
".",
"get_results",
"(",
")"
] | :returns: an IterResult object | [
":",
"returns",
":",
"an",
"IterResult",
"object"
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/baselib/parallel.py#L733-L739 |
gem/oq-engine | openquake/baselib/parallel.py | Starmap.get_results | def get_results(self):
"""
:returns: an :class:`IterResult` instance
"""
return IterResult(self._loop(), self.name, self.argnames,
self.sent, self.monitor.hdf5) | python | def get_results(self):
return IterResult(self._loop(), self.name, self.argnames,
self.sent, self.monitor.hdf5) | [
"def",
"get_results",
"(",
"self",
")",
":",
"return",
"IterResult",
"(",
"self",
".",
"_loop",
"(",
")",
",",
"self",
".",
"name",
",",
"self",
".",
"argnames",
",",
"self",
".",
"sent",
",",
"self",
".",
"monitor",
".",
"hdf5",
")"
] | :returns: an :class:`IterResult` instance | [
":",
"returns",
":",
"an",
":",
"class",
":",
"IterResult",
"instance"
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/baselib/parallel.py#L741-L746 |
gem/oq-engine | openquake/baselib/parallel.py | Starmap.reduce | def reduce(self, agg=operator.add, acc=None):
"""
Submit all tasks and reduce the results
"""
return self.submit_all().reduce(agg, acc) | python | def reduce(self, agg=operator.add, acc=None):
return self.submit_all().reduce(agg, acc) | [
"def",
"reduce",
"(",
"self",
",",
"agg",
"=",
"operator",
".",
"add",
",",
"acc",
"=",
"None",
")",
":",
"return",
"self",
".",
"submit_all",
"(",
")",
".",
"reduce",
"(",
"agg",
",",
"acc",
")"
] | Submit all tasks and reduce the results | [
"Submit",
"all",
"tasks",
"and",
"reduce",
"the",
"results"
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/baselib/parallel.py#L748-L752 |
gem/oq-engine | openquake/hazardlib/gsim/can15/utils.py | _get_equivalent_distances_east | def _get_equivalent_distances_east(wid, lng, mag, repi, focal_depth=10.,
ab06=False):
"""
Computes equivalent values of Joyner-Boore and closest distance to the
rupture given epoicentral distance. The procedure is described in
Atkinson (2012) - Appendix A (page 32).
... | python | def _get_equivalent_distances_east(wid, lng, mag, repi, focal_depth=10.,
ab06=False):
dtop = focal_depth - 0.5*wid
if ab06:
ztor_ab06 = 21-2.5*mag
dtop = np.max([ztor_ab06, dtop])
ztor = max(0, dtop)
dsurf = np.max([repi-0.3*lng, 0.1*np.o... | [
"def",
"_get_equivalent_distances_east",
"(",
"wid",
",",
"lng",
",",
"mag",
",",
"repi",
",",
"focal_depth",
"=",
"10.",
",",
"ab06",
"=",
"False",
")",
":",
"dtop",
"=",
"focal_depth",
"-",
"0.5",
"*",
"wid",
"# this computes a minimum ztor value - used for AB... | Computes equivalent values of Joyner-Boore and closest distance to the
rupture given epoicentral distance. The procedure is described in
Atkinson (2012) - Appendix A (page 32).
:param float wid:
Width of rectangular rupture
:param float lng:
Length of rectangular rupture
:param floa... | [
"Computes",
"equivalent",
"values",
"of",
"Joyner",
"-",
"Boore",
"and",
"closest",
"distance",
"to",
"the",
"rupture",
"given",
"epoicentral",
"distance",
".",
"The",
"procedure",
"is",
"described",
"in",
"Atkinson",
"(",
"2012",
")",
"-",
"Appendix",
"A",
... | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/gsim/can15/utils.py#L30-L61 |
gem/oq-engine | openquake/hazardlib/gsim/can15/utils.py | get_equivalent_distance_inslab | def get_equivalent_distance_inslab(mag, repi, hslab):
"""
:param float mag:
Magnitude
:param repi:
A :class:`numpy.ndarray` instance containing repi values
:param float hslab:
Depth of the slab
"""
area = 10**(-3.225+0.89*mag)
radius = (area / scipy.constants.pi)**0.5... | python | def get_equivalent_distance_inslab(mag, repi, hslab):
area = 10**(-3.225+0.89*mag)
radius = (area / scipy.constants.pi)**0.5
rjb = np.max([repi-radius, np.zeros_like(repi)], axis=0)
rrup = (rjb**2+hslab**2)**0.5
return rjb, rrup | [
"def",
"get_equivalent_distance_inslab",
"(",
"mag",
",",
"repi",
",",
"hslab",
")",
":",
"area",
"=",
"10",
"**",
"(",
"-",
"3.225",
"+",
"0.89",
"*",
"mag",
")",
"radius",
"=",
"(",
"area",
"/",
"scipy",
".",
"constants",
".",
"pi",
")",
"**",
"0... | :param float mag:
Magnitude
:param repi:
A :class:`numpy.ndarray` instance containing repi values
:param float hslab:
Depth of the slab | [
":",
"param",
"float",
"mag",
":",
"Magnitude",
":",
"param",
"repi",
":",
"A",
":",
"class",
":",
"numpy",
".",
"ndarray",
"instance",
"containing",
"repi",
"values",
":",
"param",
"float",
"hslab",
":",
"Depth",
"of",
"the",
"slab"
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/gsim/can15/utils.py#L82-L95 |
gem/oq-engine | openquake/hazardlib/probability_map.py | get_shape | def get_shape(pmaps):
"""
:param pmaps: a set of homogenous ProbabilityMaps
:returns: the common shape (N, L, I)
"""
for pmap in pmaps:
if pmap:
sid = next(iter(pmap))
break
else:
raise AllEmptyProbabilityMaps(pmaps)
return (len(pmap),) + pmap[sid].arr... | python | def get_shape(pmaps):
for pmap in pmaps:
if pmap:
sid = next(iter(pmap))
break
else:
raise AllEmptyProbabilityMaps(pmaps)
return (len(pmap),) + pmap[sid].array.shape | [
"def",
"get_shape",
"(",
"pmaps",
")",
":",
"for",
"pmap",
"in",
"pmaps",
":",
"if",
"pmap",
":",
"sid",
"=",
"next",
"(",
"iter",
"(",
"pmap",
")",
")",
"break",
"else",
":",
"raise",
"AllEmptyProbabilityMaps",
"(",
"pmaps",
")",
"return",
"(",
"len... | :param pmaps: a set of homogenous ProbabilityMaps
:returns: the common shape (N, L, I) | [
":",
"param",
"pmaps",
":",
"a",
"set",
"of",
"homogenous",
"ProbabilityMaps",
":",
"returns",
":",
"the",
"common",
"shape",
"(",
"N",
"L",
"I",
")"
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/probability_map.py#L356-L367 |
gem/oq-engine | openquake/hazardlib/probability_map.py | combine | def combine(pmaps):
"""
:param pmaps: a set of homogenous ProbabilityMaps
:returns: the combined map
"""
shape = get_shape(pmaps)
res = ProbabilityMap(shape[1], shape[2])
for pmap in pmaps:
res |= pmap
return res | python | def combine(pmaps):
shape = get_shape(pmaps)
res = ProbabilityMap(shape[1], shape[2])
for pmap in pmaps:
res |= pmap
return res | [
"def",
"combine",
"(",
"pmaps",
")",
":",
"shape",
"=",
"get_shape",
"(",
"pmaps",
")",
"res",
"=",
"ProbabilityMap",
"(",
"shape",
"[",
"1",
"]",
",",
"shape",
"[",
"2",
"]",
")",
"for",
"pmap",
"in",
"pmaps",
":",
"res",
"|=",
"pmap",
"return",
... | :param pmaps: a set of homogenous ProbabilityMaps
:returns: the combined map | [
":",
"param",
"pmaps",
":",
"a",
"set",
"of",
"homogenous",
"ProbabilityMaps",
":",
"returns",
":",
"the",
"combined",
"map"
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/probability_map.py#L370-L379 |
gem/oq-engine | openquake/hazardlib/probability_map.py | ProbabilityCurve.convert | def convert(self, imtls, idx=0):
"""
Convert a probability curve into a record of dtype `imtls.dt`.
:param imtls: DictArray instance
:param idx: extract the data corresponding to the given inner index
"""
curve = numpy.zeros(1, imtls.dt)
for imt in imtls:
... | python | def convert(self, imtls, idx=0):
curve = numpy.zeros(1, imtls.dt)
for imt in imtls:
curve[imt] = self.array[imtls(imt), idx]
return curve[0] | [
"def",
"convert",
"(",
"self",
",",
"imtls",
",",
"idx",
"=",
"0",
")",
":",
"curve",
"=",
"numpy",
".",
"zeros",
"(",
"1",
",",
"imtls",
".",
"dt",
")",
"for",
"imt",
"in",
"imtls",
":",
"curve",
"[",
"imt",
"]",
"=",
"self",
".",
"array",
"... | Convert a probability curve into a record of dtype `imtls.dt`.
:param imtls: DictArray instance
:param idx: extract the data corresponding to the given inner index | [
"Convert",
"a",
"probability",
"curve",
"into",
"a",
"record",
"of",
"dtype",
"imtls",
".",
"dt",
"."
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/probability_map.py#L96-L106 |
gem/oq-engine | openquake/hazardlib/probability_map.py | ProbabilityMap.build | def build(cls, shape_y, shape_z, sids, initvalue=0., dtype=F64):
"""
:param shape_y: the total number of intensity measure levels
:param shape_z: the number of inner levels
:param sids: a set of site indices
:param initvalue: the initial value of the probability (default 0)
... | python | def build(cls, shape_y, shape_z, sids, initvalue=0., dtype=F64):
dic = cls(shape_y, shape_z)
for sid in sids:
dic.setdefault(sid, initvalue, dtype)
return dic | [
"def",
"build",
"(",
"cls",
",",
"shape_y",
",",
"shape_z",
",",
"sids",
",",
"initvalue",
"=",
"0.",
",",
"dtype",
"=",
"F64",
")",
":",
"dic",
"=",
"cls",
"(",
"shape_y",
",",
"shape_z",
")",
"for",
"sid",
"in",
"sids",
":",
"dic",
".",
"setdef... | :param shape_y: the total number of intensity measure levels
:param shape_z: the number of inner levels
:param sids: a set of site indices
:param initvalue: the initial value of the probability (default 0)
:returns: a ProbabilityMap dictionary | [
":",
"param",
"shape_y",
":",
"the",
"total",
"number",
"of",
"intensity",
"measure",
"levels",
":",
"param",
"shape_z",
":",
"the",
"number",
"of",
"inner",
"levels",
":",
"param",
"sids",
":",
"a",
"set",
"of",
"site",
"indices",
":",
"param",
"initval... | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/probability_map.py#L128-L139 |
gem/oq-engine | openquake/hazardlib/probability_map.py | ProbabilityMap.from_array | def from_array(cls, array, sids):
"""
:param array: array of shape (N, L) or (N, L, I)
:param sids: array of N site IDs
"""
n_sites = len(sids)
n = len(array)
if n_sites != n:
raise ValueError('Passed %d site IDs, but the array has length %d'
... | python | def from_array(cls, array, sids):
n_sites = len(sids)
n = len(array)
if n_sites != n:
raise ValueError('Passed %d site IDs, but the array has length %d'
% (n_sites, n))
if len(array.shape) == 2:
array = array.reshape(array.s... | [
"def",
"from_array",
"(",
"cls",
",",
"array",
",",
"sids",
")",
":",
"n_sites",
"=",
"len",
"(",
"sids",
")",
"n",
"=",
"len",
"(",
"array",
")",
"if",
"n_sites",
"!=",
"n",
":",
"raise",
"ValueError",
"(",
"'Passed %d site IDs, but the array has length %... | :param array: array of shape (N, L) or (N, L, I)
:param sids: array of N site IDs | [
":",
"param",
"array",
":",
"array",
"of",
"shape",
"(",
"N",
"L",
")",
"or",
"(",
"N",
"L",
"I",
")",
":",
"param",
"sids",
":",
"array",
"of",
"N",
"site",
"IDs"
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/probability_map.py#L142-L157 |
gem/oq-engine | openquake/hazardlib/probability_map.py | ProbabilityMap.setdefault | def setdefault(self, sid, value, dtype=F64):
"""
Works like `dict.setdefault`: if the `sid` key is missing, it fills
it with an array and returns the associate ProbabilityCurve
:param sid: site ID
:param value: value used to fill the returned ProbabilityCurve
:param dtyp... | python | def setdefault(self, sid, value, dtype=F64):
try:
return self[sid]
except KeyError:
array = numpy.empty((self.shape_y, self.shape_z), dtype)
array.fill(value)
pc = ProbabilityCurve(array)
self[sid] = pc
return pc | [
"def",
"setdefault",
"(",
"self",
",",
"sid",
",",
"value",
",",
"dtype",
"=",
"F64",
")",
":",
"try",
":",
"return",
"self",
"[",
"sid",
"]",
"except",
"KeyError",
":",
"array",
"=",
"numpy",
".",
"empty",
"(",
"(",
"self",
".",
"shape_y",
",",
... | Works like `dict.setdefault`: if the `sid` key is missing, it fills
it with an array and returns the associate ProbabilityCurve
:param sid: site ID
:param value: value used to fill the returned ProbabilityCurve
:param dtype: dtype used internally (F32 or F64) | [
"Works",
"like",
"dict",
".",
"setdefault",
":",
"if",
"the",
"sid",
"key",
"is",
"missing",
"it",
"fills",
"it",
"with",
"an",
"array",
"and",
"returns",
"the",
"associate",
"ProbabilityCurve"
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/probability_map.py#L163-L179 |
gem/oq-engine | openquake/hazardlib/probability_map.py | ProbabilityMap.array | def array(self):
"""
The underlying array of shape (N, L, I)
"""
return numpy.array([self[sid].array for sid in sorted(self)]) | python | def array(self):
return numpy.array([self[sid].array for sid in sorted(self)]) | [
"def",
"array",
"(",
"self",
")",
":",
"return",
"numpy",
".",
"array",
"(",
"[",
"self",
"[",
"sid",
"]",
".",
"array",
"for",
"sid",
"in",
"sorted",
"(",
"self",
")",
"]",
")"
] | The underlying array of shape (N, L, I) | [
"The",
"underlying",
"array",
"of",
"shape",
"(",
"N",
"L",
"I",
")"
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/probability_map.py#L187-L191 |
gem/oq-engine | openquake/hazardlib/probability_map.py | ProbabilityMap.nbytes | def nbytes(self):
"""The size of the underlying array"""
try:
N, L, I = get_shape([self])
except AllEmptyProbabilityMaps:
return 0
return BYTES_PER_FLOAT * N * L * I | python | def nbytes(self):
try:
N, L, I = get_shape([self])
except AllEmptyProbabilityMaps:
return 0
return BYTES_PER_FLOAT * N * L * I | [
"def",
"nbytes",
"(",
"self",
")",
":",
"try",
":",
"N",
",",
"L",
",",
"I",
"=",
"get_shape",
"(",
"[",
"self",
"]",
")",
"except",
"AllEmptyProbabilityMaps",
":",
"return",
"0",
"return",
"BYTES_PER_FLOAT",
"*",
"N",
"*",
"L",
"*",
"I"
] | The size of the underlying array | [
"The",
"size",
"of",
"the",
"underlying",
"array"
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/probability_map.py#L194-L200 |
gem/oq-engine | openquake/hazardlib/probability_map.py | ProbabilityMap.convert | def convert(self, imtls, nsites, idx=0):
"""
Convert a probability map into a composite array of length `nsites`
and dtype `imtls.dt`.
:param imtls:
DictArray instance
:param nsites:
the total number of sites
:param idx:
index on the z... | python | def convert(self, imtls, nsites, idx=0):
curves = numpy.zeros(nsites, imtls.dt)
for imt in curves.dtype.names:
curves_by_imt = curves[imt]
for sid in self:
curves_by_imt[sid] = self[sid].array[imtls(imt), idx]
return curves | [
"def",
"convert",
"(",
"self",
",",
"imtls",
",",
"nsites",
",",
"idx",
"=",
"0",
")",
":",
"curves",
"=",
"numpy",
".",
"zeros",
"(",
"nsites",
",",
"imtls",
".",
"dt",
")",
"for",
"imt",
"in",
"curves",
".",
"dtype",
".",
"names",
":",
"curves_... | Convert a probability map into a composite array of length `nsites`
and dtype `imtls.dt`.
:param imtls:
DictArray instance
:param nsites:
the total number of sites
:param idx:
index on the z-axis (default 0) | [
"Convert",
"a",
"probability",
"map",
"into",
"a",
"composite",
"array",
"of",
"length",
"nsites",
"and",
"dtype",
"imtls",
".",
"dt",
"."
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/probability_map.py#L203-L220 |
gem/oq-engine | openquake/hazardlib/probability_map.py | ProbabilityMap.convert2 | def convert2(self, imtls, sids):
"""
Convert a probability map into a composite array of shape (N,)
and dtype `imtls.dt`.
:param imtls:
DictArray instance
:param sids:
the IDs of the sites we are interested in
:returns:
an array of cur... | python | def convert2(self, imtls, sids):
assert self.shape_z == 1, self.shape_z
curves = numpy.zeros(len(sids), imtls.dt)
for imt in curves.dtype.names:
curves_by_imt = curves[imt]
for i, sid in numpy.ndenumerate(sids):
try:
pcurve = s... | [
"def",
"convert2",
"(",
"self",
",",
"imtls",
",",
"sids",
")",
":",
"assert",
"self",
".",
"shape_z",
"==",
"1",
",",
"self",
".",
"shape_z",
"curves",
"=",
"numpy",
".",
"zeros",
"(",
"len",
"(",
"sids",
")",
",",
"imtls",
".",
"dt",
")",
"for"... | Convert a probability map into a composite array of shape (N,)
and dtype `imtls.dt`.
:param imtls:
DictArray instance
:param sids:
the IDs of the sites we are interested in
:returns:
an array of curves of shape (N,) | [
"Convert",
"a",
"probability",
"map",
"into",
"a",
"composite",
"array",
"of",
"shape",
"(",
"N",
")",
"and",
"dtype",
"imtls",
".",
"dt",
"."
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/probability_map.py#L222-L245 |
gem/oq-engine | openquake/hazardlib/probability_map.py | ProbabilityMap.filter | def filter(self, sids):
"""
Extracs a submap of self for the given sids.
"""
dic = self.__class__(self.shape_y, self.shape_z)
for sid in sids:
try:
dic[sid] = self[sid]
except KeyError:
pass
return dic | python | def filter(self, sids):
dic = self.__class__(self.shape_y, self.shape_z)
for sid in sids:
try:
dic[sid] = self[sid]
except KeyError:
pass
return dic | [
"def",
"filter",
"(",
"self",
",",
"sids",
")",
":",
"dic",
"=",
"self",
".",
"__class__",
"(",
"self",
".",
"shape_y",
",",
"self",
".",
"shape_z",
")",
"for",
"sid",
"in",
"sids",
":",
"try",
":",
"dic",
"[",
"sid",
"]",
"=",
"self",
"[",
"si... | Extracs a submap of self for the given sids. | [
"Extracs",
"a",
"submap",
"of",
"self",
"for",
"the",
"given",
"sids",
"."
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/probability_map.py#L247-L257 |
gem/oq-engine | openquake/hazardlib/probability_map.py | ProbabilityMap.extract | def extract(self, inner_idx):
"""
Extracts a component of the underlying ProbabilityCurves,
specified by the index `inner_idx`.
"""
out = self.__class__(self.shape_y, 1)
for sid in self:
curve = self[sid]
array = curve.array[:, inner_idx].reshape(-... | python | def extract(self, inner_idx):
out = self.__class__(self.shape_y, 1)
for sid in self:
curve = self[sid]
array = curve.array[:, inner_idx].reshape(-1, 1)
out[sid] = ProbabilityCurve(array)
return out | [
"def",
"extract",
"(",
"self",
",",
"inner_idx",
")",
":",
"out",
"=",
"self",
".",
"__class__",
"(",
"self",
".",
"shape_y",
",",
"1",
")",
"for",
"sid",
"in",
"self",
":",
"curve",
"=",
"self",
"[",
"sid",
"]",
"array",
"=",
"curve",
".",
"arra... | Extracts a component of the underlying ProbabilityCurves,
specified by the index `inner_idx`. | [
"Extracts",
"a",
"component",
"of",
"the",
"underlying",
"ProbabilityCurves",
"specified",
"by",
"the",
"index",
"inner_idx",
"."
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/probability_map.py#L259-L269 |
gem/oq-engine | openquake/commands/compare.py | get_diff_idxs | def get_diff_idxs(array, rtol, atol):
"""
Given an array with (C, N, L) values, being the first the reference value,
compute the relative differences and discard the one below the tolerance.
:returns: indices where there are sensible differences.
"""
C, N, L = array.shape
diff_idxs = set() ... | python | def get_diff_idxs(array, rtol, atol):
C, N, L = array.shape
diff_idxs = set()
for c in range(1, C):
for n in range(N):
if not numpy.allclose(array[c, n], array[0, n], rtol, atol):
diff_idxs.add(n)
return numpy.fromiter(diff_idxs, int) | [
"def",
"get_diff_idxs",
"(",
"array",
",",
"rtol",
",",
"atol",
")",
":",
"C",
",",
"N",
",",
"L",
"=",
"array",
".",
"shape",
"diff_idxs",
"=",
"set",
"(",
")",
"# indices of the sites with differences",
"for",
"c",
"in",
"range",
"(",
"1",
",",
"C",
... | Given an array with (C, N, L) values, being the first the reference value,
compute the relative differences and discard the one below the tolerance.
:returns: indices where there are sensible differences. | [
"Given",
"an",
"array",
"with",
"(",
"C",
"N",
"L",
")",
"values",
"being",
"the",
"first",
"the",
"reference",
"value",
"compute",
"the",
"relative",
"differences",
"and",
"discard",
"the",
"one",
"below",
"the",
"tolerance",
".",
":",
"returns",
":",
"... | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/commands/compare.py#L53-L65 |
gem/oq-engine | openquake/commands/compare.py | compare | def compare(what, imt, calc_ids, files, samplesites=100, rtol=.1, atol=1E-4):
"""
Compare the hazard curves or maps of two or more calculations
"""
sids, imtls, poes, arrays = getdata(what, calc_ids, samplesites)
try:
levels = imtls[imt]
except KeyError:
sys.exit(
'%s... | python | def compare(what, imt, calc_ids, files, samplesites=100, rtol=.1, atol=1E-4):
sids, imtls, poes, arrays = getdata(what, calc_ids, samplesites)
try:
levels = imtls[imt]
except KeyError:
sys.exit(
'%s not found. The available IMTs are %s' % (imt, list(imtls)))
imt2idx = {i... | [
"def",
"compare",
"(",
"what",
",",
"imt",
",",
"calc_ids",
",",
"files",
",",
"samplesites",
"=",
"100",
",",
"rtol",
"=",
".1",
",",
"atol",
"=",
"1E-4",
")",
":",
"sids",
",",
"imtls",
",",
"poes",
",",
"arrays",
"=",
"getdata",
"(",
"what",
"... | Compare the hazard curves or maps of two or more calculations | [
"Compare",
"the",
"hazard",
"curves",
"or",
"maps",
"of",
"two",
"or",
"more",
"calculations"
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/commands/compare.py#L69-L107 |
gem/oq-engine | openquake/hmtk/plotting/seismicity/catalogue_plots.py | build_filename | def build_filename(filename, filetype='png', resolution=300):
"""
Uses the input properties to create the string of the filename
:param str filename:
Name of the file
:param str filetype:
Type of file
:param int resolution:
DPI resolution of the output figure
"""
fil... | python | def build_filename(filename, filetype='png', resolution=300):
filevals = os.path.splitext(filename)
if filevals[1]:
filetype = filevals[1][1:]
if not filetype:
filetype = 'png'
filename = filevals[0] + '.' + filetype
if not resolution:
resolution = 300
return filena... | [
"def",
"build_filename",
"(",
"filename",
",",
"filetype",
"=",
"'png'",
",",
"resolution",
"=",
"300",
")",
":",
"filevals",
"=",
"os",
".",
"path",
".",
"splitext",
"(",
"filename",
")",
"if",
"filevals",
"[",
"1",
"]",
":",
"filetype",
"=",
"fileval... | Uses the input properties to create the string of the filename
:param str filename:
Name of the file
:param str filetype:
Type of file
:param int resolution:
DPI resolution of the output figure | [
"Uses",
"the",
"input",
"properties",
"to",
"create",
"the",
"string",
"of",
"the",
"filename"
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hmtk/plotting/seismicity/catalogue_plots.py#L61-L81 |
gem/oq-engine | openquake/hmtk/plotting/seismicity/catalogue_plots.py | _save_image | def _save_image(fig, filename, filetype='png', resolution=300):
"""
If filename is specified, saves the image
:param str filename:
Name of the file
:param str filetype:
Type of file
:param int resolution:
DPI resolution of the output figure
"""
if filename:
fi... | python | def _save_image(fig, filename, filetype='png', resolution=300):
if filename:
filename, filetype, resolution = build_filename(filename,
filetype,
resolution)
fig.savefig(filename, dpi=... | [
"def",
"_save_image",
"(",
"fig",
",",
"filename",
",",
"filetype",
"=",
"'png'",
",",
"resolution",
"=",
"300",
")",
":",
"if",
"filename",
":",
"filename",
",",
"filetype",
",",
"resolution",
"=",
"build_filename",
"(",
"filename",
",",
"filetype",
",",
... | If filename is specified, saves the image
:param str filename:
Name of the file
:param str filetype:
Type of file
:param int resolution:
DPI resolution of the output figure | [
"If",
"filename",
"is",
"specified",
"saves",
"the",
"image",
":",
"param",
"str",
"filename",
":",
"Name",
"of",
"the",
"file",
":",
"param",
"str",
"filetype",
":",
"Type",
"of",
"file",
":",
"param",
"int",
"resolution",
":",
"DPI",
"resolution",
"of"... | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hmtk/plotting/seismicity/catalogue_plots.py#L84-L100 |
gem/oq-engine | openquake/hmtk/plotting/seismicity/catalogue_plots.py | _get_catalogue_bin_limits | def _get_catalogue_bin_limits(catalogue, dmag):
"""
Returns the magnitude bins corresponing to the catalogue
"""
mag_bins = np.arange(
float(np.floor(np.min(catalogue.data['magnitude']))) - dmag,
float(np.ceil(np.max(catalogue.data['magnitude']))) + dmag,
dmag)
counter = np.h... | python | def _get_catalogue_bin_limits(catalogue, dmag):
mag_bins = np.arange(
float(np.floor(np.min(catalogue.data['magnitude']))) - dmag,
float(np.ceil(np.max(catalogue.data['magnitude']))) + dmag,
dmag)
counter = np.histogram(catalogue.data['magnitude'], mag_bins)[0]
idx = np.where(co... | [
"def",
"_get_catalogue_bin_limits",
"(",
"catalogue",
",",
"dmag",
")",
":",
"mag_bins",
"=",
"np",
".",
"arange",
"(",
"float",
"(",
"np",
".",
"floor",
"(",
"np",
".",
"min",
"(",
"catalogue",
".",
"data",
"[",
"'magnitude'",
"]",
")",
")",
")",
"-... | Returns the magnitude bins corresponing to the catalogue | [
"Returns",
"the",
"magnitude",
"bins",
"corresponing",
"to",
"the",
"catalogue"
] | train | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hmtk/plotting/seismicity/catalogue_plots.py#L103-L114 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.