-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdata-test-2-planes.py
More file actions
65 lines (53 loc) · 1.86 KB
/
data-test-2-planes.py
File metadata and controls
65 lines (53 loc) · 1.86 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
60
61
62
63
64
65
# to run unit tests:
#
# 2-planes-flow-mesh.py data-test-2-planes 16 8 1
# 2-planes-invmap.py data-test-2-planes 16 8
# 2-planes-test.py data-test-2-planes 16 8
import numpy as np
shift=8
nx,ny=256,128
nxc,nyc=128,64
nxtc,nytc=64,32
dtype=np.uint8
def load_data(basepath, top, bot):
tmp = np.random.randint(0, np.iinfo(dtype).max//2, size=(nx+shift,ny+shift), dtype=dtype)
tmp[nx//2:shift+nx//2, ny//2:shift+ny//2] = np.iinfo(dtype).max
ttop = tmp[:nx, :ny]
tbot = tmp[shift:shift+nx, shift:shift+ny]
return ttop, tbot
def crop_data(ttop, tbot):
ix = (nx-nxc)//2
iy = (ny-nyc)//2
return ttop[ix:ix+nxc, iy:iy+nyc], tbot[ix:ix+nxc, iy:iy+nyc], (iy,ix), (nyc,nxc)
def tight_crop_data(ttop, tbot):
ix = (nx-nxtc)//2
iy = (ny-nytc)//2
return ttop[ix:ix+nxtc, iy:iy+nytc], tbot[ix:ix+nxtc, iy:iy+nytc], (iy,ix), (nytc,nxtc)
def save_flow(flow, basepath, params):
np.save('1.flow'+params+'.npy', flow)
def save_mesh(mesh, basepath, params):
return np.save('2.mesh'+params+'.npy', mesh)
def load_flow(basepath, params):
flow = np.load('1.flow'+params+'.npy')
def load_mesh(basepath, params):
return np.load('2.mesh'+params+'.npy')
def save_invmap(invmap, basepath, params):
np.save('3.invmap'+params+'.npy', invmap)
def load_invmap(basepath, params):
invmap = np.load('3.invmap'+params+'.npy')
return invmap
def write_warp(shape, chunk_size, basepath, params, planes):
return ts.open({
'driver': 'zarr',
'kvstore': {"driver":"file", "path":'4.warped.'+params+'.zarr')},
'metadata': {
"compressor":{"id":"zstd","level":3},
"shape":shape,
"chunks":[2,16,16],
"fill_value":0,
'dtype': '|u1',
'dimension_separator': '/',
},
'create': True,
'delete_existing': True,
}).result().write(planes).result()