Example #1
0
def read_file_her(filename):
    """
    The function is to read 10-column .her files.
    Return a list of psignals for each orientation.
    """
    time, dis_ns, dis_ew, dis_up = [np.array([], float) for _ in xrange(4)]
    vel_ns, vel_ew, vel_up = [np.array([], float) for _ in xrange(3)]
    acc_ns, acc_ew, acc_up = [np.array([], float) for _ in xrange(3)]

    try:
        (time, dis_ns, dis_ew, dis_up, vel_ns, vel_ew, vel_up, acc_ns, acc_ew,
         acc_up) = np.loadtxt(filename, comments='#', unpack=True)
    except IOError:
        print("[ERROR]: error loading her file.")
        return False

    samples = dis_ns.size
    delta_t = time[1]

    # samples, dt, data, acceleration, velocity, displacement
    psignal_ns = seism_psignal(samples, delta_t, np.c_[dis_ns, vel_ns, acc_ns],
                               'c', acc_ns, vel_ns, dis_ns)
    psignal_ew = seism_psignal(samples, delta_t, np.c_[dis_ew, vel_ew, acc_ew],
                               'c', acc_ew, vel_ew, dis_ew)
    psignal_up = seism_psignal(samples, delta_t, np.c_[dis_up, vel_up, acc_up],
                               'c', acc_up, vel_up, dis_up)

    station = [psignal_ns, psignal_ew, psignal_up]
    return station
Example #2
0
def read_file_her(filename):
    """
    The function is to read 10-column .her files.
    Return a list of psignals for each orientation.
    """
    time, dis_ns, dis_ew, dis_up = [np.array([], float) for _ in xrange(4)]
    vel_ns, vel_ew, vel_up = [np.array([], float) for _ in xrange(3)]
    acc_ns, acc_ew, acc_up = [np.array([], float) for _ in xrange(3)]

    try:
        (time, dis_ns, dis_ew, dis_up, vel_ns, vel_ew,
         vel_up, acc_ns, acc_ew, acc_up) = np.loadtxt(filename,
                                                      comments='#',
                                                      unpack=True)
    except IOError:
        print("[ERROR]: error loading her file.")
        return False

    samples = dis_ns.size
    delta_t = time[1]

    # samples, dt, data, acceleration, velocity, displacement
    psignal_ns = seism_psignal(samples, delta_t, np.c_[dis_ns, vel_ns, acc_ns],
                               'c', acc_ns, vel_ns, dis_ns)
    psignal_ew = seism_psignal(samples, delta_t, np.c_[dis_ew, vel_ew, acc_ew],
                               'c', acc_ew, vel_ew, dis_ew)
    psignal_up = seism_psignal(samples, delta_t, np.c_[dis_up, vel_up, acc_up],
                               'c', acc_up, vel_up, dis_up)

    station = [psignal_ns, psignal_ew, psignal_up]
    return station
Example #3
0
def read_file_bbp(filename):
    """
    This function reads timeseries data from a set of BBP files
    """
    # Get filenames for displacement, velocity and acceleration bbp files
    work_dir = os.path.dirname(filename)
    base_file = os.path.basename(filename)

    base_tokens = base_file.split('.')[0:-2]
    if not base_tokens:
        print("[ERROR]: Invalid BBP filename: %s" % (filename))
        sys.exit(1)
    dis_tokens = list(base_tokens)
    vel_tokens = list(base_tokens)
    acc_tokens = list(base_tokens)

    dis_tokens.append('dis')
    vel_tokens.append('vel')
    acc_tokens.append('acc')

    dis_tokens.append('bbp')
    vel_tokens.append('bbp')
    acc_tokens.append('bbp')

    dis_file = os.path.join(work_dir, '.'.join(dis_tokens))
    vel_file = os.path.join(work_dir, '.'.join(vel_tokens))
    acc_file = os.path.join(work_dir, '.'.join(acc_tokens))

    # Read 3 bbp files
    [time, dis_ns, dis_ew, dis_up] = read_file_bbp2(dis_file)
    [_, vel_ns, vel_ew, vel_up] = read_file_bbp2(vel_file)
    [_, acc_ns, acc_ew, acc_up] = read_file_bbp2(acc_file)

    samples = dis_ns.size
    delta_t = time[1]

    # samples, dt, data, acceleration, velocity, displacement
    psignal_ns = seism_psignal(samples, delta_t, np.c_[dis_ns, vel_ns, acc_ns],
                               'c', acc_ns, vel_ns, dis_ns)
    psignal_ew = seism_psignal(samples, delta_t, np.c_[dis_ew, vel_ew, acc_ew],
                               'c', acc_ew, vel_ew, dis_ew)
    psignal_up = seism_psignal(samples, delta_t, np.c_[dis_up, vel_up, acc_up],
                               'c', acc_up, vel_up, dis_up)

    station = [psignal_ns, psignal_ew, psignal_up]
    return station
Example #4
0
def read_file_bbp(filename):
    """
    This function reads timeseries data from a set of BBP files
    """
    # Get filenames for displacement, velocity and acceleration bbp files
    work_dir = os.path.dirname(filename)
    base_file = os.path.basename(filename)

    base_tokens = base_file.split('.')[0:-2]
    if not base_tokens:
        print("[ERROR]: Invalid BBP filename: %s" % (filename))
        sys.exit(1)
    dis_tokens = list(base_tokens)
    vel_tokens = list(base_tokens)
    acc_tokens = list(base_tokens)

    dis_tokens.append('dis')
    vel_tokens.append('vel')
    acc_tokens.append('acc')

    dis_tokens.append('bbp')
    vel_tokens.append('bbp')
    acc_tokens.append('bbp')

    dis_file = os.path.join(work_dir, '.'.join(dis_tokens))
    vel_file = os.path.join(work_dir, '.'.join(vel_tokens))
    acc_file = os.path.join(work_dir, '.'.join(acc_tokens))

    # Read 3 bbp files
    [time, dis_ns, dis_ew, dis_up] = read_file_bbp2(dis_file)
    [_, vel_ns, vel_ew, vel_up] = read_file_bbp2(vel_file)
    [_, acc_ns, acc_ew, acc_up] = read_file_bbp2(acc_file)

    samples = dis_ns.size
    delta_t = time[1]

    # samples, dt, data, acceleration, velocity, displacement
    psignal_ns = seism_psignal(samples, delta_t, np.c_[dis_ns, vel_ns, acc_ns],
                               'c', acc_ns, vel_ns, dis_ns)
    psignal_ew = seism_psignal(samples, delta_t, np.c_[dis_ew, vel_ew, acc_ew],
                               'c', acc_ew, vel_ew, dis_ew)
    psignal_up = seism_psignal(samples, delta_t, np.c_[dis_up, vel_up, acc_up],
                               'c', acc_up, vel_up, dis_up)

    station = [psignal_ns, psignal_ew, psignal_up]
    return station
Example #5
0
def process(signal):
    """
    The function takes a signal, use its's current data to get
    acceleration, velocity, and displacement.
    Then return a psignal.
    """
    if not isinstance(signal, seism_signal):
        print("[ERROR]: instance error; process signal objects only.")
        return

    # Correction of base lines was commented out here to avoid problems with synchronization
    # correct_baseline(signal)

    acc = np.array([], float)
    vel = np.array([], float)
    dis = np.array([], float)
    dt = signal.dt

    if signal.type == 'a':
        acc = signal.data
        acc = s_filter(acc, signal.dt, type='highpass',
                       family='butter', fmin=0.05, N=5)
        vel = integrate(acc, dt)
        vel = s_filter(vel, signal.dt, type='highpass',
                       family='butter', fmin=0.05, N=5)
        dis = integrate(vel, dt)
        dis = s_filter(dis, signal.dt, type='highpass',
                       family='butter', fmin=0.05, N=5)
    elif signal.type == 'v':
        vel = signal.data
        vel = s_filter(vel, signal.dt, type='highpass',
                       family='butter', fmin=0.05, N=5)
        acc = derivative(vel, dt)
        dis = integrate(vel, dt)
        dis = s_filter(dis, signal.dt, type='highpass',
                       family='butter', fmin=0.05, N=5)
    elif signal.type == 'd':
        dis = signal.data
        dis = s_filter(dis, signal.dt, type='highpass',
                       family='butter', fmin=0.05, N=5)
        vel = derivative(dis, dt)
        acc = derivative(vel, dt)
    else:
        pass

    psignal = seism_psignal(signal.samples, signal.dt,
                            np.c_[dis, vel, acc], 'c', acc, vel, dis)
    return psignal
Example #6
0
def process(signal):
    """
    The function takes a signal, use its's current data to get
    acceleration, velocity, and displacement.
    Then return a psignal.
    """
    if not isinstance(signal, seism_signal):
        print("[ERROR]: instance error; process signal objects only.")
        return

    # Correction of base lines was commented out here to avoid problems with synchronization
    # correct_baseline(signal)

    acc = np.array([], float)
    vel = np.array([], float)
    dis = np.array([], float)
    dt = signal.dt

    if signal.type == 'a':
        acc = signal.data
        acc = s_filter(acc,
                       signal.dt,
                       type='highpass',
                       family='butter',
                       fmin=0.05,
                       N=5)
        vel = integrate(acc, dt)
        vel = s_filter(vel,
                       signal.dt,
                       type='highpass',
                       family='butter',
                       fmin=0.05,
                       N=5)
        dis = integrate(vel, dt)
        dis = s_filter(dis,
                       signal.dt,
                       type='highpass',
                       family='butter',
                       fmin=0.05,
                       N=5)
    elif signal.type == 'v':
        vel = signal.data
        vel = s_filter(vel,
                       signal.dt,
                       type='highpass',
                       family='butter',
                       fmin=0.05,
                       N=5)
        acc = derivative(vel, dt)
        dis = integrate(vel, dt)
        dis = s_filter(dis,
                       signal.dt,
                       type='highpass',
                       family='butter',
                       fmin=0.05,
                       N=5)
    elif signal.type == 'd':
        dis = signal.data
        dis = s_filter(dis,
                       signal.dt,
                       type='highpass',
                       family='butter',
                       fmin=0.05,
                       N=5)
        vel = derivative(dis, dt)
        acc = derivative(vel, dt)
    else:
        pass

    psignal = seism_psignal(signal.samples, signal.dt, np.c_[dis, vel, acc],
                            'c', acc, vel, dis)
    return psignal