Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
PythonControl
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
PA
Operation
PythonControl
Commits
33081a75
Commit
33081a75
authored
2 months ago
by
Vadim Gubaidulin
Browse files
Options
Downloads
Patches
Plain Diff
Class to analyze the data.
parent
7100a9de
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
growth_damp_utils.py
+179
-137
179 additions, 137 deletions
growth_damp_utils.py
with
179 additions
and
137 deletions
growth_damp_utils.py
+
179
−
137
View file @
33081a75
...
...
@@ -13,30 +13,35 @@ Q_X = 18.16
Q_Y
=
10.22
OMEGA_REV
=
2
*
pi
*
c
/
CIRCUMFERENCE
r_p
=
e
**
2
/
(
m_p
*
c
**
2
)
def
read_bunch_data
(
bunchnumber
,
filename
,
folder
):
f
=
hp
.
File
(
folder
+
filename
+
'
.hdf5
'
)
BPM_data
=
f
[
'
raw
'
][:]
class
GrowthDampDataAnalyzer
():
def
__init__
(
self
,
folder
):
self
.
folder
=
folder
self
.
filelist
=
[]
def
read_bunch_data
(
self
,
filename
,
bunchnumber
,
N
=
0
):
with
hp
.
File
(
self
.
folder
+
filename
+
'
.hdf5
'
)
as
f
:
BPM_data
=
f
[
f
'
raw_
{
N
:}
'
][:]
emitYC02before
=
np
.
array
(
f
[
'
emitZ_C02_before
'
])
emitYC02after
=
np
.
array
(
f
[
'
emitZ_C02_after
'
])
emitXC02before
=
np
.
array
(
f
[
'
emitX_C02_before
'
])
emitXC02after
=
np
.
array
(
f
[
'
emitX_C02_after
'
])
emitYC16before
=
np
.
array
(
f
[
'
emitZ_C16_before
'
])
emitYC16after
=
np
.
array
(
f
[
'
emitZ_C16_after
'
])
t0
=
1e-9
*
c
/
CIRCUMFERENCE
*
np
.
array
(
f
[
'
window_delay
'
])
t1
=
1e-6
*
c
/
CIRCUMFERENCE
*
np
.
array
(
f
[
'
window_width
'
])
Qxi
=
np
.
array
(
f
[
'
tuneX_before
'
])
Qxf
=
np
.
array
(
f
[
'
tuneX_after
'
])
Qyi
=
np
.
array
(
f
[
'
tuneZ_before
'
])
Qyf
=
np
.
array
(
f
[
'
tuneZ_after
'
])
# print('Horizontal tune before {:.3f} and after {:.3f} the measurement'.format(Qxi, Qxf))
# print('Vertical tune before {:.3f} and after {:.3f} the measurement'.format(Qyi, Qyf))
filling_pattern_before
=
np
.
array
(
f
[
'
filling_pattern_before
'
])
filling_pattern_after
=
np
.
array
(
f
[
'
filling_pattern_after
'
])
f
.
close
()
return
BPM_data
[
bunchnumber
,:],
t0
,
t1
,
emitYC02before
,
emitYC16before
,
emitYC02after
,
emitYC16after
,
emitXC02before
,
emitXC02after
def
plot_bunch_offset_data
(
ax
,
bunchnumber
,
filename
,
folder
):
mean_y_bunch
,
t0
,
t1
,
emitYC02before
,
emitYC16before
,
emitYC02after
,
emitYC16after
,
emitXC02before
,
emitXC02after
=
read_bunch_data
(
bunchnumber
,
filename
,
folder
)
def
plot_bunch_offset_data
(
self
,
ax
,
bunchnumber
,
filename
,
N
=
0
):
mean_y_bunch
,
t0
,
t1
,
emitYC02before
,
emitYC16before
,
emitYC02after
,
emitYC16after
,
emitXC02before
,
emitXC02after
=
read_bunch_data
(
bunchnumber
,
filename
,
N
)
ax
.
plot
(
mean_y_bunch
-
np
.
mean
(
mean_y_bunch
))
ax
.
axvline
(
t0
,
linestyle
=
'
dashed
'
)
ax
.
axvline
(
t1
,
linestyle
=
'
dashed
'
)
...
...
@@ -45,8 +50,8 @@ def plot_bunch_offset_data(ax, bunchnumber, filename, folder):
ax
.
set_ylabel
(
'
Bunch c.\,m. offset (arb. units)
'
)
ax
.
title
.
set_text
(
'
Bunch \# {:} c.\,m. offset
'
.
format
(
int
(
bunchnumber
)))
return
None
def
plot_bunch_spectrum_data
(
ax
,
bunchnumber
,
filename
,
folder
):
mean_y_bunch
,
t0
,
t1
,
emitYC02before
,
emitYC16before
,
emitYC02after
,
emitYC16after
,
emitXC02before
,
emitXC02after
=
read_bunch_data
(
bunchnumber
,
filename
,
folder
)
def
plot_bunch_spectrum_data
(
self
,
ax
,
bunchnumber
,
filename
,
N
=
0
):
mean_y_bunch
,
t0
,
t1
,
emitYC02before
,
emitYC16before
,
emitYC02after
,
emitYC16after
,
emitXC02before
,
emitXC02after
=
read_bunch_data
(
bunchnumber
,
filename
,
N
)
mean_y_bunch
-=
np
.
mean
(
mean_y_bunch
)
fftfreq
=
rfftfreq
(
mean_y_bunch
.
shape
[
0
])
absfft
=
np
.
abs
(
rfft
(
mean_y_bunch
))
...
...
@@ -57,13 +62,13 @@ def plot_bunch_spectrum_data(ax, bunchnumber, filename, folder):
ax
.
set_ylabel
(
'
Spectrum power (arb. units)
'
)
ax
.
title
.
set_text
(
'
Bunch \# {:} spectrum
'
.
format
(
int
(
bunchnumber
)))
return
None
def
plot_bunch_risetime_fit
(
ax
,
bunchnumber
,
filename
,
folder
,
smoothing_window_size
=
10
,
show_fitted_signal
=
False
):
mean_y_bunch
,
t0
,
t1
,
emitYC02before
,
emitYC16before
,
emitYC02after
,
emitYC16after
,
emitXC02before
,
emitXC02after
=
read_bunch_data
(
bunchnumber
,
filename
,
folder
)
def
plot_bunch_risetime_fit
(
ax
,
bunchnumber
,
filename
,
folder
,
smoothing_window_size
=
10
,
show_fitted_signal
=
False
,
N
=
0
):
mean_y_bunch
,
t0
,
t1
,
emitYC02before
,
emitYC16before
,
emitYC02after
,
emitYC16after
,
emitXC02before
,
emitXC02after
=
read_bunch_data
(
bunchnumber
,
filename
,
folder
,
N
)
mean_y_bunch
-=
np
.
mean
(
mean_y_bunch
)
signal
=
np
.
abs
(
hilbert
(
mean_y_bunch
))
if
show_fitted_signal
:
ax
.
plot
(
signal
)
min_level
=
np
.
min
((
5
.
*
np
.
mean
(
signal
[:
200
]),
5
.
*
np
.
mean
(
signal
[
-
200
:])))
min_level
=
np
.
min
((
10
.
*
np
.
mean
(
signal
[:
200
]),
10
.
*
np
.
mean
(
signal
[
-
200
:])))
risetime
=
fit_risetime
(
signal
,
min_level
=
min_level
,
smoothing_window_size
=
smoothing_window_size
,
...
...
@@ -74,15 +79,15 @@ def plot_bunch_risetime_fit(ax, bunchnumber, filename, folder, smoothing_window_
ax
.
title
.
set_text
(
'
Bunch \# {:} c.\,m. offset
'
.
format
(
int
(
bunchnumber
)))
return
risetime
def
plot_bunch_damping_time_fit
(
ax
,
bunchnumber
,
filename
,
folder
,
smoothing_window_size
=
2
,
show_fitted_signal
=
False
):
mean_y_bunch
,
t0
,
t1
,
emitYC02before
,
emitYC16before
,
emitYC02after
,
emitYC16after
,
emitXC02before
,
emitXC02after
=
read_bunch_data
(
bunchnumber
,
filename
,
folder
)
def
plot_bunch_damping_time_fit
(
ax
,
bunchnumber
,
filename
,
folder
,
smoothing_window_size
=
2
0
,
show_fitted_signal
=
False
,
N
=
0
):
mean_y_bunch
,
t0
,
t1
,
emitYC02before
,
emitYC16before
,
emitYC02after
,
emitYC16after
,
emitXC02before
,
emitXC02after
=
read_bunch_data
(
bunchnumber
,
filename
,
folder
,
N
)
mean_y_bunch
-=
np
.
mean
(
mean_y_bunch
)
mean_y_bunch
=
np
.
flip
(
mean_y_bunch
)
ax
.
plot
(
mean_y_bunch
)
signal
=
np
.
abs
(
hilbert
(
mean_y_bunch
))
if
show_fitted_signal
:
ax
.
plot
(
signal
)
min_level
=
np
.
min
((
5
*
np
.
mean
(
signal
[:
200
]),
5
*
np
.
mean
(
signal
[
-
200
:])))
min_level
=
np
.
min
((
1
5
*
np
.
mean
(
signal
[:
200
]),
1
5
*
np
.
mean
(
signal
[
-
200
:])))
damping_time
=
fit_risetime
(
signal
,
min_level
=
min_level
,
smoothing_window_size
=
smoothing_window_size
,
...
...
@@ -92,13 +97,13 @@ def plot_bunch_damping_time_fit(ax, bunchnumber, filename, folder, smoothing_win
ax
.
set_ylabel
(
'
Bunch c.\,m. offset (arb. units)
'
)
ax
.
title
.
set_text
(
'
Bunch \# {:} c.\,m. offset
'
.
format
(
int
(
bunchnumber
)))
return
damping_time
def
plot_beam_offset_data
(
ax
,
filename
,
folder
,
smoothing_window_size
=
10
):
mean_y_bunch
,
t0
,
t1
,
emitYC02before
,
emitYC16before
,
emitYC02after
,
emitYC16after
,
emitXC02before
,
emitXC02after
=
read_bunch_data
(
0
,
filename
,
folder
)
def
plot_beam_offset_data
(
ax
,
filename
,
folder
,
smoothing_window_size
=
10
,
N
=
0
):
mean_y_bunch
,
t0
,
t1
,
emitYC02before
,
emitYC16before
,
emitYC02after
,
emitYC16after
,
emitXC02before
,
emitXC02after
=
read_bunch_data
(
0
,
filename
,
folder
,
N
)
size
=
mean_y_bunch
.
shape
[
0
]
mean_y_beam
=
np
.
empty
(
shape
=
(
size
*
H_RF
),
dtype
=
np
.
float64
)
turns
=
np
.
linspace
(
0
,
size
,
H_RF
*
size
)
for
bunchnumber
in
range
(
0
,
H_RF
):
mean_y_bunch
,
t0
,
t1
,
emitYC02before
,
emitYC16before
,
emitYC02after
,
emitYC16after
,
emitXC02before
,
emitXC02after
=
read_bunch_data
(
bunchnumber
,
filename
,
folder
)
mean_y_bunch
,
t0
,
t1
,
emitYC02before
,
emitYC16before
,
emitYC02after
,
emitYC16after
,
emitXC02before
,
emitXC02after
=
read_bunch_data
(
bunchnumber
,
filename
,
folder
,
N
)
mean_y_bunch
-=
np
.
mean
(
mean_y_bunch
)
mean_y_beam
[
bunchnumber
::
H_RF
]
=
mean_y_bunch
ax
.
plot
(
turns
,
mean_y_beam
)
...
...
@@ -108,31 +113,69 @@ def plot_beam_offset_data(ax, filename, folder, smoothing_window_size = 10):
ax
.
set_xlabel
(
'
Time (turns)
'
)
ax
.
set_ylabel
(
'
Beam c.\,m. offset (arb. units)
'
)
ax
.
text
(
mean_y_beam
.
shape
[
0
]
/
10
/
H_RF
,
np
.
min
(
mean_y_beam
)
/
2
,
'
$
\\
varepsilon_i={:.1e}$,
\n
$
\\
varepsilon_f={:.1e}$
'
.
format
(
emitYC16before
,
emitYC16after
),
fontsize
=
12
)
signal
=
np
.
abs
(
hilbert
(
mean_y_bunch
))
signal_reversed
=
np
.
flip
(
signal
)
return
None
def
plot_beam_risetime_fit
(
ax
,
filename
,
folder
,
smoothing_window_size
=
2000
,
N
=
0
):
mean_y_bunch
,
t0
,
t1
,
emitYC02before
,
emitYC16before
,
emitYC02after
,
emitYC16after
,
emitXC02before
,
emitXC02after
=
read_bunch_data
(
0
,
filename
,
folder
,
N
)
size
=
mean_y_bunch
.
shape
[
0
]
mean_y_beam
=
np
.
empty
(
shape
=
(
size
*
H_RF
),
dtype
=
np
.
float64
)
turns
=
np
.
linspace
(
0
,
size
,
H_RF
*
size
)
for
bunchnumber
in
range
(
0
,
H_RF
):
mean_y_bunch
,
t0
,
t1
,
emitYC02before
,
emitYC16before
,
emitYC02after
,
emitYC16after
,
emitXC02before
,
emitXC02after
=
read_bunch_data
(
bunchnumber
,
filename
,
folder
,
N
)
mean_y_bunch
-=
np
.
mean
(
mean_y_bunch
)
mean_y_beam
[
bunchnumber
::
H_RF
]
=
mean_y_bunch
ax
.
axvline
(
t0
,
linestyle
=
'
dashed
'
,
color
=
'
black
'
)
ax
.
axvline
(
t1
,
linestyle
=
'
dashdot
'
,
color
=
'
black
'
)
ax
.
set_xlim
(
0
,)
ax
.
set_xlabel
(
'
Time (turns)
'
)
ax
.
set_ylabel
(
'
Beam c.\,m. offset (arb. units)
'
)
ax
.
text
(
mean_y_beam
.
shape
[
0
]
/
10
/
H_RF
,
np
.
min
(
mean_y_beam
)
/
2
,
'
$
\\
varepsilon_i={:.1e}$,
\n
$
\\
varepsilon_f={:.1e}$
'
.
format
(
emitYC16before
,
emitYC16after
),
fontsize
=
12
)
signal
=
np
.
abs
(
hilbert
(
mean_y_beam
))
min_level
=
np
.
min
((
5
*
np
.
mean
(
signal
[:
200
]),
5
*
np
.
mean
(
signal
[
-
200
:])))
damping_
time
=
fit_risetime
(
signal
_reversed
,
rise
time
=
fit_risetime
(
signal
,
min_level
=
min_level
,
smoothing_window_size
=
smoothing_window_size
,
matplotlib_axis
=
None
)
risetime
=
fit_risetime
(
signal_reversed
,
matplotlib_axis
=
ax
)
return
risetime
/
H_RF
def
plot_beam_damptime_fit
(
ax
,
filename
,
folder
,
smoothing_window_size
=
2000
,
N
=
0
):
mean_y_bunch
,
t0
,
t1
,
emitYC02before
,
emitYC16before
,
emitYC02after
,
emitYC16after
,
emitXC02before
,
emitXC02after
=
read_bunch_data
(
0
,
filename
,
folder
,
N
)
size
=
mean_y_bunch
.
shape
[
0
]
mean_y_beam
=
np
.
empty
(
shape
=
(
size
*
H_RF
),
dtype
=
np
.
float64
)
turns
=
np
.
linspace
(
0
,
size
,
H_RF
*
size
)
for
bunchnumber
in
range
(
0
,
H_RF
):
mean_y_bunch
,
t0
,
t1
,
emitYC02before
,
emitYC16before
,
emitYC02after
,
emitYC16after
,
emitXC02before
,
emitXC02after
=
read_bunch_data
(
bunchnumber
,
filename
,
folder
,
N
)
mean_y_bunch
-=
np
.
mean
(
mean_y_bunch
)
mean_y_beam
[
bunchnumber
::
H_RF
]
=
mean_y_bunch
ax
.
axvline
(
t0
,
linestyle
=
'
dashed
'
,
color
=
'
black
'
)
ax
.
axvline
(
t1
,
linestyle
=
'
dashdot
'
,
color
=
'
black
'
)
ax
.
set_xlim
(
0
,)
ax
.
set_xlabel
(
'
Time (turns)
'
)
ax
.
set_ylabel
(
'
Beam c.\,m. offset (arb. units)
'
)
ax
.
text
(
mean_y_beam
.
shape
[
0
]
/
10
/
H_RF
,
np
.
min
(
mean_y_beam
)
/
2
,
'
$
\\
varepsilon_i={:.1e}$,
\n
$
\\
varepsilon_f={:.1e}$
'
.
format
(
emitYC16before
,
emitYC16after
),
fontsize
=
12
)
signal
=
np
.
flip
(
np
.
abs
(
hilbert
(
mean_y_beam
)))
min_level
=
np
.
min
((
10
*
np
.
mean
(
signal
[:
200
]),
10
*
np
.
mean
(
signal
[
-
200
:])))
damptime
=
fit_risetime
(
signal
,
min_level
=
min_level
,
smoothing_window_size
=
smoothing_window_size
,
matplotlib_axis
=
None
)
return
risetime
/
H_RF
,
damping_time
/
H_RF
matplotlib_axis
=
ax
)
return
damptime
/
H_RF
def
plot_beam_spectrum
(
ax
,
filename
,
folder
):
mean_y_bunch
,
t0
,
t1
,
emitYC02before
,
emitYC16before
,
emitYC02after
,
emitYC16after
,
emitXC02before
,
emitXC02after
=
read_bunch_data
(
0
,
filename
,
folder
)
def
plot_beam_spectrum
(
ax
,
filename
,
folder
,
N
=
0
):
mean_y_bunch
,
t0
,
t1
,
emitYC02before
,
emitYC16before
,
emitYC02after
,
emitYC16after
,
emitXC02before
,
emitXC02after
=
read_bunch_data
(
0
,
filename
,
folder
,
N
)
size
=
mean_y_bunch
.
shape
[
0
]
mean_y_beam
=
np
.
empty
(
shape
=
(
size
*
H_RF
),
dtype
=
np
.
float64
)
turns
=
np
.
linspace
(
0
,
size
,
H_RF
*
size
)
for
bunchnumber
in
range
(
0
,
H_RF
):
mean_y_bunch
,
t0
,
t1
,
emitYC02before
,
emitYC16before
,
emitYC02after
,
emitYC16after
,
emitXC02before
,
emitXC02after
=
read_bunch_data
(
bunchnumber
,
filename
,
folder
)
mean_y_bunch
,
t0
,
t1
,
emitYC02before
,
emitYC16before
,
emitYC02after
,
emitYC16after
,
emitXC02before
,
emitXC02after
=
read_bunch_data
(
bunchnumber
,
filename
,
folder
,
N
)
mean_y_bunch
-=
np
.
mean
(
mean_y_bunch
)
mean_y_beam
[
bunchnumber
::
H_RF
]
=
mean_y_bunch
fftfreq
=
rfftfreq
(
mean_y_b
unch
.
shape
[
0
])
absfft
=
np
.
abs
(
rfft
(
mean_y_b
unch
))
ax
.
plot
(
fftfreq
,
absfft
/
np
.
max
(
absfft
))
fftfreq
=
H_RF
*
rfftfreq
(
mean_y_b
eam
.
shape
[
0
])
absfft
=
np
.
abs
(
rfft
(
mean_y_b
eam
))
ax
.
semilogy
(
fftfreq
,
absfft
/
np
.
max
(
absfft
))
beta_x
=
CIRCUMFERENCE
/
(
2
*
pi
)
/
Q_X
beta_y
=
CIRCUMFERENCE
/
(
2
*
pi
)
/
Q_Y
...
...
@@ -149,9 +192,8 @@ def plot_beam_spectrum(ax, filename, folder):
print
(
'
Ion frequencies H {:.1f}, {:.1f}, CO {:.1f}, {:.1f}, CO2 {:.1f}, {:.1f}
'
.
format
(
omega_Hy
/
OMEGA_REV
,
omega_H
/
OMEGA_REV
,
omega_COy
/
OMEGA_REV
,
omega_CO
/
OMEGA_REV
,
omega_CO2y
/
OMEGA_REV
,
omega_CO2
/
OMEGA_REV
))
# ax.set_xlim(0, H_RF/2)
ax
.
set_xlim
(
0
,
.
5
)
ax
.
set_ylim
(
0
,
1.05
)
ax
.
set_xlim
(
0
,
H_RF
/
2
)
ax
.
set_ylim
(
1e-3
,
1.05
)
ax
.
set_xlabel
(
'
Coherent frequency, $\omega/\omega_0$
'
)
ax
.
set_ylabel
(
'
Power spectrum (arb. units)
'
)
# ax.text(mean_y_beam.shape[0]/15/H_RF, np.min(mean_y_beam)/2, '$\\varepsilon_i={:.1e}$,\n $\\varepsilon_f={:.1e}$'.format(emitYC16before, emitYC16after), fontsize=12)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment