Computes equivalent distance

    :param repi:
        Epicentral distance
    :param theta:
        Azimuth value
    :param mag:
        Magnitude
    :param coeff:
        GMPE coefficients
428057
def get_ras(repi, theta, mag, coeff):
    
    rx = 100.
    ras = 200.
    #
    # calculate the difference between epicentral distances
    dff = fnc(ras, repi, theta, mag, coeff)
    while abs(dff) > 1e-3:
        # update the value of distance computed
        if dff > 0.:
            ras = ras - rx
        else:
            ras = ras + rx
        dff = fnc(ras, repi, theta, mag, coeff)
        rx = rx / 2.
        if rx < 1e-3:
            break
    return ras
1001606
def _compute_distance(self, rup, dists, C):
        
        rref = 1.0
        c31 = -1.7
        return (c31 * np.log10(dists.rhypo) + C['c32'] * (dists.rhypo - rref))
872709
def _compute_magnitude_term(self, C, rup):
        
        return C['c2'] * (rup.mag - 8.0) + C['c3'] * (rup.mag - 8.0) ** 2
212898
def dot(self, vector, theta=None):
        
        if theta is not None:
            return (self.magnitude() * vector.magnitude() *
                    math.degrees(math.cos(theta)))
        return (reduce(lambda x, y: x + y,
                [x * vector.vector[i] for i, x in self.to_list()()]))
452228
def _compute_magnitude_squared_term(self, P, M, Q, W, mag):
        
        return P * (mag - M) + Q * (mag - M) ** 2 + W
188945
def double_ell_distance (mjr0, mnr0, pa0, mjr1, mnr1, pa1, dx, dy):
    
    # 1. We need to rotate the frame so that ellipse 1 lies on the X axis.
    theta = -np.arctan2 (dy, dx)

    # 2. We also need to express these rotated ellipses in "biv" format.
    sx0, sy0, cxy0 = ellbiv (mjr0, mnr0, pa0 + theta)
    sx1, sy1, cxy1 = ellbiv (mjr1, mnr1, pa1 + theta)

    # 3. Their convolution is:
    sx, sy, cxy = bivconvolve (sx0, sy0, cxy0, sx1, sy1, cxy1)

    # 4. The separation between the centers is still just:
    d = np.sqrt (dx**2 + dy**2)

    # 5. The effective sigma in the purely X direction, taking into account
    # the covariance term, is:
    sigma_eff = sx * np.sqrt (1 - (cxy / (sx * sy))**2)

    # 6. Therefore the answer is:
    return d / sigma_eff
20971
def transFringe(beta=None, rho=None):
    
    m = np.eye(6, 6, dtype=np.float64)
    if None in (beta, rho):
        print("warning: 'theta', 'rho' should be positive float numbers.")
        return m
    else:
        m[1, 0] = np.tan(beta) / rho
        m[3, 2] = -np.tan(beta) / rho
        return m
243795
def get_distance_term(self, C, dists, rup):
        
        x_ij = dists.rrup
        # Get anelastic scaling term in quation 5
        if rup.ztor >= 50.:
            qslh = C["eSLH"] * (0.02 * rup.ztor - 1.0)
        else:
            qslh = 0.0
        # r_volc = np.copy(dists.rvolc)
        # r_volc[np.logical_and(r_volc > 0.0, r_volc <= 12.0)] = 12.0
        # r_volc[r_volc >= 80.0] = 80.0
        # Get r_ij - distance for geometric spreading (equations 3 and 4)
        c_m = min(rup.mag, self.CONSTANTS["m_c"])
        r_ij = x_ij + np.exp(C["alpha"] + C["beta"] * c_m)
        return C["gSL"] * np.log(r_ij) + \
            C["gLL"] * np.log(x_ij + 200.) +\
            C["eSL"] * x_ij + qslh * x_ij +\
            C["eSLV"] * dists.rvolc + C["gamma"]
16191
def _co_moving2angle_source(self, x, y):
        
        T_z = self._T_z_source
        theta_x = x / T_z
        theta_y = y / T_z
        return theta_x, theta_y
800303
def compute_nutation(t):
    
    oblm, oblt, eqeq, psi, eps = t._earth_tilt

    cobm = cos(oblm * DEG2RAD)
    sobm = sin(oblm * DEG2RAD)
    cobt = cos(oblt * DEG2RAD)
    sobt = sin(oblt * DEG2RAD)
    cpsi = cos(psi * ASEC2RAD)
    spsi = sin(psi * ASEC2RAD)

    return array(((cpsi,
                  -spsi * cobm,
                  -spsi * sobm),
                  (spsi * cobt,
                   cpsi * cobm * cobt + sobm * sobt,
                   cpsi * sobm * cobt - cobm * sobt),
                  (spsi * sobt,
                   cpsi * cobm * sobt - sobm * cobt,
                   cpsi * sobm * sobt + cobm * cobt)))
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
728163
def _compute_magnitude(self, rup, C):
        
        return C['c1'] + C['c2'] * (rup.mag - 6.0) +\
            (C['c3'] * np.log(rup.mag / 6.0))
860907
def _compute_magnitude_distance_term(self, C, rjb, mag):
        
        rval = np.sqrt(rjb ** 2. + C["h"] ** 2.)
        return (C["b4"] + C["b5"] * (mag - 4.5)) * np.log(rval)
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
35588
def _get_azimuth_correction(self, coe, azimuth):
        
        term1 = abs(np.cos(np.radians(2.*azimuth)))
        term2 = abs(np.sin(np.radians(2.*azimuth)))*coe['a5']
        return np.log(np.max(np.hstack((term1, term2))))
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
875800
def rhypo_to_rjb(rhypo, mag):
    
    epsilon = rhypo - (4.853 + 1.347E-6 * (mag ** 8.163))
    rjb = np.zeros_like(rhypo)
    idx = epsilon >= 3.
    rjb[idx] = np.sqrt((epsilon[idx] ** 2.) - 9.0)
    rjb[rjb < 0.0] = 0.0
    return rjb