Table 8 and equation 19 of 2013 report. NB change in notation,
        2013 report calls this term 'sigma_t' but it is referred to
        here as sigma. Note that Table 8 is identical to Table 7 in
        the 2013 report.
515883
def _get_SRF_sigma(self, imt_per):
        
        if imt_per < 0.6:
            srf = 0.8
        elif 0.6 <= imt_per < 1:
            srf = self._interp_function(0.7, 0.8, 1, 0.6, imt_per)
        elif 1 <= imt_per <= 10:
            srf = self._interp_function(0.6, 0.7, 10, 1, imt_per)
        else:
            srf = 1

        return srf
173827
def delta13c_constants():
    
    # possible values for constants (from NIST)
    cst = OrderedDict()
    cst['Craig'] = {'S13': 0.0112372, 'S18': 0.002079,
                    'K': 0.008333, 'A': 0.5}
    cst['IAEA'] = {'S13': 0.0112372, 'S18': 0.00206716068,
                   'K': 0.0091993, 'A': 0.5}
    cst['Werner'] = {'S13': 0.0112372, 'S18': 0.0020052,
                     'K': 0.0093704, 'A': 0.516}
    cst['Santrock'] = {'S13': 0.0112372, 'S18': 0.0020052,
                       'K': 0.0099235, 'A': 0.516}
    cst['Assonov'] = {'S13': 0.0112372, 'S18': 0.0020052,
                      'K': 0.0102819162, 'A': 0.528}
    cst['Assonov2'] = {'S13': 0.0111802, 'S18': 0.0020052,
                       'K': 0.0102819162, 'A': 0.528}
    cst['Isodat'] = {'S13': 0.0111802, 'S18': 0.0020052,
                     'K': 0.0099235, 'A': 0.516}
    return cst
446713
def __get_sigmas(self):
        """"""
        stack_sigma = {}
        _stack = self.stack

        _file_path = os.path.abspath(os.path.dirname(__file__))
        _database_folder = os.path.join(_file_path, 'reference_data', self.database)

        _list_compounds = _stack.keys()
        for _compound in _list_compounds:
            _list_element = _stack[_compound]['elements']
            stack_sigma[_compound] = {}

            for _element in _list_element:
                stack_sigma[_compound][_element] = {}
                _list_isotopes = _stack[_compound][_element]['isotopes']['list']
                _list_file_names = _stack[_compound][_element]['isotopes']['file_names']
                _list_isotopic_ratio = _stack[_compound][_element]['isotopes']['isotopic_ratio']
                _iso_file_ratio = zip(_list_isotopes, _list_file_names, _list_isotopic_ratio)
                stack_sigma[_compound][_element]['isotopic_ratio'] = _list_isotopic_ratio

                # _dict_sigma_isotopes_sum = {}
                _sigma_all_isotopes = 0
                _energy_all_isotpes = 0

                for _iso, _file, _ratio in _iso_file_ratio:
                    stack_sigma[_compound][_element][_iso] = {}
                    _file = os.path.join(_database_folder, _file)
                    _dict = _utilities.get_sigma(database_file_name=_file,
                                                 e_min=self.energy_min,
                                                 e_max=self.energy_max,
                                                 e_step=self.energy_step)
                    stack_sigma[_compound][_element][_iso]['energy_eV'] = _dict['energy_eV']
                    stack_sigma[_compound][_element][_iso]['sigma_b'] = _dict['sigma_b'] * _ratio
                    stack_sigma[_compound][_element][_iso]['sigma_b_raw'] = _dict['sigma_b']

                    # sigma for all isotopes with their isotopic ratio
                    _sigma_all_isotopes += _dict['sigma_b'] * _ratio
                    _energy_all_isotpes += _dict['energy_eV']

                # energy axis (x-axis) is averaged to take into account differences between x-axis of isotopes
                _mean_energy_all_isotopes = _energy_all_isotpes / len(_list_isotopes)
                stack_sigma[_compound][_element]['energy_eV'] = _mean_energy_all_isotopes
                stack_sigma[_compound][_element]['sigma_b'] = _sigma_all_isotopes

        self.stack_sigma = stack_sigma
167624
def tdb_minus_tt(jd_tdb):
    
    t = (jd_tdb - T0) / 36525.0

    # USNO Circular 179, eq. 2.6.
    return (0.001657 * sin ( 628.3076 * t + 6.2401)
          + 0.000022 * sin ( 575.3385 * t + 4.2970)
          + 0.000014 * sin (1256.6152 * t + 6.1969)
          + 0.000005 * sin ( 606.9777 * t + 4.0212)
          + 0.000005 * sin (  52.9691 * t + 0.4444)
          + 0.000002 * sin (  21.3299 * t + 5.5431)
          + 0.000010 * t * sin ( 628.3076 * t + 4.2490))
480324
public static void standard(ZMatrixRMaj A, ZMatrixRMaj A_tran)
    {
        int index = 0;
        int rowStrideTran = A_tran.getRowStride();
        int rowStride = A.getRowStride();
        for( int i = 0; i < A_tran.numRows; i++ ) {
            int index2 = i*2;

            int end = index + rowStrideTran;
            while( index < end ) {
                A_tran.data[index++] = A.data[ index2 ];
                A_tran.data[index++] = A.data[ index2+1 ];
                index2 += rowStride;
            }
        }
    }
1134531
static int countInPeriod(DayOfWeek dow, DayOfWeek dow0, int nDays) {
		//two cases:
		//   (1a) dow >= dow0: count === (nDays - (dow - dow0)) / 7
		//   (1b) dow < dow0:  count === (nDays - (7 - dow0 - dow)) / 7
		if (dow.getCalendarConstant() >= dow0.getCalendarConstant()) {
			return 1 + ((nDays - (dow.getCalendarConstant() - dow0.getCalendarConstant()) - 1) / 7);
		} else {
			return 1 + ((nDays - (7 - (dow0.getCalendarConstant() - dow.getCalendarConstant())) - 1) / 7);
		}
	}
473455
def _get_stddevs(self, C, mag, stddev_types, sites):
        
        num_sites = sites.vs30.size
        sigma_intra = np.zeros(num_sites)

        # interevent stddev
        tau = sigma_intra + C['tau']

        # intraevent std (equations 8a-8c page 29)
        if mag < 5.0:
            sigma_intra += C['sigmaM6'] - C['sigSlope']
        elif 5.0 <= mag < 7.0:
            sigma_intra += C['sigmaM6'] + C['sigSlope'] * (mag - 6)
        else:
            sigma_intra += C['sigmaM6'] + C['sigSlope']

        std = []

        for stddev_type in stddev_types:
            if stddev_type == const.StdDev.TOTAL:
                # equation 9 page 29
                std += [np.sqrt(sigma_intra**2 + tau**2)]
            elif stddev_type == const.StdDev.INTRA_EVENT:
                std.append(sigma_intra)
            elif stddev_type == const.StdDev.INTER_EVENT:
                std.append(tau)

        return std
481468
function sigma0_64(x)
	{
		var rotr28 = rotr_64(x, 28), rotr34 = rotr_64(x, 34),
			rotr39 = rotr_64(x, 39);

		return new Int_64(
				rotr28.highOrder ^ rotr34.highOrder ^ rotr39.highOrder,
				rotr28.lowOrder ^ rotr34.lowOrder ^ rotr39.lowOrder);
	}
819024
public static void standard(DMatrix1Row A, DMatrix1Row A_tran)
    {
        int index = 0;
        for( int i = 0; i < A_tran.numRows; i++ ) {
            int index2 = i;

            int end = index + A_tran.numCols;
            while( index < end ) {
                A_tran.data[index++ ] = A.data[ index2 ];
                index2 += A.numCols;
            }
        }
    }
160053
def ets(self):
        """"""
        r = (self.table[0, 0] + self.table[0, 1]) * (self.table[0, 0] + self.table[1, 0]) / self.N
        return (self.table[0, 0] - r) / (self.table[0, 0] + self.table[0, 1] + self.table[1, 0] - r)
690424
public void orizzonte8( double delta, int quadrata, double beta, double alfa, double[][] Z0, int[][] curv, int[][] shadow,
            double novalue ) {
        /*=====================*/

        int y, I, J;
        double zenith;

        /*======================*/

        for( int j = quadrata; j >= 0; j-- ) {
            I = -1;
            J = -1;
            y = 0;
            for( int jj = j; jj < quadrata; jj++ ) {
                for( int i = (int) floor(1 / tan(beta) * (jj - j)) + 1; i <= (int) floor(1 / tan(beta) * (jj - j + 1))
                        && i <= Z0.length; i++ ) {
                    if (jj > quadrata - Z0[0].length && Z0[i][jj - (quadrata - Z0[0].length)] != novalue) {
                        /*shadow.element[i][jj-(quadrata-Z0.nch)]=j;}}}}*/
                        if (curv[i][jj] == 1 && I == -1) {
                            I = i;
                            J = jj - (quadrata - Z0[0].length);
                            y = 1;
                        } else if (curv[i][jj - (quadrata - Z0[0].length)] == 1 && I != 1) {
                            zenith = (Z0[I][J] - Z0[i][jj - (quadrata - Z0[0].length)])
                                    / sqrt(pow((double) (I - i) * (double) delta, (double) 2)
                                            + pow((double) (J - (jj - (quadrata - Z0[0].length))) * (double) delta, (double) 2));
                            if (zenith <= tan(alfa)) {
                                shadow[i][jj - (quadrata - Z0[0].length)] = 0;
                                I = i;
                                J = jj - (quadrata - Z0[0].length);
                            } else {
                                shadow[i][jj - (quadrata - Z0[0].length)] = 1;
                            }
                        } else if (curv[i][jj - (quadrata - Z0[0].length)] == 0 && y == 1) {
                            zenith = (Z0[I][J] - Z0[i][jj - (quadrata - Z0[0].length)])
                                    / sqrt(pow((double) (I - i) * (double) delta, (double) 2)
                                            + pow((double) (J - (jj - (quadrata - Z0[0].length))) * (double) delta, (double) 2));
                            if (zenith <= tan(alfa)) {
                                shadow[i][jj - (quadrata - Z0[0].length)] = 0;
                                y = 0;
                            } else {
                                shadow[i][jj - (quadrata - Z0[0].length)] = 1;
                            }
                        }
                    }
                }
            }
        }
    }
288514
def standardize(table, option):
    
    if option == 'table':
        mean = np.mean(table)
        std = np.std(table)
    t = []
    for row in table:
        t_row = []
        if option != 'table':
            mean = np.mean(row)
            std = np.std(row)
        for i in row:
            if std == 0:
                t_row.append(0)
            else:
                t_row.append((i - mean)/std)
        t.append(t_row)
    return t
391729
def table_name(self):
        
        if self._cube.ndim < 3 and not self.ca_as_0th:
            return None

        title = self._cube.name
        table_name = self._cube.labels()[0][self._index]
        return "%s: %s" % (title, table_name)
929281
def _sigma_pi_hiE(self, Tp, a):
        
        m_p = self._m_p
        csip = (Tp - 3.0) / m_p
        m1 = a[0] * csip ** a[3] * (1 + np.exp(-a[1] * csip ** a[4]))
        m2 = 1 - np.exp(-a[2] * csip ** 0.25)
        multip = m1 * m2
        return self._sigma_inel(Tp) * multip
1099446
def get_sigma(imt):
    
    if imt.period < 0.2:
        return np.log(10**0.23)
    elif imt.period > 1.0:
        return np.log(10**0.27)
    else:
        return np.log(10**(0.23 + (imt.period - 0.2)/0.8 * 0.04))
218094
def retreive_sigma_mu_data(self):
        
        fle = h5py.File(os.path.join(BASE_PATH,
                                     "KothaEtAl2019_SigmaMu_Fixed.hdf5"), "r")
        self.mags = fle["M"][:]
        self.dists = fle["R"][:]
        self.periods = fle["T"][:]
        self.pga = fle["PGA"][:]
        self.pgv = fle["PGV"][:]
        self.s_a = fle["SA"][:]
        fle.close()
1222544
def index_name(table, columns):
    """"""
    sig = '||'.join(columns)
    key = sha1(sig.encode('utf-8')).hexdigest()[:16]
    return 'ix_%s_%s' % (table, key)