Standard deviation for WC1994. Magnitude is ignored.
497810
def get_std_dev_area(self, mag, rake):
        
        assert rake is None or -180 <= rake <= 180
        if rake is None:
            # their "All" case
            return 0.24
        elif (-45 <= rake <= 45) or (rake >= 135) or (rake <= -135):
            # strike slip
            return 0.22
        elif rake > 0:
            # thrust/reverse
            return 0.26
        else:
            # normal
            return 0.22
669550
def _get_stddevs(self, C, stddev_types, num_sites):
        
        assert all(stddev_type in self.DEFINED_FOR_STANDARD_DEVIATION_TYPES
                   for stddev_type in stddev_types)

        if self.DEFINED_FOR_INTENSITY_MEASURE_COMPONENT == 'Random horizontal':
            # Using equation 8 of the paper,
            # corrected as indicated in the erratum
            Sr = np.sqrt(C['SlZ']**2 + (C['S3']/np.sqrt(2))**2)
        else:
            Sr = C['SlZ']

        stddevs = [np.zeros(num_sites) + Sr for _ in stddev_types]
        return stddevs
656589
def fix_bad_headers(self):
        
        # WCSLIB doesn't like "nonstandard" units
        unit = self.header.get('CUNIT1', 'deg')
        if unit.upper() == 'DEGREE':
            # self.header.update('CUNIT1', 'deg')
            self.header['CUNIT1'] = 'deg'
        unit = self.header.get('CUNIT2', 'deg')
        if unit.upper() == 'DEGREE':
            # self.header.update('CUNIT2', 'deg')
            self.header['CUNIT2'] = 'deg'
1152188
def dms2dd(d,m,s):
    
    if d < 0:
        sign = -1
    else:
        sign = 1
    dd = sign * (int(abs(d)) + float(m) / 60 + float(s) / 3600)
    return dd
368038
def standard_variance(data, period):
    
    catch_errors.check_for_period_error(data, period)
    sv = [np.var(data[idx+1-period:idx+1], ddof=1) for idx in range(period-1, len(data))]
    sv = fill_for_noncomputable_vals(data, sv)

    return sv
475775
def stddev(self):
    """"""
    if len(self) < 2:
      return float('NaN')
    # The stupidest algorithm, but it works fine.
    try:
      arr = self.samples()
      mean = sum(arr) / len(arr)
      bigsum = 0.0
      for x in arr:
        bigsum += (x - mean)**2
      return sqrt(bigsum / (len(arr) - 1))
    except ZeroDivisionError:
      return float('NaN')
405057
def _get_magnitude_scaling_term(self, C, rup):
        
        dmag = rup.mag - C["Mh"]
        if rup.mag <= C["Mh"]:
            mag_term = (C["e4"] * dmag) + (C["e5"] * (dmag ** 2.0))
        else:
            mag_term = C["e6"] * dmag
        return self._get_style_of_faulting_term(C, rup) + mag_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
1115762
def precision(self):
        
        if self._precision is None:
            cov = np.atleast_3d(self.covariance)
            self._precision = np.zeros(cov.shape)  # if one covariance per dimension
            for p in range(cov.shape[-1]):
                self._precision[:, :, p] = pdinv(cov[:, :, p])[0]
        return self._precision
115440
def sd(self):
        ''''''
        v = self.var()
        if len(v):
            return np.sqrt(v)
        else:
            return None
1144288
def _mean_absolute_error(y, y_pred, w):
    """"""
    return np.average(np.abs(y_pred - y), weights=w)
650242
def get_magnitude_scaling_term(self, C, mag):
        
        mval = mag - 3.0
        return C['b1'] + C['b2'] * mval + C['b3'] * (mval ** 2.0) +\
            C['b4'] * (mval ** 3.0)
199748
def standardised_euclidean(x, y, sigma=_mock_ones):
    
    result = 0.0
    for i in range(x.shape[0]):
        result += ((x[i] - y[i]) ** 2) / sigma[i]

    return np.sqrt(result)
657416
def stdev(data, xbar=None):
    
    var = variance(data, xbar)
    try:
        return var.sqrt()
    except AttributeError:
        return math.sqrt(var)
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
551790
def _si(number):
    """"""
    prefixes = ['', 'K', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y']
    while number > 1024:
        number /= 1024.0
        prefixes.pop(0)
    return '%0.2f%s' % (number, prefixes.pop(0))
1262838
def degToDms(dec, isLatitude=True):
    
    if isLatitude:
        assert dec <= 90, WCSError("DEC (%f) > 90.0" % (dec))
        assert dec >= -90, WCSError("DEC (%f) < -90.0" % (dec))

    if dec < 0.0:
        sign = -1.0
    else:
        sign = 1.0
    dec = dec * sign

    #mnt = (dec % 1.0) * 60.0
    #sec = (dec % (1.0/60.0)) * 3600.0
    # this calculation with return values produces conversion problem.
    # e.g. dec +311600.00 -> 31.2666666667 degree
    # deg=31 min=15 sec=60 instead deg=31 min=16 sec=0.0
    # bug fixed
    mnt, sec = divmod(dec * 3600, 60)
    deg, mnt = divmod(mnt, 60)

    return (int(sign), int(deg), int(mnt), sec)