|
| 1 | +import numpy as np |
| 2 | +import matplotlib.pyplot as plt |
| 3 | + |
| 4 | +# for i in range(300): |
| 5 | +for i in range(299,-1,-1): |
| 6 | + npy_file = f'grid_files/grid_{i}.npy' |
| 7 | + txt_file = f'txt_files/output_{i}.txt' |
| 8 | + |
| 9 | + raw_data = np.load(npy_file) |
| 10 | + raw_data = np.array(raw_data, dtype=np.float64) |
| 11 | + bracket = [1] + [0 for _ in range(28)] + [1] |
| 12 | + bracket = np.array(bracket, dtype=np.float64) |
| 13 | + for _ in range(10): |
| 14 | + raw_data = np.insert(raw_data, 0, bracket, axis = 1) |
| 15 | + for _ in range(10): |
| 16 | + raw_data = np.insert(raw_data, raw_data.shape[1], bracket, axis = 1) |
| 17 | + |
| 18 | + # plt.imshow(raw_data, cmap = 'Greys') |
| 19 | + |
| 20 | + rows = len(raw_data) |
| 21 | + cols = len(raw_data[0]) |
| 22 | + |
| 23 | + BLOCK = 10 |
| 24 | + raw_data[raw_data==1] = BLOCK |
| 25 | + |
| 26 | + data = np.array(raw_data) |
| 27 | + for row in range(rows): |
| 28 | + for col in range(cols): |
| 29 | + if raw_data[row][col] == BLOCK: |
| 30 | + for nr in [row + 1, row - 1]: |
| 31 | + if 0 <= nr < rows: |
| 32 | + data[nr][col] = BLOCK |
| 33 | + for nc in [col + 1, col - 1]: |
| 34 | + if 0 <= nc < cols: |
| 35 | + data[row][nc] = BLOCK |
| 36 | + raw_data[raw_data==1] = BLOCK |
| 37 | + |
| 38 | + np.savetxt(txt_file, data, fmt='%.5e') |
| 39 | + |
0 commit comments