Calculate the shear wave velocity

        :param saturated: bool, if true then use saturated mass
        :return:
498498
def get_shear_vel(self, saturated):
        
        try:
            if saturated:
                return np.sqrt(self.g_mod / self.unit_sat_mass)
            else:
                return np.sqrt(self.g_mod / self.unit_dry_mass)
        except TypeError:
            return None
688655
def get_mean_and_stddevs(self, sites, rup, dists, imt, stddev_types):
        
        # extracting dictionary of coefficients specific to required
        # intensity measure type.
        C = self.COEFFS[imt]

        mean = (self._get_magnitude_scaling_term(C, rup.mag) +
                self._get_distance_scaling_term(C, rup.mag, dists.rrup) +
                self._get_style_of_faulting_term(C, rup.rake) +
                self._get_site_scaling_term(C, sites.vs30))

        stddevs = self._get_stddevs(imt,
                                    rup.mag,
                                    len(dists.rrup),
                                    stddev_types)
        return mean, stddevs
1279484
def load_soil_sample_data(sp):
    
    # soil
    sp.g_mod = 60.0e6  # [Pa]
    sp.phi = 30  # [degrees]
    sp.relative_density = .40  # [decimal]
    sp.gwl = 2.  # [m], ground water level
    sp.unit_dry_weight = 17000  # [N/m3]
    sp.unit_sat_weight = 18000  # [N/m3]
    sp.unit_weight_water = 9800  # [N/m3]
    sp.cohesion = 10.0  # [Pa]
    sp.poissons_ratio = 0.22
    sp.e_min = 0.55
    sp.e_max = 0.95
    sp.e_critical0 = 0.79  # Jin et al. 2015
    sp.p_critical0 = 0.7  # Jin et al. 2015
    sp.lamb_crl = 0.015
312335
def stress_vert(self, depth_within=0, effective=False):
        """"""
        assert depth_within <= self.thickness
        stress_vert = self._stress_vert + depth_within * self.unit_wt
        if effective:
            pore_pressure = self._profile.pore_pressure(self.depth +
                                                        depth_within)
            stress_vert -= pore_pressure
        return stress_vert
425888
def get_mean_and_stddevs(self, sites, rup, dists, imt, stddev_types):
        
        # extracting dictionary of coefficients specific to required
        # intensity measure type.
        C = self.COEFFS[imt]
        C_PGA = self.COEFFS[PGA()]
        imt_per = 0 if imt.name == 'PGV' else imt.period
        pga_rock = self._get_pga_on_rock(C_PGA, rup, dists)
        mean = (self._get_magnitude_scaling_term(C, rup) +
                self._get_path_scaling(C, dists, rup.mag) +
                self._get_site_scaling(C, pga_rock, sites, imt_per, dists.rjb))
        stddevs = self._get_stddevs(C, rup, dists, sites, stddev_types)
        return mean, stddevs
73546
def wind_shear(shear: str, unit_alt: str = 'ft', unit_wind: str = 'kt', spoken: bool = False) -> str:
    
    if not shear or 'WS' not in shear or '/' not in shear:
        return ''
    shear = shear[2:].rstrip(unit_wind.upper()).split('/')  # type: ignore
    wdir = core.spoken_number(shear[1][:3]) if spoken else shear[1][:3]
    return f'Wind shear {int(shear[0])*100}{unit_alt} from {wdir} at {shear[1][3:]}{unit_wind}'
105398
def get_mean_and_stddevs(self, sites, rup, dists, imt, stddev_types):
        
        # extracting dictionary of coefficients specific to required
        # intensity measure type.
        C = self.COEFFS_SSLAB[imt]

        # cap magnitude values at 8.0, see page 1709
        mag = rup.mag
        if mag >= 8.0:
            mag = 8.0

        # compute PGA on rock (needed for site amplification calculation)
        G = 10 ** (0.301 - 0.01 * mag)
        pga_rock = self._compute_mean(self.COEFFS_SSLAB[PGA()], G, mag,
                                      rup.hypo_depth, dists.rrup, sites.vs30,
                                      # by passing pga_rock > 500 the soil
                                      # amplification is 0
                                      np.zeros_like(sites.vs30) + 600,
                                      PGA())
        pga_rock = 10 ** (pga_rock)

        # compute actual mean and convert from log10 to ln and units from
        # cm/s**2 to g
        mean = self._compute_mean(C, G, mag, rup.hypo_depth, dists.rrup,
                                  sites.vs30, pga_rock, imt)
        mean = np.log((10 ** mean) * 1e-2 / g)

        if imt.period == 4.0:
            mean /= 0.550

        stddevs = self._get_stddevs(C, stddev_types, sites.vs30.shape[0])

        return mean, stddevs
399701
def getSoundFileDuration(fn):
    '''
    
    '''
    audiofile = wave.open(fn, "r")
    
    params = audiofile.getparams()
    framerate = params[2]
    nframes = params[3]
    
    duration = float(nframes) / framerate
    return duration
1331154
def moduli_to_velocities(rho, K_s, G):
    
    return np.sqrt(K_s / rho), np.sqrt(G / rho)
1063321
def get_mean_and_stddevs(self, sites, rup, dists, imt, stddev_types):
        
        C = self.COEFFS[imt]
        C_SIG = self.SIGMA_COEFFS[imt]

        mean = (self.get_magnitude_scaling_term(C, rup.mag) +
                self.get_distance_scaling_term(C, dists.rhypo))

        std_devs = self.get_stddevs(C_SIG, stddev_types, len(dists.rhypo))

        #: Mean ground motions initially returned in cm/s/s (for PGA, SA)
        #: and cm/s for PGV
        if not imt.name == "PGV":
            # Convert mean from log(cm/s/s) to g
            mean = np.log(np.exp(mean) / (100. * g))

        return mean, std_devs
712672
def _extract_coeffs(self, imt):
        
        C_HR = self.COEFFS_HARD_ROCK[imt]
        C_BC = self.COEFFS_BC[imt]
        C_SR = self.COEFFS_SOIL_RESPONSE[imt]
        SC = self.COEFFS_STRESS[imt]

        return C_HR, C_BC, C_SR, SC
383578
def _compute_soil_linear_factor(cls, pga_rock, imt):
        
        if imt.period >= 1:
            return np.ones_like(pga_rock)
        else:
            sl = np.zeros_like(pga_rock)

            pga_between_100_500 = (pga_rock > 100) & (pga_rock < 500)
            pga_greater_equal_500 = pga_rock >= 500

            is_SA_between_05_1 = 0.5 < imt.period < 1

            is_SA_less_equal_05 = imt.period <= 0.5

            if is_SA_between_05_1:
                sl[pga_between_100_500] = (1 - (1. / imt.period - 1) *
                                           (pga_rock[pga_between_100_500] -
                                           100) / 400)
                sl[pga_greater_equal_500] = 1 - (1. / imt.period - 1)

            if is_SA_less_equal_05 or imt.period == 0:
                sl[pga_between_100_500] = (1 - (pga_rock[pga_between_100_500] -
                                           100) / 400)

            sl[pga_rock <= 100] = 1

            return sl
990283
def moment_inertia(self):
        
        tensor = inertia.sphere_inertia(mass=self.volume,
                                        radius=self.primitive.radius)
        return tensor
887326
def get_rmetric( self, mode_inv = 'svd', return_svd = False ):
        
        if self.H is None:
            self.H, self.G, self.Hvv, self.Hsval = riemann_metric(self.Y, self.L, self.mdimG, invert_h = True, mode_inv = mode_inv)
        if self.G is None:
            self.G, self.Hvv, self.Hsvals,  self.Gsvals = compute_G_from_H( self.H, mode_inv = self.mode_inv )
        if mode_inv is 'svd' and return_svd:
            return self.G, self.Hvv, self.Hsvals, self.Gsvals
        else:
            return self.G
44878
def discretize_soil_profile(sp, incs=None, target=1.0):
    

    if incs is None:
        incs = np.ones(sp.n_layers) * target
    dd = {}
    dd["thickness"] = []
    dd["unit_mass"] = []
    dd["shear_vel"] = []
    cum_thickness = 0
    for i in range(sp.n_layers):
        sl = sp.layer(i + 1)
        thickness = sp.layer_height(i + 1)
        n_slices = max(int(thickness / incs[i]), 1)
        slice_thickness = float(thickness) / n_slices
        for j in range(n_slices):
            cum_thickness += slice_thickness
            if cum_thickness >= sp.gwl:
                rho = sl.unit_sat_mass
                saturation = True
            else:
                rho = sl.unit_dry_mass
                saturation = False
            if hasattr(sl, "get_shear_vel_at_v_eff_stress"):
                v_eff = sp.vertical_effective_stress(cum_thickness)
                vs = sl.get_shear_vel_at_v_eff_stress(v_eff, saturation)
            else:
                vs = sl.calc_shear_vel(saturation)
            dd["shear_vel"].append(vs)
            dd["unit_mass"].append(rho)
            dd["thickness"].append(slice_thickness)
    for item in dd:
        dd[item] = np.array(dd[item])
    return dd
1077968
def _compute_soil_amplification(cls, C, vs30, pga_rock, imt):
        
        return AtkinsonBoore2003SInterNSHMP2008._compute_soil_amplification(
            C, vs30, pga_rock, imt)
48325
def time_average_vel(self, depth):
        
        depths = [l.depth for l in self]
        # Final layer is infinite and is treated separately
        travel_times = [0] + [l.travel_time for l in self[:-1]]
        # If needed, add the final layer to the required depth
        if depths[-1] < depth:
            depths.append(depth)
            travel_times.append((depth - self[-1].depth) / self[-1].shear_vel)

        total_travel_times = np.cumsum(travel_times)
        # Interpolate the travel time to the depth of interest
        avg_shear_vel = depth / np.interp(depth, depths, total_travel_times)
        return avg_shear_vel