Beispiel #1
0
                ordered_files[index] = file

            ordered_paths = list()
            for file in ordered_files:
                if file is None:
                    ordered_files.append(file)
                    continue
                path = os.path.join(proc_folder, file)
                ordered_paths.append(path)

            spectrum_data = get_avg_spectrums(files_list=ordered_paths,
                                              frequency=signal_frequency,
                                              avg_sp_params=avg_spec_params)

            z_spectrum = nakamura_spectrum(
                components_spectrum_data=spectrum_data,
                components_order='XYZ',
                spectrum_type='HV')

            # z_spectrum=z_spectrum[(z_spectrum[:,0]>=5)*(z_spectrum[:,0]<=25)]
            z_spectrum[:,1]=(z_spectrum[:,1]-np.min(z_spectrum[:,1])) / \
                            (np.max(z_spectrum[:,1])-np.min(z_spectrum[:,1]))
            if result_array is None:
                result_array = z_spectrum
            else:
                result_array = np.column_stack((result_array, z_spectrum[:,
                                                                         1]))
            header.append(f'Num-{point_number}')
    t2 = datetime.now()
    dt = (t2 - t1).total_seconds()
    print(f'Point {point} done. Time: {dt} sec')
Beispiel #2
0
    for index, line in enumerate(handle):
        if index == 0:
            continue
        t = line.strip().split('\t')
        number = int(t[0])
        x, y = [float(q) for q in t[1:]]
        coords_data[number] = (x, y)

result = np.zeros(shape=(0, 3 + len(freq_limits)))
for index in range(len(sensor_numbers)):
    signal = signal_data[:, 1 + 3*index:1+3*(index+1)]
    x, y = coords_data[sensor_numbers[index]]
    # sp = spectrum(signal=signal, frequency=frequency)
    avg_sp=get_avg_spectrums(signals=signal, frequency=frequency,
                             avg_sp_params=avg_spec_params)
    sp=nakamura_spectrum(components_spectrum_data=avg_sp,
                         components_order='XYZ', spectrum_type='HV')
    t = [sensor_numbers[index], x, y]
    for lim in freq_limits:
        e = spectrum_energy(spectrum_data=sp, f_min=lim[0], f_max=lim[1])
        t.append(e)
    result = np.vstack((result, t))

    # sp = sp[sp[:, 0] <= 20]
    # label_value = f'Average spectrum Sensor {sensor_numbers[index]}'
    # plot_graph(x_data=sp[:, 0], y_data=sp[:, 1], label=label_value,
    #            output_folder=output_folder, output_name=label_value,
    #            x_label='Frequency', y_label='Amplitude')

header = ['Point', 'x', 'y']
for lim in freq_limits:
    p = f'E_{lim[0]}-{lim[1]}'
def proc_file(src_file_name, detrend_type, proc_type, files_list, frequency,
              avg_sp_params, cepster_params, nak_sp_params, output_path):
    # print(f'Processing: {src_file_name}')
    signals = None
    for path in files_list:
        signal = np.loadtxt(path, delimiter=' ')[:, 1]
        if str(np.max(signal)) == 'nan':
            print('Bad signal')
            return

        if signals is None:
            signals = signal
        else:
            signals = np.column_stack((signals, signal))

    no_smooth_avg_specs = None
    smooth_avg_specs = None
    for index in range(signals.shape[1]):
        ns_avg_spec = average_spectrum(signal=signals[:, index],
                                       frequency=frequency,
                                       window=avg_sp_params['window'],
                                       offset=avg_sp_params['offset'],
                                       med_filter=None,
                                       marmett_filter=None)
        s_avg_spec = average_spectrum(
            signal=signals[:, index],
            frequency=frequency,
            window=avg_sp_params['window'],
            offset=avg_sp_params['offset'],
            med_filter=avg_sp_params['med_filter'],
            marmett_filter=avg_sp_params['marmett_filter'])
        if no_smooth_avg_specs is None:
            no_smooth_avg_specs = ns_avg_spec
            smooth_avg_specs = s_avg_spec
        else:
            no_smooth_avg_specs = np.column_stack(
                (no_smooth_avg_specs, ns_avg_spec[:, 1]))
            smooth_avg_specs = np.column_stack(
                (smooth_avg_specs, s_avg_spec[:, 1]))

    smooth_cep_specs = None
    no_smooth_cep_specs = None
    for i in range(signals.shape[1]):
        spectrum = np.zeros(shape=(no_smooth_avg_specs.shape[0], 2))
        spectrum[:, 0] = no_smooth_avg_specs[:, 0]
        spectrum[:, 1] = no_smooth_avg_specs[:, i + 1]
        ns_cep_spec = cepstral_spectrum_from_spectrum(spectrum_data=spectrum)
        spectrum[:, 1] = smooth_avg_specs[:, i + 1]
        s_cep_spec = cepstral_spectrum_from_spectrum(spectrum_data=spectrum)
        if smooth_cep_specs is None:
            smooth_cep_specs = s_cep_spec
            no_smooth_cep_specs = ns_cep_spec
        else:
            smooth_cep_specs = np.column_stack(
                (smooth_cep_specs, s_cep_spec[:, 1]))
            no_smooth_cep_specs = np.column_stack(
                (no_smooth_cep_specs, ns_cep_spec[:, 1]))

    no_smooth_nak_spec = nakamura_spectrum(
        components_spectrum_data=no_smooth_avg_specs,
        components_order='XYZ',
        spectrum_type=nak_sp_params['type'])

    smooth_nak_spec = nakamura_spectrum(
        components_spectrum_data=smooth_avg_specs,
        components_order='XYZ',
        spectrum_type=nak_sp_params['type'])

    # export data
    out_folder = os.path.join(output_path, 'AverageSpectrums', proc_type,
                              detrend_type)
    if not os.path.exists(out_folder):
        os.makedirs(out_folder)

    file_name = f'{src_file_name}.sc'
    out_path = os.path.join(out_folder, file_name)
    np.savetxt(out_path,
               no_smooth_avg_specs,
               delimiter='\t',
               header='Frequency\tX\tY\tZ',
               comments='')

    file_name = f'{src_file_name}.ssc'
    out_path = os.path.join(out_folder, file_name)
    np.savetxt(out_path,
               smooth_avg_specs,
               delimiter='\t',
               header='Frequency\tX\tY\tZ',
               comments='')

    for index, component in enumerate('XYZ'):
        plot_average_spectrum(
            frequency=smooth_avg_specs[:, 0],
            spectrum_begin_amplitudes=no_smooth_avg_specs[:, index + 1],
            spectrum_smooth_amplitudes=smooth_avg_specs[:, index + 1],
            f_min=avg_sp_params['f_min'],
            f_max=avg_sp_params['f_max'],
            output_folder=out_folder,
            output_name=f'{src_file_name}_Component_{component}')

    out_folder = os.path.join(output_path, 'CepsterSpectrums', proc_type,
                              detrend_type)
    if not os.path.exists(out_folder):
        os.makedirs(out_folder)

    file_name = f'{src_file_name}.cep'
    out_path = os.path.join(out_folder, file_name)
    np.savetxt(out_path,
               no_smooth_cep_specs,
               delimiter='\t',
               header='Time\tX\tY\tZ',
               comments='')

    file_name = f'{src_file_name}.scep'
    out_path = os.path.join(out_folder, file_name)
    np.savetxt(out_path,
               smooth_cep_specs,
               delimiter='\t',
               header='Time\tX\tY\tZ',
               comments='')

    for index, component in enumerate('XYZ'):
        plot_average_spectrum(
            frequency=smooth_cep_specs[:, 0],
            spectrum_begin_amplitudes=no_smooth_cep_specs[:, index + 1],
            spectrum_smooth_amplitudes=smooth_cep_specs[:, index + 1],
            f_min=cepster_params['t_min'],
            f_max=cepster_params['t_max'],
            output_folder=out_folder,
            output_name=f'Cepster_{src_file_name}_Component_{component}')

    out_folder = os.path.join(output_path, 'NakamuraSpectrum', proc_type,
                              detrend_type)
    if not os.path.exists(out_folder):
        os.makedirs(out_folder)

    file_name = f'{nak_sp_params["type"]}_{src_file_name}.nak'
    out_path = os.path.join(out_folder, file_name)
    np.savetxt(out_path,
               no_smooth_nak_spec,
               delimiter='\t',
               header='Freq\tAmplitude',
               comments='')

    file_name = f'{nak_sp_params["type"]}_{src_file_name}.snak'
    out_path = os.path.join(out_folder, file_name)
    np.savetxt(out_path,
               smooth_nak_spec,
               delimiter='\t',
               header='Freq\tAmplitude',
               comments='')

    plot_average_spectrum(
        frequency=smooth_nak_spec[:, 0],
        spectrum_begin_amplitudes=no_smooth_nak_spec[:, 1],
        spectrum_smooth_amplitudes=smooth_nak_spec[:, 1],
        f_min=nak_sp_params['f_min'],
        f_max=nak_sp_params['f_max'],
        output_folder=out_folder,
        output_name=f'{nak_sp_params["type"]}_{src_file_name}')
Beispiel #4
0
freq_array = None
for index in range(point_count):
    signal = signal_data[:, 1 + 3 * index:1 + 3 * (index + 1)]
    x, y = coords_data[sensor_numbers[index]]

    sp_x = spectrum(signal=signal[:, 0], frequency=frequency)
    sp_y = spectrum(signal=signal[:, 1], frequency=frequency)
    sp_z = spectrum(signal=signal[:, 2], frequency=frequency)

    join_sp_data = np.zeros(shape=(sp_x.shape[0], 5))
    join_sp_data[:, :2] = sp_x
    join_sp_data[:, 2] = sp_y[:, 1]
    join_sp_data[:, 3] = sp_z[:, 1]

    nak_sp = nakamura_spectrum(components_spectrum_data=join_sp_data,
                               components_order='XYZ',
                               spectrum_type='VH')
    if result is None:
        result = np.zeros(shape=(point_count, sp_x.shape[0], 4))
        freq_array = sp_x[:, 0]

    result[index, :, 0] = sp_x[:, 1]
    result[index, :, 1] = sp_y[:, 1]
    result[index, :, 2] = sp_z[:, 1]
    result[index, :, 3] = nak_sp[:, 1]

matrix = np.zeros(shape=(point_count, intervals_count * 2 + 3))
header = ['Point', 'x', 'y']
for i in range(point_count):
    num = sensor_numbers[i]
    if num > 100: