# %% import os import h5py import matplotlib.pyplot as plt from tqdm import tqdm import pandas as pd # %% h5_dirs = ["./quakeflow_nc/waveform_h5", "./quakeflow_sc/waveform_h5"] h5_out = "waveform.h5" h5_train = "waveform_train.h5" h5_test = "waveform_test.h5" # # %% # h5_dir = "waveform_h5" # h5_out = "waveform.h5" # h5_train = "waveform_train.h5" # h5_test = "waveform_test.h5" h5_file_lists = [sorted(os.listdir(h5_dir)) for h5_dir in h5_dirs] train_file_lists = [x[:-1] for x in h5_file_lists] test_file_lists = [x[-1:] for x in h5_file_lists] # train_files = h5_files # train_files = [x for x in train_files if (x != "2014.h5") and (x not in [])] # test_files = [] print(f"train files: {train_file_lists}") print(f"test files: {test_file_lists}") # %% # %% with h5py.File(h5_out, "w") as fp: # external linked file for h5_dir, h5_files in zip(h5_dirs, h5_file_lists): for h5_file in h5_files: with h5py.File(os.path.join(h5_dir, h5_file), "r") as f: for event in tqdm(f.keys(), desc=h5_file, total=len(f.keys())): if event not in fp: fp[event] = h5py.ExternalLink(os.path.join(h5_dir, h5_file), event) else: print(f"{event} already exists") continue # %% with h5py.File(h5_train, "w") as fp: # external linked file for h5_dir, h5_files in zip(h5_dirs, train_file_lists): for h5_file in h5_files: with h5py.File(os.path.join(h5_dir, h5_file), "r") as f: for event in tqdm(f.keys(), desc=h5_file, total=len(f.keys())): if event not in fp: fp[event] = h5py.ExternalLink(os.path.join(h5_dir, h5_file), event) else: print(f"{event} already exists") continue # %% with h5py.File(h5_test, "w") as fp: # external linked file for h5_dir, h5_files in zip(h5_dirs, test_file_lists): for h5_file in h5_files: with h5py.File(os.path.join(h5_dir, h5_file), "r") as f: for event in tqdm(f.keys(), desc=h5_file, total=len(f.keys())): if event not in fp: fp[event] = h5py.ExternalLink(os.path.join(h5_dir, h5_file), event) else: print(f"{event} already exists") continue dirs = ["./quakeflow_nc", "./quakeflow_sc"] csv_files = ['events.csv', 'events_test.csv', 'events_train.csv', 'picks.csv', 'picks_test.csv', 'picks_train.csv'] for csv_file in csv_files: dfs = [] for dir in dirs: df = pd.read_csv(f"{dir}/{csv_file}") dfs.append(df) df = pd.concat(dfs) df.to_csv(csv_file, index=False, na_rep='')