-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprocess_data.py
136 lines (105 loc) · 4.43 KB
/
process_data.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
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
import numpy as np
import matplotlib.pyplot as plt
# Set bigger font of all matplotlib fonts
plt.rcParams.update({'font.size': 18})
data_path = "results/raw_data/"
hole_counts=[1, 3, 5, 7, 10, 12]
hole_widths=[0.1, 0.2, 0.3, 0.4]
data_tracker_interval = 0.1
repeats = [1, 2, 3]
# Basic plot of m vs hole count
for hole_width in hole_widths:
m_avgs = []
m_eims = []
for hole_count in hole_counts:
ms = []
for repeat in repeats:
# load dm_dt
try:
file_name = data_path + f"log_holecount_{hole_count}_holewidth_{hole_width}_repeat_{repeat}_dm_dt.npy"
dm_dt_data = np.load(file_name, allow_pickle=True)
print(f"Loaded {file_name}")
except FileNotFoundError:
print(f"File {file_name} not found")
continue
dm_dt = np.array([entry['dm_dt'] for entry in dm_dt_data], dtype=float)
# integrate dm_dt to get m
m = np.zeros_like(dm_dt)
m[1:] = np.cumsum(np.trapz(dm_dt, dx=data_tracker_interval))
ms.append(m)
# Calculate mean and std
m_avg = np.mean(ms)
m_std = np.std(ms)
m_eim = m_std / np.sqrt(len(ms))
m_avgs.append(m_avg)
m_eims.append(m_eim)
# Plot m vs hole_count
plt.errorbar(hole_counts, m_avgs, yerr=m_eims, fmt='o', label=f"Width of holes={hole_width}", capsize=5)
plt.xlabel("Number of holes")
plt.ylabel("Total flux of mass")
plt.legend()
plt.title(f"Total flux of mass through window vs number of holes in window")
plt.show()
# Load the % of window blocked for each set of parameters
# Plot the flux of mass through the window vs hole count again, but divided by the % of window not blocked
for hole_width in hole_widths:
m_avgs = []
m_eims = []
for hole_count in hole_counts:
ms = []
for repeat in repeats:
# load dm_dt
args = f"log_holecount_{hole_count}_holewidth_{hole_width}_repeat_{repeat}"
try:
file_name = data_path + args + "_dm_dt.npy"
dm_dt_data = np.load(file_name, allow_pickle=True)
print(f"Loaded {file_name}")
except FileNotFoundError:
print(f"File {file_name} not found")
continue
dm_dt = np.array([entry['dm_dt'] for entry in dm_dt_data], dtype=float)
# integrate dm_dt to get m
m = np.zeros_like(dm_dt)
m[1:] = np.cumsum(np.trapz(dm_dt, dx=data_tracker_interval))
ms.append(m)
# Get window blocked data
args = f"log_holecount_{hole_count}_holewidth_{hole_width}_repeat_1"
per_blocked = np.load("results/window_blocked/"+args+".npy")
per_free = 1 - per_blocked
print(f"per_blocked={per_blocked}, per_free={per_free}")
# Calculate mean and std
m_avg = np.mean(ms) / per_free
m_std = np.std(ms) / per_free
m_eim = m_std / np.sqrt(len(ms))
m_avgs.append(m_avg)
m_eims.append(m_eim)
# Plot m vs hole_count
plt.errorbar(hole_counts, m_avgs, yerr=m_eims, fmt='o', label=f"Width of holes={hole_width}", capsize=5)
plt.xlabel("Number of holes")
plt.ylabel("Total flux of mass")
plt.legend()
plt.title(f"Total flux of mass through window vs number of holes in window")
plt.show()
# Replot the dm_dt (i.e., Q) data vs time to add axes labels and stuff
for hole_width in hole_widths:
for hole_count in hole_counts:
for repeat in repeats:
# load dm_dt
try:
file_name = data_path + f"log_holecount_{hole_count}_holewidth_{hole_width}_repeat_{repeat}_dm_dt.npy"
dm_dt_data = np.load(file_name, allow_pickle=True)
print(f"Loaded {file_name}")
except FileNotFoundError:
print(f"File {file_name} not found")
continue
dm_dt = np.array([entry['dm_dt'] for entry in dm_dt_data], dtype=float)
time = np.arange(len(dm_dt)) * data_tracker_interval
# Plot dm_dt vs time
plt.figure(figsize=(10, 6))
plt.title("Q vs time")
plt.xlabel("Time")
plt.ylabel("Q")
plt.plot(time, dm_dt)
LOG_NAME = f"log_holecount_{hole_count}_holewidth_{hole_width}_repeat_{repeat}"
plt.savefig(f"results/dm_dtOverTime/{LOG_NAME}.pdf")
# plt.show()