File size: 1,736 Bytes
67fb03c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
### 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)