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/geo/surface/gridded.py
GriddedSurface.get_surface_boundaries
def get_surface_boundaries(self): """ :returns: (min_max lons, min_max lats) """ min_lon, min_lat, max_lon, max_lat = self.get_bounding_box() return [[min_lon, max_lon]], [[min_lat, max_lat]]
python
def get_surface_boundaries(self): min_lon, min_lat, max_lon, max_lat = self.get_bounding_box() return [[min_lon, max_lon]], [[min_lat, max_lat]]
[ "def", "get_surface_boundaries", "(", "self", ")", ":", "min_lon", ",", "min_lat", ",", "max_lon", ",", "max_lat", "=", "self", ".", "get_bounding_box", "(", ")", "return", "[", "[", "min_lon", ",", "max_lon", "]", "]", ",", "[", "[", "min_lat", ",", "...
:returns: (min_max lons, min_max lats)
[ ":", "returns", ":", "(", "min_max", "lons", "min_max", "lats", ")" ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/geo/surface/gridded.py#L82-L87
gem/oq-engine
openquake/hazardlib/geo/surface/gridded.py
GriddedSurface.get_middle_point
def get_middle_point(self): """ Compute coordinates of surface middle point. The actual definition of ``middle point`` depends on the type of surface geometry. :return: instance of :class:`openquake.hazardlib.geo.point.Point` representing surface middle ...
python
def get_middle_point(self): lons = self.mesh.lons.squeeze() lats = self.mesh.lats.squeeze() depths = self.mesh.depths.squeeze() lon_bar = lons.mean() lat_bar = lats.mean() idx = np.argmin((lons - lon_bar)**2 + (lats - lat_bar)**2) return Point(lons[idx], ...
[ "def", "get_middle_point", "(", "self", ")", ":", "lons", "=", "self", ".", "mesh", ".", "lons", ".", "squeeze", "(", ")", "lats", "=", "self", ".", "mesh", ".", "lats", ".", "squeeze", "(", ")", "depths", "=", "self", ".", "mesh", ".", "depths", ...
Compute coordinates of surface middle point. The actual definition of ``middle point`` depends on the type of surface geometry. :return: instance of :class:`openquake.hazardlib.geo.point.Point` representing surface middle point.
[ "Compute", "coordinates", "of", "surface", "middle", "point", "." ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/geo/surface/gridded.py#L164-L181
gem/oq-engine
openquake/hazardlib/gsim/boore_atkinson_2011.py
BooreAtkinson2011.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. """ # get mean and std using the superclass mean, stddevs = super...
python
def get_mean_and_stddevs(self, sites, rup, dists, imt, stddev_types): mean, stddevs = super().get_mean_and_stddevs( sites, rup, dists, imt, stddev_types) corr_fact = 10.0**(np.max([0, 3.888 - 0.674 * rup.mag]) - (np.max([0, 2.9...
[ "def", "get_mean_and_stddevs", "(", "self", ",", "sites", ",", "rup", ",", "dists", ",", "imt", ",", "stddev_types", ")", ":", "# get mean and std using the superclass", "mean", ",", "stddevs", "=", "super", "(", ")", ".", "get_mean_and_stddevs", "(", "sites", ...
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/boore_atkinson_2011.py#L39-L56
gem/oq-engine
openquake/hazardlib/gsim/boore_atkinson_2011.py
Atkinson2008prime.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. """ # get mean and std using the superclass mean, stddevs = super...
python
def get_mean_and_stddevs(self, sites, rup, dists, imt, stddev_types): mean, stddevs = super().get_mean_and_stddevs( sites, rup, dists, imt, stddev_types) A08 = self.A08_COEFFS[imt] f_ena = 10.0 ** (A08["c"] + A08["d"] * dists.rjb) return np.log(np...
[ "def", "get_mean_and_stddevs", "(", "self", ",", "sites", ",", "rup", ",", "dists", ",", "imt", ",", "stddev_types", ")", ":", "# get mean and std using the superclass", "mean", ",", "stddevs", "=", "super", "(", ")", ".", "get_mean_and_stddevs", "(", "sites", ...
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/boore_atkinson_2011.py#L67-L81
gem/oq-engine
openquake/risklib/countries.py
get_country_code
def get_country_code(longname): """ :returns: the code of the country contained in `longname`, or a ValuError >>> for country, code in country2code.items(): ... assert get_country_code('Exp_' + country) == code, (country, code) """ mo = re.search(REGEX, longname, re.I) if mo is None: ...
python
def get_country_code(longname): mo = re.search(REGEX, longname, re.I) if mo is None: raise ValueError('Could not find a valid country in %s' % longname) return country2code[COUNTRIES[mo.lastindex - 1]]
[ "def", "get_country_code", "(", "longname", ")", ":", "mo", "=", "re", ".", "search", "(", "REGEX", ",", "longname", ",", "re", ".", "I", ")", "if", "mo", "is", "None", ":", "raise", "ValueError", "(", "'Could not find a valid country in %s'", "%", "longna...
:returns: the code of the country contained in `longname`, or a ValuError >>> for country, code in country2code.items(): ... assert get_country_code('Exp_' + country) == code, (country, code)
[ ":", "returns", ":", "the", "code", "of", "the", "country", "contained", "in", "longname", "or", "a", "ValuError" ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/risklib/countries.py#L249-L259
gem/oq-engine
openquake/risklib/countries.py
from_exposures
def from_exposures(expnames): """ :returns: a dictionary E??_ -> country """ dic = {} for i, expname in enumerate(expnames, 1): cc = get_country_code(expname) dic['E%02d_' % i] = cc return dic
python
def from_exposures(expnames): dic = {} for i, expname in enumerate(expnames, 1): cc = get_country_code(expname) dic['E%02d_' % i] = cc return dic
[ "def", "from_exposures", "(", "expnames", ")", ":", "dic", "=", "{", "}", "for", "i", ",", "expname", "in", "enumerate", "(", "expnames", ",", "1", ")", ":", "cc", "=", "get_country_code", "(", "expname", ")", "dic", "[", "'E%02d_'", "%", "i", "]", ...
:returns: a dictionary E??_ -> country
[ ":", "returns", ":", "a", "dictionary", "E??_", "-", ">", "country" ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/risklib/countries.py#L262-L270
gem/oq-engine
openquake/hazardlib/mfd/base.py
BaseMFD.modify
def modify(self, modification, parameters): """ Apply a single modification to an MFD parameters. Reflects the modification method and calls it passing ``parameters`` as keyword arguments. See also :attr:`MODIFICATIONS`. Modifications can be applied one on top of another. The l...
python
def modify(self, modification, parameters): if modification not in self.MODIFICATIONS: raise ValueError('Modification %s is not supported by %s' % (modification, type(self).__name__)) meth = getattr(self, 'modify_%s' % modification) meth(**parame...
[ "def", "modify", "(", "self", ",", "modification", ",", "parameters", ")", ":", "if", "modification", "not", "in", "self", ".", "MODIFICATIONS", ":", "raise", "ValueError", "(", "'Modification %s is not supported by %s'", "%", "(", "modification", ",", "type", "...
Apply a single modification to an MFD parameters. Reflects the modification method and calls it passing ``parameters`` as keyword arguments. See also :attr:`MODIFICATIONS`. Modifications can be applied one on top of another. The logic of stacking modifications is up to a specific MFD i...
[ "Apply", "a", "single", "modification", "to", "an", "MFD", "parameters", "." ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/mfd/base.py#L34-L56
gem/oq-engine
openquake/hazardlib/gsim/travasarou_2003.py
TravasarouEtAl2003.get_mean_and_stddevs
def get_mean_and_stddevs(self, sites, rup, dists, imt, stddev_types): """ See :meth:`superclass method <.base.GroundShakingIntensityModel.get_mean_and_stddevs>` for spec of input and result values. """ # extracting dictionary of coefficients specific to required #...
python
def get_mean_and_stddevs(self, sites, rup, dists, imt, stddev_types): C = self.COEFFS[imt] mean = (self._compute_magnitude(rup, C) + self._compute_distance(dists, C) + self._get_site_amplification(sites, rup, C) + self._...
[ "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/travasarou_2003.py#L76-L93
gem/oq-engine
openquake/hazardlib/gsim/travasarou_2003.py
TravasarouEtAl2003._get_stddevs
def _get_stddevs(self, rup, arias, stddev_types, sites): """ Return standard deviations as defined in table 1, p. 200. """ stddevs = [] # Magnitude dependent inter-event term (Eq. 13) if rup.mag < 4.7: tau = 0.611 elif rup.mag > 7.6: tau = ...
python
def _get_stddevs(self, rup, arias, stddev_types, sites): stddevs = [] if rup.mag < 4.7: tau = 0.611 elif rup.mag > 7.6: tau = 0.475 else: tau = 0.611 - 0.047 * (rup.mag - 4.7) sigma1, sigma2 = self._get_intra_event_s...
[ "def", "_get_stddevs", "(", "self", ",", "rup", ",", "arias", ",", "stddev_types", ",", "sites", ")", ":", "stddevs", "=", "[", "]", "# Magnitude dependent inter-event term (Eq. 13)", "if", "rup", ".", "mag", "<", "4.7", ":", "tau", "=", "0.611", "elif", "...
Return standard deviations as defined in table 1, p. 200.
[ "Return", "standard", "deviations", "as", "defined", "in", "table", "1", "p", ".", "200", "." ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/gsim/travasarou_2003.py#L95-L128
gem/oq-engine
openquake/hazardlib/gsim/travasarou_2003.py
TravasarouEtAl2003._get_intra_event_sigmas
def _get_intra_event_sigmas(self, sites): """ The intra-event term nonlinear and dependent on both the site class and the expected ground motion. In this case the sigma coefficients are determined from the site class as described below Eq. 14 """ sigma1 = 1.18 * np.ones_l...
python
def _get_intra_event_sigmas(self, sites): sigma1 = 1.18 * np.ones_like(sites.vs30) sigma2 = 0.94 * np.ones_like(sites.vs30) idx1 = np.logical_and(sites.vs30 >= 360.0, sites.vs30 < 760.0) idx2 = sites.vs30 < 360.0 sigma1[idx1] = 1.17 sigma2[idx1] = 0.93 s...
[ "def", "_get_intra_event_sigmas", "(", "self", ",", "sites", ")", ":", "sigma1", "=", "1.18", "*", "np", ".", "ones_like", "(", "sites", ".", "vs30", ")", "sigma2", "=", "0.94", "*", "np", ".", "ones_like", "(", "sites", ".", "vs30", ")", "idx1", "="...
The intra-event term nonlinear and dependent on both the site class and the expected ground motion. In this case the sigma coefficients are determined from the site class as described below Eq. 14
[ "The", "intra", "-", "event", "term", "nonlinear", "and", "dependent", "on", "both", "the", "site", "class", "and", "the", "expected", "ground", "motion", ".", "In", "this", "case", "the", "sigma", "coefficients", "are", "determined", "from", "the", "site", ...
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/gsim/travasarou_2003.py#L130-L145
gem/oq-engine
openquake/hazardlib/gsim/travasarou_2003.py
TravasarouEtAl2003._compute_magnitude
def _compute_magnitude(self, rup, C): """ Compute the first term of the equation described on p. 1144: ``c1 + c2 * (M - 6) + c3 * log(M / 6)`` """ return C['c1'] + C['c2'] * (rup.mag - 6.0) +\ (C['c3'] * np.log(rup.mag / 6.0))
python
def _compute_magnitude(self, rup, C): return C['c1'] + C['c2'] * (rup.mag - 6.0) +\ (C['c3'] * np.log(rup.mag / 6.0))
[ "def", "_compute_magnitude", "(", "self", ",", "rup", ",", "C", ")", ":", "return", "C", "[", "'c1'", "]", "+", "C", "[", "'c2'", "]", "*", "(", "rup", ".", "mag", "-", "6.0", ")", "+", "(", "C", "[", "'c3'", "]", "*", "np", ".", "log", "("...
Compute the first term of the equation described on p. 1144: ``c1 + c2 * (M - 6) + c3 * log(M / 6)``
[ "Compute", "the", "first", "term", "of", "the", "equation", "described", "on", "p", ".", "1144", ":" ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/gsim/travasarou_2003.py#L147-L154
gem/oq-engine
openquake/hazardlib/gsim/travasarou_2003.py
TravasarouEtAl2003._compute_distance
def _compute_distance(self, dists, C): """ Compute the second term of the equation described on p. 1144: `` c4 * np.log(sqrt(R ** 2. + h ** 2.) """ return C["c4"] * np.log(np.sqrt(dists.rrup ** 2. + C["h"] ** 2.))
python
def _compute_distance(self, dists, C): return C["c4"] * np.log(np.sqrt(dists.rrup ** 2. + C["h"] ** 2.))
[ "def", "_compute_distance", "(", "self", ",", "dists", ",", "C", ")", ":", "return", "C", "[", "\"c4\"", "]", "*", "np", ".", "log", "(", "np", ".", "sqrt", "(", "dists", ".", "rrup", "**", "2.", "+", "C", "[", "\"h\"", "]", "**", "2.", ")", ...
Compute the second term of the equation described on p. 1144: `` c4 * np.log(sqrt(R ** 2. + h ** 2.)
[ "Compute", "the", "second", "term", "of", "the", "equation", "described", "on", "p", ".", "1144", ":" ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/gsim/travasarou_2003.py#L156-L162
gem/oq-engine
openquake/hazardlib/gsim/travasarou_2003.py
TravasarouEtAl2003._get_site_amplification
def _get_site_amplification(self, sites, rup, C): """ Compute the third term of the equation described on p. 1144: ``(s11 + s12 * (M - 6)) * Sc + (s21 + s22 * (M - 6)) * Sd` """ Sc, Sd = self._get_site_type_dummy_variables(sites) return (C["s11"] + C["s12"] * (rup.mag - ...
python
def _get_site_amplification(self, sites, rup, C): Sc, Sd = self._get_site_type_dummy_variables(sites) return (C["s11"] + C["s12"] * (rup.mag - 6.0)) * Sc +\ (C["s21"] + C["s22"] * (rup.mag - 6.0)) * Sd
[ "def", "_get_site_amplification", "(", "self", ",", "sites", ",", "rup", ",", "C", ")", ":", "Sc", ",", "Sd", "=", "self", ".", "_get_site_type_dummy_variables", "(", "sites", ")", "return", "(", "C", "[", "\"s11\"", "]", "+", "C", "[", "\"s12\"", "]",...
Compute the third term of the equation described on p. 1144: ``(s11 + s12 * (M - 6)) * Sc + (s21 + s22 * (M - 6)) * Sd`
[ "Compute", "the", "third", "term", "of", "the", "equation", "described", "on", "p", ".", "1144", ":" ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/gsim/travasarou_2003.py#L164-L172
gem/oq-engine
openquake/hazardlib/gsim/travasarou_2003.py
TravasarouEtAl2003._get_site_type_dummy_variables
def _get_site_type_dummy_variables(self, sites): """ Get site type dummy variables, ``Sc`` (for soft and stiff soil sites) and ``Sd`` (for rock sites). """ Sc = np.zeros_like(sites.vs30) Sd = np.zeros_like(sites.vs30) # Soft soil; Vs30 < 360 m/s. Page 199. ...
python
def _get_site_type_dummy_variables(self, sites): Sc = np.zeros_like(sites.vs30) Sd = np.zeros_like(sites.vs30) Sd[sites.vs30 < 360.0] = 1 Sc[np.logical_and(sites.vs30 >= 360.0, sites.vs30 < 760.0)] = 1 return Sc, Sd
[ "def", "_get_site_type_dummy_variables", "(", "self", ",", "sites", ")", ":", "Sc", "=", "np", ".", "zeros_like", "(", "sites", ".", "vs30", ")", "Sd", "=", "np", ".", "zeros_like", "(", "sites", ".", "vs30", ")", "# Soft soil; Vs30 < 360 m/s. Page 199.", "S...
Get site type dummy variables, ``Sc`` (for soft and stiff soil sites) and ``Sd`` (for rock sites).
[ "Get", "site", "type", "dummy", "variables", "Sc", "(", "for", "soft", "and", "stiff", "soil", "sites", ")", "and", "Sd", "(", "for", "rock", "sites", ")", "." ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/gsim/travasarou_2003.py#L174-L186
gem/oq-engine
openquake/hazardlib/gsim/travasarou_2003.py
TravasarouEtAl2003._get_mechanism
def _get_mechanism(self, rup, C): """ Compute the fourth term of the equation described on p. 199: ``f1 * Fn + f2 * Fr`` """ Fn, Fr = self._get_fault_type_dummy_variables(rup) return (C['f1'] * Fn) + (C['f2'] * Fr)
python
def _get_mechanism(self, rup, C): Fn, Fr = self._get_fault_type_dummy_variables(rup) return (C['f1'] * Fn) + (C['f2'] * Fr)
[ "def", "_get_mechanism", "(", "self", ",", "rup", ",", "C", ")", ":", "Fn", ",", "Fr", "=", "self", ".", "_get_fault_type_dummy_variables", "(", "rup", ")", "return", "(", "C", "[", "'f1'", "]", "*", "Fn", ")", "+", "(", "C", "[", "'f2'", "]", "*...
Compute the fourth term of the equation described on p. 199: ``f1 * Fn + f2 * Fr``
[ "Compute", "the", "fourth", "term", "of", "the", "equation", "described", "on", "p", ".", "199", ":" ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/gsim/travasarou_2003.py#L188-L195
gem/oq-engine
openquake/hazardlib/gsim/travasarou_2003.py
TravasarouEtAl2003._get_fault_type_dummy_variables
def _get_fault_type_dummy_variables(self, rup): """ The original classification considers four style of faulting categories (normal, strike-slip, reverse-oblique and reverse). """ Fn, Fr = 0, 0 if rup.rake >= -112.5 and rup.rake <= -67.5: # normal ...
python
def _get_fault_type_dummy_variables(self, rup): Fn, Fr = 0, 0 if rup.rake >= -112.5 and rup.rake <= -67.5: Fn = 1 elif rup.rake >= 22.5 and rup.rake <= 157.5: Fr = 1 return Fn, Fr
[ "def", "_get_fault_type_dummy_variables", "(", "self", ",", "rup", ")", ":", "Fn", ",", "Fr", "=", "0", ",", "0", "if", "rup", ".", "rake", ">=", "-", "112.5", "and", "rup", ".", "rake", "<=", "-", "67.5", ":", "# normal", "Fn", "=", "1", "elif", ...
The original classification considers four style of faulting categories (normal, strike-slip, reverse-oblique and reverse).
[ "The", "original", "classification", "considers", "four", "style", "of", "faulting", "categories", "(", "normal", "strike", "-", "slip", "reverse", "-", "oblique", "and", "reverse", ")", "." ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/gsim/travasarou_2003.py#L197-L210
gem/oq-engine
openquake/hazardlib/gsim/boore_2014.py
california_basin_model
def california_basin_model(vs30): """ Returns the centred z1.0 (mu_z1) based on the California model (equation 11) """ coeff = 570.94 ** 4.0 model = (-7.15 / 4.0) * np.log( ((vs30 ** 4.0) + coeff) / ((1360.0 ** 4.0) + coeff) ) - np.log(1000.) return np.exp(model)
python
def california_basin_model(vs30): coeff = 570.94 ** 4.0 model = (-7.15 / 4.0) * np.log( ((vs30 ** 4.0) + coeff) / ((1360.0 ** 4.0) + coeff) ) - np.log(1000.) return np.exp(model)
[ "def", "california_basin_model", "(", "vs30", ")", ":", "coeff", "=", "570.94", "**", "4.0", "model", "=", "(", "-", "7.15", "/", "4.0", ")", "*", "np", ".", "log", "(", "(", "(", "vs30", "**", "4.0", ")", "+", "coeff", ")", "/", "(", "(", "136...
Returns the centred z1.0 (mu_z1) based on the California model (equation 11)
[ "Returns", "the", "centred", "z1", ".", "0", "(", "mu_z1", ")", "based", "on", "the", "California", "model", "(", "equation", "11", ")" ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/gsim/boore_2014.py#L614-L623
gem/oq-engine
openquake/hazardlib/gsim/boore_2014.py
japan_basin_model
def japan_basin_model(vs30): """ Returns the centred z1.0 (mu_z1) based on the Japan model (equation 12) """ coeff = 412.39 ** 2.0 model = (-5.23 / 2.0) * np.log( ((vs30 ** 2.0) + coeff) / ((1360.0 ** 2.0) + coeff) ) - np.log(1000.) return np.exp(model)
python
def japan_basin_model(vs30): coeff = 412.39 ** 2.0 model = (-5.23 / 2.0) * np.log( ((vs30 ** 2.0) + coeff) / ((1360.0 ** 2.0) + coeff) ) - np.log(1000.) return np.exp(model)
[ "def", "japan_basin_model", "(", "vs30", ")", ":", "coeff", "=", "412.39", "**", "2.0", "model", "=", "(", "-", "5.23", "/", "2.0", ")", "*", "np", ".", "log", "(", "(", "(", "vs30", "**", "2.0", ")", "+", "coeff", ")", "/", "(", "(", "1360.0",...
Returns the centred z1.0 (mu_z1) based on the Japan model (equation 12)
[ "Returns", "the", "centred", "z1", ".", "0", "(", "mu_z1", ")", "based", "on", "the", "Japan", "model", "(", "equation", "12", ")" ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/gsim/boore_2014.py#L704-L713
gem/oq-engine
openquake/hazardlib/gsim/boore_2014.py
BooreEtAl2014.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] C_PGA = self.COEFFS[PGA()] imt_per = 0 if imt.name == 'PGV' else imt.period pga_rock = self._get_pga_on_rock(C_PGA, rup, dists) mean = (self._get_magnitude_scalin...
[ "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/boore_2014.py#L85-L101
gem/oq-engine
openquake/hazardlib/gsim/boore_2014.py
BooreEtAl2014._get_pga_on_rock
def _get_pga_on_rock(self, C, rup, dists): """ Returns the median PGA on rock, which is a sum of the magnitude and distance scaling """ return np.exp(self._get_magnitude_scaling_term(C, rup) + self._get_path_scaling(C, dists, rup.mag))
python
def _get_pga_on_rock(self, C, rup, dists): return np.exp(self._get_magnitude_scaling_term(C, rup) + self._get_path_scaling(C, dists, rup.mag))
[ "def", "_get_pga_on_rock", "(", "self", ",", "C", ",", "rup", ",", "dists", ")", ":", "return", "np", ".", "exp", "(", "self", ".", "_get_magnitude_scaling_term", "(", "C", ",", "rup", ")", "+", "self", ".", "_get_path_scaling", "(", "C", ",", "dists",...
Returns the median PGA on rock, which is a sum of the magnitude and distance scaling
[ "Returns", "the", "median", "PGA", "on", "rock", "which", "is", "a", "sum", "of", "the", "magnitude", "and", "distance", "scaling" ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/gsim/boore_2014.py#L103-L109
gem/oq-engine
openquake/hazardlib/gsim/boore_2014.py
BooreEtAl2014._get_magnitude_scaling_term
def _get_magnitude_scaling_term(self, C, rup): """ Returns the magnitude scling term defined in equation (2) """ dmag = rup.mag - C["Mh"] if rup.mag <= C["Mh"]: mag_term = (C["e4"] * dmag) + (C["e5"] * (dmag ** 2.0)) else: mag_term = C["e6"] * dmag...
python
def _get_magnitude_scaling_term(self, C, rup): dmag = rup.mag - C["Mh"] if rup.mag <= C["Mh"]: mag_term = (C["e4"] * dmag) + (C["e5"] * (dmag ** 2.0)) else: mag_term = C["e6"] * dmag return self._get_style_of_faulting_term(C, rup) + mag_term
[ "def", "_get_magnitude_scaling_term", "(", "self", ",", "C", ",", "rup", ")", ":", "dmag", "=", "rup", ".", "mag", "-", "C", "[", "\"Mh\"", "]", "if", "rup", ".", "mag", "<=", "C", "[", "\"Mh\"", "]", ":", "mag_term", "=", "(", "C", "[", "\"e4\""...
Returns the magnitude scling term defined in equation (2)
[ "Returns", "the", "magnitude", "scling", "term", "defined", "in", "equation", "(", "2", ")" ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/gsim/boore_2014.py#L111-L120
gem/oq-engine
openquake/hazardlib/gsim/boore_2014.py
BooreEtAl2014._get_style_of_faulting_term
def _get_style_of_faulting_term(self, C, rup): """ Get fault type dummy variables Fault type (Strike-slip, Normal, Thrust/reverse) is derived from rake angle. Rakes angles within 30 of horizontal are strike-slip, angles from 30 to 150 are reverse, and angles from ...
python
def _get_style_of_faulting_term(self, C, rup): if np.abs(rup.rake) <= 30.0 or (180.0 - np.abs(rup.rake)) <= 30.0: return C["e1"] elif rup.rake > 30.0 and rup.rake < 150.0: return C["e3"] else: return C["e2"]
[ "def", "_get_style_of_faulting_term", "(", "self", ",", "C", ",", "rup", ")", ":", "if", "np", ".", "abs", "(", "rup", ".", "rake", ")", "<=", "30.0", "or", "(", "180.0", "-", "np", ".", "abs", "(", "rup", ".", "rake", ")", ")", "<=", "30.0", "...
Get fault type dummy variables Fault type (Strike-slip, Normal, Thrust/reverse) is derived from rake angle. Rakes angles within 30 of horizontal are strike-slip, angles from 30 to 150 are reverse, and angles from -30 to -150 are normal. Note that the 'Unspecified' case is...
[ "Get", "fault", "type", "dummy", "variables", "Fault", "type", "(", "Strike", "-", "slip", "Normal", "Thrust", "/", "reverse", ")", "is", "derived", "from", "rake", "angle", ".", "Rakes", "angles", "within", "30", "of", "horizontal", "are", "strike", "-", ...
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/gsim/boore_2014.py#L122-L141
gem/oq-engine
openquake/hazardlib/gsim/boore_2014.py
BooreEtAl2014._get_path_scaling
def _get_path_scaling(self, C, dists, mag): """ Returns the path scaling term given by equation (3) """ rval = np.sqrt((dists.rjb ** 2.0) + (C["h"] ** 2.0)) scaling = (C["c1"] + C["c2"] * (mag - self.CONSTS["Mref"])) *\ np.log(rval / self.CONSTS["Rref"]) retur...
python
def _get_path_scaling(self, C, dists, mag): rval = np.sqrt((dists.rjb ** 2.0) + (C["h"] ** 2.0)) scaling = (C["c1"] + C["c2"] * (mag - self.CONSTS["Mref"])) *\ np.log(rval / self.CONSTS["Rref"]) return scaling + ((C["c3"] + C["Dc3"]) * (rval - self.CONSTS["Rref"]))
[ "def", "_get_path_scaling", "(", "self", ",", "C", ",", "dists", ",", "mag", ")", ":", "rval", "=", "np", ".", "sqrt", "(", "(", "dists", ".", "rjb", "**", "2.0", ")", "+", "(", "C", "[", "\"h\"", "]", "**", "2.0", ")", ")", "scaling", "=", "...
Returns the path scaling term given by equation (3)
[ "Returns", "the", "path", "scaling", "term", "given", "by", "equation", "(", "3", ")" ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/gsim/boore_2014.py#L143-L150
gem/oq-engine
openquake/hazardlib/gsim/boore_2014.py
BooreEtAl2014._get_site_scaling
def _get_site_scaling(self, C, pga_rock, sites, period, rjb): """ Returns the site-scaling term (equation 5), broken down into a linear scaling, a nonlinear scaling and a basin scaling term """ flin = self._get_linear_site_term(C, sites.vs30) fnl = self._get_nonlinear_sit...
python
def _get_site_scaling(self, C, pga_rock, sites, period, rjb): flin = self._get_linear_site_term(C, sites.vs30) fnl = self._get_nonlinear_site_term(C, sites.vs30, pga_rock) fbd = self._get_basin_depth_term(C, sites, period) return flin + fnl + fbd
[ "def", "_get_site_scaling", "(", "self", ",", "C", ",", "pga_rock", ",", "sites", ",", "period", ",", "rjb", ")", ":", "flin", "=", "self", ".", "_get_linear_site_term", "(", "C", ",", "sites", ".", "vs30", ")", "fnl", "=", "self", ".", "_get_nonlinear...
Returns the site-scaling term (equation 5), broken down into a linear scaling, a nonlinear scaling and a basin scaling term
[ "Returns", "the", "site", "-", "scaling", "term", "(", "equation", "5", ")", "broken", "down", "into", "a", "linear", "scaling", "a", "nonlinear", "scaling", "and", "a", "basin", "scaling", "term" ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/gsim/boore_2014.py#L152-L160
gem/oq-engine
openquake/hazardlib/gsim/boore_2014.py
BooreEtAl2014._get_linear_site_term
def _get_linear_site_term(self, C, vs30): """ Returns the linear site scaling term (equation 6) """ flin = vs30 / self.CONSTS["Vref"] flin[vs30 > C["Vc"]] = C["Vc"] / self.CONSTS["Vref"] return C["c"] * np.log(flin)
python
def _get_linear_site_term(self, C, vs30): flin = vs30 / self.CONSTS["Vref"] flin[vs30 > C["Vc"]] = C["Vc"] / self.CONSTS["Vref"] return C["c"] * np.log(flin)
[ "def", "_get_linear_site_term", "(", "self", ",", "C", ",", "vs30", ")", ":", "flin", "=", "vs30", "/", "self", ".", "CONSTS", "[", "\"Vref\"", "]", "flin", "[", "vs30", ">", "C", "[", "\"Vc\"", "]", "]", "=", "C", "[", "\"Vc\"", "]", "/", "self"...
Returns the linear site scaling term (equation 6)
[ "Returns", "the", "linear", "site", "scaling", "term", "(", "equation", "6", ")" ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/gsim/boore_2014.py#L162-L168
gem/oq-engine
openquake/hazardlib/gsim/boore_2014.py
BooreEtAl2014._get_nonlinear_site_term
def _get_nonlinear_site_term(self, C, vs30, pga_rock): """ Returns the nonlinear site scaling term (equation 7) """ v_s = np.copy(vs30) v_s[vs30 > 760.] = 760. # Nonlinear controlling parameter (equation 8) f_2 = C["f4"] * (np.exp(C["f5"] * (v_s - 360.)) - ...
python
def _get_nonlinear_site_term(self, C, vs30, pga_rock): v_s = np.copy(vs30) v_s[vs30 > 760.] = 760. f_2 = C["f4"] * (np.exp(C["f5"] * (v_s - 360.)) - np.exp(C["f5"] * 400.)) fnl = self.CONSTS["f1"] + f_2 * np.log((pga_rock + self.CONSTS["f3"]) / ...
[ "def", "_get_nonlinear_site_term", "(", "self", ",", "C", ",", "vs30", ",", "pga_rock", ")", ":", "v_s", "=", "np", ".", "copy", "(", "vs30", ")", "v_s", "[", "vs30", ">", "760.", "]", "=", "760.", "# Nonlinear controlling parameter (equation 8)", "f_2", "...
Returns the nonlinear site scaling term (equation 7)
[ "Returns", "the", "nonlinear", "site", "scaling", "term", "(", "equation", "7", ")" ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/gsim/boore_2014.py#L170-L181
gem/oq-engine
openquake/hazardlib/gsim/boore_2014.py
BooreEtAl2014._get_basin_depth_term
def _get_basin_depth_term(self, C, sites, period): """ In the case of the base model the basin depth term is switched off. Therefore we return an array of zeros. """ return np.zeros(len(sites.vs30), dtype=float)
python
def _get_basin_depth_term(self, C, sites, period): return np.zeros(len(sites.vs30), dtype=float)
[ "def", "_get_basin_depth_term", "(", "self", ",", "C", ",", "sites", ",", "period", ")", ":", "return", "np", ".", "zeros", "(", "len", "(", "sites", ".", "vs30", ")", ",", "dtype", "=", "float", ")" ]
In the case of the base model the basin depth term is switched off. Therefore we return an array of zeros.
[ "In", "the", "case", "of", "the", "base", "model", "the", "basin", "depth", "term", "is", "switched", "off", ".", "Therefore", "we", "return", "an", "array", "of", "zeros", "." ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/gsim/boore_2014.py#L183-L188
gem/oq-engine
openquake/hazardlib/gsim/boore_2014.py
BooreEtAl2014._get_stddevs
def _get_stddevs(self, C, rup, dists, sites, stddev_types): """ Returns the aleatory uncertainty terms described in equations (13) to (17) """ stddevs = [] num_sites = len(sites.vs30) tau = self._get_inter_event_tau(C, rup.mag, num_sites) phi = self._get_i...
python
def _get_stddevs(self, C, rup, dists, sites, stddev_types): stddevs = [] num_sites = len(sites.vs30) tau = self._get_inter_event_tau(C, rup.mag, num_sites) phi = self._get_intra_event_phi(C, rup.mag, ...
[ "def", "_get_stddevs", "(", "self", ",", "C", ",", "rup", ",", "dists", ",", "sites", ",", "stddev_types", ")", ":", "stddevs", "=", "[", "]", "num_sites", "=", "len", "(", "sites", ".", "vs30", ")", "tau", "=", "self", ".", "_get_inter_event_tau", "...
Returns the aleatory uncertainty terms described in equations (13) to (17)
[ "Returns", "the", "aleatory", "uncertainty", "terms", "described", "in", "equations", "(", "13", ")", "to", "(", "17", ")" ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/gsim/boore_2014.py#L190-L211
gem/oq-engine
openquake/hazardlib/gsim/boore_2014.py
BooreEtAl2014._get_inter_event_tau
def _get_inter_event_tau(self, C, mag, num_sites): """ Returns the inter-event standard deviation (tau), which is dependent on magnitude """ base_vals = np.zeros(num_sites) if mag <= 4.5: return base_vals + C["t1"] elif mag >= 5.5: return b...
python
def _get_inter_event_tau(self, C, mag, num_sites): base_vals = np.zeros(num_sites) if mag <= 4.5: return base_vals + C["t1"] elif mag >= 5.5: return base_vals + C["t2"] else: return base_vals + C["t1"] + (C["t2"] - C["t1"]) * (mag - 4.5)
[ "def", "_get_inter_event_tau", "(", "self", ",", "C", ",", "mag", ",", "num_sites", ")", ":", "base_vals", "=", "np", ".", "zeros", "(", "num_sites", ")", "if", "mag", "<=", "4.5", ":", "return", "base_vals", "+", "C", "[", "\"t1\"", "]", "elif", "ma...
Returns the inter-event standard deviation (tau), which is dependent on magnitude
[ "Returns", "the", "inter", "-", "event", "standard", "deviation", "(", "tau", ")", "which", "is", "dependent", "on", "magnitude" ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/gsim/boore_2014.py#L213-L224
gem/oq-engine
openquake/hazardlib/gsim/boore_2014.py
BooreEtAl2014._get_intra_event_phi
def _get_intra_event_phi(self, C, mag, rjb, vs30, num_sites): """ Returns the intra-event standard deviation (phi), dependent on magnitude, distance and vs30 """ base_vals = np.zeros(num_sites) # Magnitude Dependent phi (Equation 17) if mag <= 4.5: bas...
python
def _get_intra_event_phi(self, C, mag, rjb, vs30, num_sites): base_vals = np.zeros(num_sites) if mag <= 4.5: base_vals += C["f1"] elif mag >= 5.5: base_vals += C["f2"] else: base_vals += (C["f1"] + (C["f2"] - C["f1"]) * (mag - 4.5)) ...
[ "def", "_get_intra_event_phi", "(", "self", ",", "C", ",", "mag", ",", "rjb", ",", "vs30", ",", "num_sites", ")", ":", "base_vals", "=", "np", ".", "zeros", "(", "num_sites", ")", "# Magnitude Dependent phi (Equation 17)", "if", "mag", "<=", "4.5", ":", "b...
Returns the intra-event standard deviation (phi), dependent on magnitude, distance and vs30
[ "Returns", "the", "intra", "-", "event", "standard", "deviation", "(", "phi", ")", "dependent", "on", "magnitude", "distance", "and", "vs30" ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/gsim/boore_2014.py#L226-L253
gem/oq-engine
openquake/hazardlib/gsim/boore_2014.py
BooreEtAl2014CaliforniaBasin._get_basin_depth_term
def _get_basin_depth_term(self, C, sites, period): """ In the case of the base model the basin depth term is switched off. Therefore we return an array of zeros. """ if period < 0.65: f_dz1 = np.zeros(len(sites.vs30), dtype=float) else: f_dz1 = C["...
python
def _get_basin_depth_term(self, C, sites, period): if period < 0.65: f_dz1 = np.zeros(len(sites.vs30), dtype=float) else: f_dz1 = C["f7"] + np.zeros(len(sites.vs30), dtype=float) f_ratio = C["f7"] / C["f6"] dz1 = (sites.z1pt0 / 1000.0) - californi...
[ "def", "_get_basin_depth_term", "(", "self", ",", "C", ",", "sites", ",", "period", ")", ":", "if", "period", "<", "0.65", ":", "f_dz1", "=", "np", ".", "zeros", "(", "len", "(", "sites", ".", "vs30", ")", ",", "dtype", "=", "float", ")", "else", ...
In the case of the base model the basin depth term is switched off. Therefore we return an array of zeros.
[ "In", "the", "case", "of", "the", "base", "model", "the", "basin", "depth", "term", "is", "switched", "off", ".", "Therefore", "we", "return", "an", "array", "of", "zeros", "." ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/gsim/boore_2014.py#L636-L649
gem/oq-engine
openquake/hazardlib/gsim/pankow_pechmann_2004.py
PankowPechmann2004.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. """ C = self.COEFFS[imt] M = rup.mag - 6 R = np.sqrt(dist...
python
def get_mean_and_stddevs(self, sites, rup, dists, imt, stddev_types): C = self.COEFFS[imt] M = rup.mag - 6 R = np.sqrt(dists.rjb ** 2 + C['h'] ** 2) gamma = np.array([0 if v > 910. else 1 for v in sites.vs30]) mean = np.zeros_like(R) ...
[ "def", "get_mean_and_stddevs", "(", "self", ",", "sites", ",", "rup", ",", "dists", ",", "imt", ",", "stddev_types", ")", ":", "C", "=", "self", ".", "COEFFS", "[", "imt", "]", "M", "=", "rup", ".", "mag", "-", "6", "R", "=", "np", ".", "sqrt", ...
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/pankow_pechmann_2004.py#L76-L114
gem/oq-engine
openquake/hazardlib/gsim/pankow_pechmann_2004.py
PankowPechmann2004._get_stddevs
def _get_stddevs(self, C, stddev_types, num_sites): """ Return total standard deviation. """ assert all(stddev_type in self.DEFINED_FOR_STANDARD_DEVIATION_TYPES for stddev_type in stddev_types) if self.DEFINED_FOR_INTENSITY_MEASURE_COMPONENT == 'Random horizon...
python
def _get_stddevs(self, C, stddev_types, num_sites): assert all(stddev_type in self.DEFINED_FOR_STANDARD_DEVIATION_TYPES for stddev_type in stddev_types) if self.DEFINED_FOR_INTENSITY_MEASURE_COMPONENT == 'Random horizontal': Sr = np.sqrt...
[ "def", "_get_stddevs", "(", "self", ",", "C", ",", "stddev_types", ",", "num_sites", ")", ":", "assert", "all", "(", "stddev_type", "in", "self", ".", "DEFINED_FOR_STANDARD_DEVIATION_TYPES", "for", "stddev_type", "in", "stddev_types", ")", "if", "self", ".", "...
Return total standard deviation.
[ "Return", "total", "standard", "deviation", "." ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/gsim/pankow_pechmann_2004.py#L116-L131
gem/oq-engine
openquake/hazardlib/mfd/multi_mfd.py
MultiMFD.get_min_max_mag
def get_min_max_mag(self): """ :returns: minumum and maximum magnitudes from the underlying MFDs """ m1s, m2s = [], [] for mfd in self: m1, m2 = mfd.get_min_max_mag() m1s.append(m1) m2s.append(m2) return min(m1s), max(m2s)
python
def get_min_max_mag(self): m1s, m2s = [], [] for mfd in self: m1, m2 = mfd.get_min_max_mag() m1s.append(m1) m2s.append(m2) return min(m1s), max(m2s)
[ "def", "get_min_max_mag", "(", "self", ")", ":", "m1s", ",", "m2s", "=", "[", "]", ",", "[", "]", "for", "mfd", "in", "self", ":", "m1", ",", "m2", "=", "mfd", ".", "get_min_max_mag", "(", ")", "m1s", ".", "append", "(", "m1", ")", "m2s", ".", ...
:returns: minumum and maximum magnitudes from the underlying MFDs
[ ":", "returns", ":", "minumum", "and", "maximum", "magnitudes", "from", "the", "underlying", "MFDs" ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/mfd/multi_mfd.py#L121-L130
gem/oq-engine
openquake/hazardlib/mfd/multi_mfd.py
MultiMFD.modify
def modify(self, modification, parameters): """ Apply a modification to the underlying point sources, with the same parameters for all sources """ for src in self: src.modify(modification, parameters)
python
def modify(self, modification, parameters): for src in self: src.modify(modification, parameters)
[ "def", "modify", "(", "self", ",", "modification", ",", "parameters", ")", ":", "for", "src", "in", "self", ":", "src", ".", "modify", "(", "modification", ",", "parameters", ")" ]
Apply a modification to the underlying point sources, with the same parameters for all sources
[ "Apply", "a", "modification", "to", "the", "underlying", "point", "sources", "with", "the", "same", "parameters", "for", "all", "sources" ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/mfd/multi_mfd.py#L143-L149
gem/oq-engine
openquake/hazardlib/gsim/geomatrix_1993.py
Geomatrix1993SSlabNSHMP2008._compute_mean
def _compute_mean(self, C, mag, ztor, rrup): """ Compute mean value as in ``subroutine getGeom`` in ``hazgridXnga2.f`` """ gc0 = 0.2418 ci = 0.3846 gch = 0.00607 g4 = 1.7818 ge = 0.554 gm = 1.414 mean = ( gc0 + ci + ztor * gch ...
python
def _compute_mean(self, C, mag, ztor, rrup): gc0 = 0.2418 ci = 0.3846 gch = 0.00607 g4 = 1.7818 ge = 0.554 gm = 1.414 mean = ( gc0 + ci + ztor * gch + C['gc1'] + gm * mag + C['gc2'] * (10 - mag) ** 3 + C['gc3'] * np.lo...
[ "def", "_compute_mean", "(", "self", ",", "C", ",", "mag", ",", "ztor", ",", "rrup", ")", ":", "gc0", "=", "0.2418", "ci", "=", "0.3846", "gch", "=", "0.00607", "g4", "=", "1.7818", "ge", "=", "0.554", "gm", "=", "1.414", "mean", "=", "(", "gc0",...
Compute mean value as in ``subroutine getGeom`` in ``hazgridXnga2.f``
[ "Compute", "mean", "value", "as", "in", "subroutine", "getGeom", "in", "hazgridXnga2", ".", "f" ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/gsim/geomatrix_1993.py#L92-L109
gem/oq-engine
openquake/commands/abort.py
abort
def abort(job_id): """ Abort the given job """ job = logs.dbcmd('get_job', job_id) # job_id can be negative if job is None: print('There is no job %d' % job_id) return elif job.status not in ('executing', 'running'): print('Job %d is %s' % (job.id, job.status)) r...
python
def abort(job_id): job = logs.dbcmd('get_job', job_id) if job is None: print('There is no job %d' % job_id) return elif job.status not in ('executing', 'running'): print('Job %d is %s' % (job.id, job.status)) return name = 'oq-job-%d' % job.id for p in psutil.p...
[ "def", "abort", "(", "job_id", ")", ":", "job", "=", "logs", ".", "dbcmd", "(", "'get_job'", ",", "job_id", ")", "# job_id can be negative", "if", "job", "is", "None", ":", "print", "(", "'There is no job %d'", "%", "job_id", ")", "return", "elif", "job", ...
Abort the given job
[ "Abort", "the", "given", "job" ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/commands/abort.py#L27-L53
gem/oq-engine
openquake/baselib/sap.py
get_parentparser
def get_parentparser(parser, description=None, help=True): """ :param parser: :class:`argparse.ArgumentParser` instance or None :param description: string used to build a new parser if parser is None :param help: flag used to build a new parser if parser is None :returns: if parser is None the new p...
python
def get_parentparser(parser, description=None, help=True): if parser is None: return argparse.ArgumentParser( description=description, add_help=help) elif hasattr(parser, 'parentparser'): return parser.parentparser else: return parser
[ "def", "get_parentparser", "(", "parser", ",", "description", "=", "None", ",", "help", "=", "True", ")", ":", "if", "parser", "is", "None", ":", "return", "argparse", ".", "ArgumentParser", "(", "description", "=", "description", ",", "add_help", "=", "he...
:param parser: :class:`argparse.ArgumentParser` instance or None :param description: string used to build a new parser if parser is None :param help: flag used to build a new parser if parser is None :returns: if parser is None the new parser; otherwise the `.parentparser` attribute (if set) o...
[ ":", "param", "parser", ":", ":", "class", ":", "argparse", ".", "ArgumentParser", "instance", "or", "None", ":", "param", "description", ":", "string", "used", "to", "build", "a", "new", "parser", "if", "parser", "is", "None", ":", "param", "help", ":",...
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/baselib/sap.py#L60-L74
gem/oq-engine
openquake/baselib/sap.py
compose
def compose(scripts, name='main', description=None, prog=None, version=None): """ Collects together different scripts and builds a single script dispatching to the subparsers depending on the first argument, i.e. the name of the subparser to invoke. :param scripts: a list of script inst...
python
def compose(scripts, name='main', description=None, prog=None, version=None): assert len(scripts) >= 1, scripts parentparser = argparse.ArgumentParser( description=description, add_help=False) parentparser.add_argument( '--version', '-v', action='version', version=version) ...
[ "def", "compose", "(", "scripts", ",", "name", "=", "'main'", ",", "description", "=", "None", ",", "prog", "=", "None", ",", "version", "=", "None", ")", ":", "assert", "len", "(", "scripts", ")", ">=", "1", ",", "scripts", "parentparser", "=", "arg...
Collects together different scripts and builds a single script dispatching to the subparsers depending on the first argument, i.e. the name of the subparser to invoke. :param scripts: a list of script instances :param name: the name of the composed parser :param description: description of the comp...
[ "Collects", "together", "different", "scripts", "and", "builds", "a", "single", "script", "dispatching", "to", "the", "subparsers", "depending", "on", "the", "first", "argument", "i", ".", "e", ".", "the", "name", "of", "the", "subparser", "to", "invoke", "....
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/baselib/sap.py#L205-L253
gem/oq-engine
openquake/baselib/sap.py
Script._add
def _add(self, name, *args, **kw): """ Add an argument to the underlying parser and grow the list .all_arguments and the set .names """ argname = list(self.argdict)[self._argno] if argname != name: raise NameError( 'Setting argument %s, but it ...
python
def _add(self, name, *args, **kw): argname = list(self.argdict)[self._argno] if argname != name: raise NameError( 'Setting argument %s, but it should be %s' % (name, argname)) self._group.add_argument(*args, **kw) self.all_arguments.append((args, kw))...
[ "def", "_add", "(", "self", ",", "name", ",", "*", "args", ",", "*", "*", "kw", ")", ":", "argname", "=", "list", "(", "self", ".", "argdict", ")", "[", "self", ".", "_argno", "]", "if", "argname", "!=", "name", ":", "raise", "NameError", "(", ...
Add an argument to the underlying parser and grow the list .all_arguments and the set .names
[ "Add", "an", "argument", "to", "the", "underlying", "parser", "and", "grow", "the", "list", ".", "all_arguments", "and", "the", "set", ".", "names" ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/baselib/sap.py#L116-L128
gem/oq-engine
openquake/baselib/sap.py
Script.arg
def arg(self, name, help, type=None, choices=None, metavar=None, nargs=None): """Describe a positional argument""" kw = dict(help=help, type=type, choices=choices, metavar=metavar, nargs=nargs) default = self.argdict[name] if default is not NODEFAULT: ...
python
def arg(self, name, help, type=None, choices=None, metavar=None, nargs=None): kw = dict(help=help, type=type, choices=choices, metavar=metavar, nargs=nargs) default = self.argdict[name] if default is not NODEFAULT: kw['nargs'] = nargs or '?' ...
[ "def", "arg", "(", "self", ",", "name", ",", "help", ",", "type", "=", "None", ",", "choices", "=", "None", ",", "metavar", "=", "None", ",", "nargs", "=", "None", ")", ":", "kw", "=", "dict", "(", "help", "=", "help", ",", "type", "=", "type",...
Describe a positional argument
[ "Describe", "a", "positional", "argument" ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/baselib/sap.py#L130-L140
gem/oq-engine
openquake/baselib/sap.py
Script.opt
def opt(self, name, help, abbrev=None, type=None, choices=None, metavar=None, nargs=None): """Describe an option""" kw = dict(help=help, type=type, choices=choices, metavar=metavar, nargs=nargs) default = self.argdict[name] if default is not NODEFAULT: ...
python
def opt(self, name, help, abbrev=None, type=None, choices=None, metavar=None, nargs=None): kw = dict(help=help, type=type, choices=choices, metavar=metavar, nargs=nargs) default = self.argdict[name] if default is not NODEFAULT: kw['default'] = d...
[ "def", "opt", "(", "self", ",", "name", ",", "help", ",", "abbrev", "=", "None", ",", "type", "=", "None", ",", "choices", "=", "None", ",", "metavar", "=", "None", ",", "nargs", "=", "None", ")", ":", "kw", "=", "dict", "(", "help", "=", "help...
Describe an option
[ "Describe", "an", "option" ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/baselib/sap.py#L142-L158
gem/oq-engine
openquake/baselib/sap.py
Script.flg
def flg(self, name, help, abbrev=None): """Describe a flag""" abbrev = abbrev or '-' + name[0] longname = '--' + name.replace('_', '-') self._add(name, abbrev, longname, action='store_true', help=help)
python
def flg(self, name, help, abbrev=None): abbrev = abbrev or '-' + name[0] longname = '--' + name.replace('_', '-') self._add(name, abbrev, longname, action='store_true', help=help)
[ "def", "flg", "(", "self", ",", "name", ",", "help", ",", "abbrev", "=", "None", ")", ":", "abbrev", "=", "abbrev", "or", "'-'", "+", "name", "[", "0", "]", "longname", "=", "'--'", "+", "name", ".", "replace", "(", "'_'", ",", "'-'", ")", "sel...
Describe a flag
[ "Describe", "a", "flag" ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/baselib/sap.py#L160-L164
gem/oq-engine
openquake/baselib/sap.py
Script.check_arguments
def check_arguments(self): """Make sure all arguments have a specification""" for name, default in self.argdict.items(): if name not in self.names and default is NODEFAULT: raise NameError('Missing argparse specification for %r' % name)
python
def check_arguments(self): for name, default in self.argdict.items(): if name not in self.names and default is NODEFAULT: raise NameError('Missing argparse specification for %r' % name)
[ "def", "check_arguments", "(", "self", ")", ":", "for", "name", ",", "default", "in", "self", ".", "argdict", ".", "items", "(", ")", ":", "if", "name", "not", "in", "self", ".", "names", "and", "default", "is", "NODEFAULT", ":", "raise", "NameError", ...
Make sure all arguments have a specification
[ "Make", "sure", "all", "arguments", "have", "a", "specification" ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/baselib/sap.py#L166-L170
gem/oq-engine
openquake/baselib/sap.py
Script.callfunc
def callfunc(self, argv=None): """ Parse the argv list and extract a dictionary of arguments which is then passed to the function underlying the script. """ if not self.checked: self.check_arguments() self.checked = True namespace = self.parentpar...
python
def callfunc(self, argv=None): if not self.checked: self.check_arguments() self.checked = True namespace = self.parentparser.parse_args(argv or sys.argv[1:]) return self.func(**vars(namespace))
[ "def", "callfunc", "(", "self", ",", "argv", "=", "None", ")", ":", "if", "not", "self", ".", "checked", ":", "self", ".", "check_arguments", "(", ")", "self", ".", "checked", "=", "True", "namespace", "=", "self", ".", "parentparser", ".", "parse_args...
Parse the argv list and extract a dictionary of arguments which is then passed to the function underlying the script.
[ "Parse", "the", "argv", "list", "and", "extract", "a", "dictionary", "of", "arguments", "which", "is", "then", "passed", "to", "the", "function", "underlying", "the", "script", "." ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/baselib/sap.py#L172-L181
gem/oq-engine
openquake/hmtk/faults/mfd/anderson_luco_arbitrary.py
Type1RecurrenceModel.cumulative_value
def cumulative_value(self, slip_moment, mmax, mag_value, bbar, dbar): ''' Returns the rate of events with M > mag_value :param float slip_moment: :param float slip_moment: Product of slip (cm/yr) * Area (cm ^ 2) * shear_modulus (dyne-cm) :param float mmax: ...
python
def cumulative_value(self, slip_moment, mmax, mag_value, bbar, dbar): delta_m = mmax - mag_value a_1 = self._get_a1(bbar, dbar, slip_moment, mmax) return a_1 * np.exp(bbar * (delta_m)) * (delta_m > 0.0)
[ "def", "cumulative_value", "(", "self", ",", "slip_moment", ",", "mmax", ",", "mag_value", ",", "bbar", ",", "dbar", ")", ":", "delta_m", "=", "mmax", "-", "mag_value", "a_1", "=", "self", ".", "_get_a1", "(", "bbar", ",", "dbar", ",", "slip_moment", "...
Returns the rate of events with M > mag_value :param float slip_moment: :param float slip_moment: Product of slip (cm/yr) * Area (cm ^ 2) * shear_modulus (dyne-cm) :param float mmax: Maximum magnitude :param float mag_value: Magnitude value :p...
[ "Returns", "the", "rate", "of", "events", "with", "M", ">", "mag_value" ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hmtk/faults/mfd/anderson_luco_arbitrary.py#L101-L119
gem/oq-engine
openquake/hmtk/faults/mfd/anderson_luco_arbitrary.py
Type1RecurrenceModel._get_a1
def _get_a1(bbar, dbar, slip_moment, mmax): """ Returns the A1 term (I.4 of Table 2 in Anderson & Luco) """ return ((dbar - bbar) / dbar) * (slip_moment / _scale_moment(mmax))
python
def _get_a1(bbar, dbar, slip_moment, mmax): return ((dbar - bbar) / dbar) * (slip_moment / _scale_moment(mmax))
[ "def", "_get_a1", "(", "bbar", ",", "dbar", ",", "slip_moment", ",", "mmax", ")", ":", "return", "(", "(", "dbar", "-", "bbar", ")", "/", "dbar", ")", "*", "(", "slip_moment", "/", "_scale_moment", "(", "mmax", ")", ")" ]
Returns the A1 term (I.4 of Table 2 in Anderson & Luco)
[ "Returns", "the", "A1", "term", "(", "I", ".", "4", "of", "Table", "2", "in", "Anderson", "&", "Luco", ")" ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hmtk/faults/mfd/anderson_luco_arbitrary.py#L122-L126
gem/oq-engine
openquake/hmtk/faults/mfd/anderson_luco_arbitrary.py
Type1RecurrenceModel.incremental_value
def incremental_value(self, slip_moment, mmax, mag_value, bbar, dbar): """ Returns the incremental rate of earthquakes with M = mag_value """ delta_m = mmax - mag_value dirac_term = np.zeros_like(mag_value) dirac_term[np.fabs(delta_m) < 1.0E-12] = 1.0 a_1 = self._...
python
def incremental_value(self, slip_moment, mmax, mag_value, bbar, dbar): delta_m = mmax - mag_value dirac_term = np.zeros_like(mag_value) dirac_term[np.fabs(delta_m) < 1.0E-12] = 1.0 a_1 = self._get_a1(bbar, dbar, slip_moment, mmax) return a_1 * (bbar * np.exp(bbar * delta...
[ "def", "incremental_value", "(", "self", ",", "slip_moment", ",", "mmax", ",", "mag_value", ",", "bbar", ",", "dbar", ")", ":", "delta_m", "=", "mmax", "-", "mag_value", "dirac_term", "=", "np", ".", "zeros_like", "(", "mag_value", ")", "dirac_term", "[", ...
Returns the incremental rate of earthquakes with M = mag_value
[ "Returns", "the", "incremental", "rate", "of", "earthquakes", "with", "M", "=", "mag_value" ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hmtk/faults/mfd/anderson_luco_arbitrary.py#L128-L137
gem/oq-engine
openquake/hmtk/faults/mfd/anderson_luco_arbitrary.py
Type2RecurrenceModel.cumulative_value
def cumulative_value(self, slip_moment, mmax, mag_value, bbar, dbar): ''' Returns the rate of events with M > mag_value :param float slip_moment: Product of slip (cm/yr) * Area (cm ^ 2) * shear_modulus (dyne-cm) :param float mmax: Maximum magnitude :param...
python
def cumulative_value(self, slip_moment, mmax, mag_value, bbar, dbar): delta_m = mmax - mag_value a_2 = self._get_a2(bbar, dbar, slip_moment, mmax) return a_2 * (np.exp(bbar * delta_m) - 1.) * (delta_m > 0.0)
[ "def", "cumulative_value", "(", "self", ",", "slip_moment", ",", "mmax", ",", "mag_value", ",", "bbar", ",", "dbar", ")", ":", "delta_m", "=", "mmax", "-", "mag_value", "a_2", "=", "self", ".", "_get_a2", "(", "bbar", ",", "dbar", ",", "slip_moment", "...
Returns the rate of events with M > mag_value :param float slip_moment: Product of slip (cm/yr) * Area (cm ^ 2) * shear_modulus (dyne-cm) :param float mmax: Maximum magnitude :param float mag_value: Magnitude value :param float bbar: \bar{...
[ "Returns", "the", "rate", "of", "events", "with", "M", ">", "mag_value" ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hmtk/faults/mfd/anderson_luco_arbitrary.py#L146-L163
gem/oq-engine
openquake/hmtk/faults/mfd/anderson_luco_arbitrary.py
Type2RecurrenceModel._get_a2
def _get_a2(bbar, dbar, slip_moment, mmax): """ Returns the A2 value defined in II.4 of Table 2 """ return ((dbar - bbar) / bbar) * (slip_moment / _scale_moment(mmax))
python
def _get_a2(bbar, dbar, slip_moment, mmax): return ((dbar - bbar) / bbar) * (slip_moment / _scale_moment(mmax))
[ "def", "_get_a2", "(", "bbar", ",", "dbar", ",", "slip_moment", ",", "mmax", ")", ":", "return", "(", "(", "dbar", "-", "bbar", ")", "/", "bbar", ")", "*", "(", "slip_moment", "/", "_scale_moment", "(", "mmax", ")", ")" ]
Returns the A2 value defined in II.4 of Table 2
[ "Returns", "the", "A2", "value", "defined", "in", "II", ".", "4", "of", "Table", "2" ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hmtk/faults/mfd/anderson_luco_arbitrary.py#L166-L170
gem/oq-engine
openquake/hmtk/faults/mfd/anderson_luco_arbitrary.py
Type3RecurrenceModel.cumulative_value
def cumulative_value(self, slip_moment, mmax, mag_value, bbar, dbar): ''' Returns the rate of events with M > mag_value :param float slip_moment: Product of slip (cm/yr) * Area (cm ^ 2) * shear_modulus (dyne-cm) :param float mmax: Maximum magnitude :param...
python
def cumulative_value(self, slip_moment, mmax, mag_value, bbar, dbar): delta_m = mmax - mag_value a_3 = self._get_a3(bbar, dbar, slip_moment, mmax) central_term = np.exp(bbar * delta_m) - 1.0 - (bbar * delta_m) return a_3 * central_term * (delta_m > 0.0)
[ "def", "cumulative_value", "(", "self", ",", "slip_moment", ",", "mmax", ",", "mag_value", ",", "bbar", ",", "dbar", ")", ":", "delta_m", "=", "mmax", "-", "mag_value", "a_3", "=", "self", ".", "_get_a3", "(", "bbar", ",", "dbar", ",", "slip_moment", "...
Returns the rate of events with M > mag_value :param float slip_moment: Product of slip (cm/yr) * Area (cm ^ 2) * shear_modulus (dyne-cm) :param float mmax: Maximum magnitude :param float mag_value: Magnitude value :param float bbar: \bar{...
[ "Returns", "the", "rate", "of", "events", "with", "M", ">", "mag_value" ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hmtk/faults/mfd/anderson_luco_arbitrary.py#L187-L205
gem/oq-engine
openquake/hmtk/faults/mfd/anderson_luco_arbitrary.py
Type3RecurrenceModel._get_a3
def _get_a3(bbar, dbar, slip_moment, mmax): """ Returns the A3 term (III.4 in Table 4) """ return ((dbar * (dbar - bbar)) / (bbar ** 2.)) * (slip_moment / _scale_moment(mmax))
python
def _get_a3(bbar, dbar, slip_moment, mmax): return ((dbar * (dbar - bbar)) / (bbar ** 2.)) * (slip_moment / _scale_moment(mmax))
[ "def", "_get_a3", "(", "bbar", ",", "dbar", ",", "slip_moment", ",", "mmax", ")", ":", "return", "(", "(", "dbar", "*", "(", "dbar", "-", "bbar", ")", ")", "/", "(", "bbar", "**", "2.", ")", ")", "*", "(", "slip_moment", "/", "_scale_moment", "("...
Returns the A3 term (III.4 in Table 4)
[ "Returns", "the", "A3", "term", "(", "III", ".", "4", "in", "Table", "4", ")" ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hmtk/faults/mfd/anderson_luco_arbitrary.py#L208-L213
gem/oq-engine
openquake/hmtk/faults/mfd/anderson_luco_arbitrary.py
Type3RecurrenceModel.incremental_value
def incremental_value(self, slip_moment, mmax, mag_value, bbar, dbar): """ Returns the incremental rate with Mmax = Mag_value """ delta_m = mmax - mag_value a_3 = self._get_a3(bbar, dbar, slip_moment, mmax) return a_3 * bbar * (np.exp(bbar * delta_m) - 1.0) * (delta_m > 0...
python
def incremental_value(self, slip_moment, mmax, mag_value, bbar, dbar): delta_m = mmax - mag_value a_3 = self._get_a3(bbar, dbar, slip_moment, mmax) return a_3 * bbar * (np.exp(bbar * delta_m) - 1.0) * (delta_m > 0.0)
[ "def", "incremental_value", "(", "self", ",", "slip_moment", ",", "mmax", ",", "mag_value", ",", "bbar", ",", "dbar", ")", ":", "delta_m", "=", "mmax", "-", "mag_value", "a_3", "=", "self", ".", "_get_a3", "(", "bbar", ",", "dbar", ",", "slip_moment", ...
Returns the incremental rate with Mmax = Mag_value
[ "Returns", "the", "incremental", "rate", "with", "Mmax", "=", "Mag_value" ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hmtk/faults/mfd/anderson_luco_arbitrary.py#L215-L221
gem/oq-engine
openquake/hmtk/faults/mfd/anderson_luco_arbitrary.py
AndersonLucoArbitrary.setUp
def setUp(self, mfd_conf): ''' Input core configuration parameters as specified in the configuration file :param dict mfd_conf: Configuration file containing the following attributes: * 'Type' - Choose between the 1st, 2nd or 3rd type of recurrence mo...
python
def setUp(self, mfd_conf): self.mfd_type = mfd_conf['Model_Type'] self.mfd_model = 'Anderson & Luco (Arbitrary) ' + self.mfd_type self.mfd_weight = mfd_conf['Model_Weight'] self.bin_width = mfd_conf['MFD_spacing'] self.mmin = mfd_conf['Minimum_Magnitude'] self.mm...
[ "def", "setUp", "(", "self", ",", "mfd_conf", ")", ":", "self", ".", "mfd_type", "=", "mfd_conf", "[", "'Model_Type'", "]", "self", ".", "mfd_model", "=", "'Anderson & Luco (Arbitrary) '", "+", "self", ".", "mfd_type", "self", ".", "mfd_weight", "=", "mfd_co...
Input core configuration parameters as specified in the configuration file :param dict mfd_conf: Configuration file containing the following attributes: * 'Type' - Choose between the 1st, 2nd or 3rd type of recurrence model {'First' | 'Second' | 'Third'} ...
[ "Input", "core", "configuration", "parameters", "as", "specified", "in", "the", "configuration", "file" ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hmtk/faults/mfd/anderson_luco_arbitrary.py#L260-L288
gem/oq-engine
openquake/hmtk/faults/mfd/anderson_luco_arbitrary.py
AndersonLucoArbitrary.get_mmax
def get_mmax(self, mfd_conf, msr, rake, area): ''' Gets the mmax for the fault - reading directly from the config file or using the msr otherwise :param dict mfd_config: Configuration file (see setUp for paramters) :param msr: Instance of :class:`nhlib.s...
python
def get_mmax(self, mfd_conf, msr, rake, area): if mfd_conf['Maximum_Magnitude']: self.mmax = mfd_conf['Maximum_Magnitude'] else: self.mmax = msr.get_median_mag(area, rake) if ('Maximum_Magnitude_Uncertainty' in mfd_conf and mfd_conf['Maximum_Magn...
[ "def", "get_mmax", "(", "self", ",", "mfd_conf", ",", "msr", ",", "rake", ",", "area", ")", ":", "if", "mfd_conf", "[", "'Maximum_Magnitude'", "]", ":", "self", ".", "mmax", "=", "mfd_conf", "[", "'Maximum_Magnitude'", "]", "else", ":", "self", ".", "m...
Gets the mmax for the fault - reading directly from the config file or using the msr otherwise :param dict mfd_config: Configuration file (see setUp for paramters) :param msr: Instance of :class:`nhlib.scalerel` :param float rake: Rake of the fault ...
[ "Gets", "the", "mmax", "for", "the", "fault", "-", "reading", "directly", "from", "the", "config", "file", "or", "using", "the", "msr", "otherwise" ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hmtk/faults/mfd/anderson_luco_arbitrary.py#L290-L316
gem/oq-engine
openquake/hmtk/faults/mfd/anderson_luco_arbitrary.py
AndersonLucoArbitrary.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 fault_area: Width of the fault (km) :param float shear_modulus: Shear modulus of the fault (GPa) ...
python
def get_mfd(self, slip, area, shear_modulus=30.0): slip_moment = (shear_modulus * 1E10) * (area * 1E10) * (slip / 10.) dbar = D_VALUE * np.log(10.0) bbar = self.b_value * np.log(10.0) mags = np.arange(self.mmin - (self.bin_width / 2.), ...
[ "def", "get_mfd", "(", "self", ",", "slip", ",", "area", ",", "shear_modulus", "=", "30.0", ")", ":", "# Convert shear modulus GPa -> dyne-cm, area km ** 2 -> cm ** 2 and", "# slip mm/yr -> cm/yr", "slip_moment", "=", "(", "shear_modulus", "*", "1E10", ")", "*", "(", ...
Calculates activity rate on the fault :param float slip: Slip rate in mm/yr :param fault_area: Width of the fault (km) :param float shear_modulus: Shear modulus of the fault (GPa) :returns: * Minimum Magnitude (float) * Bin ...
[ "Calculates", "activity", "rate", "on", "the", "fault" ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hmtk/faults/mfd/anderson_luco_arbitrary.py#L318-L358
gem/oq-engine
openquake/commands/reduce_sm.py
reduce_sm
def reduce_sm(calc_id): """ Reduce the source model of the given (pre)calculation by discarding all sources that do not contribute to the hazard. """ with datastore.read(calc_id) as dstore: oqparam = dstore['oqparam'] info = dstore['source_info'].value ok = info['weight'] > 0...
python
def reduce_sm(calc_id): with datastore.read(calc_id) as dstore: oqparam = dstore['oqparam'] info = dstore['source_info'].value ok = info['weight'] > 0 source_ids = set(info[ok]['source_id']) with performance.Monitor() as mon: readinput.reduce_source_model( ...
[ "def", "reduce_sm", "(", "calc_id", ")", ":", "with", "datastore", ".", "read", "(", "calc_id", ")", "as", "dstore", ":", "oqparam", "=", "dstore", "[", "'oqparam'", "]", "info", "=", "dstore", "[", "'source_info'", "]", ".", "value", "ok", "=", "info"...
Reduce the source model of the given (pre)calculation by discarding all sources that do not contribute to the hazard.
[ "Reduce", "the", "source", "model", "of", "the", "given", "(", "pre", ")", "calculation", "by", "discarding", "all", "sources", "that", "do", "not", "contribute", "to", "the", "hazard", "." ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/commands/reduce_sm.py#L24-L37
gem/oq-engine
openquake/hazardlib/gsim/lin_2009.py
Lin2009.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. """ C = self.COEFFS[imt] mean = ( self._get_magnitude_...
python
def get_mean_and_stddevs(self, sites, rup, dists, imt, stddev_types): C = self.COEFFS[imt] mean = ( self._get_magnitude_term(C, rup.mag) + self._get_distance_term(C, rup.mag, dists.rrup) + self._get_style_of_faulting_term(C, rup.rake) + self._get_...
[ "def", "get_mean_and_stddevs", "(", "self", ",", "sites", ",", "rup", ",", "dists", ",", "imt", ",", "stddev_types", ")", ":", "C", "=", "self", ".", "COEFFS", "[", "imt", "]", "mean", "=", "(", "self", ".", "_get_magnitude_term", "(", "C", ",", "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/lin_2009.py#L67-L81
gem/oq-engine
openquake/hazardlib/gsim/lin_2009.py
Lin2009._get_magnitude_term
def _get_magnitude_term(self, C, mag): """ Returns the magnitude scaling term. """ lny = C['C1'] + (C['C3'] * ((8.5 - mag) ** 2.)) if mag > 6.3: return lny + (-C['H'] * C['C5']) * (mag - 6.3) else: return lny + C['C2'] * (mag - 6.3)
python
def _get_magnitude_term(self, C, mag): lny = C['C1'] + (C['C3'] * ((8.5 - mag) ** 2.)) if mag > 6.3: return lny + (-C['H'] * C['C5']) * (mag - 6.3) else: return lny + C['C2'] * (mag - 6.3)
[ "def", "_get_magnitude_term", "(", "self", ",", "C", ",", "mag", ")", ":", "lny", "=", "C", "[", "'C1'", "]", "+", "(", "C", "[", "'C3'", "]", "*", "(", "(", "8.5", "-", "mag", ")", "**", "2.", ")", ")", "if", "mag", ">", "6.3", ":", "retur...
Returns the magnitude scaling term.
[ "Returns", "the", "magnitude", "scaling", "term", "." ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/gsim/lin_2009.py#L83-L91
gem/oq-engine
openquake/hazardlib/gsim/lin_2009.py
Lin2009._get_distance_term
def _get_distance_term(self, C, mag, rrup): """ Returns the distance scaling term """ return (C['C4'] + C['C5'] * (mag - 6.3)) *\ np.log(np.sqrt(rrup ** 2. + np.exp(C['H']) ** 2.))
python
def _get_distance_term(self, C, mag, rrup): return (C['C4'] + C['C5'] * (mag - 6.3)) *\ np.log(np.sqrt(rrup ** 2. + np.exp(C['H']) ** 2.))
[ "def", "_get_distance_term", "(", "self", ",", "C", ",", "mag", ",", "rrup", ")", ":", "return", "(", "C", "[", "'C4'", "]", "+", "C", "[", "'C5'", "]", "*", "(", "mag", "-", "6.3", ")", ")", "*", "np", ".", "log", "(", "np", ".", "sqrt", "...
Returns the distance scaling term
[ "Returns", "the", "distance", "scaling", "term" ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/gsim/lin_2009.py#L93-L98
gem/oq-engine
openquake/hazardlib/gsim/lin_2009.py
Lin2009._get_style_of_faulting_term
def _get_style_of_faulting_term(self, C, rake): """ Returns the style of faulting factor """ f_n, f_r = self._get_fault_type_dummy_variables(rake) return C['C6'] * f_n + C['C7'] * f_r
python
def _get_style_of_faulting_term(self, C, rake): f_n, f_r = self._get_fault_type_dummy_variables(rake) return C['C6'] * f_n + C['C7'] * f_r
[ "def", "_get_style_of_faulting_term", "(", "self", ",", "C", ",", "rake", ")", ":", "f_n", ",", "f_r", "=", "self", ".", "_get_fault_type_dummy_variables", "(", "rake", ")", "return", "C", "[", "'C6'", "]", "*", "f_n", "+", "C", "[", "'C7'", "]", "*", ...
Returns the style of faulting factor
[ "Returns", "the", "style", "of", "faulting", "factor" ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/gsim/lin_2009.py#L100-L105
gem/oq-engine
openquake/hazardlib/gsim/lin_2009.py
Lin2009._get_fault_type_dummy_variables
def _get_fault_type_dummy_variables(self, rake): """ Defines the fault type dummy variables for normal faulting (f_n) and reverse faulting (f_r) from rake. Classification based on that found in the original fortran code of Lin (2009) """ f_n, f_r = 0, 0 if rake >=...
python
def _get_fault_type_dummy_variables(self, rake): f_n, f_r = 0, 0 if rake >= -120 and rake <= -60: f_n = 1 elif rake >= 30 and rake <= 150: f_r = 1 return f_n, f_r
[ "def", "_get_fault_type_dummy_variables", "(", "self", ",", "rake", ")", ":", "f_n", ",", "f_r", "=", "0", ",", "0", "if", "rake", ">=", "-", "120", "and", "rake", "<=", "-", "60", ":", "# normal", "f_n", "=", "1", "elif", "rake", ">=", "30", "and"...
Defines the fault type dummy variables for normal faulting (f_n) and reverse faulting (f_r) from rake. Classification based on that found in the original fortran code of Lin (2009)
[ "Defines", "the", "fault", "type", "dummy", "variables", "for", "normal", "faulting", "(", "f_n", ")", "and", "reverse", "faulting", "(", "f_r", ")", "from", "rake", ".", "Classification", "based", "on", "that", "found", "in", "the", "original", "fortran", ...
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/gsim/lin_2009.py#L107-L120
gem/oq-engine
openquake/hazardlib/gsim/lin_2009.py
Lin2009._get_stddevs
def _get_stddevs(self, C, stddev_types, nsites): """ Compute total standard deviation, see table 4.2, page 50. """ stddevs = [] for stddev_type in stddev_types: assert stddev_type in self.DEFINED_FOR_STANDARD_DEVIATION_TYPES if stddev_type == const.StdDev....
python
def _get_stddevs(self, C, stddev_types, nsites): stddevs = [] for stddev_type in stddev_types: assert stddev_type in self.DEFINED_FOR_STANDARD_DEVIATION_TYPES if stddev_type == const.StdDev.TOTAL: stddevs.append(C['sigma'] + np.zeros(nsites, dtype=float))...
[ "def", "_get_stddevs", "(", "self", ",", "C", ",", "stddev_types", ",", "nsites", ")", ":", "stddevs", "=", "[", "]", "for", "stddev_type", "in", "stddev_types", ":", "assert", "stddev_type", "in", "self", ".", "DEFINED_FOR_STANDARD_DEVIATION_TYPES", "if", "st...
Compute total standard deviation, see table 4.2, page 50.
[ "Compute", "total", "standard", "deviation", "see", "table", "4", ".", "2", "page", "50", "." ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/gsim/lin_2009.py#L128-L137
gem/oq-engine
openquake/hazardlib/imt.py
imt2tup
def imt2tup(string): """ >>> imt2tup('PGA') ('PGA',) >>> imt2tup('SA(1.0)') ('SA', 1.0) >>> imt2tup('SA(1)') ('SA', 1.0) """ s = string.strip() if not s.endswith(')'): # no parenthesis, PGA is considered the same as PGA() return (s,) name, rest = s.split('(', ...
python
def imt2tup(string): s = string.strip() if not s.endswith(')'): return (s,) name, rest = s.split('(', 1) return (name,) + tuple(float(x) for x in ast.literal_eval(rest[:-1] + ','))
[ "def", "imt2tup", "(", "string", ")", ":", "s", "=", "string", ".", "strip", "(", ")", "if", "not", "s", ".", "endswith", "(", "')'", ")", ":", "# no parenthesis, PGA is considered the same as PGA()", "return", "(", "s", ",", ")", "name", ",", "rest", "=...
>>> imt2tup('PGA') ('PGA',) >>> imt2tup('SA(1.0)') ('SA', 1.0) >>> imt2tup('SA(1)') ('SA', 1.0)
[ ">>>", "imt2tup", "(", "PGA", ")", "(", "PGA", ")", ">>>", "imt2tup", "(", "SA", "(", "1", ".", "0", ")", ")", "(", "SA", "1", ".", "0", ")", ">>>", "imt2tup", "(", "SA", "(", "1", ")", ")", "(", "SA", "1", ".", "0", ")" ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/imt.py#L41-L55
gem/oq-engine
openquake/baselib/slots.py
with_slots
def with_slots(cls): """ Decorator for a class with _slots_. It automatically defines the methods __eq__, __ne__, assert_equal. """ def _compare(self, other): for slot in self.__class__._slots_: attr = operator.attrgetter(slot) source = attr(self) target =...
python
def with_slots(cls): def _compare(self, other): for slot in self.__class__._slots_: attr = operator.attrgetter(slot) source = attr(self) target = attr(other) if isinstance(source, numpy.ndarray): eq = numpy.array_equal(source, target) ...
[ "def", "with_slots", "(", "cls", ")", ":", "def", "_compare", "(", "self", ",", "other", ")", ":", "for", "slot", "in", "self", ".", "__class__", ".", "_slots_", ":", "attr", "=", "operator", ".", "attrgetter", "(", "slot", ")", "source", "=", "attr"...
Decorator for a class with _slots_. It automatically defines the methods __eq__, __ne__, assert_equal.
[ "Decorator", "for", "a", "class", "with", "_slots_", ".", "It", "automatically", "defines", "the", "methods", "__eq__", "__ne__", "assert_equal", "." ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/baselib/slots.py#L23-L58
gem/oq-engine
openquake/hazardlib/calc/disagg.py
make_iml4
def make_iml4(R, iml_disagg, imtls=None, poes_disagg=(None,), curves=()): """ :returns: an ArrayWrapper over a 4D array of shape (N, R, M, P) """ if imtls is None: imtls = {imt: [iml] for imt, iml in iml_disagg.items()} N = len(curves) or 1 M = len(imtls) P = len(poes_disagg) arr...
python
def make_iml4(R, iml_disagg, imtls=None, poes_disagg=(None,), curves=()): if imtls is None: imtls = {imt: [iml] for imt, iml in iml_disagg.items()} N = len(curves) or 1 M = len(imtls) P = len(poes_disagg) arr = numpy.zeros((N, R, M, P)) imts = [from_string(imt) for imt in imtls] ...
[ "def", "make_iml4", "(", "R", ",", "iml_disagg", ",", "imtls", "=", "None", ",", "poes_disagg", "=", "(", "None", ",", ")", ",", "curves", "=", "(", ")", ")", ":", "if", "imtls", "is", "None", ":", "imtls", "=", "{", "imt", ":", "[", "iml", "]"...
:returns: an ArrayWrapper over a 4D array of shape (N, R, M, P)
[ ":", "returns", ":", "an", "ArrayWrapper", "over", "a", "4D", "array", "of", "shape", "(", "N", "R", "M", "P", ")" ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/calc/disagg.py#L53-L69
gem/oq-engine
openquake/hazardlib/calc/disagg.py
collect_bin_data
def collect_bin_data(ruptures, sitecol, cmaker, iml4, truncation_level, n_epsilons, monitor=Monitor()): """ :param ruptures: a list of ruptures :param sitecol: a SiteCollection instance :param cmaker: a ContextMaker instance :param iml4: an ArrayWrapper of intensities of shape (...
python
def collect_bin_data(ruptures, sitecol, cmaker, iml4, truncation_level, n_epsilons, monitor=Monitor()): truncnorm = scipy.stats.truncnorm(-truncation_level, truncation_level) epsilons = numpy.linspace(truncnorm.a, truncnorm.b, n_epsilons + 1) acc = cmaker.disaggregate( ...
[ "def", "collect_bin_data", "(", "ruptures", ",", "sitecol", ",", "cmaker", ",", "iml4", ",", "truncation_level", ",", "n_epsilons", ",", "monitor", "=", "Monitor", "(", ")", ")", ":", "# NB: instantiating truncnorm is slow and calls the infamous \"doccer\"", "truncnorm"...
:param ruptures: a list of ruptures :param sitecol: a SiteCollection instance :param cmaker: a ContextMaker instance :param iml4: an ArrayWrapper of intensities of shape (N, R, M, P) :param truncation_level: the truncation level :param n_epsilons: the number of epsilons :param monitor: a Monitor...
[ ":", "param", "ruptures", ":", "a", "list", "of", "ruptures", ":", "param", "sitecol", ":", "a", "SiteCollection", "instance", ":", "param", "cmaker", ":", "a", "ContextMaker", "instance", ":", "param", "iml4", ":", "an", "ArrayWrapper", "of", "intensities",...
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/calc/disagg.py#L72-L89
gem/oq-engine
openquake/hazardlib/calc/disagg.py
lon_lat_bins
def lon_lat_bins(bb, coord_bin_width): """ Define bin edges for disaggregation histograms. Given bins data as provided by :func:`collect_bin_data`, this function finds edges of histograms, taking into account maximum and minimum values of magnitude, distance and coordinates as well as requested siz...
python
def lon_lat_bins(bb, coord_bin_width): west, south, east, north = bb west = numpy.floor(west / coord_bin_width) * coord_bin_width east = numpy.ceil(east / coord_bin_width) * coord_bin_width lon_extent = get_longitudinal_extent(west, east) lon_bins, _, _ = npoints_between( west, 0, 0, ea...
[ "def", "lon_lat_bins", "(", "bb", ",", "coord_bin_width", ")", ":", "west", ",", "south", ",", "east", ",", "north", "=", "bb", "west", "=", "numpy", ".", "floor", "(", "west", "/", "coord_bin_width", ")", "*", "coord_bin_width", "east", "=", "numpy", ...
Define bin edges for disaggregation histograms. Given bins data as provided by :func:`collect_bin_data`, this function finds edges of histograms, taking into account maximum and minimum values of magnitude, distance and coordinates as well as requested sizes/numbers of bins.
[ "Define", "bin", "edges", "for", "disaggregation", "histograms", "." ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/calc/disagg.py#L92-L111
gem/oq-engine
openquake/hazardlib/calc/disagg.py
get_shape
def get_shape(bin_edges, sid): """ :returns: the shape of the disaggregation matrix for the given site, of form (#mags-1, #dists-1, #lons-1, #lats-1, #eps-1) """ mag_bins, dist_bins, lon_bins, lat_bins, eps_bins = bin_edges return (len(mag_bins) - 1, len(dist_bins) - 1, l...
python
def get_shape(bin_edges, sid): mag_bins, dist_bins, lon_bins, lat_bins, eps_bins = bin_edges return (len(mag_bins) - 1, len(dist_bins) - 1, len(lon_bins[sid]) - 1, len(lat_bins[sid]) - 1, len(eps_bins) - 1)
[ "def", "get_shape", "(", "bin_edges", ",", "sid", ")", ":", "mag_bins", ",", "dist_bins", ",", "lon_bins", ",", "lat_bins", ",", "eps_bins", "=", "bin_edges", "return", "(", "len", "(", "mag_bins", ")", "-", "1", ",", "len", "(", "dist_bins", ")", "-",...
:returns: the shape of the disaggregation matrix for the given site, of form (#mags-1, #dists-1, #lons-1, #lats-1, #eps-1)
[ ":", "returns", ":", "the", "shape", "of", "the", "disaggregation", "matrix", "for", "the", "given", "site", "of", "form", "(", "#mags", "-", "1", "#dists", "-", "1", "#lons", "-", "1", "#lats", "-", "1", "#eps", "-", "1", ")" ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/calc/disagg.py#L114-L122
gem/oq-engine
openquake/hazardlib/calc/disagg.py
build_disagg_matrix
def build_disagg_matrix(bdata, bin_edges, sid, mon=Monitor): """ :param bdata: a dictionary of probabilities of no exceedence :param bin_edges: bin edges :param sid: site index :param mon: a Monitor instance :returns: a dictionary key -> matrix|pmf for each key in bdata """ with mon('bui...
python
def build_disagg_matrix(bdata, bin_edges, sid, mon=Monitor): with mon('build_disagg_matrix'): mag_bins, dist_bins, lon_bins, lat_bins, eps_bins = bin_edges dim1, dim2, dim3, dim4, dim5 = shape = get_shape(bin_edges, sid) mags_idx = ...
[ "def", "build_disagg_matrix", "(", "bdata", ",", "bin_edges", ",", "sid", ",", "mon", "=", "Monitor", ")", ":", "with", "mon", "(", "'build_disagg_matrix'", ")", ":", "mag_bins", ",", "dist_bins", ",", "lon_bins", ",", "lat_bins", ",", "eps_bins", "=", "bi...
:param bdata: a dictionary of probabilities of no exceedence :param bin_edges: bin edges :param sid: site index :param mon: a Monitor instance :returns: a dictionary key -> matrix|pmf for each key in bdata
[ ":", "param", "bdata", ":", "a", "dictionary", "of", "probabilities", "of", "no", "exceedence", ":", "param", "bin_edges", ":", "bin", "edges", ":", "param", "sid", ":", "site", "index", ":", "param", "mon", ":", "a", "Monitor", "instance", ":", "returns...
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/calc/disagg.py#L126-L185
gem/oq-engine
openquake/hazardlib/calc/disagg.py
_digitize_lons
def _digitize_lons(lons, lon_bins): """ Return indices of the bins to which each value in lons belongs. Takes into account the case in which longitude values cross the international date line. :parameter lons: An instance of `numpy.ndarray`. :parameter lons_bins: An instance of ...
python
def _digitize_lons(lons, lon_bins): if cross_idl(lon_bins[0], lon_bins[-1]): idx = numpy.zeros_like(lons, dtype=numpy.int) for i_lon in range(len(lon_bins) - 1): extents = get_longitudinal_extent(lons, lon_bins[i_lon + 1]) lon_idx = extents > 0 if i_lon != 0:...
[ "def", "_digitize_lons", "(", "lons", ",", "lon_bins", ")", ":", "if", "cross_idl", "(", "lon_bins", "[", "0", "]", ",", "lon_bins", "[", "-", "1", "]", ")", ":", "idx", "=", "numpy", ".", "zeros_like", "(", "lons", ",", "dtype", "=", "numpy", ".",...
Return indices of the bins to which each value in lons belongs. Takes into account the case in which longitude values cross the international date line. :parameter lons: An instance of `numpy.ndarray`. :parameter lons_bins: An instance of `numpy.ndarray`.
[ "Return", "indices", "of", "the", "bins", "to", "which", "each", "value", "in", "lons", "belongs", ".", "Takes", "into", "account", "the", "case", "in", "which", "longitude", "values", "cross", "the", "international", "date", "line", "." ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/calc/disagg.py#L188-L210
gem/oq-engine
openquake/hazardlib/calc/disagg.py
disaggregation
def disaggregation( sources, site, imt, iml, gsim_by_trt, truncation_level, n_epsilons, mag_bin_width, dist_bin_width, coord_bin_width, source_filter=filters.nofilter, filter_distance='rjb'): """ Compute "Disaggregation" matrix representing conditional probability of an intensity mes...
python
def disaggregation( sources, site, imt, iml, gsim_by_trt, truncation_level, n_epsilons, mag_bin_width, dist_bin_width, coord_bin_width, source_filter=filters.nofilter, filter_distance='rjb'): trts = sorted(set(src.tectonic_region_type for src in sources)) trt_num = dict((trt, i) for...
[ "def", "disaggregation", "(", "sources", ",", "site", ",", "imt", ",", "iml", ",", "gsim_by_trt", ",", "truncation_level", ",", "n_epsilons", ",", "mag_bin_width", ",", "dist_bin_width", ",", "coord_bin_width", ",", "source_filter", "=", "filters", ".", "nofilte...
Compute "Disaggregation" matrix representing conditional probability of an intensity mesaure type ``imt`` exceeding, at least once, an intensity measure level ``iml`` at a geographical location ``site``, given rupture scenarios classified in terms of: - rupture magnitude - Joyner-Boore distance fro...
[ "Compute", "Disaggregation", "matrix", "representing", "conditional", "probability", "of", "an", "intensity", "mesaure", "type", "imt", "exceeding", "at", "least", "once", "an", "intensity", "measure", "level", "iml", "at", "a", "geographical", "location", "site", ...
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/calc/disagg.py#L214-L335
gem/oq-engine
openquake/hazardlib/calc/disagg.py
mag_pmf
def mag_pmf(matrix): """ Fold full disaggregation matrix to magnitude PMF. :returns: 1d array, a histogram representing magnitude PMF. """ nmags, ndists, nlons, nlats, neps = matrix.shape mag_pmf = numpy.zeros(nmags) for i in range(nmags): mag_pmf[i] = numpy.prod( ...
python
def mag_pmf(matrix): nmags, ndists, nlons, nlats, neps = matrix.shape mag_pmf = numpy.zeros(nmags) for i in range(nmags): mag_pmf[i] = numpy.prod( [1. - matrix[i, j, k, l, m] for j in range(ndists) for k in range(nlons) for l in range(nlats) ...
[ "def", "mag_pmf", "(", "matrix", ")", ":", "nmags", ",", "ndists", ",", "nlons", ",", "nlats", ",", "neps", "=", "matrix", ".", "shape", "mag_pmf", "=", "numpy", ".", "zeros", "(", "nmags", ")", "for", "i", "in", "range", "(", "nmags", ")", ":", ...
Fold full disaggregation matrix to magnitude PMF. :returns: 1d array, a histogram representing magnitude PMF.
[ "Fold", "full", "disaggregation", "matrix", "to", "magnitude", "PMF", "." ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/calc/disagg.py#L338-L354
gem/oq-engine
openquake/hazardlib/calc/disagg.py
trt_pmf
def trt_pmf(matrices): """ Fold full disaggregation matrix to tectonic region type PMF. :param matrices: a matrix with T submatrices :returns: an array of T probabilities one per each tectonic region type """ ntrts, nmags, ndists, nlons, nlats, neps = matrices.shape pmf = nu...
python
def trt_pmf(matrices): ntrts, nmags, ndists, nlons, nlats, neps = matrices.shape pmf = numpy.zeros(ntrts) for t in range(ntrts): pmf[t] = 1. - numpy.prod( [1. - matrices[t, i, j, k, l, m] for i in range(nmags) for j in range(ndists) for k in ra...
[ "def", "trt_pmf", "(", "matrices", ")", ":", "ntrts", ",", "nmags", ",", "ndists", ",", "nlons", ",", "nlats", ",", "neps", "=", "matrices", ".", "shape", "pmf", "=", "numpy", ".", "zeros", "(", "ntrts", ")", "for", "t", "in", "range", "(", "ntrts"...
Fold full disaggregation matrix to tectonic region type PMF. :param matrices: a matrix with T submatrices :returns: an array of T probabilities one per each tectonic region type
[ "Fold", "full", "disaggregation", "matrix", "to", "tectonic", "region", "type", "PMF", "." ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/calc/disagg.py#L376-L395
gem/oq-engine
openquake/hazardlib/calc/disagg.py
lon_lat_trt_pmf
def lon_lat_trt_pmf(matrices): """ Fold full disaggregation matrices to lon / lat / TRT PMF. :param matrices: a matrix with T submatrices :returns: 3d array. First dimension represents longitude histogram bins, second one latitude histogram bins, third one trt histogram bins. ...
python
def lon_lat_trt_pmf(matrices): res = numpy.array([lon_lat_pmf(mat) for mat in matrices]) return res.transpose(1, 2, 0)
[ "def", "lon_lat_trt_pmf", "(", "matrices", ")", ":", "res", "=", "numpy", ".", "array", "(", "[", "lon_lat_pmf", "(", "mat", ")", "for", "mat", "in", "matrices", "]", ")", "return", "res", ".", "transpose", "(", "1", ",", "2", ",", "0", ")" ]
Fold full disaggregation matrices to lon / lat / TRT PMF. :param matrices: a matrix with T submatrices :returns: 3d array. First dimension represents longitude histogram bins, second one latitude histogram bins, third one trt histogram bins.
[ "Fold", "full", "disaggregation", "matrices", "to", "lon", "/", "lat", "/", "TRT", "PMF", "." ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/calc/disagg.py#L459-L470
gem/oq-engine
openquake/commands/db.py
db
def db(cmd, args=()): """ Run a database command """ if cmd not in commands: okcmds = '\n'.join( '%s %s' % (name, repr(' '.join(args)) if args else '') for name, args in sorted(commands.items())) print('Invalid command "%s": choose one from\n%s' % (cmd, okcmds)) ...
python
def db(cmd, args=()): if cmd not in commands: okcmds = '\n'.join( '%s %s' % (name, repr(' '.join(args)) if args else '') for name, args in sorted(commands.items())) print('Invalid command "%s": choose one from\n%s' % (cmd, okcmds)) elif len(args) != len(commands[cmd]...
[ "def", "db", "(", "cmd", ",", "args", "=", "(", ")", ")", ":", "if", "cmd", "not", "in", "commands", ":", "okcmds", "=", "'\\n'", ".", "join", "(", "'%s %s'", "%", "(", "name", ",", "repr", "(", "' '", ".", "join", "(", "args", ")", ")", "if"...
Run a database command
[ "Run", "a", "database", "command" ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/commands/db.py#L47-L65
gem/oq-engine
openquake/hmtk/faults/fault_geometries.py
SimpleFaultGeometry.get_area
def get_area(self): ''' Calculates the area of the fault (km ** 2.) as the product of length (km) and downdip width (km) ''' d_z = self.lower_depth - self.upper_depth self.downdip_width = d_z / np.sin(self.dip * np.pi / 180.) self.surface_width = self.downdip_widt...
python
def get_area(self): d_z = self.lower_depth - self.upper_depth self.downdip_width = d_z / np.sin(self.dip * np.pi / 180.) self.surface_width = self.downdip_width * np.cos(self.dip * np.pi / 180.) self.area = self.length * s...
[ "def", "get_area", "(", "self", ")", ":", "d_z", "=", "self", ".", "lower_depth", "-", "self", ".", "upper_depth", "self", ".", "downdip_width", "=", "d_z", "/", "np", ".", "sin", "(", "self", ".", "dip", "*", "np", ".", "pi", "/", "180.", ")", "...
Calculates the area of the fault (km ** 2.) as the product of length (km) and downdip width (km)
[ "Calculates", "the", "area", "of", "the", "fault", "(", "km", "**", "2", ".", ")", "as", "the", "product", "of", "length", "(", "km", ")", "and", "downdip", "width", "(", "km", ")" ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hmtk/faults/fault_geometries.py#L112-L122
gem/oq-engine
openquake/commands/download_shakemap.py
download_shakemap
def download_shakemap(id): """ Example of usage: utils/shakemap usp000fjta """ with performance.Monitor('shakemap', measuremem=True) as mon: dest = '%s.npy' % id numpy.save(dest, download_array(id)) print(mon) print('Saved %s' % dest)
python
def download_shakemap(id): with performance.Monitor('shakemap', measuremem=True) as mon: dest = '%s.npy' % id numpy.save(dest, download_array(id)) print(mon) print('Saved %s' % dest)
[ "def", "download_shakemap", "(", "id", ")", ":", "with", "performance", ".", "Monitor", "(", "'shakemap'", ",", "measuremem", "=", "True", ")", "as", "mon", ":", "dest", "=", "'%s.npy'", "%", "id", "numpy", ".", "save", "(", "dest", ",", "download_array"...
Example of usage: utils/shakemap usp000fjta
[ "Example", "of", "usage", ":", "utils", "/", "shakemap", "usp000fjta" ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/commands/download_shakemap.py#L25-L33
gem/oq-engine
openquake/hazardlib/stats.py
mean_curve
def mean_curve(values, weights=None): """ Compute the mean by using numpy.average on the first axis. """ if weights is None: weights = [1. / len(values)] * len(values) if not isinstance(values, numpy.ndarray): values = numpy.array(values) return numpy.average(values, axis=0, weig...
python
def mean_curve(values, weights=None): if weights is None: weights = [1. / len(values)] * len(values) if not isinstance(values, numpy.ndarray): values = numpy.array(values) return numpy.average(values, axis=0, weights=weights)
[ "def", "mean_curve", "(", "values", ",", "weights", "=", "None", ")", ":", "if", "weights", "is", "None", ":", "weights", "=", "[", "1.", "/", "len", "(", "values", ")", "]", "*", "len", "(", "values", ")", "if", "not", "isinstance", "(", "values",...
Compute the mean by using numpy.average on the first axis.
[ "Compute", "the", "mean", "by", "using", "numpy", ".", "average", "on", "the", "first", "axis", "." ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/stats.py#L25-L33
gem/oq-engine
openquake/hazardlib/stats.py
quantile_curve
def quantile_curve(quantile, curves, weights=None): """ Compute the weighted quantile aggregate of a set of curves. :param quantile: Quantile value to calculate. Should be in the range [0.0, 1.0]. :param curves: Array of R PoEs (possibly arrays) :param weights: Array-like of...
python
def quantile_curve(quantile, curves, weights=None): if not isinstance(curves, numpy.ndarray): curves = numpy.array(curves) R = len(curves) if weights is None: weights = numpy.ones(R) / R else: weights = numpy.array(weights) assert len(weights) == R, (len(weights), R)...
[ "def", "quantile_curve", "(", "quantile", ",", "curves", ",", "weights", "=", "None", ")", ":", "if", "not", "isinstance", "(", "curves", ",", "numpy", ".", "ndarray", ")", ":", "curves", "=", "numpy", ".", "array", "(", "curves", ")", "R", "=", "len...
Compute the weighted quantile aggregate of a set of curves. :param quantile: Quantile value to calculate. Should be in the range [0.0, 1.0]. :param curves: Array of R PoEs (possibly arrays) :param weights: Array-like of weights, 1 for each input curve, or None :returns: ...
[ "Compute", "the", "weighted", "quantile", "aggregate", "of", "a", "set", "of", "curves", "." ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/stats.py#L44-L74
gem/oq-engine
openquake/hazardlib/stats.py
compute_pmap_stats
def compute_pmap_stats(pmaps, stats, weights, imtls): """ :param pmaps: a list of R probability maps :param stats: a sequence of S statistic functions :param weights: a list of ImtWeights :param imtls: a DictArray of intensity measure types :returns: a pro...
python
def compute_pmap_stats(pmaps, stats, weights, imtls): sids = set() p0 = next(iter(pmaps)) L = p0.shape_y for pmap in pmaps: sids.update(pmap) assert pmap.shape_y == L, (pmap.shape_y, L) if len(sids) == 0: raise ValueError('All empty probability maps!') sids = numpy.a...
[ "def", "compute_pmap_stats", "(", "pmaps", ",", "stats", ",", "weights", ",", "imtls", ")", ":", "sids", "=", "set", "(", ")", "p0", "=", "next", "(", "iter", "(", "pmaps", ")", ")", "L", "=", "p0", ".", "shape_y", "for", "pmap", "in", "pmaps", "...
:param pmaps: a list of R probability maps :param stats: a sequence of S statistic functions :param weights: a list of ImtWeights :param imtls: a DictArray of intensity measure types :returns: a probability map with S internal values
[ ":", "param", "pmaps", ":", "a", "list", "of", "R", "probability", "maps", ":", "param", "stats", ":", "a", "sequence", "of", "S", "statistic", "functions", ":", "param", "weights", ":", "a", "list", "of", "ImtWeights", ":", "param", "imtls", ":", "a",...
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/stats.py#L89-L124
gem/oq-engine
openquake/hazardlib/stats.py
compute_stats
def compute_stats(array, stats, weights): """ :param array: an array of R elements (which can be arrays) :param stats: a sequence of S statistic functions :param weights: a list of R weights :returns: an array of S elements (which can be arrays) """ result = n...
python
def compute_stats(array, stats, weights): result = numpy.zeros((len(stats),) + array.shape[1:], array.dtype) for i, func in enumerate(stats): result[i] = apply_stat(func, array, weights) return result
[ "def", "compute_stats", "(", "array", ",", "stats", ",", "weights", ")", ":", "result", "=", "numpy", ".", "zeros", "(", "(", "len", "(", "stats", ")", ",", ")", "+", "array", ".", "shape", "[", "1", ":", "]", ",", "array", ".", "dtype", ")", "...
:param array: an array of R elements (which can be arrays) :param stats: a sequence of S statistic functions :param weights: a list of R weights :returns: an array of S elements (which can be arrays)
[ ":", "param", "array", ":", "an", "array", "of", "R", "elements", "(", "which", "can", "be", "arrays", ")", ":", "param", "stats", ":", "a", "sequence", "of", "S", "statistic", "functions", ":", "param", "weights", ":", "a", "list", "of", "R", "weigh...
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/stats.py#L128-L142
gem/oq-engine
openquake/hazardlib/stats.py
compute_stats2
def compute_stats2(arrayNR, stats, weights): """ :param arrayNR: an array of (N, R) elements :param stats: a sequence of S statistic functions :param weights: a list of R weights :returns: an array of (N, S) elements """ newshape = list(arrayNR.shape) if n...
python
def compute_stats2(arrayNR, stats, weights): newshape = list(arrayNR.shape) if newshape[1] != len(weights): raise ValueError('Got %d weights but %d values!' % (len(weights), newshape[1])) newshape[1] = len(stats) newarray = numpy.zeros(newshape, arrayNR.dtype) ...
[ "def", "compute_stats2", "(", "arrayNR", ",", "stats", ",", "weights", ")", ":", "newshape", "=", "list", "(", "arrayNR", ".", "shape", ")", "if", "newshape", "[", "1", "]", "!=", "len", "(", "weights", ")", ":", "raise", "ValueError", "(", "'Got %d we...
:param arrayNR: an array of (N, R) elements :param stats: a sequence of S statistic functions :param weights: a list of R weights :returns: an array of (N, S) elements
[ ":", "param", "arrayNR", ":", "an", "array", "of", "(", "N", "R", ")", "elements", ":", "param", "stats", ":", "a", "sequence", "of", "S", "statistic", "functions", ":", "param", "weights", ":", "a", "list", "of", "R", "weights", ":", "returns", ":",...
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/stats.py#L146-L166
gem/oq-engine
openquake/hazardlib/stats.py
apply_stat
def apply_stat(f, arraylist, *extra, **kw): """ :param f: a callable arraylist -> array (of the same shape and dtype) :param arraylist: a list of arrays of the same shape and dtype :param extra: additional positional arguments :param kw: keyword arguments :returns: an array of the same shape and...
python
def apply_stat(f, arraylist, *extra, **kw): dtype = arraylist[0].dtype shape = arraylist[0].shape if dtype.names: new = numpy.zeros(shape, dtype) for name in dtype.names: new[name] = f([arr[name] for arr in arraylist], *extra, **kw) return new else: r...
[ "def", "apply_stat", "(", "f", ",", "arraylist", ",", "*", "extra", ",", "*", "*", "kw", ")", ":", "dtype", "=", "arraylist", "[", "0", "]", ".", "dtype", "shape", "=", "arraylist", "[", "0", "]", ".", "shape", "if", "dtype", ".", "names", ":", ...
:param f: a callable arraylist -> array (of the same shape and dtype) :param arraylist: a list of arrays of the same shape and dtype :param extra: additional positional arguments :param kw: keyword arguments :returns: an array of the same shape and dtype Broadcast statistical functions to composite...
[ ":", "param", "f", ":", "a", "callable", "arraylist", "-", ">", "array", "(", "of", "the", "same", "shape", "and", "dtype", ")", ":", "param", "arraylist", ":", "a", "list", "of", "arrays", "of", "the", "same", "shape", "and", "dtype", ":", "param", ...
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/stats.py#L169-L193
gem/oq-engine
openquake/hazardlib/stats.py
set_rlzs_stats
def set_rlzs_stats(dstore, prefix, arrayNR=None): """ :param dstore: a DataStore object :param prefix: dataset prefix :param arrayNR: an array of shape (N, R, ...) """ if arrayNR is None: # assume the -rlzs array is already stored arrayNR = dstore[prefix + '-rlzs'].value else...
python
def set_rlzs_stats(dstore, prefix, arrayNR=None): if arrayNR is None: arrayNR = dstore[prefix + '-rlzs'].value else: dstore[prefix + '-rlzs'] = arrayNR R = arrayNR.shape[1] if R > 1: stats = dstore['oqparam'].hazard_stats() statnames, statfuncs = zi...
[ "def", "set_rlzs_stats", "(", "dstore", ",", "prefix", ",", "arrayNR", "=", "None", ")", ":", "if", "arrayNR", "is", "None", ":", "# assume the -rlzs array is already stored", "arrayNR", "=", "dstore", "[", "prefix", "+", "'-rlzs'", "]", ".", "value", "else", ...
:param dstore: a DataStore object :param prefix: dataset prefix :param arrayNR: an array of shape (N, R, ...)
[ ":", "param", "dstore", ":", "a", "DataStore", "object", ":", "param", "prefix", ":", "dataset", "prefix", ":", "param", "arrayNR", ":", "an", "array", "of", "shape", "(", "N", "R", "...", ")" ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/stats.py#L196-L214
gem/oq-engine
openquake/hazardlib/gsim/toro_2002.py
ToroEtAl2002.get_mean_and_stddevs
def get_mean_and_stddevs(self, sites, rup, dists, imt, stddev_types): """ See :meth:`superclass method <.base.GroundShakingIntensityModel.get_mean_and_stddevs>` for spec of input and result values. """ assert all(stddev_type in self.DEFINED_FOR_STANDARD_DEVIATION_TYPES ...
python
def get_mean_and_stddevs(self, sites, rup, dists, imt, stddev_types): assert all(stddev_type in self.DEFINED_FOR_STANDARD_DEVIATION_TYPES for stddev_type in stddev_types) C = self.COEFFS[imt] mean = self._compute_mean(C, rup.mag, dists.rjb) stddevs = self._co...
[ "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/toro_2002.py#L76-L97
gem/oq-engine
openquake/hazardlib/gsim/toro_2002.py
ToroEtAl2002._compute_term1
def _compute_term1(self, C, mag): """ Compute magnitude dependent terms (2nd and 3rd) in equation 3 page 46. """ mag_diff = mag - 6 return C['c2'] * mag_diff + C['c3'] * mag_diff ** 2
python
def _compute_term1(self, C, mag): mag_diff = mag - 6 return C['c2'] * mag_diff + C['c3'] * mag_diff ** 2
[ "def", "_compute_term1", "(", "self", ",", "C", ",", "mag", ")", ":", "mag_diff", "=", "mag", "-", "6", "return", "C", "[", "'c2'", "]", "*", "mag_diff", "+", "C", "[", "'c3'", "]", "*", "mag_diff", "**", "2" ]
Compute magnitude dependent terms (2nd and 3rd) in equation 3 page 46.
[ "Compute", "magnitude", "dependent", "terms", "(", "2nd", "and", "3rd", ")", "in", "equation", "3", "page", "46", "." ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/gsim/toro_2002.py#L99-L106
gem/oq-engine
openquake/hazardlib/gsim/toro_2002.py
ToroEtAl2002._compute_term2
def _compute_term2(self, C, mag, rjb): """ Compute distance dependent terms (4th, 5th and 6th) in equation 3 page 46. The factor 'RM' is computed according to the 2002 model (equation 4-3). """ RM = np.sqrt(rjb ** 2 + (C['c7'] ** 2) * np.exp(-1.25 + 0...
python
def _compute_term2(self, C, mag, rjb): RM = np.sqrt(rjb ** 2 + (C['c7'] ** 2) * np.exp(-1.25 + 0.227 * mag) ** 2) return (-C['c4'] * np.log(RM) - (C['c5'] - C['c4']) * np.maximum(np.log(RM / 100), 0) - C['c6'] * RM)
[ "def", "_compute_term2", "(", "self", ",", "C", ",", "mag", ",", "rjb", ")", ":", "RM", "=", "np", ".", "sqrt", "(", "rjb", "**", "2", "+", "(", "C", "[", "'c7'", "]", "**", "2", ")", "*", "np", ".", "exp", "(", "-", "1.25", "+", "0.227", ...
Compute distance dependent terms (4th, 5th and 6th) in equation 3 page 46. The factor 'RM' is computed according to the 2002 model (equation 4-3).
[ "Compute", "distance", "dependent", "terms", "(", "4th", "5th", "and", "6th", ")", "in", "equation", "3", "page", "46", ".", "The", "factor", "RM", "is", "computed", "according", "to", "the", "2002", "model", "(", "equation", "4", "-", "3", ")", "." ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/gsim/toro_2002.py#L108-L119
gem/oq-engine
openquake/hazardlib/gsim/toro_2002.py
ToroEtAl2002._compute_mean
def _compute_mean(self, C, mag, rjb): """ Compute mean value according to equation 3, page 46. """ mean = (C['c1'] + self._compute_term1(C, mag) + self._compute_term2(C, mag, rjb)) return mean
python
def _compute_mean(self, C, mag, rjb): mean = (C['c1'] + self._compute_term1(C, mag) + self._compute_term2(C, mag, rjb)) return mean
[ "def", "_compute_mean", "(", "self", ",", "C", ",", "mag", ",", "rjb", ")", ":", "mean", "=", "(", "C", "[", "'c1'", "]", "+", "self", ".", "_compute_term1", "(", "C", ",", "mag", ")", "+", "self", ".", "_compute_term2", "(", "C", ",", "mag", "...
Compute mean value according to equation 3, page 46.
[ "Compute", "mean", "value", "according", "to", "equation", "3", "page", "46", "." ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/gsim/toro_2002.py#L121-L128
gem/oq-engine
openquake/hazardlib/gsim/toro_2002.py
ToroEtAl2002._compute_stddevs
def _compute_stddevs(self, C, mag, rjb, imt, stddev_types): """ Compute total standard deviation, equations 5 and 6, page 48. """ # aleatory uncertainty sigma_ale_m = np.interp(mag, [5.0, 5.5, 8.0], [C['m50'], C['m55'], C['m80']]) sigma_ale...
python
def _compute_stddevs(self, C, mag, rjb, imt, stddev_types): sigma_ale_m = np.interp(mag, [5.0, 5.5, 8.0], [C['m50'], C['m55'], C['m80']]) sigma_ale_rjb = np.interp(rjb, [5.0, 20.0], [C['r5'], C['r20']]) sigma_ale = np.sqrt(sigma_ale_m ** 2 + sigm...
[ "def", "_compute_stddevs", "(", "self", ",", "C", ",", "mag", ",", "rjb", ",", "imt", ",", "stddev_types", ")", ":", "# aleatory uncertainty", "sigma_ale_m", "=", "np", ".", "interp", "(", "mag", ",", "[", "5.0", ",", "5.5", ",", "8.0", "]", ",", "["...
Compute total standard deviation, equations 5 and 6, page 48.
[ "Compute", "total", "standard", "deviation", "equations", "5", "and", "6", "page", "48", "." ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/gsim/toro_2002.py#L130-L152
gem/oq-engine
openquake/hazardlib/gsim/mgmpe/nrcan15_site_term.py
NRCan15SiteTerm.get_mean_and_stddevs
def get_mean_and_stddevs(self, sites, rup, dists, imt, stds_types): """ See :meth:`superclass method <.base.GroundShakingIntensityModel.get_mean_and_stddevs>` for spec of input and result values. """ # Prepare sites sites_rock = copy.deepcopy(sites) sites_...
python
def get_mean_and_stddevs(self, sites, rup, dists, imt, stds_types): sites_rock = copy.deepcopy(sites) sites_rock.vs30 = np.ones_like(sites_rock.vs30) * 760. mean, stddvs = self.gmpe.get_mean_and_stddevs(sites_rock, rup, dists, ...
[ "def", "get_mean_and_stddevs", "(", "self", ",", "sites", ",", "rup", ",", "dists", ",", "imt", ",", "stds_types", ")", ":", "# Prepare sites", "sites_rock", "=", "copy", ".", "deepcopy", "(", "sites", ")", "sites_rock", ".", "vs30", "=", "np", ".", "one...
See :meth:`superclass method <.base.GroundShakingIntensityModel.get_mean_and_stddevs>` for spec of input and result values.
[ "See", ":", "meth", ":", "superclass", "method", "<", ".", "base", ".", "GroundShakingIntensityModel", ".", "get_mean_and_stddevs", ">", "for", "spec", "of", "input", "and", "result", "values", "." ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/gsim/mgmpe/nrcan15_site_term.py#L67-L87
gem/oq-engine
openquake/hazardlib/gsim/mgmpe/nrcan15_site_term.py
NRCan15SiteTerm.BA08_AB06
def BA08_AB06(self, vs30, imt, pgar): """ Computes amplification factor similarly to what is done in the 2015 version of the Canada building code. An initial version of this code was kindly provided by Michal Kolaj - Geological Survey of Canada :param vs30: Can be ei...
python
def BA08_AB06(self, vs30, imt, pgar): fa = np.ones_like(vs30) if np.isscalar(vs30): vs30 = np.array([vs30]) if np.isscalar(pgar): pgar = np.array([pgar]) vs = copy.copy(vs30) vs[vs >= 2000] = 1999. ...
[ "def", "BA08_AB06", "(", "self", ",", "vs30", ",", "imt", ",", "pgar", ")", ":", "fa", "=", "np", ".", "ones_like", "(", "vs30", ")", "if", "np", ".", "isscalar", "(", "vs30", ")", ":", "vs30", "=", "np", ".", "array", "(", "[", "vs30", "]", ...
Computes amplification factor similarly to what is done in the 2015 version of the Canada building code. An initial version of this code was kindly provided by Michal Kolaj - Geological Survey of Canada :param vs30: Can be either a scalar or a :class:`~numpy.ndarray` instance ...
[ "Computes", "amplification", "factor", "similarly", "to", "what", "is", "done", "in", "the", "2015", "version", "of", "the", "Canada", "building", "code", ".", "An", "initial", "version", "of", "this", "code", "was", "kindly", "provided", "by", "Michal", "Ko...
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/gsim/mgmpe/nrcan15_site_term.py#L89-L149
gem/oq-engine
openquake/calculators/scenario_damage.py
scenario_damage
def scenario_damage(riskinputs, riskmodel, param, monitor): """ Core function for a damage computation. :param riskinputs: :class:`openquake.risklib.riskinput.RiskInput` objects :param riskmodel: a :class:`openquake.risklib.riskinput.CompositeRiskModel` instance :param monitor: ...
python
def scenario_damage(riskinputs, riskmodel, param, monitor): L = len(riskmodel.loss_types) D = len(riskmodel.damage_states) E = param['number_of_ground_motion_fields'] R = riskinputs[0].hazard_getter.num_rlzs result = dict(d_asset=[], d_event=numpy.zeros((E, R, L, D), F64), c_a...
[ "def", "scenario_damage", "(", "riskinputs", ",", "riskmodel", ",", "param", ",", "monitor", ")", ":", "L", "=", "len", "(", "riskmodel", ".", "loss_types", ")", "D", "=", "len", "(", "riskmodel", ".", "damage_states", ")", "E", "=", "param", "[", "'nu...
Core function for a damage computation. :param riskinputs: :class:`openquake.risklib.riskinput.RiskInput` objects :param riskmodel: a :class:`openquake.risklib.riskinput.CompositeRiskModel` instance :param monitor: :class:`openquake.baselib.performance.Monitor` instance :param p...
[ "Core", "function", "for", "a", "damage", "computation", "." ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/calculators/scenario_damage.py#L28-L71
gem/oq-engine
openquake/calculators/views.py
form
def form(value): """ Format numbers in a nice way. >>> form(0) '0' >>> form(0.0) '0.0' >>> form(0.0001) '1.000E-04' >>> form(1003.4) '1,003' >>> form(103.4) '103' >>> form(9.3) '9.30000' >>> form(-1.2) '-1.2' """ if isinstance(value, FLOAT + INT):...
python
def form(value): if isinstance(value, FLOAT + INT): if value <= 0: return str(value) elif value < .001: return '%.3E' % value elif value < 10 and isinstance(value, FLOAT): return '%.5f' % value elif value > 1000: return '{:,d}'.for...
[ "def", "form", "(", "value", ")", ":", "if", "isinstance", "(", "value", ",", "FLOAT", "+", "INT", ")", ":", "if", "value", "<=", "0", ":", "return", "str", "(", "value", ")", "elif", "value", "<", ".001", ":", "return", "'%.3E'", "%", "value", "...
Format numbers in a nice way. >>> form(0) '0' >>> form(0.0) '0.0' >>> form(0.0001) '1.000E-04' >>> form(1003.4) '1,003' >>> form(103.4) '103' >>> form(9.3) '9.30000' >>> form(-1.2) '-1.2'
[ "Format", "numbers", "in", "a", "nice", "way", "." ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/calculators/views.py#L51-L91
gem/oq-engine
openquake/calculators/views.py
rst_table
def rst_table(data, header=None, fmt=None): """ Build a .rst table from a matrix. >>> tbl = [['a', 1], ['b', 2]] >>> print(rst_table(tbl, header=['Name', 'Value'])) ==== ===== Name Value ==== ===== a 1 b 2 ==== ===== """ if header is None and hasattr(da...
python
def rst_table(data, header=None, fmt=None): if header is None and hasattr(data, '_fields'): header = data._fields try: data.dtype.fields except AttributeError: header = header or () else: if not header: header = [col.split(':')[0] for co...
[ "def", "rst_table", "(", "data", ",", "header", "=", "None", ",", "fmt", "=", "None", ")", ":", "if", "header", "is", "None", "and", "hasattr", "(", "data", ",", "'_fields'", ")", ":", "header", "=", "data", ".", "_fields", "try", ":", "# see if data...
Build a .rst table from a matrix. >>> tbl = [['a', 1], ['b', 2]] >>> print(rst_table(tbl, header=['Name', 'Value'])) ==== ===== Name Value ==== ===== a 1 b 2 ==== =====
[ "Build", "a", ".", "rst", "table", "from", "a", "matrix", ".", ">>>", "tbl", "=", "[[", "a", "1", "]", "[", "b", "2", "]]", ">>>", "print", "(", "rst_table", "(", "tbl", "header", "=", "[", "Name", "Value", "]", "))", "====", "=====", "Name", "...
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/calculators/views.py#L94-L142
gem/oq-engine
openquake/calculators/views.py
sum_tbl
def sum_tbl(tbl, kfield, vfields): """ Aggregate a composite array and compute the totals on a given key. >>> dt = numpy.dtype([('name', (bytes, 10)), ('value', int)]) >>> tbl = numpy.array([('a', 1), ('a', 2), ('b', 3)], dt) >>> sum_tbl(tbl, 'name', ['value'])['value'] array([3, 3]) """ ...
python
def sum_tbl(tbl, kfield, vfields): pairs = [(n, tbl.dtype[n]) for n in [kfield] + vfields] dt = numpy.dtype(pairs + [('counts', int)]) def sum_all(group): vals = numpy.zeros(1, dt)[0] for rec in group: for vfield in vfields: vals[vfield] += rec[vfield] ...
[ "def", "sum_tbl", "(", "tbl", ",", "kfield", ",", "vfields", ")", ":", "pairs", "=", "[", "(", "n", ",", "tbl", ".", "dtype", "[", "n", "]", ")", "for", "n", "in", "[", "kfield", "]", "+", "vfields", "]", "dt", "=", "numpy", ".", "dtype", "("...
Aggregate a composite array and compute the totals on a given key. >>> dt = numpy.dtype([('name', (bytes, 10)), ('value', int)]) >>> tbl = numpy.array([('a', 1), ('a', 2), ('b', 3)], dt) >>> sum_tbl(tbl, 'name', ['value'])['value'] array([3, 3])
[ "Aggregate", "a", "composite", "array", "and", "compute", "the", "totals", "on", "a", "given", "key", "." ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/calculators/views.py#L145-L170
gem/oq-engine
openquake/calculators/views.py
view_slow_sources
def view_slow_sources(token, dstore, maxrows=20): """ Returns the slowest sources """ info = dstore['source_info'].value info.sort(order='calc_time') return rst_table(info[::-1][:maxrows])
python
def view_slow_sources(token, dstore, maxrows=20): info = dstore['source_info'].value info.sort(order='calc_time') return rst_table(info[::-1][:maxrows])
[ "def", "view_slow_sources", "(", "token", ",", "dstore", ",", "maxrows", "=", "20", ")", ":", "info", "=", "dstore", "[", "'source_info'", "]", ".", "value", "info", ".", "sort", "(", "order", "=", "'calc_time'", ")", "return", "rst_table", "(", "info", ...
Returns the slowest sources
[ "Returns", "the", "slowest", "sources" ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/calculators/views.py#L183-L189
gem/oq-engine
openquake/calculators/views.py
view_contents
def view_contents(token, dstore): """ Returns the size of the contents of the datastore and its total size """ try: desc = dstore['oqparam'].description except KeyError: desc = '' data = sorted((dstore.getsize(key), key) for key in dstore) rows = [(key, humansize(nbytes)) for...
python
def view_contents(token, dstore): try: desc = dstore['oqparam'].description except KeyError: desc = '' data = sorted((dstore.getsize(key), key) for key in dstore) rows = [(key, humansize(nbytes)) for nbytes, key in data] total = '\n%s : %s' % ( dstore.filename, humansize...
[ "def", "view_contents", "(", "token", ",", "dstore", ")", ":", "try", ":", "desc", "=", "dstore", "[", "'oqparam'", "]", ".", "description", "except", "KeyError", ":", "desc", "=", "''", "data", "=", "sorted", "(", "(", "dstore", ".", "getsize", "(", ...
Returns the size of the contents of the datastore and its total size
[ "Returns", "the", "size", "of", "the", "contents", "of", "the", "datastore", "and", "its", "total", "size" ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/calculators/views.py#L193-L205
gem/oq-engine
openquake/calculators/views.py
view_job_info
def view_job_info(token, dstore): """ Determine the amount of data transferred from the controller node to the workers and back in a classical calculation. """ data = [['task', 'sent', 'received']] for task in dstore['task_info']: dset = dstore['task_info/' + task] if 'argnames' ...
python
def view_job_info(token, dstore): data = [['task', 'sent', 'received']] for task in dstore['task_info']: dset = dstore['task_info/' + task] if 'argnames' in dset.attrs: argnames = dset.attrs['argnames'].split() totsent = dset.attrs['sent'] sent = ['%s=%s'...
[ "def", "view_job_info", "(", "token", ",", "dstore", ")", ":", "data", "=", "[", "[", "'task'", ",", "'sent'", ",", "'received'", "]", "]", "for", "task", "in", "dstore", "[", "'task_info'", "]", ":", "dset", "=", "dstore", "[", "'task_info/'", "+", ...
Determine the amount of data transferred from the controller node to the workers and back in a classical calculation.
[ "Determine", "the", "amount", "of", "data", "transferred", "from", "the", "controller", "node", "to", "the", "workers", "and", "back", "in", "a", "classical", "calculation", "." ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/calculators/views.py#L309-L324
gem/oq-engine
openquake/calculators/views.py
avglosses_data_transfer
def avglosses_data_transfer(token, dstore): """ Determine the amount of average losses transferred from the workers to the controller node in a risk calculation. """ oq = dstore['oqparam'] N = len(dstore['assetcol']) R = dstore['csm_info'].get_num_rlzs() L = len(dstore.get_attr('risk_mod...
python
def avglosses_data_transfer(token, dstore): oq = dstore['oqparam'] N = len(dstore['assetcol']) R = dstore['csm_info'].get_num_rlzs() L = len(dstore.get_attr('risk_model', 'loss_types')) ct = oq.concurrent_tasks size_bytes = N * R * L * 8 * ct return ( '%d asset(s) x %d realiza...
[ "def", "avglosses_data_transfer", "(", "token", ",", "dstore", ")", ":", "oq", "=", "dstore", "[", "'oqparam'", "]", "N", "=", "len", "(", "dstore", "[", "'assetcol'", "]", ")", "R", "=", "dstore", "[", "'csm_info'", "]", ".", "get_num_rlzs", "(", ")",...
Determine the amount of average losses transferred from the workers to the controller node in a risk calculation.
[ "Determine", "the", "amount", "of", "average", "losses", "transferred", "from", "the", "workers", "to", "the", "controller", "node", "in", "a", "risk", "calculation", "." ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/calculators/views.py#L328-L341