forked from NatLabRockies/Phase-space-sampling
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvisualizeDownSampled_subplots.py
More file actions
110 lines (94 loc) · 3.35 KB
/
Copy pathvisualizeDownSampled_subplots.py
File metadata and controls
110 lines (94 loc) · 3.35 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import sys
import numpy as np
sys.path.append("utils")
import os
import matplotlib.pyplot as plt
import myparser
from mpl_toolkits.axes_grid1 import make_axes_locatable
from plotsUtil import *
def plotScatterProjection(data, fullData, fieldNames, lims):
nDim = data.shape[1]
if nDim > 2:
fig, axs = plt.subplots(
nDim - 1, nDim - 1, figsize=(12, 12), sharex="col", sharey="row"
)
for idim in range(nDim - 1):
for jdim in range(idim + 1, nDim):
# plot contours of support of all data
a = axs[jdim - 1, idim].scatter(
fullData[:, idim], fullData[:, jdim], color="gray", s=0.2
)
a = axs[jdim - 1, idim].scatter(
data[:, idim], data[:, jdim], color="blue", s=0.2
)
for idim in range(nDim - 1):
axs[nDim - 2, idim].set_xlabel(fieldNames[idim])
axs[nDim - 2, idim].set_xlim(lims[idim])
for tick in axs[nDim - 2, idim].get_xticklabels():
tick.set_rotation(33)
axs[idim, 0].set_ylabel(fieldNames[idim + 1])
axs[idim, 0].set_ylim(lims[idim + 1])
for idim in range(nDim - 2):
for jdim in range(idim + 1, nDim - 1):
axs[idim, jdim].axis("off")
if nDim == 2:
fig = plt.figure()
plt.scatter(fullData[:, 0], fullData[:, 1], color="gray", s=0.2)
plt.scatter(data[:, 0], data[:, 1], color="blue", s=0.2)
ax = plt.gca()
axprettyLabels(ax, fieldNames[0], fieldNames[1], 14)
ax.set_xlim(lims[0])
for tick in ax.get_xticklabels():
tick.set_rotation(33)
ax.set_ylim(lims[1])
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# ~~~~ Parse input
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
inpt = myparser.parseInputFile()
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# ~~~~ Parameters to save
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# List of sample size
nSamples = [int(float(n)) for n in inpt["nSamples"].split()]
# Data size used to learn the data probability
nWorkingData = int(float(inpt["nWorkingData"]))
if not nWorkingData in nSamples:
nSamples += [nWorkingData]
# Data file name
fullDataFile = inpt["dataFile"]
# Scaler file name
scalerFile = inpt["scalerFile"]
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# ~~~~ Plot
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
print("LOAD DATA ... ", end="")
sys.stdout.flush()
fullData = np.load(fullDataFile)
print("DONE!")
mins = np.load(scalerFile)["minVal"]
maxs = np.load(scalerFile)["maxVal"]
lims = [
(xmin - 0.05 * (xmax - xmin), xmax + 0.05 * (xmax - xmin))
for xmin, xmax in zip(mins, maxs)
]
fieldNames = ["feature" + str(i) for i in range(fullData.shape[1])]
# Folder where figures are saved
figureFolder = "Figures"
os.makedirs(figureFolder, exist_ok=True)
for nSample in nSamples:
print("plot nSample : %d" % (nSample) + " ... ", end="")
sys.stdout.flush()
dataFile = inpt["prefixDownsampledData"] + "_" + str(nSample) + ".npz"
downSampledData = np.load(dataFile)["data"]
plotScatterProjection(downSampledData, fullData, fieldNames, lims)
plt.savefig(
figureFolder
+ "/"
+ inpt["prefixDownsampledData"]
+ "_"
+ str(nSample)
+ ".png"
)
plt.close()
print("DONE!")
sys.stdout.flush()