Ejemplo n.º 1
0
                    else:
                        this_line = f'{this_hour}{param.separator}{X}{param.separator}{int(round(float(V)))}'
                        key = f'{X}:{int(round(float(V)))}'
                    h_file.append(this_line)
                    if key in d_file.keys():
                        d_file[key] += 1
                    else:
                        d_file[key] = 1

            file.close()

    # Open the output file.
    pdf_dir_tag, pdf_file_tag = file_lib.get_dir(param.dataDirectory,
                                                 param.pdfDirectory, network,
                                                 station, location, channel)
    file_lib.make_path(pdf_dir_tag)
    this_path = os.path.join(pdf_dir_tag, f'Y{this_year}')
    file_lib.make_path(this_path)
    output_file = os.path.join(this_path, f'D{this_doy}.bin')
    msg_lib.info(f'DAILY OUTPUT FILE: {output_file}')
    with open(output_file, 'w') as output_file:
        for key in sorted(d_file.keys()):
            day, db = key.split(':')
            output_file.write(
                f'{day}{param.separator}{db}{param.separator}{d_file[key]}\n')
    output_file.close()

    if param.pdfHourlySave > 0:
        this_path = os.path.join(this_path, param.pdfHourlyDirectory)
        file_lib.make_path(this_path)
        output_file = os.path.join(this_path, f'H{this_doy}.bin')
Ejemplo n.º 2
0
            # get the response information

            msg_lib.info(tr.stats.response)

            # Convert to dB.
            power = 10.0 * np.log10(power)
            smooth_psd = 10.0 * np.log10(smooth_psd)

            # Create output paths if they do not exist.
            if utils_lib.param(param, 'outputValues').outputValues > 0:
                filePath, psd_file_tag = file_lib.get_dir(data_directory,
                                                          psd_db_directory,
                                                          network,
                                                          station, location, channel)
                filePath = os.path.join(filePath, segment_start_year, segment_start_doy)
                file_lib.make_path(filePath)

                # Output is based on the xtype.
                if verbose:
                    msg_lib.info(f'trChannel.stats: {tr.stats} '
                                 f'REQUEST: {segment_start} '
                                 f'TRACE: {tr.stats.starttime.strftime("%Y-%m-%dT%H:%M:%S")} '
                                 f'DELTA: {tr.stats.delta} '
                                 f'SAMPLES: '
                                 f'{int(window_length / float(tr.stats.delta) + 1)} ')

                time_label = tr.stats.starttime.strftime('%Y-%m-%dT%H:%M:%S')
                tagList = [psd_file_tag, time_label,
                           f'{window_length}', xtype]
                output_file_name = file_lib.get_file_name(utils_lib.param(
                    param, 'namingConvention').namingConvention, filePath, tagList)
Ejemplo n.º 3
0
elif date_range < 45:
    ax.xaxis.set_major_locator(weeks)
    ax.xaxis.set_major_formatter(daysFmt)
elif date_range < 90:
    ax.xaxis.set_major_locator(weeks)
    ax.xaxis.set_major_formatter(monthsFmt)
elif date_range < 400:
    ax.xaxis.set_major_locator(months)
    ax.xaxis.set_major_formatter(monthsFmt)
else:
    ax.xaxis.set_major_locator(years)
    ax.xaxis.set_major_formatter(yearsFmt)

#
# rotate the x labels by 60 degrees
#
for xlab in ax.get_xticklabels():
    xlab.set_rotation(60)

fig.subplots_adjust(top=0.95, right=0.95, bottom=0.2, hspace=0)
image_directory = os.path.join(param.ntkDirectory, param.imageDirectory)
file_lib.make_path(image_directory)
image_file = os.path.join(
    image_directory,
    "_".join([file_name.replace('.txt', ''), image_tag, window_tag]))
plt.savefig(f'{image_file}.eps', format="eps", dpi=300)
msg_lib.info(f'image file: {image_file}.eps')
plt.savefig(f'{image_file}.png', format="png", dpi=150)
msg_lib.info(f'image file: {image_file}.png')
plt.show()
Ejemplo n.º 4
0
window_width_second = float(window_width_hour) * 3600.0
window_shift_second = param.windowShiftSecond
msg_lib.info(
    f'Wind length and shift in seconds {window_width_second}, {window_shift_second}'
)
start_time = UTCDateTime(start) - (window_width_second / 2.0
                                   )  # we want the first sample at start_time
end_time = UTCDateTime(end) + (window_width_second / 2.0)
duration = end_time - start_time  # seconds to process
n_shift = int(float(duration / window_shift_second))

# Place the median directory under the power directory.
if verbose:
    msg_lib.info(f'POWER PATH: {power_directory}')

if not file_lib.make_path(power_directory):
    code = msg_lib.error(f'Error, failed to access {power_directory}', 2)
    sys.exit(code)

# Out_power_file_name = file_lib.getFileName(param.namingConvention, power_directory,
out_power_file_name = file_lib.get_file_name(
    param.namingConvention, power_directory,
    [power_file.replace('.txt', ''), window_tag])

# Open the output file.
with open(os.path.join(power_directory, out_power_file_name),
          'w') as output_file:
    # w\Write the output header.
    output_file.write(f'Period\n')
    output_file.write(f'{"Date-Time":20s}')
    for k in range(len(bin_start)):
Ejemplo n.º 5
0
      NM_SLM_--_BH_2009-01-06
"""
psd_db_dir_tag, psd_db_file_tag = file_lib.get_dir(param.dataDirectory,
                                                   param.psdDbDirectory,
                                                   network, station, location,
                                                   channel)

msg_lib.info(f'PSD DIR TAG: {psd_db_dir_tag}')
if verbose > 0:
    msg_lib.info(f'PSD FILE TAG: {psd_db_file_tag}')

# Open the output file.
psd_dir_tag, psd_file_tag = file_lib.get_dir(param.dataDirectory,
                                             param.psdDirectory, network,
                                             station, location, channel)
file_lib.make_path(psd_dir_tag)
tag_list = [
    psd_file_tag,
    start_date_time.split('.')[0],
    end_date_time.split('.')[0], xtype
]
output_file_name = file_lib.get_file_name(param.namingConvention, psd_dir_tag,
                                          tag_list)
with open(output_file_name, 'w') as output_file:
    # Loop through the windows.
    for n in range(len(data_days_list)):

        thisFile = os.path.join(psd_db_dir_tag, data_days_list[n],
                                psd_db_file_tag + '*' + xtype + '.txt')
        msg_lib.info(f'Day: {data_days_list[n]}')
        this_file_list = sorted(glob.glob(thisFile))