-
Notifications
You must be signed in to change notification settings - Fork 0
/
subsample.py
62 lines (53 loc) · 2.33 KB
/
subsample.py
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
import pickle
import numpy as np
import pyvista as pv
import os
import shutil
pwd = os.getcwd()
orig_dir = 'ORIG_DATA'
new_dir = 'SUBSAMPLED_DATA'
###################################################################
# Load data (and subsample)
###################################################################
orig_dir = os.path.join(pwd,orig_dir)
new_dir = os.path.join(pwd,new_dir)
# Load baseline mesh (and subsample)
basegrid = pv.read(os.path.join(orig_dir,'basegrid.vtk'))
xskip = 5
yskip = 3
nx,ny,_ = basegrid.dimensions
npts = int(nx*ny)
idx = np.arange(npts).reshape(nx,ny,order='F')[::yskip,::xskip].T
points = basegrid.points_matrix[:,:,0,:2].transpose([1,0,2])
pts = idx.flatten()
x = points[:,0,0][::xskip]
y = points[0,:,1][::yskip]
assert len(x)*len(y)==len(pts)
# Load and index with `pts` array to subsample
# Load poly coeffs etc
coeffs = np.load(os.path.join(orig_dir,'coeffs.npy'))[pts]
lowers = np.load(os.path.join(orig_dir,'lowers.npy'))[pts]
uppers = np.load(os.path.join(orig_dir,'uppers.npy'))[pts]
W = np.load(os.path.join(orig_dir,'W.npy'))[pts]
# Load training data to plot on summary plots
Y = np.load(os.path.join(orig_dir,'Y.npy'))[pts,:,:]
###################################################################
# Save subsampled data
###################################################################
np.save(os.path.join(new_dir,'coeffs.npy'),coeffs)
np.save(os.path.join(new_dir,'lowers.npy'),lowers)
np.save(os.path.join(new_dir,'uppers.npy'),uppers)
np.save(os.path.join(new_dir,'W.npy'),W)
np.save(os.path.join(new_dir,'Y.npy'),Y)
np.save(os.path.join(new_dir,'xpts.npy'),x)
np.save(os.path.join(new_dir,'ypts.npy'),y)
###################################################################
# Copy across other files that don't need subsampling
###################################################################
shutil.copyfile(os.path.join(orig_dir,'surface_base.vtk'),os.path.join(new_dir,'surface_base.vtk'))
shutil.copyfile(os.path.join(orig_dir,'X.npy'),os.path.join(new_dir,'X.npy'))
###################################################################
# Load vtk file and convert to numpy to remove pyvista dependency
###################################################################
base_airfoil = pv.read(os.path.join(orig_dir,'surface_base.vtk')).points
np.save(os.path.join(new_dir,'base_airfoil.npy'),base_airfoil)