Compute and return hanging wall model term, that is the sixth term in
        equation 1, page 74. The calculation of this term is explained in
        paragraph 'Hanging-Wall Model', page 77.
960442
def _compute_hanging_wall_term(self, C, dists, rup):
        
        if rup.dip == 90.0:
            return np.zeros_like(dists.rx)
        else:
            idx = dists.rx > 0
            Fhw = np.zeros_like(dists.rx)
            Fhw[idx] = 1

            # equation 8, page 77
            T1 = np.zeros_like(dists.rx)
            idx1 = (dists.rjb < 30.0) & (idx)
            T1[idx1] = 1.0 - dists.rjb[idx1] / 30.0

            # equation 9, page 77
            T2 = np.ones_like(dists.rx)
            idx2 = ((dists.rx <= rup.width * np.cos(np.radians(rup.dip))) &
                    (idx))
            T2[idx2] = (0.5 + dists.rx[idx2] /
                        (2 * rup.width * np.cos(np.radians(rup.dip))))

            # equation 10, page 78
            T3 = np.ones_like(dists.rx)
            idx3 = (dists.rx < rup.ztor) & (idx)
            T3[idx3] = dists.rx[idx3] / rup.ztor

            # equation 11, page 78
            if rup.mag <= 6.0:
                T4 = 0.0
            elif rup.mag > 6 and rup.mag < 7:
                T4 = rup.mag - 6
            else:
                T4 = 1.0

            # equation 5, in AS08_NGA_errata.pdf
            if rup.dip >= 30:
                T5 = 1.0 - (rup.dip - 30.0) / 60.0
            else:
                T5 = 1.0

            return Fhw * C['a14'] * T1 * T2 * T3 * T4 * T5
1126236
function(term, any) {
                    var max = Math.max.apply(null, term.terms),
                        count = 0, idx;

                    if(!any) {
                        for(var i=0; i<term.terms.length; i++) {
                            if(term.terms[i].equals(max)) {
                                idx = i; count++;
                            }
                            if(count > 1) return;
                        }
                    }
                    if(any) {
                        for(i=0; i<term.terms.length; i++) 
                            if(term.terms[i].equals(max)) {
                                idx = i; break;
                            }
                    }
                    return [max, idx, term];
                }
1085985
def _compute_mean(self, C, mag, r):
        
        mean = (C['c1'] +
                self._compute_term1(C, mag) +
                self._compute_term2(C, mag, r))
        return mean
224047
def _get_hanging_wall_coeffs_mag(self, C, mag):
        
        if mag < 5.5:
            return 0.0
        elif mag > 6.5:
            return 1.0 + C["a2"] * (mag - 6.5)
        else:
            return (mag - 5.5) * (1.0 + C["a2"] * (mag - 6.5))
404874
function getTermsForCollectingAddition(node) {
  let terms = {};

  for(let i = 0; i < node.args.length; i++) {
    const child = node.args[i];

    if (Node.PolynomialTerm.isPolynomialTerm(child)) {
      const termName = getTermName(child, '+');
      terms = Util.appendToArrayInObject(terms, termName, child);
    }
    else if (Node.Type.isIntegerFraction(child)) {
      terms = Util.appendToArrayInObject(terms, CONSTANT_FRACTION, child);
    }
    else if (Node.Type.isConstant(child)) {
      terms = Util.appendToArrayInObject(terms, CONSTANT, child);
    }
    else if (Node.Type.isOperator(node) ||
             Node.Type.isFunction(node) ||
             Node.Type.isParenthesis(node) ||
             Node.Type.isUnaryMinus(node)) {
      terms = Util.appendToArrayInObject(terms, OTHER, child);
    }
    else {
      // Note that we shouldn't get any symbol nodes in the switch statement
      // since they would have been handled by isPolynomialTerm
      throw Error('Unsupported node type: ' + child.type);
    }
  }
  // If there's exactly one constant and one fraction, we collect them
  // to add them together.
  // e.g. 2 + 1/3 + 5 would collect the constants (2+5) + 1/3
  // but 2 + 1/3 + x would collect (2 + 1/3) + x so we can add them together
  if (terms[CONSTANT] && terms[CONSTANT].length === 1 &&
     terms[CONSTANT_FRACTION] && terms[CONSTANT_FRACTION].length === 1) {
    const fraction = terms[CONSTANT_FRACTION][0];
    terms = Util.appendToArrayInObject(terms, CONSTANT, fraction);
    delete terms[CONSTANT_FRACTION];
  }

  return terms;
}
890859
def _compute_magnitude_scaling_term(self, C, mag):
        
        assert mag <= 8.5
        return C['c1'] + C['c2'] * mag + C['c3'] * (8.5 - mag) ** 2.5
394987
def _M(self, k, t, tips=None, gaps=None):
        """"""
        if self._distributionmodel:
            return self.model.M(k, t, tips, gaps)
        else:
            return self.model.M(t, tips, gaps)
86906
def _termsize():
    '''
    
    '''

    try:
        return struct.unpack(
            'hh',
            fcntl.ioctl(sys.stdout.fileno(), termios.TIOCGWINSZ, '1234')
        )
    except:
        return (
            int(os.environ.get('LINES', 25)),
            int(os.environ.get('COLUMNS', 80)),
        )
1256310
def _compute_mean(self, C, mag, rjb):
        
        mean = (C['c1'] +
                self._compute_term1(C, mag) +
                self._compute_term2(C, mag, rjb))
        return mean
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)
        )
600313
def equation(self):
        
        mat = np.empty((self.nunknowns, self.model.neq))
        rhs = np.zeros(self.nunknowns)  # Needs to be initialized to zero
        for icp in range(self.ncp):
            istart = icp * self.nlayers
            ieq = 0
            for e in self.model.elementlist:
                if e.nunknowns > 0:
                    fluxin = self.intflux(e.disvecinflayers, self.xcin[icp], self.ycin[icp],
                                          self.xcin[icp + 1], self.ycin[icp + 1], self.layers, aq=self.aqin)
                    fluxout = self.intflux(e.disvecinflayers, self.xcout[icp], self.ycout[icp],
                                           self.xcout[icp + 1], self.ycout[icp + 1], self.layers, aq=self.aqout)
                    mat[istart:istart + self.nlayers, ieq:ieq + e.nunknowns] = fluxin - fluxout
                    ieq += e.nunknowns
                else:
                    fluxin = self.intflux(e.disveclayers, self.xcin[icp], self.ycin[icp],
                                          self.xcin[icp + 1], self.ycin[icp + 1], self.layers, aq=self.aqin)
                    fluxout = self.intflux(e.disveclayers, self.xcout[icp], self.ycout[icp],
                                           self.xcout[icp + 1], self.ycout[icp + 1], self.layers, aq=self.aqout)
                    rhs[istart:istart + self.nlayers] -= fluxin - fluxout
        return mat, rhs
819407
def _compute_distance_term(self, C, rrup, mag):
        
        exponent_term = (1.0 + C["c3"] * np.exp(mag - 5.)) ** 2.
        return C["c2"] * np.log(np.sqrt(rrup ** 2. + exponent_term))
930577
def predictMean(self):
        
        assert self.noisPos!=None,      'No noise element'
        assert self.init,               'GP not initialised'
                
        KiY = self.gp.agetKEffInvYCache()
                
        if self.fast==False:
            KiY = KiY.reshape(self.P,self.N).T
                
        Ymean = None
        for term_i in range(self.n_terms):
            if term_i!=self.noisPos:
                Kstar = self.vd.getTerm(term_i).getKcf().Kcross(SP.zeros(1))
                term  = SP.dot(Kstar.T,KiY)
                if self.P>1:
                    C    = self.getEstTraitCovar(term_i)
                    term = SP.dot(term,C)
                if Ymean==None:     Ymean  = term
                else:               Ymean += term
            
        # to generalise
        Ymean+=self.getFixed()[:,0]
                
        return Ymean
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.)))
940251
def get_next_non_summer_term(term):
    
    next_term = get_term_after(term)
    if next_term.is_summer_quarter():
        return get_next_autumn_term(next_term)
    return next_term
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
839774
def _compute_large_distance_term(self, C, dists, rup):
        
        # equation 15, page 79
        if rup.mag < 5.5:
            T6 = 1.0
        elif rup.mag >= 5.5 and rup.mag <= 6.5:
            T6 = 0.5 * (6.5 - rup.mag) + 0.5
        else:
            T6 = 0.5

        # equation 14, page 79
        large_distance_term = np.zeros_like(dists.rrup)
        idx = dists.rrup >= 100.0
        large_distance_term[idx] = C['a18'] * (dists.rrup[idx] - 100.0) * T6

        return large_distance_term