Spaces:
Runtime error
Runtime error
| ### For only keeping the available data ids | |
| import re | |
| file_paths = ['train_val_test_splits_400/test_design_ids.txt', | |
| 'train_val_test_splits_400/val_design_ids.txt', | |
| 'train_val_test_splits_400/train_design_ids.txt'] | |
| for file_path in file_paths: | |
| with open(file_path, 'r') as file: | |
| lines = file.readlines() | |
| updated_lines = [] | |
| for line in lines: | |
| integers = list(map(int, re.findall(r'\d+', line))) | |
| if 'F_D_WM_WW_' not in line: | |
| continue | |
| elif integers[0] > 403: | |
| continue | |
| else: | |
| updated_lines.append(line) | |
| with open(file_path, "w") as file: | |
| file.writelines(updated_lines) | |
| ### For restructuring the vtk data folder for accessing in code | |
| import os | |
| import shutil | |
| def flatten_folder(main_folder): | |
| # Walk through subfolders (bottom-up so we can delete them) | |
| for dirpath, dirnames, filenames in os.walk(main_folder, topdown=False): | |
| # Skip the main folder itself | |
| if dirpath == main_folder: | |
| continue | |
| for filename in filenames: | |
| src = os.path.join(dirpath, filename) | |
| dst = os.path.join(main_folder, filename) | |
| # If filename exists, append a counter to avoid overwriting | |
| base, ext = os.path.splitext(filename) | |
| count = 1 | |
| while os.path.exists(dst): | |
| dst = os.path.join(main_folder, f"{base}_{count}{ext}") | |
| count += 1 | |
| shutil.move(src, dst) | |
| print(f"Moved {src} to {dst}") | |
| # Remove the (now empty) subfolder | |
| os.rmdir(dirpath) | |
| print(f"Deleted folder {dirpath}") | |
| # Usage | |
| main_folder = '../driveaer_raw' | |
| flatten_folder(main_folder) |