Compute term 3 and 4 in equation 1 page 1.
483264
def _compute_term_3_4(self, dists, C):
        
        cutoff = 6.056877878
        rhypo = dists.rhypo.copy()
        rhypo[rhypo <= cutoff] = cutoff
        return C['c3'] * np.log(rhypo) + C['c4'] * rhypo
160651
private int trMedian3(int ISAd, int v1, int v2, int v3) {
        if (SA[ISAd + SA[v1]] > SA[ISAd + SA[v2]]) {
            int t = v1;
            v1 = v2;
            v2 = t;
        }
        if (SA[ISAd + SA[v2]] > SA[ISAd + SA[v3]]) {
            if (SA[ISAd + SA[v1]] > SA[ISAd + SA[v3]]) {
                return v1;
            } else {
                return v3;
            }
        }
        return v2;
    }
1131202
def _compute_term_1(self, C, mag):
        
        return (
            C['a1'] + C['a2'] * mag + C['a3'] *
            np.power(mag, 2) + C['a4'] * np.power(mag, 3)
            + C['a5'] * np.power(mag, 4) + C['a6'] *
            np.power(mag, 5) + C['a7'] * np.power(mag, 6)
        )
1199953
def _get_magnitude_term(self, C, mag):
        
        dmag = mag - 8.0
        return C["c0"] + C["c3"] * dmag + C["c4"] * (dmag ** 2.)
10617
function f1(d, m, r) {
    const t = m + d;
    const I = (t << r) | (t >>> (32 - r));
    return ((sBox[0][I >>> 24] ^ sBox[1][(I >>> 16) & 255]) - sBox[2][(I >>> 8) & 255]) + sBox[3][I & 255];
  }
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
1184011
def _compute_mag_dist_terms(cls, rup, dists, coeffs):
        

        log_pre = coeffs['c'] + coeffs['a']*rup.mag + coeffs['b']*dists.rrup \
            - np.log10(dists.rrup + coeffs['d']*10**(coeffs['e']*rup.mag))

        return log_pre
1037588
def _compute_non_linear_term(self, C, pga_only, sites):
        
        Vref = 750.0
        Vcon = 1000.0
        lnS = np.zeros_like(sites.vs30)

        # equation (3a)
        idx = sites.vs30 < Vref
        lnS[idx] = (
            C['b1'] * np.log(sites.vs30[idx] / Vref) +
            C['b2'] * np.log(
                (pga_only[idx] + C['c'] * (sites.vs30[idx] / Vref) ** C['n']) /
                ((pga_only[idx] + C['c']) * (sites.vs30[idx] / Vref) ** C['n'])
            )
        )

        # equation (3b)
        idx = (sites.vs30 >= Vref) & (sites.vs30 <= Vcon)
        lnS[idx] = C['b1'] * np.log(sites.vs30[idx]/Vref)

        # equation (3c)
        idx = sites.vs30 > Vcon
        lnS[idx] = C['b1'] * np.log(Vcon/Vref)

        return lnS
728163
def _compute_magnitude(self, rup, C):
        
        return C['c1'] + C['c2'] * (rup.mag - 6.0) +\
            (C['c3'] * np.log(rup.mag / 6.0))
279061
def B(g,i):
    """"""
    g1 = g&(2**i)
    if i:
        nA = Awidth(i)
        nB = Bwidth(i)
        i=i-1
        Bn = B(g,i)
        if g1:
            return Bn            << (nA+nB) | int('1'*nA,2) << nB | Bn
        else:
            return int('1'*nB,2) << (nA+nB) | A(g,i)      << nB | Bn
    else:
        if g1:
            return 1
        else:
            return 0
3386
def _n_2(self):
        """"""
        return (self._f(3, 1) * self._f(2, 1) +
                self._f(3, 0) * self._f(1, 3) * self._f(2, 1) +
                self._f(3, 0) * self._f(2, 0) * self._f(1, 2))
139935
def _compute_term_5(self, C, mag, R):
        
        return (
            (C['a20'] + C['a21'] * mag + C['a22'] * np.power(mag, 2) +
             C['a23'] * np.power(mag, 3)) * np.power(R, 4)
        )
1085985
def _compute_mean(self, C, mag, r):
        
        mean = (C['c1'] +
                self._compute_term1(C, mag) +
                self._compute_term2(C, mag, r))
        return mean
458668
def _compute_magnitude_term(self, C, dc1, mag):
        
        base = C['theta1'] + (self.CONSTS['theta4'] * dc1)
        dmag = self.CONSTS["C1"] + dc1
        if mag > dmag:
            f_mag = (self.CONSTS['theta5'] * (mag - dmag)) +\
                C['theta13'] * ((10. - mag) ** 2.)

        else:
            f_mag = (self.CONSTS['theta4'] * (mag - dmag)) +\
                C['theta13'] * ((10. - mag) ** 2.)

        return base + f_mag
1212564
def j1_2(a=1):
    """

    def lhs(x):
        return np.exp(-a*x)

    def rhs(b):
        return (np.sqrt(b**2 + a**2) - a)/(b*np.sqrt(b**2 + a**2))

    return Ghosh('j1', lhs, rhs)
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
369270
def _get_basic_term(self, C, rup, dists):
        
        # Fictitious depth calculation
        if rup.mag > 5.:
            c4m = C['c4']
        elif rup.mag > 4.:
            c4m = C['c4'] - (C['c4']-1.) * (5. - rup.mag)
        else:
            c4m = 1.
        R = np.sqrt(dists.rrup**2. + c4m**2.)
        # basic form
        base_term = C['a1'] * np.ones_like(dists.rrup) + C['a17'] * dists.rrup
        # equation 2 at page 1030
        if rup.mag >= C['m1']:
            base_term += (C['a5'] * (rup.mag - C['m1']) +
                          C['a8'] * (8.5 - rup.mag)**2. +
                          (C['a2'] + C['a3'] * (rup.mag - C['m1'])) *
                          np.log(R))
        elif rup.mag >= self.CONSTS['m2']:
            base_term += (C['a4'] * (rup.mag - C['m1']) +
                          C['a8'] * (8.5 - rup.mag)**2. +
                          (C['a2'] + C['a3'] * (rup.mag - C['m1'])) *
                          np.log(R))
        else:
            base_term += (C['a4'] * (self.CONSTS['m2'] - C['m1']) +
                          C['a8'] * (8.5 - self.CONSTS['m2'])**2. +
                          C['a6'] * (rup.mag - self.CONSTS['m2']) +
                          C['a7'] * (rup.mag - self.CONSTS['m2'])**2. +
                          (C['a2'] + C['a3'] * (self.CONSTS['m2'] - C['m1'])) *
                          np.log(R))
        return base_term