コード例 #1
0
ファイル: ccpprofile.py プロジェクト: xumi1993/seispy
def bin_shape(cpara):
    if cpara.bin_radius is None:
        depmod = DepModel(cpara.stack_range)
        fzone = km2deg(
            np.sqrt(0.5 * cpara.domperiod * depmod.vs * cpara.stack_range))
    else:
        fzone = np.ones_like(cpara.stack_range) * km2deg(cpara.bin_radius)
    return fzone
コード例 #2
0
def gen_bin_radius(cpara):
    if cpara.bin_radius is None:
        velmod = DepModel(cpara.stack_range, cpara.velmod)
        bin_radius = km2deg(
            np.sqrt(0.5 * cpara.domperiod * velmod.vs * cpara.stack_range))
    else:
        bin_radius = np.zeros(cpara.stack_range.shape[0]) * km2deg(
            cpara.bin_radius)
    return bin_radius
コード例 #3
0
ファイル: ccp3d.py プロジェクト: xumi1993/seispy
def bin_shape(cpara):
    if cpara.shape == 'rect':
        raise ValueError(
            'The shape of bins must be set to \'circle\' in ccp3d mode.')
    if cpara.bin_radius is None:
        depmod = DepModel(cpara.stack_range)
        fzone = km2deg(
            np.sqrt(0.5 * cpara.domperiod * depmod.vs * cpara.stack_range))
    else:
        fzone = np.ones_like(cpara.stack_range) * km2deg(cpara.bin_radius)
    return fzone
コード例 #4
0
ファイル: ccpprofile.py プロジェクト: xumi1993/seispy
def init_profile(lat1, lon1, lat2, lon2, val):
    """ Initial bins along a profile with given position of two points.

    :param lat1: The latitude of the start point
    :type lat1: float
    :param lon1: The lontitude of the start point
    :type lon1: float
    :param lat2: The latitude of the end point
    :type lat2: float
    :param lon2: The lontitude of the end point
    :type lon2: float
    :param val: The interval between two points in km
    :type val: float
    :return: The location of bins (bin_loca), and length between each bin and the start point (profile_range)

    The bin_loca is positions of bins with a numpy.array with two column. The profile_range is distance between bin center and the start point with an 1D numpy.array.
    :rtype: (numpy.array, numpy.array)
    """
    azi = distaz(lat1, lon1, lat2, lon2).baz
    dis = distaz(lat1, lon1, lat2, lon2).delta
    profile_range = np.arange(0, deg2km(dis), val)
    lat_loca, lon_loca = latlon_from(lat1, lon1, azi, km2deg(profile_range))
    bin_loca = np.zeros([lat_loca.shape[0], 2])
    bin_loca = np.vstack((lat_loca, lon_loca)).T
    return bin_loca, profile_range
コード例 #5
0
ファイル: ccp_center_bin.py プロジェクト: weijias-fork/seispy
def search_pierce(rfdep, depaxis, bin_loca, bin_radius=75):
    bin_radius = km2deg(bin_radius)
    # data = np.zeros((bin_loca.shape[0], depaxis.shape[0]), dtype='O')
    stack_data = []
    for i in range(bin_loca.shape[0]):
        boot_stack = {}
        bin_mu = np.zeros(depaxis.shape[0])
        bin_ci = np.zeros([depaxis.shape[0], 2])
        bin_count = np.zeros(depaxis.shape[0])
        print('{}/{}'.format(i + 1, bin_loca.shape[0]))
        for j, dep in zip(range(depaxis.shape[0]), depaxis):
            bin_dep = np.array([])
            for sta in rfdep:
                fall_idx = np.where(
                    distaz(sta['Piercelat'][0, 0][:, dep], sta['Piercelon'][
                        0, 0][:, dep], bin_loca[i, 0], bin_loca[i, 1]).delta <
                    bin_radius)[0]
                bin_dep = np.append(
                    bin_dep, sta['moveout_correct'][0, 0][fall_idx, dep])
            bin_mu[j], cci, bin_count[j] = boot_bin_stack(bin_dep)
            bin_ci[j, 0] = cci[0]
            bin_ci[j, 1] = cci[1]
        boot_stack['bin_lat'] = bin_loca[i, 0]
        boot_stack['bin_lon'] = bin_loca[i, 1]
        boot_stack['mu'] = bin_mu
        boot_stack['ci'] = bin_ci
        boot_stack['count'] = bin_count
        stack_data.append(boot_stack)
    return stack_data
コード例 #6
0
ファイル: ccp_profile.py プロジェクト: weijias-fork/seispy
def init_profile(lat1, lon1, lat2, lon2, val):
    azi = distaz(lat1, lon1, lat2, lon2).baz
    dis = distaz(lat1, lon1, lat2, lon2).delta
    profile_range = np.arange(0, deg2km(dis), val)
    lat_loca, lon_loca = latlon_from(lat1, lon1, azi, km2deg(profile_range))
    bin_loca = np.zeros([lat_loca.shape[0], 2])
    for i in range(lat_loca.shape[0]):
        bin_loca[i, 0] = lat_loca[i]
        bin_loca[i, 1] = lon_loca[i]
    return bin_loca, profile_range
コード例 #7
0
ファイル: ccp_profile.py プロジェクト: weijias-fork/seispy
def search_pierce(rfdep, depaxis, bin_loca, profile_range, bin_radius=75):
    bin_radius = km2deg(bin_radius)
    data = []
    for i in range(bin_loca.shape[0]):
        rfbin = {}
        print('{}/{}'.format(i + 1, bin_loca.shape[0]))
        ccp_mean = np.zeros(depaxis.shape[0])
        ccp_count = np.zeros(depaxis.shape[0])
        ccp_ci = np.zeros((depaxis.shape[0], 2))
        for j, dep in zip(range(depaxis.shape[0]), depaxis):
            bin_dep = np.array([])
            for sta in rfdep:
                fall_idx = np.where(
                    distaz(sta['Piercelat'][0, 0][:, dep], sta['Piercelon'][
                        0, 0][:, dep], bin_loca[i, 0], bin_loca[i, 1]).delta <
                    bin_radius)[0]
                bin_dep = np.append(
                    bin_dep, sta['moveout_correct'][0, 0][fall_idx, dep])
            if bin_dep.shape[0] > 1:
                bin_ci = ci(bin_dep, n_samples=2000)
                bin_mu = np.average(bin_dep)
            else:
                bin_ci = (np.nan, np.nan)
                bin_mu = np.nan
            ccp_count[j] = bin_dep.shape[0]
            ccp_mean[j] = bin_mu
            ccp_ci[j, 0] = bin_ci[0]
            ccp_ci[j, 1] = bin_ci[1]
        rfbin['bin_lat'] = bin_loca[i, 0]
        rfbin['bin_lon'] = bin_loca[i, 1]
        rfbin['profile_dis'] = profile_range[i]
        rfbin['mu'] = ccp_mean
        rfbin['ci'] = ccp_ci
        rfbin['count'] = ccp_count
        data.append(rfbin)
    return data
コード例 #8
0
ファイル: ccp3d.py プロジェクト: xumi1993/seispy
                        mu[low_idx:up_idx + 1]) / np.sqrt(up_idx - low_idx + 1)
                elif type == 'ci':
                    cvalue = self.stack_data[i]['ci'][idx, 0]
                else:
                    self.logger.error(
                        'Reference type should be in \'std\' and \'ci\'')
                    sys.exit(1)
                moho_err[i, 0], moho_err[i, 1] = self._get_err(
                    mu[low_idx:up_idx + 1],
                    self.cpara.stack_range[low_idx:up_idx + 1], cvalue)
        return moho_err

    def _get_err(self, tr, dep, cvalue):
        result = np.array([])
        for i, amp in enumerate(tr[:-1]):
            if (amp <= cvalue < tr[i + 1]) or (amp > cvalue >= tr[i + 1]):
                result = np.append(
                    result,
                    interp1d([amp, tr[i + 1]], [dep[i], dep[i + 1]])(cvalue))
        if len(result) == 2:
            return result[0], result[1]
        else:
            return np.nan, np.nan


if __name__ == '__main__':
    bin_loca = gen_center_bin(48.5, 100, 5, 8, km2deg(55))
    with open('/workspace/WMHG_MTZ/ccp_results/bin_loca.dat', 'w') as f:
        for binin in bin_loca:
            f.write('{} {}\n'.format(binin[1], binin[0]))
コード例 #9
0
def psrf_3D_raytracing(stadatar, YAxisRange, mod3d, srayp=None):
    """
Back ray trace the S wavs with a assumed ray parameter of P.

Parameters
--------------
stla: float
    The latitude of the station
stlo: float
    The longitude of the station
stadatar: object SACStation
    The data class including PRFs and more parameters
YAxisRange: array_like
    The depth array with the same intervals
mod3d: 'Mod3DPerturbation' object
    The 3D velocity model with fields of ``dep``, ``lat``,
    ``lon``, ``vp`` and ``vs``.
    """
    R = 6371 - YAxisRange
    ddepth = np.mean(np.diff(YAxisRange))
    pplat_s = np.zeros([stadatar.ev_num, YAxisRange.shape[0]])
    pplon_s = np.zeros([stadatar.ev_num, YAxisRange.shape[0]])
    pplat_p = np.zeros([stadatar.ev_num, YAxisRange.shape[0]])
    pplon_p = np.zeros([stadatar.ev_num, YAxisRange.shape[0]])
    x_s = np.zeros([stadatar.ev_num, YAxisRange.shape[0]])
    x_p = np.zeros([stadatar.ev_num, YAxisRange.shape[0]])
    Tpds = np.zeros([stadatar.ev_num, YAxisRange.shape[0]])
    rayps = srad2skm(stadatar.rayp)

    if isinstance(srayp, str) or isinstance(srayp, np.lib.npyio.NpzFile):
        if isinstance(srayp, str):
            if not exists(srayp):
                raise FileNotFoundError('Ps rayp lib file not found')
            else:
                rayp_lib = np.load(srayp)
        else:
            rayp_lib = srayp
    elif srayp is None:
        pass
    else:
        raise TypeError('srayp should be path to Ps rayp lib')

    for i in range(stadatar.ev_num):
        if srayp is None:
            srayps = stadatar.rayp[i]
        else:
            srayps = get_psrayp(rayp_lib, stadatar.dis[i], stadatar.evdp[i],
                                YAxisRange)
            srayps = skm2srad(sdeg2skm(srayps))
        pplat_s[i][0] = pplat_p[i][0] = stadatar.stla
        pplon_s[i][0] = pplon_p[i][0] = stadatar.stlo
        x_s[i][0] = 0
        x_p[i][0] = 0
        vs = np.zeros_like(YAxisRange)
        vp = np.zeros_like(YAxisRange)
        for j, dep in enumerate(YAxisRange[:-1]):
            vs[j] = interpn(
                (mod3d.model['dep'], mod3d.model['lat'], mod3d.model['lon']),
                mod3d.model['vs'], (dep, pplat_s[i, j], pplon_s[i, j]),
                bounds_error=False,
                fill_value=None)
            vp[j] = interpn(
                (mod3d.model['dep'], mod3d.model['lat'], mod3d.model['lon']),
                mod3d.model['vp'], (dep, pplat_p[i, j], pplon_p[i, j]),
                bounds_error=False,
                fill_value=None)
            x_s[i, j + 1] = ddepth * tand(asind(vs[j] * rayps[i])) + x_s[i, j]
            x_p[i, j + 1] = ddepth * tand(asind(vp[j] * rayps[i])) + x_p[i, j]
            pplat_s[i, j + 1], pplon_s[i, j + 1] = latlon_from(
                stadatar.stla, stadatar.stlo, stadatar.bazi[i],
                km2deg(x_s[i, j + 1]))
            pplat_p[i, j + 1], pplon_p[i, j + 1] = latlon_from(
                stadatar.stla, stadatar.stlo, stadatar.bazi[i],
                km2deg(x_p[i, j + 1]))
        Tpds[i] = np.cumsum(
            (np.sqrt((R / vs)**2 - srayps**2) -
             np.sqrt((R / vp)**2 - stadatar.rayp[i]**2)) * (ddepth / R))
    return pplat_s, pplon_s, pplat_p, pplon_p, Tpds
コード例 #10
0
def psrf_3D_raytracing(stadatar,
                       YAxisRange,
                       mod3d,
                       srayp=None,
                       elevation=0,
                       sphere=True):
    """
    Back ray trace the S wavs with a assumed ray parameter of P.

    :param stadatar: The data class including PRFs and more parameters
    :type stadatar: object RFStation
    :param YAxisRange: The depth array with the same intervals
    :type YAxisRange: numpy.ndarray
    :param mod3d:  The 3D velocity model with fields of ``dep``, ``lat``,
                    ``lon``, ``vp`` and ``vs``.
    :type mod3d: 'Mod3DPerturbation' object
    :param elevation: Elevation of this station relative to sea level
    :type elevation: float
    :return: pplat_s, pplon_s, pplat_p, pplon_p, tps
    :type: numpy.ndarray * 5
    """
    if sphere:
        R = 6371.0 - YAxisRange + elevation
    else:
        R = 6371.0 + elevation
    dep_range = YAxisRange.copy()
    YAxisRange -= elevation
    ddepth = np.mean(np.diff(YAxisRange))
    pplat_s = np.zeros([stadatar.ev_num, YAxisRange.shape[0]])
    pplon_s = np.zeros([stadatar.ev_num, YAxisRange.shape[0]])
    pplat_p = np.zeros([stadatar.ev_num, YAxisRange.shape[0]])
    pplon_p = np.zeros([stadatar.ev_num, YAxisRange.shape[0]])
    x_s = np.zeros([stadatar.ev_num, YAxisRange.shape[0]])
    x_p = np.zeros([stadatar.ev_num, YAxisRange.shape[0]])
    tps = np.zeros([stadatar.ev_num, YAxisRange.shape[0]])
    rayps = srad2skm(stadatar.rayp)

    if isinstance(srayp, str) or isinstance(srayp, np.lib.npyio.NpzFile):
        if isinstance(srayp, str):
            if not exists(srayp):
                raise FileNotFoundError('Ps rayp lib file not found')
            else:
                rayp_lib = np.load(srayp)
        else:
            rayp_lib = srayp
    elif srayp is None:
        pass
    else:
        raise TypeError('srayp should be path to Ps rayp lib')

    for i in range(stadatar.ev_num):
        if srayp is None:
            srayps = stadatar.rayp[i]
        else:
            srayps = get_psrayp(rayp_lib, stadatar.dis[i], stadatar.evdp[i],
                                YAxisRange)
            srayps = skm2srad(sdeg2skm(srayps))
        pplat_s[i][0] = pplat_p[i][0] = stadatar.stla
        pplon_s[i][0] = pplon_p[i][0] = stadatar.stlo
        x_s[i][0] = 0
        x_p[i][0] = 0
        vs = np.zeros_like(YAxisRange)
        vp = np.zeros_like(YAxisRange)
        for j, dep in enumerate(YAxisRange[:-1]):
            vs[j] = interpn(
                (mod3d.model['dep'], mod3d.model['lat'], mod3d.model['lon']),
                mod3d.model['vs'], (dep, pplat_s[i, j], pplon_s[i, j]),
                bounds_error=False,
                fill_value=None)
            vp[j] = interpn(
                (mod3d.model['dep'], mod3d.model['lat'], mod3d.model['lon']),
                mod3d.model['vp'], (dep, pplat_p[i, j], pplon_p[i, j]),
                bounds_error=False,
                fill_value=None)
            x_s[i, j + 1] = ddepth * tand(asind(vs[j] * rayps[i])) + x_s[i, j]
            x_p[i, j + 1] = ddepth * tand(asind(vp[j] * rayps[i])) + x_p[i, j]
            pplat_s[i, j + 1], pplon_s[i, j + 1] = latlon_from(
                stadatar.stla, stadatar.stlo, stadatar.bazi[i],
                km2deg(x_s[i, j + 1]))
            pplat_p[i, j + 1], pplon_p[i, j + 1] = latlon_from(
                stadatar.stla, stadatar.stlo, stadatar.bazi[i],
                km2deg(x_p[i, j + 1]))
        tps_corr = np.cumsum(
            (np.sqrt((R / vs)**2 - srayps**2) -
             np.sqrt((R / vp)**2 - stadatar.rayp[i]**2)) * (ddepth / R))
        if elevation != 0:
            tps[i] = interp1d(YAxisRange, tps_corr)(dep_range)
    return pplat_s, pplon_s, pplat_p, pplon_p, tps
コード例 #11
0
def ccppara(cfg_file):
    cpara = CCPPara()
    cf = configparser.ConfigParser()
    try:
        cf.read(cfg_file)
    except Exception:
        raise FileNotFoundError('Cannot open configure file %s' % cfg_file)
    # para for FileIO section
    cpara.rfpath = cf.get('FileIO', 'rfpath')
    rayp_lib = cf.get('FileIO', 'rayp_lib')
    if rayp_lib == '':
        cpara.rayp_lib = None
    else:
        cpara.rayp_lib = rayp_lib
    cpara.depthdat = cf.get('FileIO', 'depthdat')
    cpara.stackfile = cf.get('FileIO', 'stackfile')
    cpara.stalist = cf.get('FileIO', 'stalist')
    cpara.stack_sta_list = cf.get('FileIO', 'stack_sta_list')
    if cf.has_option('FileIO', 'peakfile'):
        fname = cf.get('FileIO', 'peakfile')
        if fname != '':
            cpara.peakfile = fname
    velmod = cf.get('FileIO', 'velmod')
    if velmod == '':
        cpara.velmod = join(dirname(__file__), 'data', 'iasp91.vel')
    elif not exists(velmod):
        cpara.velmod = join(dirname(__file__), 'data',
                            '{}.vel'.format(velmod.lower()))
    else:
        cpara.velmod = velmod
    # para for bin section
    cpara.shape = cf.get('bin', 'shape')
    try:
        cpara.adaptive = cf.getboolean('bin', 'adaptive')
    except:
        cpara.adaptive = False
    try:
        cpara.domperiod = cf.getfloat('bin', 'domperiod')
    except:
        cpara.domperiod = None
    try:
        cpara.width = cf.getfloat('bin', 'width')
    except:
        cpara.width = None
    try:
        cpara.bin_radius = cf.getfloat('bin', 'bin_radius')
    except:
        cpara.bin_radius = None
    cpara.slide_val = cf.getfloat('bin', 'slide_val')
    # para for line section
    lat1 = cf.getfloat('line', 'profile_lat1')
    lon1 = cf.getfloat('line', 'profile_lon1')
    lat2 = cf.getfloat('line', 'profile_lat2')
    lon2 = cf.getfloat('line', 'profile_lon2')
    cpara.line = np.array([lat1, lon1, lat2, lon2])
    # para for depth section
    dep_end = cf.getfloat('depth', 'dep_end')
    cpara.dep_val = cf.getfloat('depth', 'dep_val')
    try:
        cpara.phase = cf.getint('depth', 'phase')
    except:
        cpara.phase = 1
    cpara.depth_axis = np.append(np.arange(0, dep_end, cpara.dep_val), dep_end)

    stack_start = cf.getfloat('stack', 'stack_start')
    stack_end = cf.getfloat('stack', 'stack_end')
    cpara.stack_val = cf.getfloat('stack', 'stack_val')
    cpara.stack_range = np.arange(stack_start, stack_end, cpara.stack_val)
    try:
        cpara.boot_samples = cf.getint('stack', 'boot_samples')
    except:
        cpara.boot_samples = None
    # para for center bins
    if cf.has_section('spacedbins'):
        cla = cf.getfloat('spacedbins', 'center_lat')
        clo = cf.getfloat('spacedbins', 'center_lon')
        hlla = cf.getfloat('spacedbins', 'half_len_lat')
        hllo = cf.getfloat('spacedbins', 'half_len_lon')
        cpara.center_bin = [cla, clo, hlla, hllo, km2deg(cpara.slide_val)]

    return cpara