Returns the magnitude scaling term
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
696331
def _compute_mean(self, C, mag, dists, rake):
        
        mean = (
            C['a1'] +
            self._compute_linear_magnitude_term(C, mag) +
            self._compute_quadratic_magnitude_term(C, mag) +
            self._compute_logarithmic_distance_term(C, mag, dists) +
            self._compute_faulting_style_term(C, rake)
        )

        return mean
944975
def magnitude(a):
    ""
    from math import sqrt
    sum = 0
    for coord in a:
        sum += coord ** 2
    return sqrt(sum)
354935
def _get_magnitude_term(self, C, mag):
        
        lny = C['C1'] + (C['C3'] * ((8.5 - mag) ** 2.))
        if mag > 6.3:
            return lny + (-C['H'] * C['C5']) * (mag - 6.3)
        else:
            return lny + C['C2'] * (mag - 6.3)
955204
def _get_pga_on_rock(self, C, rup, dists):
        
        return np.exp(self._get_magnitude_scaling_term(C, rup) +
                      self._get_path_scaling(C, dists, rup.mag))
16817
def moment_magnitude_scalar(moment):
    '''
    
    '''
    if isinstance(moment, np.ndarray):
        return (2. / 3.) * (np.log10(moment) - 9.05)
    else:
        return (2. / 3.) * (log10(moment) - 9.05)
1152763
def _compute_distance_scaling(self, C, rrup, mag):
        
        rscale1 = rrup + C["c2"] * (10.0 ** (C["c3"] * mag))
        return -np.log10(rscale1) - (C["c4"] * rrup)
487353
def log_magnitude_spectrum(frames):
    """"""
    return N.log(N.abs(N.fft.rfft(frames)).clip(1e-5, N.inf))
1069399
def _compute_mean(self, C, rup, rjb):
        
        mean = (C['c1'] +
                self._compute_magnitude_term(C, rup) +
                self._compute_distance_term(C, rup, rjb))
        return mean
602089
def get_scaling_function(y_m, y_M, x_m, x_M):
    
    if x_M <= x_m:
        return lambda _: y_m
    k = (y_M - y_m) / (x_M - x_m)
    b = y_m - k * x_m
    return lambda _: int(k * _ + b)
554591
def _getScalesRand(self):
        
        if self.P>1:
            scales = []
            for term_i in range(self.n_terms):
                _scales = SP.randn(self.diag[term_i].shape[0])
                if self.offset[term_i]>0:
                    _scales = SP.concatenate((_scales,SP.array([SP.sqrt(self.offset[term_i])])))
                scales.append(_scales)
            scales = SP.concatenate(scales)
        else:
            scales=SP.randn(self.vd.getNumberScales())

        return scales
641156
function getScales(xyMinMaxCurr, xyMinMaxOrigin) {
    var sizeCurr = getSize(xyMinMaxCurr);
    var sizeOrigin = getSize(xyMinMaxOrigin);
    var scales = [sizeCurr[0] / sizeOrigin[0], sizeCurr[1] / sizeOrigin[1]];
    isNaN(scales[0]) && (scales[0] = 1);
    isNaN(scales[1]) && (scales[1] = 1);
    return scales;
}
726373
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)
1199953
def _get_magnitude_term(self, C, mag):
        
        dmag = mag - 8.0
        return C["c0"] + C["c3"] * dmag + C["c4"] * (dmag ** 2.)
833436
def _compute_magnitude_scaling_term(self, C, mag):
        
        c1 = self.CONSTS['c1']
        if mag <= c1:
            return C['b1'] + C['b2'] * (mag - c1) + C['b3'] * (8.5 - mag) ** 2
        else:
            return C['b1'] + C['b7'] * (mag - c1) + C['b3'] * (8.5 - mag) ** 2
1015420
def _compute_mean(self, C, rup, dists, sites, imt):
        
        # Convert rhypo to rrup
        rrup = rhypo_to_rrup(dists.rhypo, rup.mag)
        mean = (self._get_magnitude_scaling_term(C, rup.mag) +
                self._get_distance_scaling_term(C, rup.mag, rrup) +
                self._get_style_of_faulting_term(C, rup.rake) +
                self._get_site_amplification_term(C, sites.vs30))
        # convert from cm/s**2 to g for SA and from cm/s**2 to g for PGA (PGV
        # is already in cm/s) and also convert from base 10 to base e.
        if isinstance(imt, PGA):
            mean = np.log((10 ** mean) * ((2 * np.pi / 0.01) ** 2) *
                          1e-2 / g)
        elif isinstance(imt, SA):
            mean = np.log((10 ** mean) * ((2 * np.pi / imt.period) ** 2) *
                          1e-2 / g)
        else:
            mean = np.log(10 ** mean)

        return mean + self.adjustment_factor
690649
def scale(p, factor, o=(0, 0)):
    
    v = vector(o, p)
    sv = v[0] * factor, v[1] * factor
    return translate(sv, o)