Returns the distance scaling term accounting for geometric and
        anelastic attenuation
559871
def _compute_distance_scaling(self, C, rhypo):
        
        return C["c"] * np.log10(np.sqrt((rhypo ** 2.) + (C["h"] ** 2.))) +\
            (C["d"] * rhypo)
792009
def distance_to(self, *args):
        """"""
        if not len(args) > 0:
            raise ValueError("at least one parameter must be given")

        x = args[0]
        if len(args) > 1:
            unit = args[1]
        else:
            unit = "px"
        u = {"px": (1.,1.), "in": (1.,72.), "cm": (2.54, 72.),
             "mm": (25.4, 72.)}
        f = u[unit][0] / u[unit][1]
        if type(x) is Point:
            return abs(self - x) * f

# from here on, x is a rectangle
# as a safeguard, make a finite copy of it
        r = Rect(x.top_left, x.top_left)
        r = r | x.bottom_right
        if self in r:
            return 0.0
        if self.x > r.x1:
            if self.y >= r.y1:
                return self.distance_to(r.bottom_right, unit)
            elif self.y <= r.y0:
                return self.distance_to(r.top_right, unit)
            else:
                return (self.x - r.x1) * f
        elif r.x0 <= self.x <= r.x1:
            if self.y >= r.y1:
                return (self.y - r.y1) * f
            else:
                return (r.y0 - self.y) * f
        else:
            if self.y >= r.y1:
                return self.distance_to(r.bottom_left, unit)
            elif self.y <= r.y0:
                return self.distance_to(r.top_left, unit)
            else:
                return (r.x0 - self.x) * f
555461
def _get_geometric_attenuation_term(self, C, mag, rrup):
        
        return (C["c5"] + C["c6"] * mag) * np.log(np.sqrt((rrup ** 2.) +
                                                          (C["c7"] ** 2.)))
961447
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
1033379
def nn_dims(self, x, y, dims_x, dims_y, k=1, radius=np.inf, eps=0.0, p=2):
        
        assert len(x) == len(dims_x)
        assert len(y) == len(dims_y)
        if len(dims_x) == 0:
            kdtree = scipy.spatial.cKDTree([np.array(data_y)[np.array(dims_y) - self.dim_x] for data_y in self.data[DATA_Y]])
        elif len(dims_y) == 0:
            kdtree = scipy.spatial.cKDTree([np.array(data_x)[dims_x] for data_x in self.data[DATA_X]])
        else:
            kdtree = scipy.spatial.cKDTree([np.hstack((np.array(data_x)[dims_x], np.array(data_y)[np.array(dims_y) - self.dim_x])) for data_x,data_y in zip(self.data[DATA_X], self.data[DATA_Y])])
        dists, idxes =  kdtree.query(np.hstack((x, y)), 
                               k = k, 
                               distance_upper_bound = radius,
                               eps = eps, 
                               p = p)
        if k == 1:
            dists, idxes = np.array([dists]), [idxes]
        return dists, idxes
688655
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]

        mean = (self._get_magnitude_scaling_term(C, rup.mag) +
                self._get_distance_scaling_term(C, rup.mag, dists.rrup) +
                self._get_style_of_faulting_term(C, rup.rake) +
                self._get_site_scaling_term(C, sites.vs30))

        stddevs = self._get_stddevs(imt,
                                    rup.mag,
                                    len(dists.rrup),
                                    stddev_types)
        return mean, stddevs
1266311
def _compute_distance_term(self, C, mag, rrup):
        
        term1 = C['b'] * rrup
        term2 = - np.log(rrup + C['c'] * np.exp(C['d'] * mag))

        return term1 + term2
936458
def _get_magnitude_scaling_term(self, C, mag):
        
        if mag < 6.75:
            return C["a1_lo"] + C["a2_lo"] * mag + C["a3"] *\
                ((8.5 - mag) ** 2.0)
        else:
            return C["a1_hi"] + C["a2_hi"] * mag + C["a3"] *\
                ((8.5 - mag) ** 2.0)
634529
def _get_distance_term(self, C, rrup, mag):
        
        r_adj = np.sqrt(rrup ** 2.0 + (mag ** 2.0 - 3.1 * mag - 14.55) ** 2.)
        return C["c1"] * np.log10(r_adj) + C["c2"] * r_adj
411797
def _get_site_scaling(self, C, pga_rock, sites, period, rjb):
        
        flin = self._get_linear_site_term(C, sites.vs30)
        fnl = self._get_nonlinear_site_term(C, sites.vs30, pga_rock)
        fbd = self._get_basin_depth_term(C, sites, period)
        return flin + fnl + fbd
677333
def _compute_geometrical_spreading_term(self, C, rrup):
        
        f2 = np.ones_like(rrup)
        idx1 = np.nonzero(rrup <= 70.)
        idx2 = np.nonzero((rrup > 70.) & (rrup <= 130.))
        idx3 = np.nonzero(rrup > 130.)

        f2[idx1] = (C['c9'] * np.log(rrup[idx1] + 4.5))
        f2[idx2] = (C['c10'] * np.log(rrup[idx2]/70.) +
                    C['c9'] * np.log(rrup[idx2] + 4.5))
        f2[idx3] = (C['c11'] * np.log(rrup[idx3]/130.) +
                    C['c10'] * np.log(rrup[idx3]/70.) +
                    C['c9'] * np.log(rrup[idx3] + 4.5))
        return f2
1369181
def _get_distance_term(self, C, rjb, mag):
        
        c_3 = self._get_anelastic_coeff(C)
        rval = np.sqrt(rjb ** 2. + C["h"] ** 2.)
        return (C["c1"] + C["c2"] * (mag - self.CONSTS["Mref"])) *\
            np.log(rval / self.CONSTS["Rref"]) +\
            c_3 * (rval - self.CONSTS["Rref"])
159423
def get_magnitude_term(self, C, rup):
        
        b0, stress_drop = self._get_sof_terms(C, rup.rake)
        if rup.mag <= C["m1"]:
            return b0
        else:
            # Calculate moment (equation 5)
            m_0 = 10.0 ** (1.5 * rup.mag + 16.05)
            # Get stress-drop scaling (equation 6)
            if rup.mag > C["m2"]:
                stress_drop += (C["b2"] * (C["m2"] - self.CONSTANTS["mstar"]) +
                                (C["b3"] * (rup.mag - C["m2"])))
            else:
                stress_drop += (C["b2"] * (rup.mag - self.CONSTANTS["mstar"]))
            stress_drop = np.exp(stress_drop)
            # Get corner frequency (equation 4)
            f0 = 4.9 * 1.0E6 * 3.2 * ((stress_drop / m_0) ** (1. / 3.))
            return 1. / f0
515910
def t(self):
        
        t = np.array([self._plane_width / 2,
                      self._plane_height / 2,
                      self._depth_scale / 2])
        return t
234428
def scale(self):
        
        # use vertices peak-peak rather than exact extents
        scale = float((self.vertices.ptp(axis=0) ** 2).sum() ** .5)
        return scale
1291382
def _compute_magnitude_scaling(self, rup, C):
        
        U, SS, NS, RS = self._get_fault_type_dummy_variables(rup)
        if rup.mag <= C['Mh']:
            return C['e1'] * U + C['e2'] * SS + C['e3'] * NS + C['e4'] * RS + \
                C['e5'] * (rup.mag - C['Mh']) + \
                C['e6'] * (rup.mag - C['Mh']) ** 2
        else:
            return C['e1'] * U + C['e2'] * SS + C['e3'] * NS + C['e4'] * RS + \
                C['e7'] * (rup.mag - C['Mh'])
1101577
def geometricMean(alldistribT):
    """"""
    return np.exp(np.mean(np.log(alldistribT), axis=1))