-
Notifications
You must be signed in to change notification settings - Fork 0
/
view_corr.py
58 lines (49 loc) · 1.55 KB
/
view_corr.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
import os
import sys
import json
import numpy as np
import pyvista as pv
from tqdm import tqdm
#################
# Settings
#################
points = [ [0.01,0.03], [1.1,0.08], [0.085,-0.055], [0.085, 0.055], [0.98,0.02] ]
vars = [0,1,2]
#####################
# Setup stuff
#####################
basedir = os.getcwd()
# Read json file
inputfile = sys.argv[1]
with open(inputfile) as json_file:
json_dat = json.load(json_file)
# Parse json options
casename = json_dat['casename']
datadir = json_dat['datadir']
if datadir == '.':
datadir = basedir
# Read in base vtk file
dataloc = os.path.join(datadir,'CFD_DATA',casename)
grid = pv.read(os.path.join(dataloc,'basegrid.vtk'))
coords = grid.points[:,:2]
# Read in corr matrix
dataloc = os.path.join(datadir,'PROCESSED_DATA',casename)
print('Reading on correlation matrices...')
corr = []
for var in vars:
print(var)
corr.append(np.load(os.path.join(dataloc,'corr_%d.npy'%var)))
###########################################################
# Save correlations for given points (and vars) to vtk file
###########################################################
for p, pt in enumerate(points):
# Find nearest point
dist = coords - pt
dist = np.sqrt(dist[:,0]**2.0 + dist[:,1]**2.0)
loc = np.argmin(dist)
# Save correlation between all points and point above
for j, var in enumerate(vars):
corr_w_pt = corr[j][loc,:]
grid['corr_pt%d_var%d' %(p,var)] = corr_w_pt
saveloc = os.path.join(datadir,'POSTPROC_DATA',casename)
grid.save(os.path.join(saveloc,'corr.vtk'))