Skip to content

Commit ec0c973

Browse files
committed
Work on slice monitor
1 parent 69c9ec7 commit ec0c973

File tree

1 file changed

+78
-0
lines changed

1 file changed

+78
-0
lines changed

000s_make_slice_matrices.py

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
import numpy as np
2+
3+
import PyPARIS.myfilemanager as mfm
4+
5+
sim_folder = '../PyECLOUD_coupled_bunch_example'
6+
tag = 'noecloud'
7+
n_rings = 3
8+
n_parts = 2
9+
10+
to_be_saved = [
11+
'epsn_x',
12+
'epsn_y',
13+
'epsn_z',
14+
'n_macroparticles_per_slice',
15+
'mean_dp',
16+
'mean_x',
17+
'mean_xp',
18+
'mean_y',
19+
'mean_yp',
20+
'mean_z',
21+
'sigma_dp',
22+
'sigma_x',
23+
'sigma_y',
24+
'sigma_z']
25+
26+
27+
def make_part_matrices(list_files, to_be_saved):
28+
29+
slice_data = mfm.monitorh5list_to_dict(list_files, key='Slices', flag_transpose=True, permissive=True)
30+
print 'Slice data loaded!'
31+
bunch_data = mfm.monitorh5list_to_dict(list_files, key='Bunch', permissive=True)
32+
print 'Bunch data loaded!'
33+
34+
n_turns = int(np.max(bunch_data['i_turn'])) + 1
35+
n_bunches = int(np.max(bunch_data['i_bunch'])) + 1
36+
n_slices = slice_data['mean_x'].shape[0]
37+
38+
list_bunches = []
39+
for i_bunch_obs in range(n_bunches):
40+
print('Bunch %d/%d'%(i_bunch_obs, n_bunches))
41+
dict_bunch = {kk:np.zeros((n_slices, n_turns), dtype=np.float64) + np.nan for kk in slice_data.keys()}
42+
for ii in xrange(len(bunch_data['i_bunch'])):
43+
if int(bunch_data['i_bunch'][ii]) == int(i_bunch_obs):
44+
i_turn = int(bunch_data['i_turn'][ii])
45+
if bunch_data['macroparticlenumber'][ii] > 0:
46+
for kk in slice_data.keys():
47+
dict_bunch[kk][:, i_turn] = slice_data[kk][:, ii]
48+
49+
list_bunches.append(dict_bunch)
50+
51+
dict_matrices = {kk: np.zeros((n_slices, n_turns, n_bunches)) for kk in to_be_saved}
52+
53+
for i_bunch_obs in range(n_bunches):
54+
n_turns_this = len(list_bunches[i_bunch_obs]['epsn_x'])
55+
mask_notnan = ~np.isnan(list_bunches[i_bunch_obs]['n_macroparticles_per_slice'])
56+
57+
for kk in to_be_saved:
58+
dict_matrices[kk][:, :n_turns_this, i_bunch_obs][mask_notnan] \
59+
= list_bunches[i_bunch_obs][kk][mask_notnan]
60+
61+
return dict_matrices
62+
63+
list_dicts = []
64+
for i_part in range(n_parts):
65+
list_files = [sim_folder+'/slice_monitor_part%03d_ring%03d.h5'%(i_part, ii) for ii in range(n_rings)]
66+
this_dict_matrices = make_part_matrices(list_files, to_be_saved)
67+
list_dicts.append(this_dict_matrices)
68+
69+
dict_matrices = {}
70+
for kk in list_dicts[0].keys():
71+
dict_matrices[kk] = np.concatenate(
72+
[dd[kk] for dd in list_dicts], axis=1)
73+
74+
import scipy.io as sio
75+
sio.savemat(tag+'_slice_matrices.mat', dict_matrices, oned_as='row')
76+
mfm.dict_to_h5(dict_matrices, tag+'_slice_matrices.h5', compression='gzip')
77+
78+

0 commit comments

Comments
 (0)