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/commands/purge.py
purge
def purge(calc_id): """ Remove the given calculation. If you want to remove all calculations, use oq reset. """ if calc_id < 0: try: calc_id = datastore.get_calc_ids(datadir)[calc_id] except IndexError: print('Calculation %d not found' % calc_id) r...
python
def purge(calc_id): if calc_id < 0: try: calc_id = datastore.get_calc_ids(datadir)[calc_id] except IndexError: print('Calculation %d not found' % calc_id) return purge_one(calc_id, getpass.getuser())
[ "def", "purge", "(", "calc_id", ")", ":", "if", "calc_id", "<", "0", ":", "try", ":", "calc_id", "=", "datastore", ".", "get_calc_ids", "(", "datadir", ")", "[", "calc_id", "]", "except", "IndexError", ":", "print", "(", "'Calculation %d not found'", "%", ...
Remove the given calculation. If you want to remove all calculations, use oq reset.
[ "Remove", "the", "given", "calculation", ".", "If", "you", "want", "to", "remove", "all", "calculations", "use", "oq", "reset", "." ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/commands/purge.py#L60-L71
gem/oq-engine
openquake/hmtk/plotting/patch.py
PolygonPatch
def PolygonPatch(polygon, **kwargs): """Constructs a matplotlib patch from a geometric object The `polygon` may be a Shapely or GeoJSON-like object possibly with holes. The `kwargs` are those supported by the matplotlib.patches.Polygon class constructor. Returns an instance of matplotlib.patches.PathPa...
python
def PolygonPatch(polygon, **kwargs): def coding(ob): n = len(getattr(ob, 'coords', None) or ob) vals = ones(n, dtype=Path.code_type) * Path.LINETO vals[0] = Path.MOVETO return vals if hasattr(polygon, 'geom_type'): ptype = polygon.geom_type ...
[ "def", "PolygonPatch", "(", "polygon", ",", "*", "*", "kwargs", ")", ":", "def", "coding", "(", "ob", ")", ":", "# The codes will be all \"LINETO\" commands, except for \"MOVETO\"s at the", "# beginning of each subpath", "n", "=", "len", "(", "getattr", "(", "ob", "...
Constructs a matplotlib patch from a geometric object The `polygon` may be a Shapely or GeoJSON-like object possibly with holes. The `kwargs` are those supported by the matplotlib.patches.Polygon class constructor. Returns an instance of matplotlib.patches.PathPatch. Example (using Shapely Point and a...
[ "Constructs", "a", "matplotlib", "patch", "from", "a", "geometric", "object" ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hmtk/plotting/patch.py#L43-L93
gem/oq-engine
openquake/hazardlib/gsim/kotha_2019.py
KothaEtAl2019.retreive_sigma_mu_data
def retreive_sigma_mu_data(self): """ For the general form of the GMPE this retrieves the sigma mu values from the hdf5 file using the "general" model, i.e. sigma mu factors that are independent of the choice of region or depth """ fle = h5py.File(os.path.join(BASE_PATH, ...
python
def retreive_sigma_mu_data(self): fle = h5py.File(os.path.join(BASE_PATH, "KothaEtAl2019_SigmaMu_Fixed.hdf5"), "r") self.mags = fle["M"][:] self.dists = fle["R"][:] self.periods = fle["T"][:] self.pga = fle["PGA"][:] self.pgv ...
[ "def", "retreive_sigma_mu_data", "(", "self", ")", ":", "fle", "=", "h5py", ".", "File", "(", "os", ".", "path", ".", "join", "(", "BASE_PATH", ",", "\"KothaEtAl2019_SigmaMu_Fixed.hdf5\"", ")", ",", "\"r\"", ")", "self", ".", "mags", "=", "fle", "[", "\"...
For the general form of the GMPE this retrieves the sigma mu values from the hdf5 file using the "general" model, i.e. sigma mu factors that are independent of the choice of region or depth
[ "For", "the", "general", "form", "of", "the", "GMPE", "this", "retrieves", "the", "sigma", "mu", "values", "from", "the", "hdf5", "file", "using", "the", "general", "model", "i", ".", "e", ".", "sigma", "mu", "factors", "that", "are", "independent", "of"...
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/gsim/kotha_2019.py#L129-L143
gem/oq-engine
openquake/hazardlib/gsim/kotha_2019.py
KothaEtAl2019.get_mean_and_stddevs
def get_mean_and_stddevs(self, sites, rup, dists, imt, stddev_types): """ See :meth:`superclass method <.base.GroundShakingIntensityModel.get_mean_and_stddevs>` for spec of input and result values. """ # extracting dictionary of coefficients specific to required #...
python
def get_mean_and_stddevs(self, sites, rup, dists, imt, stddev_types): C = self.COEFFS[imt] mean = (self.get_magnitude_scaling(C, rup.mag) + self.get_distance_term(C, rup, dists.rjb, imt) + self.get_site_amplification(C, sites)) ...
[ "def", "get_mean_and_stddevs", "(", "self", ",", "sites", ",", "rup", ",", "dists", ",", "imt", ",", "stddev_types", ")", ":", "# extracting dictionary of coefficients specific to required", "# intensity measure type.", "C", "=", "self", ".", "COEFFS", "[", "imt", "...
See :meth:`superclass method <.base.GroundShakingIntensityModel.get_mean_and_stddevs>` for spec of input and result values.
[ "See", ":", "meth", ":", "superclass", "method", "<", ".", "base", ".", "GroundShakingIntensityModel", ".", "get_mean_and_stddevs", ">", "for", "spec", "of", "input", "and", "result", "values", "." ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/gsim/kotha_2019.py#L145-L172
gem/oq-engine
openquake/hazardlib/gsim/kotha_2019.py
KothaEtAl2019.get_magnitude_scaling
def get_magnitude_scaling(self, C, mag): """ Returns the magnitude scaling term """ d_m = mag - self.CONSTANTS["Mh"] if mag < self.CONSTANTS["Mh"]: return C["e1"] + C["b1"] * d_m + C["b2"] * (d_m ** 2.0) else: return C["e1"] + C["b3"] * d_m
python
def get_magnitude_scaling(self, C, mag): d_m = mag - self.CONSTANTS["Mh"] if mag < self.CONSTANTS["Mh"]: return C["e1"] + C["b1"] * d_m + C["b2"] * (d_m ** 2.0) else: return C["e1"] + C["b3"] * d_m
[ "def", "get_magnitude_scaling", "(", "self", ",", "C", ",", "mag", ")", ":", "d_m", "=", "mag", "-", "self", ".", "CONSTANTS", "[", "\"Mh\"", "]", "if", "mag", "<", "self", ".", "CONSTANTS", "[", "\"Mh\"", "]", ":", "return", "C", "[", "\"e1\"", "]...
Returns the magnitude scaling term
[ "Returns", "the", "magnitude", "scaling", "term" ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/gsim/kotha_2019.py#L174-L182
gem/oq-engine
openquake/hazardlib/gsim/kotha_2019.py
KothaEtAl2019.get_distance_term
def get_distance_term(self, C, rup, rjb, imt): """ Returns the distance attenuation factor """ h = self._get_h(C, rup.hypo_depth) rval = np.sqrt(rjb ** 2. + h ** 2.) c3 = self.get_distance_coefficients(C, imt) f_r = (C["c1"] + C["c2"] * (rup.mag - self.CONSTANTS[...
python
def get_distance_term(self, C, rup, rjb, imt): h = self._get_h(C, rup.hypo_depth) rval = np.sqrt(rjb ** 2. + h ** 2.) c3 = self.get_distance_coefficients(C, imt) f_r = (C["c1"] + C["c2"] * (rup.mag - self.CONSTANTS["Mref"])) *\ np.log(rval / self.CONSTANTS["Rref"]) ...
[ "def", "get_distance_term", "(", "self", ",", "C", ",", "rup", ",", "rjb", ",", "imt", ")", ":", "h", "=", "self", ".", "_get_h", "(", "C", ",", "rup", ".", "hypo_depth", ")", "rval", "=", "np", ".", "sqrt", "(", "rjb", "**", "2.", "+", "h", ...
Returns the distance attenuation factor
[ "Returns", "the", "distance", "attenuation", "factor" ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/gsim/kotha_2019.py#L184-L195
gem/oq-engine
openquake/hazardlib/gsim/kotha_2019.py
KothaEtAl2019.get_distance_coefficients
def get_distance_coefficients(self, C, imt): """ Returns the c3 term """ c3 = self.c3[imt]["c3"] if self.c3 else C["c3"] return c3
python
def get_distance_coefficients(self, C, imt): c3 = self.c3[imt]["c3"] if self.c3 else C["c3"] return c3
[ "def", "get_distance_coefficients", "(", "self", ",", "C", ",", "imt", ")", ":", "c3", "=", "self", ".", "c3", "[", "imt", "]", "[", "\"c3\"", "]", "if", "self", ".", "c3", "else", "C", "[", "\"c3\"", "]", "return", "c3" ]
Returns the c3 term
[ "Returns", "the", "c3", "term" ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/gsim/kotha_2019.py#L208-L213
gem/oq-engine
openquake/hazardlib/gsim/kotha_2019.py
KothaEtAl2019.get_sigma_mu_adjustment
def get_sigma_mu_adjustment(self, C, imt, rup, dists): """ Returns the sigma mu adjustment factor """ if imt.name in "PGA PGV": # PGA and PGV are 2D arrays of dimension [nmags, ndists] sigma_mu = getattr(self, imt.name.lower()) if rup.mag <= self.mags[...
python
def get_sigma_mu_adjustment(self, C, imt, rup, dists): if imt.name in "PGA PGV": sigma_mu = getattr(self, imt.name.lower()) if rup.mag <= self.mags[0]: sigma_mu_m = sigma_mu[0, :] elif rup.mag >= self.mags[-1]: sigma_mu_m ...
[ "def", "get_sigma_mu_adjustment", "(", "self", ",", "C", ",", "imt", ",", "rup", ",", "dists", ")", ":", "if", "imt", ".", "name", "in", "\"PGA PGV\"", ":", "# PGA and PGV are 2D arrays of dimension [nmags, ndists]", "sigma_mu", "=", "getattr", "(", "self", ",",...
Returns the sigma mu adjustment factor
[ "Returns", "the", "sigma", "mu", "adjustment", "factor" ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/gsim/kotha_2019.py#L221-L258
gem/oq-engine
openquake/hazardlib/gsim/kotha_2019.py
KothaEtAl2019SERA.get_site_amplification
def get_site_amplification(self, C, sites): """ Returns the linear site amplification term depending on whether the Vs30 is observed of inferred """ ampl = np.zeros(sites.vs30.shape) # For observed vs30 sites ampl[sites.vs30measured] = (C["d0_obs"] + C["d1_obs"] *...
python
def get_site_amplification(self, C, sites): ampl = np.zeros(sites.vs30.shape) ampl[sites.vs30measured] = (C["d0_obs"] + C["d1_obs"] * np.log(sites.vs30[sites.vs30measured])) idx = np.logical_not(sites.vs30measured) ampl[idx] ...
[ "def", "get_site_amplification", "(", "self", ",", "C", ",", "sites", ")", ":", "ampl", "=", "np", ".", "zeros", "(", "sites", ".", "vs30", ".", "shape", ")", "# For observed vs30 sites", "ampl", "[", "sites", ".", "vs30measured", "]", "=", "(", "C", "...
Returns the linear site amplification term depending on whether the Vs30 is observed of inferred
[ "Returns", "the", "linear", "site", "amplification", "term", "depending", "on", "whether", "the", "Vs30", "is", "observed", "of", "inferred" ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/gsim/kotha_2019.py#L332-L344
gem/oq-engine
openquake/hazardlib/gsim/kotha_2019.py
KothaEtAl2019SERA.get_stddevs
def get_stddevs(self, C, stddev_shape, stddev_types, sites): """ Returns the standard deviations, with different site standard deviation for inferred vs. observed vs30 sites. """ stddevs = [] tau = C["tau_event"] sigma_s = np.zeros(sites.vs30measured.shape, dtype=...
python
def get_stddevs(self, C, stddev_shape, stddev_types, sites): stddevs = [] tau = C["tau_event"] sigma_s = np.zeros(sites.vs30measured.shape, dtype=float) sigma_s[sites.vs30measured] += C["sigma_s_obs"] sigma_s[np.logical_not(sites.vs30measured)] += C["sigma_s_inf"] ...
[ "def", "get_stddevs", "(", "self", ",", "C", ",", "stddev_shape", ",", "stddev_types", ",", "sites", ")", ":", "stddevs", "=", "[", "]", "tau", "=", "C", "[", "\"tau_event\"", "]", "sigma_s", "=", "np", ".", "zeros", "(", "sites", ".", "vs30measured", ...
Returns the standard deviations, with different site standard deviation for inferred vs. observed vs30 sites.
[ "Returns", "the", "standard", "deviations", "with", "different", "site", "standard", "deviation", "for", "inferred", "vs", ".", "observed", "vs30", "sites", "." ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/gsim/kotha_2019.py#L346-L366
gem/oq-engine
openquake/hazardlib/geo/geodetic.py
geodetic_distance
def geodetic_distance(lons1, lats1, lons2, lats2, diameter=2*EARTH_RADIUS): """ Calculate the geodetic distance between two points or two collections of points. Parameters are coordinates in decimal degrees. They could be scalar float numbers or numpy arrays, in which case they should "broadcast ...
python
def geodetic_distance(lons1, lats1, lons2, lats2, diameter=2*EARTH_RADIUS): lons1, lats1, lons2, lats2 = _prepare_coords(lons1, lats1, lons2, lats2) distance = numpy.arcsin(numpy.sqrt( numpy.sin((lats1 - lats2) / 2.0) ** 2.0 + numpy.cos(lats1) * numpy.cos(lats2) * numpy.sin((lons1 -...
[ "def", "geodetic_distance", "(", "lons1", ",", "lats1", ",", "lons2", ",", "lats2", ",", "diameter", "=", "2", "*", "EARTH_RADIUS", ")", ":", "lons1", ",", "lats1", ",", "lons2", ",", "lats2", "=", "_prepare_coords", "(", "lons1", ",", "lats1", ",", "l...
Calculate the geodetic distance between two points or two collections of points. Parameters are coordinates in decimal degrees. They could be scalar float numbers or numpy arrays, in which case they should "broadcast together". Implements http://williams.best.vwh.net/avform.htm#Dist :returns:...
[ "Calculate", "the", "geodetic", "distance", "between", "two", "points", "or", "two", "collections", "of", "points", "." ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/geo/geodetic.py#L34-L54
gem/oq-engine
openquake/hazardlib/geo/geodetic.py
azimuth
def azimuth(lons1, lats1, lons2, lats2): """ Calculate the azimuth between two points or two collections of points. Parameters are the same as for :func:`geodetic_distance`. Implements an "alternative formula" from http://williams.best.vwh.net/avform.htm#Crs :returns: Azimuth as an an...
python
def azimuth(lons1, lats1, lons2, lats2): lons1, lats1, lons2, lats2 = _prepare_coords(lons1, lats1, lons2, lats2) cos_lat2 = numpy.cos(lats2) true_course = numpy.degrees(numpy.arctan2( numpy.sin(lons1 - lons2) * cos_lat2, numpy.cos(lats1) * numpy.sin(lats2) - numpy.sin(lats1) * ...
[ "def", "azimuth", "(", "lons1", ",", "lats1", ",", "lons2", ",", "lats2", ")", ":", "lons1", ",", "lats1", ",", "lons2", ",", "lats2", "=", "_prepare_coords", "(", "lons1", ",", "lats1", ",", "lons2", ",", "lats2", ")", "cos_lat2", "=", "numpy", ".",...
Calculate the azimuth between two points or two collections of points. Parameters are the same as for :func:`geodetic_distance`. Implements an "alternative formula" from http://williams.best.vwh.net/avform.htm#Crs :returns: Azimuth as an angle between direction to north from first point and ...
[ "Calculate", "the", "azimuth", "between", "two", "points", "or", "two", "collections", "of", "points", "." ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/geo/geodetic.py#L57-L77
gem/oq-engine
openquake/hazardlib/geo/geodetic.py
distance
def distance(lons1, lats1, depths1, lons2, lats2, depths2): """ Calculate a distance between two points (or collections of points) considering points' depth. Calls :func:`geodetic_distance`, finds the "vertical" distance between points by subtracting one depth from another and combine both using ...
python
def distance(lons1, lats1, depths1, lons2, lats2, depths2): hdist = geodetic_distance(lons1, lats1, lons2, lats2) vdist = depths1 - depths2 return numpy.sqrt(hdist ** 2 + vdist ** 2)
[ "def", "distance", "(", "lons1", ",", "lats1", ",", "depths1", ",", "lons2", ",", "lats2", ",", "depths2", ")", ":", "hdist", "=", "geodetic_distance", "(", "lons1", ",", "lats1", ",", "lons2", ",", "lats2", ")", "vdist", "=", "depths1", "-", "depths2"...
Calculate a distance between two points (or collections of points) considering points' depth. Calls :func:`geodetic_distance`, finds the "vertical" distance between points by subtracting one depth from another and combine both using Pythagoras theorem. :returns: Distance in km, a square ro...
[ "Calculate", "a", "distance", "between", "two", "points", "(", "or", "collections", "of", "points", ")", "considering", "points", "depth", "." ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/geo/geodetic.py#L80-L96
gem/oq-engine
openquake/hazardlib/geo/geodetic.py
min_distance_to_segment
def min_distance_to_segment(seglons, seglats, lons, lats): """ This function computes the shortest distance to a segment in a 2D reference system. :parameter seglons: A list or an array of floats specifying the longitude values of the two vertexes delimiting the segment. :parameter ...
python
def min_distance_to_segment(seglons, seglats, lons, lats): assert len(seglons) == len(seglats) == 2 seg_azim = azimuth(seglons[0], seglats[0], seglons[1], seglats[1]) azimuth1 = azimuth(seglons[0], seglats[0], lons, lats) azimuth2 = azimuth(seglons[1], seglats[1], ...
[ "def", "min_distance_to_segment", "(", "seglons", ",", "seglats", ",", "lons", ",", "lats", ")", ":", "# Check the size of the seglons, seglats arrays", "assert", "len", "(", "seglons", ")", "==", "len", "(", "seglats", ")", "==", "2", "# Compute the azimuth of the ...
This function computes the shortest distance to a segment in a 2D reference system. :parameter seglons: A list or an array of floats specifying the longitude values of the two vertexes delimiting the segment. :parameter seglats: A list or an array of floats specifying the latitude v...
[ "This", "function", "computes", "the", "shortest", "distance", "to", "a", "segment", "in", "a", "2D", "reference", "system", "." ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/geo/geodetic.py#L99-L174
gem/oq-engine
openquake/hazardlib/geo/geodetic.py
spherical_to_cartesian
def spherical_to_cartesian(lons, lats, depths=None): """ Return the position vectors (in Cartesian coordinates) of list of spherical coordinates. For equations see: http://mathworld.wolfram.com/SphericalCoordinates.html. Parameters are components of spherical coordinates in a form of scalars, ...
python
def spherical_to_cartesian(lons, lats, depths=None): phi = numpy.radians(lons) theta = numpy.radians(lats) if depths is None: rr = EARTH_RADIUS else: rr = EARTH_RADIUS - numpy.array(depths) cos_theta_r = rr * numpy.cos(theta) try: shape = lons.shape except Attrib...
[ "def", "spherical_to_cartesian", "(", "lons", ",", "lats", ",", "depths", "=", "None", ")", ":", "phi", "=", "numpy", ".", "radians", "(", "lons", ")", "theta", "=", "numpy", ".", "radians", "(", "lats", ")", "if", "depths", "is", "None", ":", "rr", ...
Return the position vectors (in Cartesian coordinates) of list of spherical coordinates. For equations see: http://mathworld.wolfram.com/SphericalCoordinates.html. Parameters are components of spherical coordinates in a form of scalars, lists or numpy arrays. ``depths`` can be ``None`` in which case i...
[ "Return", "the", "position", "vectors", "(", "in", "Cartesian", "coordinates", ")", "of", "list", "of", "spherical", "coordinates", "." ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/geo/geodetic.py#L183-L221
gem/oq-engine
openquake/hazardlib/geo/geodetic.py
min_geodetic_distance
def min_geodetic_distance(a, b): """ Compute the minimum distance between first mesh and each point of the second mesh when both are defined on the earth surface. :param a: a pair of (lons, lats) or an array of cartesian coordinates :param b: a pair of (lons, lats) or an array of cartesian coordina...
python
def min_geodetic_distance(a, b): if isinstance(a, tuple): a = spherical_to_cartesian(a[0].flatten(), a[1].flatten()) if isinstance(b, tuple): b = spherical_to_cartesian(b[0].flatten(), b[1].flatten()) return cdist(a, b).min(axis=0)
[ "def", "min_geodetic_distance", "(", "a", ",", "b", ")", ":", "if", "isinstance", "(", "a", ",", "tuple", ")", ":", "a", "=", "spherical_to_cartesian", "(", "a", "[", "0", "]", ".", "flatten", "(", ")", ",", "a", "[", "1", "]", ".", "flatten", "(...
Compute the minimum distance between first mesh and each point of the second mesh when both are defined on the earth surface. :param a: a pair of (lons, lats) or an array of cartesian coordinates :param b: a pair of (lons, lats) or an array of cartesian coordinates
[ "Compute", "the", "minimum", "distance", "between", "first", "mesh", "and", "each", "point", "of", "the", "second", "mesh", "when", "both", "are", "defined", "on", "the", "earth", "surface", "." ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/geo/geodetic.py#L224-L236
gem/oq-engine
openquake/hazardlib/geo/geodetic.py
distance_matrix
def distance_matrix(lons, lats, diameter=2*EARTH_RADIUS): """ :param lons: array of m longitudes :param lats: array of m latitudes :returns: matrix of (m, m) distances """ m = len(lons) assert m == len(lats), (m, len(lats)) lons = numpy.radians(lons) lats = numpy.radians(lats) co...
python
def distance_matrix(lons, lats, diameter=2*EARTH_RADIUS): m = len(lons) assert m == len(lats), (m, len(lats)) lons = numpy.radians(lons) lats = numpy.radians(lats) cos_lats = numpy.cos(lats) result = numpy.zeros((m, m)) for i in range(len(lons)): a = numpy.sin((lats[i] - lats) /...
[ "def", "distance_matrix", "(", "lons", ",", "lats", ",", "diameter", "=", "2", "*", "EARTH_RADIUS", ")", ":", "m", "=", "len", "(", "lons", ")", "assert", "m", "==", "len", "(", "lats", ")", ",", "(", "m", ",", "len", "(", "lats", ")", ")", "lo...
:param lons: array of m longitudes :param lats: array of m latitudes :returns: matrix of (m, m) distances
[ ":", "param", "lons", ":", "array", "of", "m", "longitudes", ":", "param", "lats", ":", "array", "of", "m", "latitudes", ":", "returns", ":", "matrix", "of", "(", "m", "m", ")", "distances" ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/geo/geodetic.py#L239-L256
gem/oq-engine
openquake/hazardlib/geo/geodetic.py
intervals_between
def intervals_between(lon1, lat1, depth1, lon2, lat2, depth2, length): """ Find a list of points between two given ones that lie on the same great circle arc and are equally spaced by ``length`` km. :param float lon1, lat1, depth1: Coordinates of a point to start placing intervals from. The fir...
python
def intervals_between(lon1, lat1, depth1, lon2, lat2, depth2, length): assert length > 0 hdist = geodetic_distance(lon1, lat1, lon2, lat2) vdist = depth2 - depth1 total_distance = round(numpy.sqrt(hdist ** 2 + vdist ** 2), 7) num_intervals = int...
[ "def", "intervals_between", "(", "lon1", ",", "lat1", ",", "depth1", ",", "lon2", ",", "lat2", ",", "depth2", ",", "length", ")", ":", "assert", "length", ">", "0", "hdist", "=", "geodetic_distance", "(", "lon1", ",", "lat1", ",", "lon2", ",", "lat2", ...
Find a list of points between two given ones that lie on the same great circle arc and are equally spaced by ``length`` km. :param float lon1, lat1, depth1: Coordinates of a point to start placing intervals from. The first point in the resulting list has these coordinates. :param float lon2...
[ "Find", "a", "list", "of", "points", "between", "two", "given", "ones", "that", "lie", "on", "the", "same", "great", "circle", "arc", "and", "are", "equally", "spaced", "by", "length", "km", "." ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/geo/geodetic.py#L259-L302
gem/oq-engine
openquake/hazardlib/geo/geodetic.py
npoints_between
def npoints_between(lon1, lat1, depth1, lon2, lat2, depth2, npoints): """ Find a list of specified number of points between two given ones that are equally spaced along the great circle arc connecting given points. :param float lon1, lat1, depth1: Coordinates of a point to start from. The first...
python
def npoints_between(lon1, lat1, depth1, lon2, lat2, depth2, npoints): hdist = geodetic_distance(lon1, lat1, lon2, lat2) vdist = depth2 - depth1 rlons, rlats, rdepths = npoints_towards( lon1, lat1, depth1, azimuth(lon1, lat1, lon2, lat2), hdist, vdist, npoints ) rlons[-1] = ...
[ "def", "npoints_between", "(", "lon1", ",", "lat1", ",", "depth1", ",", "lon2", ",", "lat2", ",", "depth2", ",", "npoints", ")", ":", "hdist", "=", "geodetic_distance", "(", "lon1", ",", "lat1", ",", "lon2", ",", "lat2", ")", "vdist", "=", "depth2", ...
Find a list of specified number of points between two given ones that are equally spaced along the great circle arc connecting given points. :param float lon1, lat1, depth1: Coordinates of a point to start from. The first point in a resulting list has these coordinates. :param float lon2, l...
[ "Find", "a", "list", "of", "specified", "number", "of", "points", "between", "two", "given", "ones", "that", "are", "equally", "spaced", "along", "the", "great", "circle", "arc", "connecting", "given", "points", "." ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/geo/geodetic.py#L305-L336
gem/oq-engine
openquake/hazardlib/geo/geodetic.py
npoints_towards
def npoints_towards(lon, lat, depth, azimuth, hdist, vdist, npoints): """ Find a list of specified number of points starting from a given one along a great circle arc with a given azimuth measured in a given point. :param float lon, lat, depth: Coordinates of a point to start from. The first po...
python
def npoints_towards(lon, lat, depth, azimuth, hdist, vdist, npoints): assert npoints > 1 rlon, rlat = numpy.radians(lon), numpy.radians(lat) tc = numpy.radians(360 - azimuth) hdists = numpy.arange(npoints, dtype=float) hdists *= (hdist / EARTH_RADIUS) / (npoints - 1) vdists = numpy.arange(n...
[ "def", "npoints_towards", "(", "lon", ",", "lat", ",", "depth", ",", "azimuth", ",", "hdist", ",", "vdist", ",", "npoints", ")", ":", "assert", "npoints", ">", "1", "rlon", ",", "rlat", "=", "numpy", ".", "radians", "(", "lon", ")", ",", "numpy", "...
Find a list of specified number of points starting from a given one along a great circle arc with a given azimuth measured in a given point. :param float lon, lat, depth: Coordinates of a point to start from. The first point in a resulting list has these coordinates. :param azimuth: ...
[ "Find", "a", "list", "of", "specified", "number", "of", "points", "starting", "from", "a", "given", "one", "along", "a", "great", "circle", "arc", "with", "a", "given", "azimuth", "measured", "in", "a", "given", "point", "." ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/geo/geodetic.py#L339-L393
gem/oq-engine
openquake/hazardlib/geo/geodetic.py
point_at
def point_at(lon, lat, azimuth, distance): """ Perform a forward geodetic transformation: find a point lying at a given distance from a given one on a great circle arc defined by azimuth. :param float lon, lat: Coordinates of a reference point, in decimal degrees. :param azimuth: An...
python
def point_at(lon, lat, azimuth, distance): lon, lat = numpy.radians(lon), numpy.radians(lat) tc = numpy.radians(360 - azimuth) sin_dists = numpy.sin(distance / EARTH_RADIUS) cos_dists = numpy.cos(distance / EARTH_RADIUS) sin_lat = numpy.sin(lat) cos_lat = numpy.cos(lat) sin_l...
[ "def", "point_at", "(", "lon", ",", "lat", ",", "azimuth", ",", "distance", ")", ":", "# this is a simplified version of npoints_towards().", "# code duplication is justified by performance reasons.", "lon", ",", "lat", "=", "numpy", ".", "radians", "(", "lon", ")", "...
Perform a forward geodetic transformation: find a point lying at a given distance from a given one on a great circle arc defined by azimuth. :param float lon, lat: Coordinates of a reference point, in decimal degrees. :param azimuth: An azimuth of a great circle arc of interest measured in ...
[ "Perform", "a", "forward", "geodetic", "transformation", ":", "find", "a", "point", "lying", "at", "a", "given", "distance", "from", "a", "given", "one", "on", "a", "great", "circle", "arc", "defined", "by", "azimuth", "." ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/geo/geodetic.py#L396-L431
gem/oq-engine
openquake/hazardlib/geo/geodetic.py
distance_to_semi_arc
def distance_to_semi_arc(alon, alat, aazimuth, plons, plats): """ In this method we use a reference system centerd on (alon, alat) and with the y-axis corresponding to aazimuth direction to calculate the minimum distance from a semiarc with generates in (alon, alat). Parameters are the same as for ...
python
def distance_to_semi_arc(alon, alat, aazimuth, plons, plats): if type(plons) is float: plons = numpy.array([plons]) plats = numpy.array([plats]) azimuth_to_target = azimuth(alon, alat, plons, plats) idx = numpy.nonzero(numpy.cos( numpy.radians((aazimuth-azimuth_to_target...
[ "def", "distance_to_semi_arc", "(", "alon", ",", "alat", ",", "aazimuth", ",", "plons", ",", "plats", ")", ":", "if", "type", "(", "plons", ")", "is", "float", ":", "plons", "=", "numpy", ".", "array", "(", "[", "plons", "]", ")", "plats", "=", "nu...
In this method we use a reference system centerd on (alon, alat) and with the y-axis corresponding to aazimuth direction to calculate the minimum distance from a semiarc with generates in (alon, alat). Parameters are the same as for :func:`distance_to_arc`.
[ "In", "this", "method", "we", "use", "a", "reference", "system", "centerd", "on", "(", "alon", "alat", ")", "and", "with", "the", "y", "-", "axis", "corresponding", "to", "aazimuth", "direction", "to", "calculate", "the", "minimum", "distance", "from", "a"...
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/geo/geodetic.py#L434-L486
gem/oq-engine
openquake/hazardlib/geo/geodetic.py
distance_to_arc
def distance_to_arc(alon, alat, aazimuth, plons, plats): """ Calculate a closest distance between a great circle arc and a point (or a collection of points). :param float alon, alat: Arc reference point longitude and latitude, in decimal degrees. :param azimuth: Arc azimuth (an angl...
python
def distance_to_arc(alon, alat, aazimuth, plons, plats): azimuth_to_target = azimuth(alon, alat, plons, plats) distance_to_target = geodetic_distance(alon, alat, plons, plats) t_angle = (azimuth_to_target - aazimuth + 360) % 360 angle = numpy.arccos( (numpy.s...
[ "def", "distance_to_arc", "(", "alon", ",", "alat", ",", "aazimuth", ",", "plons", ",", "plats", ")", ":", "azimuth_to_target", "=", "azimuth", "(", "alon", ",", "alat", ",", "plons", ",", "plats", ")", "distance_to_target", "=", "geodetic_distance", "(", ...
Calculate a closest distance between a great circle arc and a point (or a collection of points). :param float alon, alat: Arc reference point longitude and latitude, in decimal degrees. :param azimuth: Arc azimuth (an angle between direction to a north and arc in clockwise direction...
[ "Calculate", "a", "closest", "distance", "between", "a", "great", "circle", "arc", "and", "a", "point", "(", "or", "a", "collection", "of", "points", ")", "." ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/geo/geodetic.py#L489-L525
gem/oq-engine
openquake/hazardlib/geo/geodetic.py
_prepare_coords
def _prepare_coords(lons1, lats1, lons2, lats2): """ Convert two pairs of spherical coordinates in decimal degrees to numpy arrays of radians. Makes sure that respective coordinates in pairs have the same shape. """ lons1 = numpy.radians(lons1) lats1 = numpy.radians(lats1) assert lons1.s...
python
def _prepare_coords(lons1, lats1, lons2, lats2): lons1 = numpy.radians(lons1) lats1 = numpy.radians(lats1) assert lons1.shape == lats1.shape lons2 = numpy.radians(lons2) lats2 = numpy.radians(lats2) assert lons2.shape == lats2.shape return lons1, lats1, lons2, lats2
[ "def", "_prepare_coords", "(", "lons1", ",", "lats1", ",", "lons2", ",", "lats2", ")", ":", "lons1", "=", "numpy", ".", "radians", "(", "lons1", ")", "lats1", "=", "numpy", ".", "radians", "(", "lats1", ")", "assert", "lons1", ".", "shape", "==", "la...
Convert two pairs of spherical coordinates in decimal degrees to numpy arrays of radians. Makes sure that respective coordinates in pairs have the same shape.
[ "Convert", "two", "pairs", "of", "spherical", "coordinates", "in", "decimal", "degrees", "to", "numpy", "arrays", "of", "radians", ".", "Makes", "sure", "that", "respective", "coordinates", "in", "pairs", "have", "the", "same", "shape", "." ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/geo/geodetic.py#L528-L540
gem/oq-engine
openquake/hmtk/sources/simple_fault_source.py
mtkSimpleFaultSource._check_seismogenic_depths
def _check_seismogenic_depths(self, upper_depth, lower_depth): ''' Checks the seismic depths for physical consistency :param float upper_depth: Upper seismogenic depth (km) :param float lower_depth: Lower seismogenic depth (km) ''' # Simple check ...
python
def _check_seismogenic_depths(self, upper_depth, lower_depth): if upper_depth: if upper_depth < 0.: raise ValueError('Upper seismogenic depth must be greater than' ' or equal to 0.0!') else: self.upper_dep...
[ "def", "_check_seismogenic_depths", "(", "self", ",", "upper_depth", ",", "lower_depth", ")", ":", "# Simple check on depths", "if", "upper_depth", ":", "if", "upper_depth", "<", "0.", ":", "raise", "ValueError", "(", "'Upper seismogenic depth must be greater than'", "'...
Checks the seismic depths for physical consistency :param float upper_depth: Upper seismogenic depth (km) :param float lower_depth: Lower seismogenic depth (km)
[ "Checks", "the", "seismic", "depths", "for", "physical", "consistency", ":", "param", "float", "upper_depth", ":", "Upper", "seismogenic", "depth", "(", "km", ")" ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hmtk/sources/simple_fault_source.py#L119-L145
gem/oq-engine
openquake/hmtk/sources/simple_fault_source.py
mtkSimpleFaultSource.create_geometry
def create_geometry(self, input_geometry, dip, upper_depth, lower_depth, mesh_spacing=1.0): ''' If geometry is defined as a numpy array then create instance of nhlib.geo.line.Line class, otherwise if already instance of class accept class :param input_geo...
python
def create_geometry(self, input_geometry, dip, upper_depth, lower_depth, mesh_spacing=1.0): assert((dip > 0.) and (dip <= 90.)) self.dip = dip self._check_seismogenic_depths(upper_depth, lower_depth) if not isinstance(input_geometry, Line): i...
[ "def", "create_geometry", "(", "self", ",", "input_geometry", ",", "dip", ",", "upper_depth", ",", "lower_depth", ",", "mesh_spacing", "=", "1.0", ")", ":", "assert", "(", "(", "dip", ">", "0.", ")", "and", "(", "dip", "<=", "90.", ")", ")", "self", ...
If geometry is defined as a numpy array then create instance of nhlib.geo.line.Line class, otherwise if already instance of class accept class :param input_geometry: Trace (line) of the fault source as either i) instance of nhlib.geo.line.Line class ii) numpy...
[ "If", "geometry", "is", "defined", "as", "a", "numpy", "array", "then", "create", "instance", "of", "nhlib", ".", "geo", ".", "line", ".", "Line", "class", "otherwise", "if", "already", "instance", "of", "class", "accept", "class" ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hmtk/sources/simple_fault_source.py#L147-L189
gem/oq-engine
openquake/hmtk/sources/simple_fault_source.py
mtkSimpleFaultSource.select_catalogue
def select_catalogue(self, selector, distance, distance_metric='joyner-boore', upper_eq_depth=None, lower_eq_depth=None): ''' Selects earthquakes within a distance of the fault :param selector: Populated instance of :class: ...
python
def select_catalogue(self, selector, distance, distance_metric='joyner-boore', upper_eq_depth=None, lower_eq_depth=None): if selector.catalogue.get_number_events() < 1: raise ValueError('No events found in catalogue!') if (...
[ "def", "select_catalogue", "(", "self", ",", "selector", ",", "distance", ",", "distance_metric", "=", "'joyner-boore'", ",", "upper_eq_depth", "=", "None", ",", "lower_eq_depth", "=", "None", ")", ":", "if", "selector", ".", "catalogue", ".", "get_number_events...
Selects earthquakes within a distance of the fault :param selector: Populated instance of :class: `openquake.hmtk.seismicity.selector.CatalogueSelector` :param distance: Distance from point (km) for selection :param str distance_metric Choice of...
[ "Selects", "earthquakes", "within", "a", "distance", "of", "the", "fault" ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hmtk/sources/simple_fault_source.py#L191-L237
gem/oq-engine
openquake/hmtk/sources/simple_fault_source.py
mtkSimpleFaultSource.create_oqhazardlib_source
def create_oqhazardlib_source(self, tom, mesh_spacing, use_defaults=False): """ Returns an instance of the :class: `openquake.hazardlib.source.simple_fault.SimpleFaultSource` :param tom: Temporal occurrance model :param float mesh_spacing: Mesh spacing ...
python
def create_oqhazardlib_source(self, tom, mesh_spacing, use_defaults=False): if not self.mfd: raise ValueError("Cannot write to hazardlib without MFD") return SimpleFaultSource( self.id, self.name, self.trt, self.mfd, mesh_s...
[ "def", "create_oqhazardlib_source", "(", "self", ",", "tom", ",", "mesh_spacing", ",", "use_defaults", "=", "False", ")", ":", "if", "not", "self", ".", "mfd", ":", "raise", "ValueError", "(", "\"Cannot write to hazardlib without MFD\"", ")", "return", "SimpleFaul...
Returns an instance of the :class: `openquake.hazardlib.source.simple_fault.SimpleFaultSource` :param tom: Temporal occurrance model :param float mesh_spacing: Mesh spacing
[ "Returns", "an", "instance", "of", "the", ":", "class", ":", "openquake", ".", "hazardlib", ".", "source", ".", "simple_fault", ".", "SimpleFaultSource" ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hmtk/sources/simple_fault_source.py#L239-L264
gem/oq-engine
openquake/hmtk/plotting/faults/geology_mfd_plot.py
plot_recurrence_models
def plot_recurrence_models( configs, area, slip, msr, rake, shear_modulus=30.0, disp_length_ratio=1.25E-5, msr_sigma=0., figure_size=(8, 6), filename=None, filetype='png', dpi=300, ax=None): """ Plots a set of recurrence models :param list configs: List of configuration dict...
python
def plot_recurrence_models( configs, area, slip, msr, rake, shear_modulus=30.0, disp_length_ratio=1.25E-5, msr_sigma=0., figure_size=(8, 6), filename=None, filetype='png', dpi=300, ax=None): if ax is None: fig, ax = plt.subplots(figsize=figure_size) else: fig = ax.ge...
[ "def", "plot_recurrence_models", "(", "configs", ",", "area", ",", "slip", ",", "msr", ",", "rake", ",", "shear_modulus", "=", "30.0", ",", "disp_length_ratio", "=", "1.25E-5", ",", "msr_sigma", "=", "0.", ",", "figure_size", "=", "(", "8", ",", "6", ")"...
Plots a set of recurrence models :param list configs: List of configuration dictionaries
[ "Plots", "a", "set", "of", "recurrence", "models" ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hmtk/plotting/faults/geology_mfd_plot.py#L69-L105
gem/oq-engine
openquake/hazardlib/sourcewriter.py
build_area_source_geometry
def build_area_source_geometry(area_source): """ Returns the area source geometry as a Node :param area_source: Area source model as an instance of the :class: `openquake.hazardlib.source.area.AreaSource` :returns: Instance of :class:`openquake.baselib.node.Node` """ geo...
python
def build_area_source_geometry(area_source): geom = [] for lon_lat in zip(area_source.polygon.lons, area_source.polygon.lats): geom.extend(lon_lat) poslist_node = Node("gml:posList", text=geom) linear_ring_node = Node("gml:LinearRing", nodes=[poslist_node]) exterior_node = Node("gml:ext...
[ "def", "build_area_source_geometry", "(", "area_source", ")", ":", "geom", "=", "[", "]", "for", "lon_lat", "in", "zip", "(", "area_source", ".", "polygon", ".", "lons", ",", "area_source", ".", "polygon", ".", "lats", ")", ":", "geom", ".", "extend", "(...
Returns the area source geometry as a Node :param area_source: Area source model as an instance of the :class: `openquake.hazardlib.source.area.AreaSource` :returns: Instance of :class:`openquake.baselib.node.Node`
[ "Returns", "the", "area", "source", "geometry", "as", "a", "Node" ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/sourcewriter.py#L35-L58
gem/oq-engine
openquake/hazardlib/sourcewriter.py
build_point_source_geometry
def build_point_source_geometry(point_source): """ Returns the poing source geometry as a Node :param point_source: Point source model as an instance of the :class: `openquake.hazardlib.source.point.PointSource` :returns: Instance of :class:`openquake.baselib.node.Node` """ ...
python
def build_point_source_geometry(point_source): xy = point_source.location.x, point_source.location.y pos_node = Node("gml:pos", text=xy) point_node = Node("gml:Point", nodes=[pos_node]) upper_depth_node = Node( "upperSeismoDepth", text=point_source.upper_seismogenic_depth) lower_depth_n...
[ "def", "build_point_source_geometry", "(", "point_source", ")", ":", "xy", "=", "point_source", ".", "location", ".", "x", ",", "point_source", ".", "location", ".", "y", "pos_node", "=", "Node", "(", "\"gml:pos\"", ",", "text", "=", "xy", ")", "point_node",...
Returns the poing source geometry as a Node :param point_source: Point source model as an instance of the :class: `openquake.hazardlib.source.point.PointSource` :returns: Instance of :class:`openquake.baselib.node.Node`
[ "Returns", "the", "poing", "source", "geometry", "as", "a", "Node" ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/sourcewriter.py#L61-L80
gem/oq-engine
openquake/hazardlib/sourcewriter.py
build_linestring_node
def build_linestring_node(line, with_depth=False): """ Parses a line to a Node class :param line: Line as instance of :class:`openquake.hazardlib.geo.line.Line` :param bool with_depth: Include the depth values (True) or not (False): :returns: Instance of :class:`openquake.ba...
python
def build_linestring_node(line, with_depth=False): geom = [] for p in line.points: if with_depth: geom.extend((p.x, p.y, p.z)) else: geom.extend((p.x, p.y)) poslist_node = Node("gml:posList", text=geom) return Node("gml:LineString", nodes=[poslist_node])
[ "def", "build_linestring_node", "(", "line", ",", "with_depth", "=", "False", ")", ":", "geom", "=", "[", "]", "for", "p", "in", "line", ".", "points", ":", "if", "with_depth", ":", "geom", ".", "extend", "(", "(", "p", ".", "x", ",", "p", ".", "...
Parses a line to a Node class :param line: Line as instance of :class:`openquake.hazardlib.geo.line.Line` :param bool with_depth: Include the depth values (True) or not (False): :returns: Instance of :class:`openquake.baselib.node.Node`
[ "Parses", "a", "line", "to", "a", "Node", "class" ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/sourcewriter.py#L83-L101
gem/oq-engine
openquake/hazardlib/sourcewriter.py
build_simple_fault_geometry
def build_simple_fault_geometry(fault_source): """ Returns the simple fault source geometry as a Node :param fault_source: Simple fault source model as an instance of the :class: `openquake.hazardlib.source.simple_fault.SimpleFaultSource` :returns: Instance of :class:`openquake....
python
def build_simple_fault_geometry(fault_source): linestring_node = build_linestring_node(fault_source.fault_trace, with_depth=False) dip_node = Node("dip", text=fault_source.dip) upper_depth_node = Node( "upperSeismoDepth", text=fault_source.upper_seism...
[ "def", "build_simple_fault_geometry", "(", "fault_source", ")", ":", "linestring_node", "=", "build_linestring_node", "(", "fault_source", ".", "fault_trace", ",", "with_depth", "=", "False", ")", "dip_node", "=", "Node", "(", "\"dip\"", ",", "text", "=", "fault_s...
Returns the simple fault source geometry as a Node :param fault_source: Simple fault source model as an instance of the :class: `openquake.hazardlib.source.simple_fault.SimpleFaultSource` :returns: Instance of :class:`openquake.baselib.node.Node`
[ "Returns", "the", "simple", "fault", "source", "geometry", "as", "a", "Node" ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/sourcewriter.py#L104-L123
gem/oq-engine
openquake/hazardlib/sourcewriter.py
build_complex_fault_geometry
def build_complex_fault_geometry(fault_source): """ Returns the complex fault source geometry as a Node :param fault_source: Complex fault source model as an instance of the :class: `openquake.hazardlib.source.complex_fault.ComplexFaultSource` :returns: Instance of :class:`openq...
python
def build_complex_fault_geometry(fault_source): num_edges = len(fault_source.edges) edge_nodes = [] for iloc, edge in enumerate(fault_source.edges): if iloc == 0: node_name = "faultTopEdge" elif iloc == (num_edges - 1): node_name = "fau...
[ "def", "build_complex_fault_geometry", "(", "fault_source", ")", ":", "num_edges", "=", "len", "(", "fault_source", ".", "edges", ")", "edge_nodes", "=", "[", "]", "for", "iloc", ",", "edge", "in", "enumerate", "(", "fault_source", ".", "edges", ")", ":", ...
Returns the complex fault source geometry as a Node :param fault_source: Complex fault source model as an instance of the :class: `openquake.hazardlib.source.complex_fault.ComplexFaultSource` :returns: Instance of :class:`openquake.baselib.node.Node`
[ "Returns", "the", "complex", "fault", "source", "geometry", "as", "a", "Node" ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/sourcewriter.py#L126-L152
gem/oq-engine
openquake/hazardlib/sourcewriter.py
build_evenly_discretised_mfd
def build_evenly_discretised_mfd(mfd): """ Returns the evenly discretized MFD as a Node :param mfd: MFD as instance of :class: `openquake.hazardlib.mfd.evenly_discretized.EvenlyDiscretizedMFD` :returns: Instance of :class:`openquake.baselib.node.Node` """ occur_rates = N...
python
def build_evenly_discretised_mfd(mfd): occur_rates = Node("occurRates", text=mfd.occurrence_rates) return Node("incrementalMFD", {"binWidth": mfd.bin_width, "minMag": mfd.min_mag}, nodes=[occur_rates])
[ "def", "build_evenly_discretised_mfd", "(", "mfd", ")", ":", "occur_rates", "=", "Node", "(", "\"occurRates\"", ",", "text", "=", "mfd", ".", "occurrence_rates", ")", "return", "Node", "(", "\"incrementalMFD\"", ",", "{", "\"binWidth\"", ":", "mfd", ".", "bin_...
Returns the evenly discretized MFD as a Node :param mfd: MFD as instance of :class: `openquake.hazardlib.mfd.evenly_discretized.EvenlyDiscretizedMFD` :returns: Instance of :class:`openquake.baselib.node.Node`
[ "Returns", "the", "evenly", "discretized", "MFD", "as", "a", "Node" ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/sourcewriter.py#L156-L169
gem/oq-engine
openquake/hazardlib/sourcewriter.py
build_truncated_gr_mfd
def build_truncated_gr_mfd(mfd): """ Parses the truncated Gutenberg Richter MFD as a Node :param mfd: MFD as instance of :class: `openquake.hazardlib.mfd.truncated_gr.TruncatedGRMFD` :returns: Instance of :class:`openquake.baselib.node.Node` """ return Node("truncGutenbe...
python
def build_truncated_gr_mfd(mfd): return Node("truncGutenbergRichterMFD", {"aValue": mfd.a_val, "bValue": mfd.b_val, "minMag": mfd.min_mag, "maxMag": mfd.max_mag})
[ "def", "build_truncated_gr_mfd", "(", "mfd", ")", ":", "return", "Node", "(", "\"truncGutenbergRichterMFD\"", ",", "{", "\"aValue\"", ":", "mfd", ".", "a_val", ",", "\"bValue\"", ":", "mfd", ".", "b_val", ",", "\"minMag\"", ":", "mfd", ".", "min_mag", ",", ...
Parses the truncated Gutenberg Richter MFD as a Node :param mfd: MFD as instance of :class: `openquake.hazardlib.mfd.truncated_gr.TruncatedGRMFD` :returns: Instance of :class:`openquake.baselib.node.Node`
[ "Parses", "the", "truncated", "Gutenberg", "Richter", "MFD", "as", "a", "Node" ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/sourcewriter.py#L173-L185
gem/oq-engine
openquake/hazardlib/sourcewriter.py
build_arbitrary_mfd
def build_arbitrary_mfd(mfd): """ Parses the arbitrary MFD as a Node :param mfd: MFD as instance of :class: `openquake.hazardlib.mfd.arbitrary.ArbitraryMFD` :returns: Instance of :class:`openquake.baselib.node.Node` """ magnitudes = Node("magnitudes", text=mfd.magnitudes...
python
def build_arbitrary_mfd(mfd): magnitudes = Node("magnitudes", text=mfd.magnitudes) occur_rates = Node("occurRates", text=mfd.occurrence_rates) return Node("arbitraryMFD", nodes=[magnitudes, occur_rates])
[ "def", "build_arbitrary_mfd", "(", "mfd", ")", ":", "magnitudes", "=", "Node", "(", "\"magnitudes\"", ",", "text", "=", "mfd", ".", "magnitudes", ")", "occur_rates", "=", "Node", "(", "\"occurRates\"", ",", "text", "=", "mfd", ".", "occurrence_rates", ")", ...
Parses the arbitrary MFD as a Node :param mfd: MFD as instance of :class: `openquake.hazardlib.mfd.arbitrary.ArbitraryMFD` :returns: Instance of :class:`openquake.baselib.node.Node`
[ "Parses", "the", "arbitrary", "MFD", "as", "a", "Node" ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/sourcewriter.py#L189-L201
gem/oq-engine
openquake/hazardlib/sourcewriter.py
build_youngs_coppersmith_mfd
def build_youngs_coppersmith_mfd(mfd): """ Parses the Youngs & Coppersmith MFD as a node. Note that the MFD does not hold the total moment rate, but only the characteristic rate. Therefore the node is written to the characteristic rate version regardless of whether or not it was originally created f...
python
def build_youngs_coppersmith_mfd(mfd): return Node("YoungsCoppersmithMFD", {"minMag": mfd.min_mag, "bValue": mfd.b_val, "characteristicMag": mfd.char_mag, "characteristicRate": mfd.char_rate, "binWidth": mfd.bin_width})
[ "def", "build_youngs_coppersmith_mfd", "(", "mfd", ")", ":", "return", "Node", "(", "\"YoungsCoppersmithMFD\"", ",", "{", "\"minMag\"", ":", "mfd", ".", "min_mag", ",", "\"bValue\"", ":", "mfd", ".", "b_val", ",", "\"characteristicMag\"", ":", "mfd", ".", "cha...
Parses the Youngs & Coppersmith MFD as a node. Note that the MFD does not hold the total moment rate, but only the characteristic rate. Therefore the node is written to the characteristic rate version regardless of whether or not it was originally created from total moment rate :param mfd: MFD ...
[ "Parses", "the", "Youngs", "&", "Coppersmith", "MFD", "as", "a", "node", ".", "Note", "that", "the", "MFD", "does", "not", "hold", "the", "total", "moment", "rate", "but", "only", "the", "characteristic", "rate", ".", "Therefore", "the", "node", "is", "w...
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/sourcewriter.py#L205-L223
gem/oq-engine
openquake/hazardlib/sourcewriter.py
build_multi_mfd
def build_multi_mfd(mfd): """ Parses the MultiMFD as a Node :param mfd: MFD as instance of :class: `openquake.hazardlib.mfd.multi_mfd.MultiMFD` :returns: Instance of :class:`openquake.baselib.node.Node` """ node = Node("multiMFD", dict(kind=mfd.kind, size=mfd.size)) ...
python
def build_multi_mfd(mfd): node = Node("multiMFD", dict(kind=mfd.kind, size=mfd.size)) for name in sorted(mfd.kwargs): values = mfd.kwargs[name] if name in ('magnitudes', 'occurRates'): if len(values[0]) > 1: values = list(numpy.concatenate(values)) ...
[ "def", "build_multi_mfd", "(", "mfd", ")", ":", "node", "=", "Node", "(", "\"multiMFD\"", ",", "dict", "(", "kind", "=", "mfd", ".", "kind", ",", "size", "=", "mfd", ".", "size", ")", ")", "for", "name", "in", "sorted", "(", "mfd", ".", "kwargs", ...
Parses the MultiMFD as a Node :param mfd: MFD as instance of :class: `openquake.hazardlib.mfd.multi_mfd.MultiMFD` :returns: Instance of :class:`openquake.baselib.node.Node`
[ "Parses", "the", "MultiMFD", "as", "a", "Node" ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/sourcewriter.py#L227-L249
gem/oq-engine
openquake/hazardlib/sourcewriter.py
build_nodal_plane_dist
def build_nodal_plane_dist(npd): """ Returns the nodal plane distribution as a Node instance :param npd: Nodal plane distribution as instance of :class: `openquake.hazardlib.pmf.PMF` :returns: Instance of :class:`openquake.baselib.node.Node` """ npds = [] for prob, n...
python
def build_nodal_plane_dist(npd): npds = [] for prob, npd in npd.data: nodal_plane = Node( "nodalPlane", {"dip": npd.dip, "probability": prob, "strike": npd.strike, "rake": npd.rake}) npds.append(nodal_plane) return Node("nodalPlaneDist", nodes=npds...
[ "def", "build_nodal_plane_dist", "(", "npd", ")", ":", "npds", "=", "[", "]", "for", "prob", ",", "npd", "in", "npd", ".", "data", ":", "nodal_plane", "=", "Node", "(", "\"nodalPlane\"", ",", "{", "\"dip\"", ":", "npd", ".", "dip", ",", "\"probability\...
Returns the nodal plane distribution as a Node instance :param npd: Nodal plane distribution as instance of :class: `openquake.hazardlib.pmf.PMF` :returns: Instance of :class:`openquake.baselib.node.Node`
[ "Returns", "the", "nodal", "plane", "distribution", "as", "a", "Node", "instance" ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/sourcewriter.py#L252-L268
gem/oq-engine
openquake/hazardlib/sourcewriter.py
build_hypo_depth_dist
def build_hypo_depth_dist(hdd): """ Returns the hypocentral depth distribution as a Node instance :param hdd: Hypocentral depth distribution as an instance of :class: `openquake.hzardlib.pmf.PMF` :returns: Instance of :class:`openquake.baselib.node.Node` """ hdds = [] ...
python
def build_hypo_depth_dist(hdd): hdds = [] for (prob, depth) in hdd.data: hdds.append( Node("hypoDepth", {"depth": depth, "probability": prob})) return Node("hypoDepthDist", nodes=hdds)
[ "def", "build_hypo_depth_dist", "(", "hdd", ")", ":", "hdds", "=", "[", "]", "for", "(", "prob", ",", "depth", ")", "in", "hdd", ".", "data", ":", "hdds", ".", "append", "(", "Node", "(", "\"hypoDepth\"", ",", "{", "\"depth\"", ":", "depth", ",", "...
Returns the hypocentral depth distribution as a Node instance :param hdd: Hypocentral depth distribution as an instance of :class: `openquake.hzardlib.pmf.PMF` :returns: Instance of :class:`openquake.baselib.node.Node`
[ "Returns", "the", "hypocentral", "depth", "distribution", "as", "a", "Node", "instance" ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/sourcewriter.py#L271-L285
gem/oq-engine
openquake/hazardlib/sourcewriter.py
get_distributed_seismicity_source_nodes
def get_distributed_seismicity_source_nodes(source): """ Returns list of nodes of attributes common to all distributed seismicity source classes :param source: Seismic source as instance of :class: `openquake.hazardlib.source.area.AreaSource` or :class: `openquake.hazardlib.sour...
python
def get_distributed_seismicity_source_nodes(source): source_nodes = [] source_nodes.append( Node("magScaleRel", text=source.magnitude_scaling_relationship.__class__.__name__)) source_nodes.append( Node("ruptAspectRatio", text=source.rupture_aspect_ratio)) ...
[ "def", "get_distributed_seismicity_source_nodes", "(", "source", ")", ":", "source_nodes", "=", "[", "]", "# parse msr", "source_nodes", ".", "append", "(", "Node", "(", "\"magScaleRel\"", ",", "text", "=", "source", ".", "magnitude_scaling_relationship", ".", "__c...
Returns list of nodes of attributes common to all distributed seismicity source classes :param source: Seismic source as instance of :class: `openquake.hazardlib.source.area.AreaSource` or :class: `openquake.hazardlib.source.point.PointSource` :returns: List of instances of ...
[ "Returns", "list", "of", "nodes", "of", "attributes", "common", "to", "all", "distributed", "seismicity", "source", "classes" ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/sourcewriter.py#L288-L316
gem/oq-engine
openquake/hazardlib/sourcewriter.py
build_hypo_list_node
def build_hypo_list_node(hypo_list): """ :param hypo_list: an array of shape (N, 3) with columns (alongStrike, downDip, weight) :returns: a hypoList node containing N hypo nodes """ hypolist = Node('hypoList', {}) for row in hypo_list: n = Node( 'hypo', dict(al...
python
def build_hypo_list_node(hypo_list): hypolist = Node('hypoList', {}) for row in hypo_list: n = Node( 'hypo', dict(alongStrike=row[0], downDip=row[1], weight=row[2])) hypolist.append(n) return hypolist
[ "def", "build_hypo_list_node", "(", "hypo_list", ")", ":", "hypolist", "=", "Node", "(", "'hypoList'", ",", "{", "}", ")", "for", "row", "in", "hypo_list", ":", "n", "=", "Node", "(", "'hypo'", ",", "dict", "(", "alongStrike", "=", "row", "[", "0", "...
:param hypo_list: an array of shape (N, 3) with columns (alongStrike, downDip, weight) :returns: a hypoList node containing N hypo nodes
[ ":", "param", "hypo_list", ":", "an", "array", "of", "shape", "(", "N", "3", ")", "with", "columns", "(", "alongStrike", "downDip", "weight", ")", ":", "returns", ":", "a", "hypoList", "node", "containing", "N", "hypo", "nodes" ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/sourcewriter.py#L319-L331
gem/oq-engine
openquake/hazardlib/sourcewriter.py
build_slip_list_node
def build_slip_list_node(slip_list): """ :param slip_list: an array of shape (N, 2) with columns (slip, weight) :returns: a hypoList node containing N slip nodes """ sliplist = Node('slipList', {}) for row in slip_list: sliplist.append( Node('slip', dict(weight...
python
def build_slip_list_node(slip_list): sliplist = Node('slipList', {}) for row in slip_list: sliplist.append( Node('slip', dict(weight=row[1]), row[0])) return sliplist
[ "def", "build_slip_list_node", "(", "slip_list", ")", ":", "sliplist", "=", "Node", "(", "'slipList'", ",", "{", "}", ")", "for", "row", "in", "slip_list", ":", "sliplist", ".", "append", "(", "Node", "(", "'slip'", ",", "dict", "(", "weight", "=", "ro...
:param slip_list: an array of shape (N, 2) with columns (slip, weight) :returns: a hypoList node containing N slip nodes
[ ":", "param", "slip_list", ":", "an", "array", "of", "shape", "(", "N", "2", ")", "with", "columns", "(", "slip", "weight", ")", ":", "returns", ":", "a", "hypoList", "node", "containing", "N", "slip", "nodes" ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/sourcewriter.py#L334-L345
gem/oq-engine
openquake/hazardlib/sourcewriter.py
get_fault_source_nodes
def get_fault_source_nodes(source): """ Returns list of nodes of attributes common to all fault source classes :param source: Fault source as instance of :class: `openquake.hazardlib.source.simple_fault.SimpleFaultSource` or :class: `openquake.hazardlib.source.complex_fault.ComplexF...
python
def get_fault_source_nodes(source): source_nodes = [] source_nodes.append( Node( "magScaleRel", text=source.magnitude_scaling_relationship.__class__.__name__)) source_nodes.append( Node("ruptAspectRatio", text=source.rupture_aspect_ratio)) sour...
[ "def", "get_fault_source_nodes", "(", "source", ")", ":", "source_nodes", "=", "[", "]", "# parse msr", "source_nodes", ".", "append", "(", "Node", "(", "\"magScaleRel\"", ",", "text", "=", "source", ".", "magnitude_scaling_relationship", ".", "__class__", ".", ...
Returns list of nodes of attributes common to all fault source classes :param source: Fault source as instance of :class: `openquake.hazardlib.source.simple_fault.SimpleFaultSource` or :class: `openquake.hazardlib.source.complex_fault.ComplexFaultSource` :returns: List of instan...
[ "Returns", "list", "of", "nodes", "of", "attributes", "common", "to", "all", "fault", "source", "classes" ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/sourcewriter.py#L348-L376
gem/oq-engine
openquake/hazardlib/sourcewriter.py
get_source_attributes
def get_source_attributes(source): """ Retreives a dictionary of source attributes from the source class :param source: Seismic source as instance of :class: `openquake.hazardlib.source.base.BaseSeismicSource` :returns: Dictionary of source attributes """ attrs = {"id": ...
python
def get_source_attributes(source): attrs = {"id": source.source_id, "name": source.name, "tectonicRegion": source.tectonic_region_type} if isinstance(source, NonParametricSeismicSource): if source.data[0][0].weight is not None: weights = [] for data...
[ "def", "get_source_attributes", "(", "source", ")", ":", "attrs", "=", "{", "\"id\"", ":", "source", ".", "source_id", ",", "\"name\"", ":", "source", ".", "name", ",", "\"tectonicRegion\"", ":", "source", ".", "tectonic_region_type", "}", "if", "isinstance", ...
Retreives a dictionary of source attributes from the source class :param source: Seismic source as instance of :class: `openquake.hazardlib.source.base.BaseSeismicSource` :returns: Dictionary of source attributes
[ "Retreives", "a", "dictionary", "of", "source", "attributes", "from", "the", "source", "class" ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/sourcewriter.py#L379-L399
gem/oq-engine
openquake/hazardlib/sourcewriter.py
build_area_source_node
def build_area_source_node(area_source): """ Parses an area source to a Node class :param area_source: Area source as instance of :class: `openquake.hazardlib.source.area.AreaSource` :returns: Instance of :class:`openquake.baselib.node.Node` """ # parse geometry sour...
python
def build_area_source_node(area_source): source_nodes = [build_area_source_geometry(area_source)] source_nodes.extend(get_distributed_seismicity_source_nodes(area_source)) return Node( "areaSource", get_source_attributes(area_source), nodes=source_nodes)
[ "def", "build_area_source_node", "(", "area_source", ")", ":", "# parse geometry", "source_nodes", "=", "[", "build_area_source_geometry", "(", "area_source", ")", "]", "# parse common distributed attributes", "source_nodes", ".", "extend", "(", "get_distributed_seismicity_so...
Parses an area source to a Node class :param area_source: Area source as instance of :class: `openquake.hazardlib.source.area.AreaSource` :returns: Instance of :class:`openquake.baselib.node.Node`
[ "Parses", "an", "area", "source", "to", "a", "Node", "class" ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/sourcewriter.py#L403-L418
gem/oq-engine
openquake/hazardlib/sourcewriter.py
build_rupture_node
def build_rupture_node(rupt, probs_occur): """ :param rupt: a hazardlib rupture object :param probs_occur: a list of floats with sum 1 """ s = sum(probs_occur) if abs(s - 1) > pmf.PRECISION: raise ValueError('The sum of %s is not 1: %s' % (probs_occur, s)) h = rupt.hypocenter hp_...
python
def build_rupture_node(rupt, probs_occur): s = sum(probs_occur) if abs(s - 1) > pmf.PRECISION: raise ValueError('The sum of %s is not 1: %s' % (probs_occur, s)) h = rupt.hypocenter hp_dict = dict(lon=h.longitude, lat=h.latitude, depth=h.depth) rupt_nodes = [Node('magnitude', {}, rupt.ma...
[ "def", "build_rupture_node", "(", "rupt", ",", "probs_occur", ")", ":", "s", "=", "sum", "(", "probs_occur", ")", "if", "abs", "(", "s", "-", "1", ")", ">", "pmf", ".", "PRECISION", ":", "raise", "ValueError", "(", "'The sum of %s is not 1: %s'", "%", "(...
:param rupt: a hazardlib rupture object :param probs_occur: a list of floats with sum 1
[ ":", "param", "rupt", ":", "a", "hazardlib", "rupture", "object", ":", "param", "probs_occur", ":", "a", "list", "of", "floats", "with", "sum", "1" ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/sourcewriter.py#L442-L467
gem/oq-engine
openquake/hazardlib/sourcewriter.py
build_multi_point_source_node
def build_multi_point_source_node(multi_point_source): """ Parses a point source to a Node class :param point_source: MultiPoint source as instance of :class: `openquake.hazardlib.source.point.MultiPointSource` :returns: Instance of :class:`openquake.baselib.node.Node` """ ...
python
def build_multi_point_source_node(multi_point_source): pos = [] for p in multi_point_source.mesh: pos.append(p.x) pos.append(p.y) mesh_node = Node('gml:posList', text=pos) upper_depth_node = Node( "upperSeismoDepth", text=multi_point_source.upper_seismogenic_depth) ...
[ "def", "build_multi_point_source_node", "(", "multi_point_source", ")", ":", "# parse geometry", "pos", "=", "[", "]", "for", "p", "in", "multi_point_source", ".", "mesh", ":", "pos", ".", "append", "(", "p", ".", "x", ")", "pos", ".", "append", "(", "p", ...
Parses a point source to a Node class :param point_source: MultiPoint source as instance of :class: `openquake.hazardlib.source.point.MultiPointSource` :returns: Instance of :class:`openquake.baselib.node.Node`
[ "Parses", "a", "point", "source", "to", "a", "Node", "class" ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/sourcewriter.py#L471-L499
gem/oq-engine
openquake/hazardlib/sourcewriter.py
build_point_source_node
def build_point_source_node(point_source): """ Parses a point source to a Node class :param point_source: Point source as instance of :class: `openquake.hazardlib.source.point.PointSource` :returns: Instance of :class:`openquake.baselib.node.Node` """ # parse geometry ...
python
def build_point_source_node(point_source): source_nodes = [build_point_source_geometry(point_source)] source_nodes.extend(get_distributed_seismicity_source_nodes(point_source)) return Node("pointSource", get_source_attributes(point_source), nodes=source_nodes)
[ "def", "build_point_source_node", "(", "point_source", ")", ":", "# parse geometry", "source_nodes", "=", "[", "build_point_source_geometry", "(", "point_source", ")", "]", "# parse common distributed attributes", "source_nodes", ".", "extend", "(", "get_distributed_seismicit...
Parses a point source to a Node class :param point_source: Point source as instance of :class: `openquake.hazardlib.source.point.PointSource` :returns: Instance of :class:`openquake.baselib.node.Node`
[ "Parses", "a", "point", "source", "to", "a", "Node", "class" ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/sourcewriter.py#L503-L520
gem/oq-engine
openquake/hazardlib/sourcewriter.py
build_simple_fault_source_node
def build_simple_fault_source_node(fault_source): """ Parses a simple fault source to a Node class :param fault_source: Simple fault source as instance of :class: `openquake.hazardlib.source.simple_fault.SimpleFaultSource` :returns: Instance of :class:`openquake.baselib.node.Nod...
python
def build_simple_fault_source_node(fault_source): source_nodes = [build_simple_fault_geometry(fault_source)] source_nodes.extend(get_fault_source_nodes(fault_source)) return Node("simpleFaultSource", get_source_attributes(fault_source), nodes=source_nodes)
[ "def", "build_simple_fault_source_node", "(", "fault_source", ")", ":", "# Parse geometry", "source_nodes", "=", "[", "build_simple_fault_geometry", "(", "fault_source", ")", "]", "# Parse common fault source attributes", "source_nodes", ".", "extend", "(", "get_fault_source_...
Parses a simple fault source to a Node class :param fault_source: Simple fault source as instance of :class: `openquake.hazardlib.source.simple_fault.SimpleFaultSource` :returns: Instance of :class:`openquake.baselib.node.Node`
[ "Parses", "a", "simple", "fault", "source", "to", "a", "Node", "class" ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/sourcewriter.py#L524-L540
gem/oq-engine
openquake/hazardlib/sourcewriter.py
build_complex_fault_source_node
def build_complex_fault_source_node(fault_source): """ Parses a complex fault source to a Node class :param fault_source: Simple fault source as instance of :class: `openquake.hazardlib.source.complex_fault.ComplexFaultSource` :returns: Instance of :class:`openquake.baselib.node...
python
def build_complex_fault_source_node(fault_source): source_nodes = [build_complex_fault_geometry(fault_source)] source_nodes.extend(get_fault_source_nodes(fault_source)) return Node("complexFaultSource", get_source_attributes(fault_source), nodes=source_nodes)
[ "def", "build_complex_fault_source_node", "(", "fault_source", ")", ":", "# Parse geometry", "source_nodes", "=", "[", "build_complex_fault_geometry", "(", "fault_source", ")", "]", "# Parse common fault source attributes", "source_nodes", ".", "extend", "(", "get_fault_sourc...
Parses a complex fault source to a Node class :param fault_source: Simple fault source as instance of :class: `openquake.hazardlib.source.complex_fault.ComplexFaultSource` :returns: Instance of :class:`openquake.baselib.node.Node`
[ "Parses", "a", "complex", "fault", "source", "to", "a", "Node", "class" ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/sourcewriter.py#L544-L560
gem/oq-engine
openquake/hazardlib/sourcewriter.py
write_source_model
def write_source_model(dest, sources_or_groups, name=None, investigation_time=None): """ Writes a source model to XML. :param dest: Destination path :param sources_or_groups: Source model in different formats :param name: Name of the source model (if m...
python
def write_source_model(dest, sources_or_groups, name=None, investigation_time=None): if isinstance(sources_or_groups, nrml.SourceModel): with open(dest, 'wb') as f: nrml.write([obj_to_node(sources_or_groups)], f, '%s') return if isinstance(sources_or_group...
[ "def", "write_source_model", "(", "dest", ",", "sources_or_groups", ",", "name", "=", "None", ",", "investigation_time", "=", "None", ")", ":", "if", "isinstance", "(", "sources_or_groups", ",", "nrml", ".", "SourceModel", ")", ":", "with", "open", "(", "des...
Writes a source model to XML. :param dest: Destination path :param sources_or_groups: Source model in different formats :param name: Name of the source model (if missing, extracted from the filename)
[ "Writes", "a", "source", "model", "to", "XML", "." ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/sourcewriter.py#L610-L641
gem/oq-engine
openquake/hazardlib/sourcewriter.py
hdf5write
def hdf5write(h5file, obj, root=''): """ Write a generic object serializable to a Node-like object into a :class: `openquake.baselib.hdf5.File` """ dic = node_to_dict(obj_to_node(obj)) h5file.save(dic, root)
python
def hdf5write(h5file, obj, root=''): dic = node_to_dict(obj_to_node(obj)) h5file.save(dic, root)
[ "def", "hdf5write", "(", "h5file", ",", "obj", ",", "root", "=", "''", ")", ":", "dic", "=", "node_to_dict", "(", "obj_to_node", "(", "obj", ")", ")", "h5file", ".", "save", "(", "dic", ",", "root", ")" ]
Write a generic object serializable to a Node-like object into a :class: `openquake.baselib.hdf5.File`
[ "Write", "a", "generic", "object", "serializable", "to", "a", "Node", "-", "like", "object", "into", "a", ":", "class", ":", "openquake", ".", "baselib", ".", "hdf5", ".", "File" ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/sourcewriter.py#L644-L650
gem/oq-engine
openquake/hazardlib/gsim/sharma_2009.py
SharmaEtAl2009.get_mean_and_stddevs
def get_mean_and_stddevs(self, sites, rup, dists, imt, stddev_types): # pylint: disable=too-many-arguments """ See :meth:`superclass method <.base.GroundShakingIntensityModel.get_mean_and_stddevs>` for specification of input and result values. """ # extract dicti...
python
def get_mean_and_stddevs(self, sites, rup, dists, imt, stddev_types): coeffs = self.COEFFS[imt] coeffs.update(self.CONSTS) log_mean = (self._compute_magnitude(rup, coeffs) + self._compute_distance(dists, coeffs) + ...
[ "def", "get_mean_and_stddevs", "(", "self", ",", "sites", ",", "rup", ",", "dists", ",", "imt", ",", "stddev_types", ")", ":", "# pylint: disable=too-many-arguments", "# extract dictionary of coefficients specific to required", "# intensity measure type", "coeffs", "=", "se...
See :meth:`superclass method <.base.GroundShakingIntensityModel.get_mean_and_stddevs>` for specification of input and result values.
[ "See", ":", "meth", ":", "superclass", "method", "<", ".", "base", ".", "GroundShakingIntensityModel", ".", "get_mean_and_stddevs", ">", "for", "specification", "of", "input", "and", "result", "values", "." ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/gsim/sharma_2009.py#L94-L119
gem/oq-engine
openquake/hazardlib/gsim/sharma_2009.py
SharmaEtAl2009._get_stddevs
def _get_stddevs(self, coeffs, stddev_types, num_sites): """ Return total sigma as reported in Table 2, p. 1202. """ stddevs = [] for stddev_type in stddev_types: assert stddev_type in self.DEFINED_FOR_STANDARD_DEVIATION_TYPES stddevs.append(coeffs['sigma'...
python
def _get_stddevs(self, coeffs, stddev_types, num_sites): stddevs = [] for stddev_type in stddev_types: assert stddev_type in self.DEFINED_FOR_STANDARD_DEVIATION_TYPES stddevs.append(coeffs['sigma'] + np.zeros(num_sites)) return np.array(stddevs)
[ "def", "_get_stddevs", "(", "self", ",", "coeffs", ",", "stddev_types", ",", "num_sites", ")", ":", "stddevs", "=", "[", "]", "for", "stddev_type", "in", "stddev_types", ":", "assert", "stddev_type", "in", "self", ".", "DEFINED_FOR_STANDARD_DEVIATION_TYPES", "st...
Return total sigma as reported in Table 2, p. 1202.
[ "Return", "total", "sigma", "as", "reported", "in", "Table", "2", "p", ".", "1202", "." ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/gsim/sharma_2009.py#L121-L129
gem/oq-engine
openquake/hazardlib/gsim/sharma_2009.py
SharmaEtAl2009._compute_distance
def _compute_distance(cls, dists, coeffs): """ Compute third term of equation (1) on p. 1200: ``b3 * log(sqrt(Rjb ** 2 + b4 ** 2))`` """ return coeffs['b3']*np.log10(np.sqrt(dists.rjb**2. + coeffs['b4']**2.))
python
def _compute_distance(cls, dists, coeffs): return coeffs['b3']*np.log10(np.sqrt(dists.rjb**2. + coeffs['b4']**2.))
[ "def", "_compute_distance", "(", "cls", ",", "dists", ",", "coeffs", ")", ":", "return", "coeffs", "[", "'b3'", "]", "*", "np", ".", "log10", "(", "np", ".", "sqrt", "(", "dists", ".", "rjb", "**", "2.", "+", "coeffs", "[", "'b4'", "]", "**", "2....
Compute third term of equation (1) on p. 1200: ``b3 * log(sqrt(Rjb ** 2 + b4 ** 2))``
[ "Compute", "third", "term", "of", "equation", "(", "1", ")", "on", "p", ".", "1200", ":" ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/gsim/sharma_2009.py#L141-L147
gem/oq-engine
openquake/hazardlib/gsim/sharma_2009.py
SharmaEtAl2009._get_site_amplification
def _get_site_amplification(self, sites, coeffs): """ Compute fourth term of equation (1) on p. 1200: ``b5 * S`` """ is_rock = self.get_site_type_dummy_variables(sites) return coeffs['b5']*is_rock
python
def _get_site_amplification(self, sites, coeffs): is_rock = self.get_site_type_dummy_variables(sites) return coeffs['b5']*is_rock
[ "def", "_get_site_amplification", "(", "self", ",", "sites", ",", "coeffs", ")", ":", "is_rock", "=", "self", ".", "get_site_type_dummy_variables", "(", "sites", ")", "return", "coeffs", "[", "'b5'", "]", "*", "is_rock" ]
Compute fourth term of equation (1) on p. 1200: ``b5 * S``
[ "Compute", "fourth", "term", "of", "equation", "(", "1", ")", "on", "p", ".", "1200", ":" ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/gsim/sharma_2009.py#L149-L156
gem/oq-engine
openquake/hazardlib/gsim/sharma_2009.py
SharmaEtAl2009._get_mechanism
def _get_mechanism(self, rup, coeffs): """ Compute fifth term of equation (1) on p. 1200: ``b6 * H`` """ is_strike_slip = self.get_fault_type_dummy_variables(rup) return coeffs['b6']*is_strike_slip
python
def _get_mechanism(self, rup, coeffs): is_strike_slip = self.get_fault_type_dummy_variables(rup) return coeffs['b6']*is_strike_slip
[ "def", "_get_mechanism", "(", "self", ",", "rup", ",", "coeffs", ")", ":", "is_strike_slip", "=", "self", ".", "get_fault_type_dummy_variables", "(", "rup", ")", "return", "coeffs", "[", "'b6'", "]", "*", "is_strike_slip" ]
Compute fifth term of equation (1) on p. 1200: ``b6 * H``
[ "Compute", "fifth", "term", "of", "equation", "(", "1", ")", "on", "p", ".", "1200", ":" ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/gsim/sharma_2009.py#L158-L165
gem/oq-engine
openquake/hazardlib/gsim/sharma_2009.py
SharmaEtAl2009.get_site_type_dummy_variables
def get_site_type_dummy_variables(self, sites): """ Binary rock/soil classification dummy variable based on sites.vs30. "``S`` is 1 for a rock site and 0 otherwise" (p. 1201). """ is_rock = np.array(sites.vs30 > self.NEHRP_BC_BOUNDARY) return is_rock
python
def get_site_type_dummy_variables(self, sites): is_rock = np.array(sites.vs30 > self.NEHRP_BC_BOUNDARY) return is_rock
[ "def", "get_site_type_dummy_variables", "(", "self", ",", "sites", ")", ":", "is_rock", "=", "np", ".", "array", "(", "sites", ".", "vs30", ">", "self", ".", "NEHRP_BC_BOUNDARY", ")", "return", "is_rock" ]
Binary rock/soil classification dummy variable based on sites.vs30. "``S`` is 1 for a rock site and 0 otherwise" (p. 1201).
[ "Binary", "rock", "/", "soil", "classification", "dummy", "variable", "based", "on", "sites", ".", "vs30", "." ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/gsim/sharma_2009.py#L167-L174
gem/oq-engine
openquake/hazardlib/gsim/sharma_2009.py
SharmaEtAl2009.get_fault_type_dummy_variables
def get_fault_type_dummy_variables(self, rup): """ Fault-type classification dummy variable based on rup.rake. "``H`` is 1 for a strike-slip mechanism and 0 for a reverse mechanism" (p. 1201). Note: UserWarning is raised if mechanism is determined to be normal ...
python
def get_fault_type_dummy_variables(self, rup): is_normal = np.array( self.RAKE_THRESH < -rup.rake < (180. - self.RAKE_THRESH)) is_reverse = np.array( self.RAKE_THRESH < rup.rake < (180. - self.RAKE_THRESH)) if not self.ALREADY_WARNED and is_n...
[ "def", "get_fault_type_dummy_variables", "(", "self", ",", "rup", ")", ":", "# normal faulting", "is_normal", "=", "np", ".", "array", "(", "self", ".", "RAKE_THRESH", "<", "-", "rup", ".", "rake", "<", "(", "180.", "-", "self", ".", "RAKE_THRESH", ")", ...
Fault-type classification dummy variable based on rup.rake. "``H`` is 1 for a strike-slip mechanism and 0 for a reverse mechanism" (p. 1201). Note: UserWarning is raised if mechanism is determined to be normal faulting, since as summarized in Table 2 on p. 1197 the data...
[ "Fault", "-", "type", "classification", "dummy", "variable", "based", "on", "rup", ".", "rake", "." ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/gsim/sharma_2009.py#L176-L208
gem/oq-engine
openquake/hmtk/parsers/strain/strain_csv_parser.py
ReadStrainCsv.read_data
def read_data(self, scaling_factor=1E-9, strain_headers=None): ''' Reads the data from the csv file :param float scaling_factor: Scaling factor used for all strain values (default 1E-9 for nanostrain) :param list strain_headers: List of the variables...
python
def read_data(self, scaling_factor=1E-9, strain_headers=None): if strain_headers: self.strain.data_variables = strain_headers else: self.strain.data_variables = STRAIN_VARIABLES datafile = open(self.filename, 'r') reader = csv.DictReader(datafile) ...
[ "def", "read_data", "(", "self", ",", "scaling_factor", "=", "1E-9", ",", "strain_headers", "=", "None", ")", ":", "if", "strain_headers", ":", "self", ".", "strain", ".", "data_variables", "=", "strain_headers", "else", ":", "self", ".", "strain", ".", "d...
Reads the data from the csv file :param float scaling_factor: Scaling factor used for all strain values (default 1E-9 for nanostrain) :param list strain_headers: List of the variables in the file that correspond to strain parameters :returns: ...
[ "Reads", "the", "data", "from", "the", "csv", "file" ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hmtk/parsers/strain/strain_csv_parser.py#L82-L132
gem/oq-engine
openquake/hmtk/parsers/strain/strain_csv_parser.py
ReadStrainCsv._check_invalid_longitudes
def _check_invalid_longitudes(self): ''' Checks to ensure that all longitudes are in the range -180. to 180 ''' idlon = self.strain.data['longitude'] > 180. if np.any(idlon): self.strain.data['longitude'][idlon] = \ self.strain.data['longitude'][idlon]...
python
def _check_invalid_longitudes(self): idlon = self.strain.data['longitude'] > 180. if np.any(idlon): self.strain.data['longitude'][idlon] = \ self.strain.data['longitude'][idlon] - 360.
[ "def", "_check_invalid_longitudes", "(", "self", ")", ":", "idlon", "=", "self", ".", "strain", ".", "data", "[", "'longitude'", "]", ">", "180.", "if", "np", ".", "any", "(", "idlon", ")", ":", "self", ".", "strain", ".", "data", "[", "'longitude'", ...
Checks to ensure that all longitudes are in the range -180. to 180
[ "Checks", "to", "ensure", "that", "all", "longitudes", "are", "in", "the", "range", "-", "180", ".", "to", "180" ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hmtk/parsers/strain/strain_csv_parser.py#L134-L141
gem/oq-engine
openquake/hmtk/parsers/strain/strain_csv_parser.py
WriteStrainCsv.write_file
def write_file(self, strain, scaling_factor=1E-9): ''' Main writer function for the csv file :param strain: Instance of :class: openquake.hmtk.strain.geodetic_strain.GeodeticStrain :param float scaling_factor: Scaling factor used for all strain values (default 1E...
python
def write_file(self, strain, scaling_factor=1E-9): if not isinstance(strain, GeodeticStrain): raise ValueError('Strain data must be instance of GeodeticStrain') for key in strain.data.keys(): if key in strain.data_variables: if key in ['...
[ "def", "write_file", "(", "self", ",", "strain", ",", "scaling_factor", "=", "1E-9", ")", ":", "if", "not", "isinstance", "(", "strain", ",", "GeodeticStrain", ")", ":", "raise", "ValueError", "(", "'Strain data must be instance of GeodeticStrain'", ")", "for", ...
Main writer function for the csv file :param strain: Instance of :class: openquake.hmtk.strain.geodetic_strain.GeodeticStrain :param float scaling_factor: Scaling factor used for all strain values (default 1E-9 for nanostrain)
[ "Main", "writer", "function", "for", "the", "csv", "file" ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hmtk/parsers/strain/strain_csv_parser.py#L160-L196
gem/oq-engine
openquake/hmtk/parsers/strain/strain_csv_parser.py
WriteStrainCsv.slice_rates_to_data
def slice_rates_to_data(self, strain): ''' For the strain data, checks to see if seismicity rates have been calculated. If so, each column in the array is sliced and stored as a single vector in the strain.data dictionary with the corresponding magnitude as a key. :param...
python
def slice_rates_to_data(self, strain): output_variables = list(strain.data) cond = (isinstance(strain.target_magnitudes, np.ndarray) or isinstance(strain.target_magnitudes, list)) if cond: magnitude_list = ['%.3f' % mag for mag in strain.target_magnitudes] ...
[ "def", "slice_rates_to_data", "(", "self", ",", "strain", ")", ":", "output_variables", "=", "list", "(", "strain", ".", "data", ")", "cond", "=", "(", "isinstance", "(", "strain", ".", "target_magnitudes", ",", "np", ".", "ndarray", ")", "or", "isinstance...
For the strain data, checks to see if seismicity rates have been calculated. If so, each column in the array is sliced and stored as a single vector in the strain.data dictionary with the corresponding magnitude as a key. :param strain: Instance of :class: openquake.hmtk.str...
[ "For", "the", "strain", "data", "checks", "to", "see", "if", "seismicity", "rates", "have", "been", "calculated", ".", "If", "so", "each", "column", "in", "the", "array", "is", "sliced", "and", "stored", "as", "a", "single", "vector", "in", "the", "strai...
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hmtk/parsers/strain/strain_csv_parser.py#L198-L228
gem/oq-engine
openquake/baselib/__init__.py
read
def read(*paths, **validators): """ Load the configuration, make each section available in a separate dict. The configuration location can specified via an environment variable: - OQ_CONFIG_FILE In the absence of this environment variable the following paths will be used: - sys.prefi...
python
def read(*paths, **validators): paths = config.paths + list(paths) parser = configparser.ConfigParser() found = parser.read(os.path.normpath(os.path.expanduser(p)) for p in paths) if not found: raise IOError('No configuration file found in %s' % str(paths)) config.found = found conf...
[ "def", "read", "(", "*", "paths", ",", "*", "*", "validators", ")", ":", "paths", "=", "config", ".", "paths", "+", "list", "(", "paths", ")", "parser", "=", "configparser", ".", "ConfigParser", "(", ")", "found", "=", "parser", ".", "read", "(", "...
Load the configuration, make each section available in a separate dict. The configuration location can specified via an environment variable: - OQ_CONFIG_FILE In the absence of this environment variable the following paths will be used: - sys.prefix + /openquake.cfg when in a virtualenv ...
[ "Load", "the", "configuration", "make", "each", "section", "available", "in", "a", "separate", "dict", "." ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/baselib/__init__.py#L56-L84
gem/oq-engine
openquake/baselib/__init__.py
boolean
def boolean(flag): """ Convert string in boolean """ s = flag.lower() if s in ('1', 'yes', 'true'): return True elif s in ('0', 'no', 'false'): return False raise ValueError('Unknown flag %r' % s)
python
def boolean(flag): s = flag.lower() if s in ('1', 'yes', 'true'): return True elif s in ('0', 'no', 'false'): return False raise ValueError('Unknown flag %r' % s)
[ "def", "boolean", "(", "flag", ")", ":", "s", "=", "flag", ".", "lower", "(", ")", "if", "s", "in", "(", "'1'", ",", "'yes'", ",", "'true'", ")", ":", "return", "True", "elif", "s", "in", "(", "'0'", ",", "'no'", ",", "'false'", ")", ":", "re...
Convert string in boolean
[ "Convert", "string", "in", "boolean" ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/baselib/__init__.py#L90-L99
gem/oq-engine
openquake/hazardlib/gsim/atkinson_boore_2006.py
AtkinsonBoore2006.get_mean_and_stddevs
def get_mean_and_stddevs(self, sites, rup, dists, imt, stddev_types): """ See :meth:`superclass method <.base.GroundShakingIntensityModel.get_mean_and_stddevs>` for spec of input and result values. """ mean = self._get_mean(sites.vs30, rup.mag, dists.rrup, imt, scale_fac=...
python
def get_mean_and_stddevs(self, sites, rup, dists, imt, stddev_types): mean = self._get_mean(sites.vs30, rup.mag, dists.rrup, imt, scale_fac=0) stddevs = self._get_stddevs(stddev_types, num_sites=sites.vs30.size) return mean, stddevs
[ "def", "get_mean_and_stddevs", "(", "self", ",", "sites", ",", "rup", ",", "dists", ",", "imt", ",", "stddev_types", ")", ":", "mean", "=", "self", ".", "_get_mean", "(", "sites", ".", "vs30", ",", "rup", ".", "mag", ",", "dists", ".", "rrup", ",", ...
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/atkinson_boore_2006.py#L98-L107
gem/oq-engine
openquake/hazardlib/gsim/atkinson_boore_2006.py
AtkinsonBoore2006._get_mean
def _get_mean(self, vs30, mag, rrup, imt, scale_fac): """ Compute and return mean """ C_HR, C_BC, C_SR, SC = self._extract_coeffs(imt) rrup = self._clip_distances(rrup) f0 = self._compute_f0_factor(rrup) f1 = self._compute_f1_factor(rrup) f2 = self._comp...
python
def _get_mean(self, vs30, mag, rrup, imt, scale_fac): C_HR, C_BC, C_SR, SC = self._extract_coeffs(imt) rrup = self._clip_distances(rrup) f0 = self._compute_f0_factor(rrup) f1 = self._compute_f1_factor(rrup) f2 = self._compute_f2_factor(rrup) pga_bc = self._get...
[ "def", "_get_mean", "(", "self", ",", "vs30", ",", "mag", ",", "rrup", ",", "imt", ",", "scale_fac", ")", ":", "C_HR", ",", "C_BC", ",", "C_SR", ",", "SC", "=", "self", ".", "_extract_coeffs", "(", "imt", ")", "rrup", "=", "self", ".", "_clip_dista...
Compute and return mean
[ "Compute", "and", "return", "mean" ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/gsim/atkinson_boore_2006.py#L109-L142
gem/oq-engine
openquake/hazardlib/gsim/atkinson_boore_2006.py
AtkinsonBoore2006._get_pga_bc
def _get_pga_bc(self, f0, f1, f2, SC, mag, rrup, vs30, scale_fac): """ Compute and return PGA on BC boundary """ pga_bc = np.zeros_like(vs30) self._compute_mean(self.COEFFS_BC[PGA()], f0, f1, f2, SC, mag, rrup, vs30 < 2000.0, pga_bc, scale_fac) ...
python
def _get_pga_bc(self, f0, f1, f2, SC, mag, rrup, vs30, scale_fac): pga_bc = np.zeros_like(vs30) self._compute_mean(self.COEFFS_BC[PGA()], f0, f1, f2, SC, mag, rrup, vs30 < 2000.0, pga_bc, scale_fac) return (10 ** pga_bc) * 1e-2 / g
[ "def", "_get_pga_bc", "(", "self", ",", "f0", ",", "f1", ",", "f2", ",", "SC", ",", "mag", ",", "rrup", ",", "vs30", ",", "scale_fac", ")", ":", "pga_bc", "=", "np", ".", "zeros_like", "(", "vs30", ")", "self", ".", "_compute_mean", "(", "self", ...
Compute and return PGA on BC boundary
[ "Compute", "and", "return", "PGA", "on", "BC", "boundary" ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/gsim/atkinson_boore_2006.py#L144-L152
gem/oq-engine
openquake/hazardlib/gsim/atkinson_boore_2006.py
AtkinsonBoore2006._extract_coeffs
def _extract_coeffs(self, imt): """ Extract dictionaries of coefficients specific to required intensity measure type. """ C_HR = self.COEFFS_HARD_ROCK[imt] C_BC = self.COEFFS_BC[imt] C_SR = self.COEFFS_SOIL_RESPONSE[imt] SC = self.COEFFS_STRESS[imt] ...
python
def _extract_coeffs(self, imt): C_HR = self.COEFFS_HARD_ROCK[imt] C_BC = self.COEFFS_BC[imt] C_SR = self.COEFFS_SOIL_RESPONSE[imt] SC = self.COEFFS_STRESS[imt] return C_HR, C_BC, C_SR, SC
[ "def", "_extract_coeffs", "(", "self", ",", "imt", ")", ":", "C_HR", "=", "self", ".", "COEFFS_HARD_ROCK", "[", "imt", "]", "C_BC", "=", "self", ".", "COEFFS_BC", "[", "imt", "]", "C_SR", "=", "self", ".", "COEFFS_SOIL_RESPONSE", "[", "imt", "]", "SC",...
Extract dictionaries of coefficients specific to required intensity measure type.
[ "Extract", "dictionaries", "of", "coefficients", "specific", "to", "required", "intensity", "measure", "type", "." ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/gsim/atkinson_boore_2006.py#L154-L164
gem/oq-engine
openquake/hazardlib/gsim/atkinson_boore_2006.py
AtkinsonBoore2006._compute_f0_factor
def _compute_f0_factor(self, rrup): """ Compute and return factor f0 - see equation (5), 6th term, p. 2191. """ # f0 = max(log10(R0/rrup),0) f0 = np.log10(self.COEFFS_IMT_INDEPENDENT['R0'] / rrup) f0[f0 < 0] = 0.0 return f0
python
def _compute_f0_factor(self, rrup): f0 = np.log10(self.COEFFS_IMT_INDEPENDENT['R0'] / rrup) f0[f0 < 0] = 0.0 return f0
[ "def", "_compute_f0_factor", "(", "self", ",", "rrup", ")", ":", "# f0 = max(log10(R0/rrup),0)", "f0", "=", "np", ".", "log10", "(", "self", ".", "COEFFS_IMT_INDEPENDENT", "[", "'R0'", "]", "/", "rrup", ")", "f0", "[", "f0", "<", "0", "]", "=", "0.0", ...
Compute and return factor f0 - see equation (5), 6th term, p. 2191.
[ "Compute", "and", "return", "factor", "f0", "-", "see", "equation", "(", "5", ")", "6th", "term", "p", ".", "2191", "." ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/gsim/atkinson_boore_2006.py#L178-L186
gem/oq-engine
openquake/hazardlib/gsim/atkinson_boore_2006.py
AtkinsonBoore2006._compute_f1_factor
def _compute_f1_factor(self, rrup): """ Compute and return factor f1 - see equation (5), 4th term, p. 2191 """ # f1 = min(log10(rrup),log10(R1)) f1 = np.log10(rrup) logR1 = np.log10(self.COEFFS_IMT_INDEPENDENT['R1']) f1[f1 > logR1] = logR1 return f1
python
def _compute_f1_factor(self, rrup): f1 = np.log10(rrup) logR1 = np.log10(self.COEFFS_IMT_INDEPENDENT['R1']) f1[f1 > logR1] = logR1 return f1
[ "def", "_compute_f1_factor", "(", "self", ",", "rrup", ")", ":", "# f1 = min(log10(rrup),log10(R1))", "f1", "=", "np", ".", "log10", "(", "rrup", ")", "logR1", "=", "np", ".", "log10", "(", "self", ".", "COEFFS_IMT_INDEPENDENT", "[", "'R1'", "]", ")", "f1"...
Compute and return factor f1 - see equation (5), 4th term, p. 2191
[ "Compute", "and", "return", "factor", "f1", "-", "see", "equation", "(", "5", ")", "4th", "term", "p", ".", "2191" ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/gsim/atkinson_boore_2006.py#L188-L197
gem/oq-engine
openquake/hazardlib/gsim/atkinson_boore_2006.py
AtkinsonBoore2006._compute_f2_factor
def _compute_f2_factor(self, rrup): """ Compute and return factor f2, see equation (5), 5th term, pag 2191 """ # f2 = max(log10(rrup/R2),0) f2 = np.log10(rrup / self.COEFFS_IMT_INDEPENDENT['R2']) f2[f2 < 0] = 0.0 return f2
python
def _compute_f2_factor(self, rrup): f2 = np.log10(rrup / self.COEFFS_IMT_INDEPENDENT['R2']) f2[f2 < 0] = 0.0 return f2
[ "def", "_compute_f2_factor", "(", "self", ",", "rrup", ")", ":", "# f2 = max(log10(rrup/R2),0)", "f2", "=", "np", ".", "log10", "(", "rrup", "/", "self", ".", "COEFFS_IMT_INDEPENDENT", "[", "'R2'", "]", ")", "f2", "[", "f2", "<", "0", "]", "=", "0.0", ...
Compute and return factor f2, see equation (5), 5th term, pag 2191
[ "Compute", "and", "return", "factor", "f2", "see", "equation", "(", "5", ")", "5th", "term", "pag", "2191" ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/gsim/atkinson_boore_2006.py#L199-L207
gem/oq-engine
openquake/hazardlib/gsim/atkinson_boore_2006.py
AtkinsonBoore2006._compute_stress_drop_adjustment
def _compute_stress_drop_adjustment(self, SC, mag, scale_fac): """ Compute equation (6) p. 2200 """ return scale_fac * np.minimum( SC['delta'] + 0.05, 0.05 + SC['delta'] * ( np.maximum(mag - SC['M1'], 0) / (SC['Mh'] - SC['M1']) ) ...
python
def _compute_stress_drop_adjustment(self, SC, mag, scale_fac): return scale_fac * np.minimum( SC['delta'] + 0.05, 0.05 + SC['delta'] * ( np.maximum(mag - SC['M1'], 0) / (SC['Mh'] - SC['M1']) ) )
[ "def", "_compute_stress_drop_adjustment", "(", "self", ",", "SC", ",", "mag", ",", "scale_fac", ")", ":", "return", "scale_fac", "*", "np", ".", "minimum", "(", "SC", "[", "'delta'", "]", "+", "0.05", ",", "0.05", "+", "SC", "[", "'delta'", "]", "*", ...
Compute equation (6) p. 2200
[ "Compute", "equation", "(", "6", ")", "p", ".", "2200" ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/gsim/atkinson_boore_2006.py#L209-L218
gem/oq-engine
openquake/hazardlib/gsim/atkinson_boore_2006.py
AtkinsonBoore2006._compute_mean
def _compute_mean(self, C, f0, f1, f2, SC, mag, rrup, idxs, mean, scale_fac): """ Compute mean value (for a set of indexes) without site amplification terms. This is equation (5), p. 2191, without S term. """ mean[idxs] = (C['c1'] + C['...
python
def _compute_mean(self, C, f0, f1, f2, SC, mag, rrup, idxs, mean, scale_fac): mean[idxs] = (C['c1'] + C['c2'] * mag + C['c3'] * (mag ** 2) + (C['c4'] + C['c5'] * mag) * f1[idxs] + (C['c6'] + C[...
[ "def", "_compute_mean", "(", "self", ",", "C", ",", "f0", ",", "f1", ",", "f2", ",", "SC", ",", "mag", ",", "rrup", ",", "idxs", ",", "mean", ",", "scale_fac", ")", ":", "mean", "[", "idxs", "]", "=", "(", "C", "[", "'c1'", "]", "+", "C", "...
Compute mean value (for a set of indexes) without site amplification terms. This is equation (5), p. 2191, without S term.
[ "Compute", "mean", "value", "(", "for", "a", "set", "of", "indexes", ")", "without", "site", "amplification", "terms", ".", "This", "is", "equation", "(", "5", ")", "p", ".", "2191", "without", "S", "term", "." ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/gsim/atkinson_boore_2006.py#L220-L233
gem/oq-engine
openquake/hazardlib/gsim/atkinson_boore_2006.py
AtkinsonBoore2006._compute_soil_amplification
def _compute_soil_amplification(self, C, vs30, pga_bc, mean): """ Compute soil amplification, that is S term in equation (5), p. 2191, and add to mean values for non hard rock sites. """ # convert from base e (as defined in BA2008) to base 10 (as used in # AB2006) ...
python
def _compute_soil_amplification(self, C, vs30, pga_bc, mean): sal = np.log10(np.exp(self._get_site_amplification_linear(vs30, C))) sanl = np.log10(np.exp( self._get_site_amplification_non_linear(vs30, pga_bc, C))) idxs = vs30 < 2000.0 mean[idxs] = ...
[ "def", "_compute_soil_amplification", "(", "self", ",", "C", ",", "vs30", ",", "pga_bc", ",", "mean", ")", ":", "# convert from base e (as defined in BA2008) to base 10 (as used in", "# AB2006)", "sal", "=", "np", ".", "log10", "(", "np", ".", "exp", "(", "self", ...
Compute soil amplification, that is S term in equation (5), p. 2191, and add to mean values for non hard rock sites.
[ "Compute", "soil", "amplification", "that", "is", "S", "term", "in", "equation", "(", "5", ")", "p", ".", "2191", "and", "add", "to", "mean", "values", "for", "non", "hard", "rock", "sites", "." ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/gsim/atkinson_boore_2006.py#L235-L247
gem/oq-engine
openquake/hazardlib/gsim/atkinson_boore_2006.py
AtkinsonBoore2006Modified2011._get_stress_drop_scaling_factor
def _get_stress_drop_scaling_factor(self, magnitude): """ Returns the magnitude dependent stress drop scaling factor defined in equation 6 (page 1128) of Atkinson & Boore (2011) """ stress_drop = 10.0 ** (3.45 - 0.2 * magnitude) cap = 10.0 ** (3.45 - 0.2 * 5.0) if...
python
def _get_stress_drop_scaling_factor(self, magnitude): stress_drop = 10.0 ** (3.45 - 0.2 * magnitude) cap = 10.0 ** (3.45 - 0.2 * 5.0) if stress_drop > cap: stress_drop = cap return log10(stress_drop / 140.0) / log10(2.0)
[ "def", "_get_stress_drop_scaling_factor", "(", "self", ",", "magnitude", ")", ":", "stress_drop", "=", "10.0", "**", "(", "3.45", "-", "0.2", "*", "magnitude", ")", "cap", "=", "10.0", "**", "(", "3.45", "-", "0.2", "*", "5.0", ")", "if", "stress_drop", ...
Returns the magnitude dependent stress drop scaling factor defined in equation 6 (page 1128) of Atkinson & Boore (2011)
[ "Returns", "the", "magnitude", "dependent", "stress", "drop", "scaling", "factor", "defined", "in", "equation", "6", "(", "page", "1128", ")", "of", "Atkinson", "&", "Boore", "(", "2011", ")" ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/gsim/atkinson_boore_2006.py#L522-L531
gem/oq-engine
openquake/hazardlib/gsim/utils.py
clip_mean
def clip_mean(imt, mean): """ Clip GMPE mean value at 1.5 g for PGA and 3 g for short periods (0.02 < T < 0.55) """ if imt.period == 0: mean[mean > 0.405] = 0.405 if 0.02 < imt.period < 0.55: mean[mean > 1.099] = 1.099 return mean
python
def clip_mean(imt, mean): if imt.period == 0: mean[mean > 0.405] = 0.405 if 0.02 < imt.period < 0.55: mean[mean > 1.099] = 1.099 return mean
[ "def", "clip_mean", "(", "imt", ",", "mean", ")", ":", "if", "imt", ".", "period", "==", "0", ":", "mean", "[", "mean", ">", "0.405", "]", "=", "0.405", "if", "0.02", "<", "imt", ".", "period", "<", "0.55", ":", "mean", "[", "mean", ">", "1.099...
Clip GMPE mean value at 1.5 g for PGA and 3 g for short periods (0.02 < T < 0.55)
[ "Clip", "GMPE", "mean", "value", "at", "1", ".", "5", "g", "for", "PGA", "and", "3", "g", "for", "short", "periods", "(", "0", ".", "02", "<", "T", "<", "0", ".", "55", ")" ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/gsim/utils.py#L45-L56
gem/oq-engine
openquake/calculators/getters.py
gen_rupture_getters
def gen_rupture_getters(dstore, slc=slice(None), concurrent_tasks=1, hdf5cache=None): """ :yields: RuptureGetters """ if dstore.parent: dstore = dstore.parent csm_info = dstore['csm_info'] trt_by_grp = csm_info.grp_by("trt") samples = csm_info.get_samples_by_g...
python
def gen_rupture_getters(dstore, slc=slice(None), concurrent_tasks=1, hdf5cache=None): if dstore.parent: dstore = dstore.parent csm_info = dstore['csm_info'] trt_by_grp = csm_info.grp_by("trt") samples = csm_info.get_samples_by_grp() rlzs_by_gsim = csm_info.get_rl...
[ "def", "gen_rupture_getters", "(", "dstore", ",", "slc", "=", "slice", "(", "None", ")", ",", "concurrent_tasks", "=", "1", ",", "hdf5cache", "=", "None", ")", ":", "if", "dstore", ".", "parent", ":", "dstore", "=", "dstore", ".", "parent", "csm_info", ...
:yields: RuptureGetters
[ ":", "yields", ":", "RuptureGetters" ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/calculators/getters.py#L433-L460
gem/oq-engine
openquake/calculators/getters.py
get_maxloss_rupture
def get_maxloss_rupture(dstore, loss_type): """ :param dstore: a DataStore instance :param loss_type: a loss type string :returns: EBRupture instance corresponding to the maximum loss for the given loss type """ lti = dstore['oqparam'].lti[loss_type] ridx = dstore.get_attr('r...
python
def get_maxloss_rupture(dstore, loss_type): lti = dstore['oqparam'].lti[loss_type] ridx = dstore.get_attr('rup_loss_table', 'ridx')[lti] [rgetter] = gen_rupture_getters(dstore, slice(ridx, ridx + 1)) [ebr] = rgetter.get_ruptures() return ebr
[ "def", "get_maxloss_rupture", "(", "dstore", ",", "loss_type", ")", ":", "lti", "=", "dstore", "[", "'oqparam'", "]", ".", "lti", "[", "loss_type", "]", "ridx", "=", "dstore", ".", "get_attr", "(", "'rup_loss_table'", ",", "'ridx'", ")", "[", "lti", "]",...
:param dstore: a DataStore instance :param loss_type: a loss type string :returns: EBRupture instance corresponding to the maximum loss for the given loss type
[ ":", "param", "dstore", ":", "a", "DataStore", "instance", ":", "param", "loss_type", ":", "a", "loss", "type", "string", ":", "returns", ":", "EBRupture", "instance", "corresponding", "to", "the", "maximum", "loss", "for", "the", "given", "loss", "type" ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/calculators/getters.py#L463-L475
gem/oq-engine
openquake/calculators/getters.py
PmapGetter.init
def init(self): """ Read the poes and set the .data attribute with the hazard curves """ if hasattr(self, 'data'): # already initialized return if isinstance(self.dstore, str): self.dstore = hdf5.File(self.dstore, 'r') else: self.dstor...
python
def init(self): if hasattr(self, 'data'): return if isinstance(self.dstore, str): self.dstore = hdf5.File(self.dstore, 'r') else: self.dstore.open('r') if self.sids is None: self.sids = self.dstore['sitecol'].sids oq = ...
[ "def", "init", "(", "self", ")", ":", "if", "hasattr", "(", "self", ",", "'data'", ")", ":", "# already initialized", "return", "if", "isinstance", "(", "self", ".", "dstore", ",", "str", ")", ":", "self", ".", "dstore", "=", "hdf5", ".", "File", "("...
Read the poes and set the .data attribute with the hazard curves
[ "Read", "the", "poes", "and", "set", "the", ".", "data", "attribute", "with", "the", "hazard", "curves" ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/calculators/getters.py#L66-L91
gem/oq-engine
openquake/calculators/getters.py
PmapGetter.pmap_by_grp
def pmap_by_grp(self): """ :returns: dictionary "grp-XXX" -> ProbabilityMap instance """ if hasattr(self, '_pmap_by_grp'): # already called return self._pmap_by_grp # populate _pmap_by_grp self._pmap_by_grp = {} if 'poes' in self.dstore: #...
python
def pmap_by_grp(self): if hasattr(self, '_pmap_by_grp'): return self._pmap_by_grp self._pmap_by_grp = {} if 'poes' in self.dstore: ok_sids = set(self.sids) for grp, dset in self.dstore['poes'].items(): ds = dset...
[ "def", "pmap_by_grp", "(", "self", ")", ":", "if", "hasattr", "(", "self", ",", "'_pmap_by_grp'", ")", ":", "# already called", "return", "self", ".", "_pmap_by_grp", "# populate _pmap_by_grp", "self", ".", "_pmap_by_grp", "=", "{", "}", "if", "'poes'", "in", ...
:returns: dictionary "grp-XXX" -> ProbabilityMap instance
[ ":", "returns", ":", "dictionary", "grp", "-", "XXX", "-", ">", "ProbabilityMap", "instance" ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/calculators/getters.py#L94-L114
gem/oq-engine
openquake/calculators/getters.py
PmapGetter.get
def get(self, rlzi, grp=None): """ :param rlzi: a realization index :param grp: None (all groups) or a string of the form "grp-XX" :returns: the hazard curves for the given realization """ self.init() assert self.sids is not None pmap = probability_map.Pro...
python
def get(self, rlzi, grp=None): self.init() assert self.sids is not None pmap = probability_map.ProbabilityMap(len(self.imtls.array), 1) grps = [grp] if grp is not None else sorted(self.pmap_by_grp) array = self.rlzs_assoc.by_grp() for grp in grps: for...
[ "def", "get", "(", "self", ",", "rlzi", ",", "grp", "=", "None", ")", ":", "self", ".", "init", "(", ")", "assert", "self", ".", "sids", "is", "not", "None", "pmap", "=", "probability_map", ".", "ProbabilityMap", "(", "len", "(", "self", ".", "imtl...
:param rlzi: a realization index :param grp: None (all groups) or a string of the form "grp-XX" :returns: the hazard curves for the given realization
[ ":", "param", "rlzi", ":", "a", "realization", "index", ":", "param", "grp", ":", "None", "(", "all", "groups", ")", "or", "a", "string", "of", "the", "form", "grp", "-", "XX", ":", "returns", ":", "the", "hazard", "curves", "for", "the", "given", ...
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/calculators/getters.py#L123-L140
gem/oq-engine
openquake/calculators/getters.py
PmapGetter.get_hcurves
def get_hcurves(self, imtls=None): """ :param imtls: intensity measure types and levels :returns: an array of (R, N) hazard curves """ self.init() if imtls is None: imtls = self.imtls pmaps = [pmap.convert2(imtls, self.sids) for pmap i...
python
def get_hcurves(self, imtls=None): self.init() if imtls is None: imtls = self.imtls pmaps = [pmap.convert2(imtls, self.sids) for pmap in self.get_pmaps()] return numpy.array(pmaps)
[ "def", "get_hcurves", "(", "self", ",", "imtls", "=", "None", ")", ":", "self", ".", "init", "(", ")", "if", "imtls", "is", "None", ":", "imtls", "=", "self", ".", "imtls", "pmaps", "=", "[", "pmap", ".", "convert2", "(", "imtls", ",", "self", "....
:param imtls: intensity measure types and levels :returns: an array of (R, N) hazard curves
[ ":", "param", "imtls", ":", "intensity", "measure", "types", "and", "levels", ":", "returns", ":", "an", "array", "of", "(", "R", "N", ")", "hazard", "curves" ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/calculators/getters.py#L148-L158
gem/oq-engine
openquake/calculators/getters.py
PmapGetter.items
def items(self, kind=''): """ Extract probability maps from the datastore, possibly generating on the fly the ones corresponding to the individual realizations. Yields pairs (tag, pmap). :param kind: the kind of PoEs to extract; if not given, returns the realization ...
python
def items(self, kind=''): num_rlzs = len(self.weights) if not kind or kind == 'all': if 'hcurves' in self.dstore: for k in sorted(self.dstore['hcurves']): yield k, self.dstore['hcurves/' + k].value elif num_rlzs == 1: ...
[ "def", "items", "(", "self", ",", "kind", "=", "''", ")", ":", "num_rlzs", "=", "len", "(", "self", ".", "weights", ")", "if", "not", "kind", "or", "kind", "==", "'all'", ":", "# use default", "if", "'hcurves'", "in", "self", ".", "dstore", ":", "f...
Extract probability maps from the datastore, possibly generating on the fly the ones corresponding to the individual realizations. Yields pairs (tag, pmap). :param kind: the kind of PoEs to extract; if not given, returns the realization if there is only one or the statis...
[ "Extract", "probability", "maps", "from", "the", "datastore", "possibly", "generating", "on", "the", "fly", "the", "ones", "corresponding", "to", "the", "individual", "realizations", ".", "Yields", "pairs", "(", "tag", "pmap", ")", "." ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/calculators/getters.py#L160-L187
gem/oq-engine
openquake/calculators/getters.py
PmapGetter.get_mean
def get_mean(self, grp=None): """ Compute the mean curve as a ProbabilityMap :param grp: if not None must be a string of the form "grp-XX"; in that case returns the mean considering only the contribution for group XX """ self.init() if len(self.we...
python
def get_mean(self, grp=None): self.init() if len(self.weights) == 1: pmap = self.get(0, grp) for sid, pcurve in pmap.items(): array = numpy.zeros(pcurve.array.shape[:-1] + (2,)) array[:, 0] = pcurve.array[:, 0] ...
[ "def", "get_mean", "(", "self", ",", "grp", "=", "None", ")", ":", "self", ".", "init", "(", ")", "if", "len", "(", "self", ".", "weights", ")", "==", "1", ":", "# one realization", "# the standard deviation is zero", "pmap", "=", "self", ".", "get", "...
Compute the mean curve as a ProbabilityMap :param grp: if not None must be a string of the form "grp-XX"; in that case returns the mean considering only the contribution for group XX
[ "Compute", "the", "mean", "curve", "as", "a", "ProbabilityMap" ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/calculators/getters.py#L189-L212
gem/oq-engine
openquake/calculators/getters.py
GmfGetter.init
def init(self): """ Initialize the computers. Should be called on the workers """ if hasattr(self, 'computers'): # init already called return with hdf5.File(self.rupgetter.filename, 'r') as parent: self.weights = parent['weights'].value self.compu...
python
def init(self): if hasattr(self, 'computers'): return with hdf5.File(self.rupgetter.filename, 'r') as parent: self.weights = parent['weights'].value self.computers = [] for ebr in self.rupgetter.get_ruptures(self.srcfilter): sitecol = self.s...
[ "def", "init", "(", "self", ")", ":", "if", "hasattr", "(", "self", ",", "'computers'", ")", ":", "# init already called", "return", "with", "hdf5", ".", "File", "(", "self", ".", "rupgetter", ".", "filename", ",", "'r'", ")", "as", "parent", ":", "sel...
Initialize the computers. Should be called on the workers
[ "Initialize", "the", "computers", ".", "Should", "be", "called", "on", "the", "workers" ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/calculators/getters.py#L306-L326
gem/oq-engine
openquake/calculators/getters.py
GmfGetter.gen_gmfs
def gen_gmfs(self): """ Compute the GMFs for the given realization and yields arrays of the dtype (sid, eid, imti, gmv), one for rupture """ self.sig_eps = [] for computer in self.computers: rup = computer.rupture sids = computer.sids e...
python
def gen_gmfs(self): self.sig_eps = [] for computer in self.computers: rup = computer.rupture sids = computer.sids eids_by_rlz = rup.get_eids_by_rlz(self.rlzs_by_gsim) data = [] for gs, rlzs in self.rlzs_by_gsim.items(): ...
[ "def", "gen_gmfs", "(", "self", ")", ":", "self", ".", "sig_eps", "=", "[", "]", "for", "computer", "in", "self", ".", "computers", ":", "rup", "=", "computer", ".", "rupture", "sids", "=", "computer", ".", "sids", "eids_by_rlz", "=", "rup", ".", "ge...
Compute the GMFs for the given realization and yields arrays of the dtype (sid, eid, imti, gmv), one for rupture
[ "Compute", "the", "GMFs", "for", "the", "given", "realization", "and", "yields", "arrays", "of", "the", "dtype", "(", "sid", "eid", "imti", "gmv", ")", "one", "for", "rupture" ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/calculators/getters.py#L328-L368
gem/oq-engine
openquake/calculators/getters.py
GmfGetter.get_gmfdata
def get_gmfdata(self): """ :returns: an array of the dtype (sid, eid, imti, gmv) """ alldata = list(self.gen_gmfs()) if not alldata: return numpy.zeros(0, self.gmv_dt) return numpy.concatenate(alldata)
python
def get_gmfdata(self): alldata = list(self.gen_gmfs()) if not alldata: return numpy.zeros(0, self.gmv_dt) return numpy.concatenate(alldata)
[ "def", "get_gmfdata", "(", "self", ")", ":", "alldata", "=", "list", "(", "self", ".", "gen_gmfs", "(", ")", ")", "if", "not", "alldata", ":", "return", "numpy", ".", "zeros", "(", "0", ",", "self", ".", "gmv_dt", ")", "return", "numpy", ".", "conc...
:returns: an array of the dtype (sid, eid, imti, gmv)
[ ":", "returns", ":", "an", "array", "of", "the", "dtype", "(", "sid", "eid", "imti", "gmv", ")" ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/calculators/getters.py#L370-L377
gem/oq-engine
openquake/calculators/getters.py
GmfGetter.get_hazard
def get_hazard(self, data=None): """ :param data: if given, an iterator of records of dtype gmf_dt :returns: sid -> records """ if data is None: data = self.get_gmfdata() return general.group_array(data, 'sid')
python
def get_hazard(self, data=None): if data is None: data = self.get_gmfdata() return general.group_array(data, 'sid')
[ "def", "get_hazard", "(", "self", ",", "data", "=", "None", ")", ":", "if", "data", "is", "None", ":", "data", "=", "self", ".", "get_gmfdata", "(", ")", "return", "general", ".", "group_array", "(", "data", ",", "'sid'", ")" ]
:param data: if given, an iterator of records of dtype gmf_dt :returns: sid -> records
[ ":", "param", "data", ":", "if", "given", "an", "iterator", "of", "records", "of", "dtype", "gmf_dt", ":", "returns", ":", "sid", "-", ">", "records" ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/calculators/getters.py#L379-L386
gem/oq-engine
openquake/calculators/getters.py
GmfGetter.compute_gmfs_curves
def compute_gmfs_curves(self, monitor): """ :returns: a dict with keys gmfdata, indices, hcurves """ oq = self.oqparam with monitor('GmfGetter.init', measuremem=True): self.init() hcurves = {} # key -> poes if oq.hazard_curves_from_gmfs: h...
python
def compute_gmfs_curves(self, monitor): oq = self.oqparam with monitor('GmfGetter.init', measuremem=True): self.init() hcurves = {} if oq.hazard_curves_from_gmfs: hc_mon = monitor('building hazard curves', measuremem=False) duration = oq.inv...
[ "def", "compute_gmfs_curves", "(", "self", ",", "monitor", ")", ":", "oq", "=", "self", ".", "oqparam", "with", "monitor", "(", "'GmfGetter.init'", ",", "measuremem", "=", "True", ")", ":", "self", ".", "init", "(", ")", "hcurves", "=", "{", "}", "# ke...
:returns: a dict with keys gmfdata, indices, hcurves
[ ":", "returns", ":", "a", "dict", "with", "keys", "gmfdata", "indices", "hcurves" ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/calculators/getters.py#L388-L430
gem/oq-engine
openquake/calculators/getters.py
RuptureGetter.set_weights
def set_weights(self, src_filter, num_taxonomies_by_site): """ :returns: the weights of the ruptures in the getter """ weights = [] for rup in self.rup_array: sids = src_filter.close_sids(rup, self.trt, rup['mag']) weights.append(num_taxonomies_by_site[sid...
python
def set_weights(self, src_filter, num_taxonomies_by_site): weights = [] for rup in self.rup_array: sids = src_filter.close_sids(rup, self.trt, rup['mag']) weights.append(num_taxonomies_by_site[sids].sum()) self.weights = numpy.array(weights) self.weight =...
[ "def", "set_weights", "(", "self", ",", "src_filter", ",", "num_taxonomies_by_site", ")", ":", "weights", "=", "[", "]", "for", "rup", "in", "self", ".", "rup_array", ":", "sids", "=", "src_filter", ".", "close_sids", "(", "rup", ",", "self", ".", "trt",...
:returns: the weights of the ruptures in the getter
[ ":", "returns", ":", "the", "weights", "of", "the", "ruptures", "in", "the", "getter" ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/calculators/getters.py#L540-L549
gem/oq-engine
openquake/calculators/getters.py
RuptureGetter.split
def split(self, maxweight): """ :yields: RuptureGetters with weight <= maxweight """ # NB: can be called only after .set_weights() has been called idx = {ri: i for i, ri in enumerate(self.rup_indices)} for rup_indices in general.block_splitter( self.rup_in...
python
def split(self, maxweight): idx = {ri: i for i, ri in enumerate(self.rup_indices)} for rup_indices in general.block_splitter( self.rup_indices, maxweight, lambda ri: self.weights[idx[ri]]): if rup_indices: rgetter = self.__cl...
[ "def", "split", "(", "self", ",", "maxweight", ")", ":", "# NB: can be called only after .set_weights() has been called", "idx", "=", "{", "ri", ":", "i", "for", "i", ",", "ri", "in", "enumerate", "(", "self", ".", "rup_indices", ")", "}", "for", "rup_indices"...
:yields: RuptureGetters with weight <= maxweight
[ ":", "yields", ":", "RuptureGetters", "with", "weight", "<", "=", "maxweight" ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/calculators/getters.py#L551-L567
gem/oq-engine
openquake/calculators/getters.py
RuptureGetter.get_eid_rlz
def get_eid_rlz(self, monitor=None): """ :returns: a composite array with the associations eid->rlz """ eid_rlz = [] for rup in self.rup_array: ebr = EBRupture(mock.Mock(serial=rup['serial']), rup['srcidx'], self.grp_id, rup['n_occ'], self....
python
def get_eid_rlz(self, monitor=None): eid_rlz = [] for rup in self.rup_array: ebr = EBRupture(mock.Mock(serial=rup['serial']), rup['srcidx'], self.grp_id, rup['n_occ'], self.samples) for rlz, eids in ebr.get_eids_by_rlz(self.rlzs_by_gsim).items...
[ "def", "get_eid_rlz", "(", "self", ",", "monitor", "=", "None", ")", ":", "eid_rlz", "=", "[", "]", "for", "rup", "in", "self", ".", "rup_array", ":", "ebr", "=", "EBRupture", "(", "mock", ".", "Mock", "(", "serial", "=", "rup", "[", "'serial'", "]...
:returns: a composite array with the associations eid->rlz
[ ":", "returns", ":", "a", "composite", "array", "with", "the", "associations", "eid", "-", ">", "rlz" ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/calculators/getters.py#L569-L580
gem/oq-engine
openquake/calculators/getters.py
RuptureGetter.get_rupdict
def get_rupdict(self): """ :returns: a dictionary with the parameters of the rupture """ assert len(self.rup_array) == 1, 'Please specify a slice of length 1' dic = {'trt': self.trt, 'samples': self.samples} with datastore.read(self.filename) as dstore: rupgeo...
python
def get_rupdict(self): assert len(self.rup_array) == 1, 'Please specify a slice of length 1' dic = {'trt': self.trt, 'samples': self.samples} with datastore.read(self.filename) as dstore: rupgeoms = dstore['rupgeoms'] source_ids = dstore['source_info']['source_id...
[ "def", "get_rupdict", "(", "self", ")", ":", "assert", "len", "(", "self", ".", "rup_array", ")", "==", "1", ",", "'Please specify a slice of length 1'", "dic", "=", "{", "'trt'", ":", "self", ".", "trt", ",", "'samples'", ":", "self", ".", "samples", "}...
:returns: a dictionary with the parameters of the rupture
[ ":", "returns", ":", "a", "dictionary", "with", "the", "parameters", "of", "the", "rupture" ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/calculators/getters.py#L582-L607
gem/oq-engine
openquake/calculators/getters.py
RuptureGetter.get_ruptures
def get_ruptures(self, srcfilter=calc.filters.nofilter): """ :returns: a list of EBRuptures filtered by bounding box """ ebrs = [] with datastore.read(self.filename) as dstore: rupgeoms = dstore['rupgeoms'] for rec in self.rup_array: if src...
python
def get_ruptures(self, srcfilter=calc.filters.nofilter): ebrs = [] with datastore.read(self.filename) as dstore: rupgeoms = dstore['rupgeoms'] for rec in self.rup_array: if srcfilter.integration_distance: sids = srcfilter.close_sids(re...
[ "def", "get_ruptures", "(", "self", ",", "srcfilter", "=", "calc", ".", "filters", ".", "nofilter", ")", ":", "ebrs", "=", "[", "]", "with", "datastore", ".", "read", "(", "self", ".", "filename", ")", "as", "dstore", ":", "rupgeoms", "=", "dstore", ...
:returns: a list of EBRuptures filtered by bounding box
[ ":", "returns", ":", "a", "list", "of", "EBRuptures", "filtered", "by", "bounding", "box" ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/calculators/getters.py#L609-L660
gem/oq-engine
openquake/calculators/getters.py
RuptureGetter.E2R
def E2R(self, array, rlzi): """ :param array: an array of shape (E, ...) :param rlzi: an array of E realization indices :returns: an aggregated array of shape (R, ...) """ z = numpy.zeros((self.num_rlzs,) + array.shape[1:], array.dtype) for a, r in zip(array, rlzi...
python
def E2R(self, array, rlzi): z = numpy.zeros((self.num_rlzs,) + array.shape[1:], array.dtype) for a, r in zip(array, rlzi): z[self.rlz2idx[r]] += a return z
[ "def", "E2R", "(", "self", ",", "array", ",", "rlzi", ")", ":", "z", "=", "numpy", ".", "zeros", "(", "(", "self", ".", "num_rlzs", ",", ")", "+", "array", ".", "shape", "[", "1", ":", "]", ",", "array", ".", "dtype", ")", "for", "a", ",", ...
:param array: an array of shape (E, ...) :param rlzi: an array of E realization indices :returns: an aggregated array of shape (R, ...)
[ ":", "param", "array", ":", "an", "array", "of", "shape", "(", "E", "...", ")", ":", "param", "rlzi", ":", "an", "array", "of", "E", "realization", "indices", ":", "returns", ":", "an", "aggregated", "array", "of", "shape", "(", "R", "...", ")" ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/calculators/getters.py#L662-L671
gem/oq-engine
openquake/hazardlib/gsim/bindi_2017.py
BindiEtAl2017Rjb.get_mean_and_stddevs
def get_mean_and_stddevs(self, sites, rup, dists, imt, stddev_types): """ See :meth:`superclass method <.base.GroundShakingIntensityModel.get_mean_and_stddevs>` for spec of input and result values. """ # extracting dictionary of coefficients specific to required #...
python
def get_mean_and_stddevs(self, sites, rup, dists, imt, stddev_types): C = self.COEFFS[imt] mean = (self._get_magnitude_scaling(C, rup.mag) + self._get_distance_scaling(C, dists, rup.mag) + self._get_site_term(C, sites.vs30)) m...
[ "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/bindi_2017.py#L79-L96
gem/oq-engine
openquake/hazardlib/gsim/bindi_2017.py
BindiEtAl2017Rjb._get_magnitude_scaling
def _get_magnitude_scaling(self, C, mag): """ Implements the magnitude scaling function F(M) presented in equation 4 """ if mag < self.CONSTANTS["mh"]: return C["e1"] + C["b1"] * (mag - self.CONSTANTS["mref"]) +\ C["b2"] * ((mag - self.CONSTANTS["mref"]) ** 2....
python
def _get_magnitude_scaling(self, C, mag): if mag < self.CONSTANTS["mh"]: return C["e1"] + C["b1"] * (mag - self.CONSTANTS["mref"]) +\ C["b2"] * ((mag - self.CONSTANTS["mref"]) ** 2.) else: d_m = self.CONSTANTS["mh"] - self.CONSTANTS["mref"] re...
[ "def", "_get_magnitude_scaling", "(", "self", ",", "C", ",", "mag", ")", ":", "if", "mag", "<", "self", ".", "CONSTANTS", "[", "\"mh\"", "]", ":", "return", "C", "[", "\"e1\"", "]", "+", "C", "[", "\"b1\"", "]", "*", "(", "mag", "-", "self", ".",...
Implements the magnitude scaling function F(M) presented in equation 4
[ "Implements", "the", "magnitude", "scaling", "function", "F", "(", "M", ")", "presented", "in", "equation", "4" ]
train
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/gsim/bindi_2017.py#L98-L108