-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild_images.py
More file actions
59 lines (47 loc) · 1.49 KB
/
build_images.py
File metadata and controls
59 lines (47 loc) · 1.49 KB
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
56
57
58
59
import numpy as np
import sys
import matplotlib.pyplot as plt
import multiprocessing
def cell_to_pos(msx, msy, pos):
return (pos % msx, int(pos / msx))
filename = sys.argv[1]
'''
data = np.load(filename)
shapex, shapey = data['shape']
print(shapex, shapey)
def processStep(img, i, data=data, shapex=shapex, shapey=shapey):
image = img
print('processing step %d'%i)
grid = np.zeros((shapey, shapex))
fig, ax = plt.subplots(1, 1, figsize=(20,20))
for id, type in enumerate(image):
x, y = cell_to_pos(shapex, shapey, id)
grid[y][x] = type
ax.imshow(grid)
fig.savefig(("{0:0>%d}_water_dummy.jpg" % displ).format(i))
plt.close(fig)
'''
displ = 4
data = np.load("gids-"+filename)
shapex, shapey = data['shape']
print(data.files)
type = data['type']
print(shapex, shapey)
print(type[0])
def processStep(img, i, shapex=shapex, shapey=shapey, type=type):
image = img
print('processing %s' % i)
if(type == 1):
grid = np.zeros((shapey, shapex))
else:
grid = np.ones((shapey, shapex))
fig, ax = plt.subplots(1, 1, figsize=(20, 20))
for id in image:
x, y = cell_to_pos(shapex, shapey, id)
grid[y][x] = type
ax.imshow(grid)
fig.savefig(("{0:0>%d}_water_dummy.pdf" % displ).format(i.split('_')[-1]))
plt.close(fig)
cpu_count = multiprocessing.cpu_count()
pool = multiprocessing.Pool(cpu_count)
pool.starmap(processStep, [(data[i], i, shapex, shapey, type[0]) for i in [f for f in data.files if 'step' in f]])