| import os
|
| import re
|
| import h5py
|
| import numpy as np
|
|
|
| def read_h5_data(h5_path, dataset_name):
|
| with h5py.File(h5_path, 'r') as h5_file:
|
| return h5_file[dataset_name][()]
|
|
|
| def main(file_name:str):
|
| target_directory = os.getcwd()
|
| folder_pattern = re.compile(r'^(\d+)-(\d+)$')
|
| file_pattern = re.compile(r'^(\d+)-(\d+)\.h5$')
|
|
|
| print(f"target_directory = {target_directory}")
|
|
|
| folders = [f for f in os.listdir(target_directory) if folder_pattern.match(f)]
|
| folders.sort(key=lambda x: int(folder_pattern.match(x).group(1)))
|
|
|
| print(f"Found {len(folders)} folders: {folders}")
|
|
|
|
|
| Acc_Floor_Responses = []
|
| DS_Blgs = []
|
|
|
|
|
| for folder in folders:
|
| h5_file_name = f"{folder}.h5"
|
| h5_path = os.path.join(target_directory, folder, h5_file_name)
|
| if os.path.exists(h5_path) and file_pattern.match(h5_file_name):
|
| print(f"Processing {h5_path}...")
|
| Acc_Floor_Response = read_h5_data(h5_path, 'Acc_Floor_Response')
|
| DS_Blg = read_h5_data(h5_path, 'DS_Blg')
|
|
|
|
|
| Acc_Floor_Responses.append(Acc_Floor_Response)
|
| DS_Blgs.append(DS_Blg)
|
| else:
|
| print(f"Expected file {h5_file_name} not found in {folder}")
|
|
|
|
|
| Acc_Floor_Responses = np.concatenate(Acc_Floor_Responses, axis=0)
|
| DS_Blgs = np.concatenate(DS_Blgs, axis=0)
|
|
|
|
|
| print(f"Acc_Floor_Responses shape: {Acc_Floor_Responses.shape}")
|
| print(f"DS_Blgs shape: {DS_Blgs.shape}")
|
|
|
|
|
| h5_combined_path = os.path.join(target_directory, file_name)
|
| with h5py.File(h5_combined_path, 'w') as h5_combined:
|
| h5_combined.create_dataset('Acc_Floor_Response', data=Acc_Floor_Responses)
|
| h5_combined.create_dataset('Blg_Damage_State', data=DS_Blgs)
|
| print(f"Combined data saved to {h5_combined_path}")
|
|
|
| if __name__ == "__main__":
|
| main('Blg_F2_6m_IM7_SCD2.h5') |