forked from PyCOMPLETE/CoupledBunchAnalysis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path000_make_matrices.py
104 lines (74 loc) · 2.94 KB
/
000_make_matrices.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
import sys, os
import numpy as np
sim_folder = '../first_test/PyPARIS/004_multibunch_with_ecloud/'
tag = 'first_sim_20b'
n_rings = 8
sim_folder = '../test_40b/'
tag = 'sim_40b'
n_rings = 10
sim_folder = '../test_20b_8kicks_12.5ns/004_multibunch_with_ecloud'
tag = 'sim_20b_8kicks'
n_rings = 5
sim_folder = '../test_20b_8kicks/004_multibunch_with_ecloud'
tag = 'sim_20b_8kicks_correct'
n_rings = 5
sim_folder = '../test_20b_8kicks_onlyH/004_multibunch_with_ecloud'
tag = 'sim_20b_8kicks_onlyH'
n_rings = 5
sim_folder = '../test_on_HPC_cluster_speed/004_multibunch_with_ecloud'
tag = 'test_on_HPC_cluster_speed'
n_rings = 40
sim_folder = '../test3_on_HPC_25ns/004_multibunch_with_ecloud'
tag = 'test3_on_HPC_25ns'
n_rings = 45
sim_folder = '../test7_on_HPC_25ns_checksynch/004_multibunch_with_ecloud'
tag = 'test7_on_HPC_25ns_checksynch'
n_rings = 45
sim_folder = '../test8_on_HPC_25ns_swaporder/004_multibunch_with_ecloud'
tag = 'test8_on_HPC_25ns_swaporder'
n_rings = 45
sim_folder = '../test9_on_HPC_25ns_correct/004_multibunch_with_ecloud'
tag = 'test9_on_HPC_25ns_correct'
n_rings = 45
sim_folder = '../test10_onHPC_144b/004_multibunch_with_ecloud'
tag = 'test10_onHPC_144b'
n_rings = 94
sim_folder = '../test11_on_HPC_25ns_more_slices/004_multibunch_with_ecloud'
tag = 'test11_on_HPC_25ns_more_slices'
n_rings = 45
sim_folder = '../test12_onHPC_288b/004_multibunch_with_ecloud'
tag = 'test12_onHPC_288b'
n_rings = 150
list_files = [sim_folder+'/bunch_monitor_ring%03d.h5'%ii for ii in range(n_rings)]
import myfilemanager as mfm
dict_data = mfm.bunchh5list_to_dict(list_files, permissive=True)
print 'Data loaded!'
n_turns = int(np.max(dict_data['i_turn']))+1
n_bunches = int(np.max(dict_data['i_bunch']))+1
list_bunches = []
for i_bunch_obs in range(n_bunches):
print('Bunch %d/%d'%(i_bunch_obs, n_bunches))
dict_bunch = {kk:np.zeros(n_turns, dtype=np.float64)+np.nan for kk in dict_data.keys()}
for ii in xrange(len(dict_data['i_bunch'])):
if int(dict_data['i_bunch'][ii]) == int(i_bunch_obs):
i_turn = int(dict_data['i_turn'][ii])
for kk in dict_data.keys():
dict_bunch[kk][i_turn] = dict_data[kk][ii]
list_bunches.append(dict_bunch)
x_mat = np.zeros((n_turns, n_bunches))
y_mat = np.zeros((n_turns, n_bunches))
n_mat = np.zeros((n_turns, n_bunches))
for i_bunch_obs in range(n_bunches):
n_turns_this = len(list_bunches[i_bunch_obs]['epsn_x'])
mask_notnan = ~np.isnan(list_bunches[i_bunch_obs]['macroparticlenumber'])
x_mat[:n_turns_this, i_bunch_obs][mask_notnan] = list_bunches[i_bunch_obs]['mean_x'][mask_notnan]
y_mat[:n_turns_this, i_bunch_obs][mask_notnan] = list_bunches[i_bunch_obs]['mean_y'][mask_notnan]
n_mat[:n_turns_this, i_bunch_obs][mask_notnan] = list_bunches[i_bunch_obs]['macroparticlenumber'][mask_notnan]
import scipy.io as sio
sio.savemat(tag+'_matrices.mat',
{
'x_mat':x_mat,
'y_mat':y_mat,
'n_mat':n_mat
},
oned_as='row')