Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
cs
util
sequencer
scan-p-gun-vgrid
Commits
b298d6f5
Commit
b298d6f5
authored
Nov 21, 2022
by
Francesco Tripaldi
Browse files
Changed module, scipy findpeaks not installed on server
parent
a3f4daae
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
src/ScanPGunVgrid.py
View file @
b298d6f5
...
...
@@ -24,8 +24,8 @@ import numpy as np
import
io
import
requests
from
datetime
import
datetime
from
scipy.signal
import
find_peaks
#
from scipy.signal import find_peaks
from
peakdetect
import
peakdetect
def
fig2elog
(
file_buffer
,
text
,
elog_url
=
'http://elog.elettra.eu/upload/upload.php'
,
text_after
=
''
):
try
:
...
...
@@ -85,10 +85,10 @@ def main():
selfseq_dev
.
write_attribute
(
"ScriptErr"
,
"Grid disabled or zero voltage during scan"
)
gun_dev
.
write_attribute
(
'FastGridVoltage'
,
starting_gun
)
sys
.
exit
(
1
)
if
topup_test_mode
==
True
and
(
plc_status
[
9
]
==
True
or
bool
(
trigger_gun
.
read_attribute
(
"gun_trigger_on"
).
value
)
==
False
):
#print("Interlock dcct booster, stop")
scan_stop
=
x
break
#
if topup_test_mode == True and (plc_status[9] == True or bool(trigger_gun.read_attribute("gun_trigger_on").value) == False):
#
#print("Interlock dcct booster, stop")
#
scan_stop = x
#
break
#print("valore gun: " + str(x))
gun_dev
.
write_attribute
(
'FastGridVoltage'
,
x
)
...
...
@@ -113,6 +113,9 @@ def main():
smooth_width
=
50
z
=
np
.
polyfit
(
X
,
Y
,
5
)
p
=
np
.
poly1d
(
z
)
xp
=
np
.
linspace
(
scan_start
,
scan_stop
,
smooth_width
)
# create convolution kernel for calculating
# the smoothed second order derivative
...
...
@@ -122,22 +125,40 @@ def main():
y1
=
(
4
*
x1
**
2
-
2
)
*
np
.
exp
(
-
x1
**
2
)
/
smooth_width
*
8
#norm*(x1[1]-x1[0])
yp
=
p
(
xp
)
topup_grid
=
xp
[
np
.
abs
(
yp
-
0.25
).
argmin
()]
try
:
selfseq_dev
.
write_attribute
(
"topup_voltage"
,
topup_grid
)
except
:
pass
print
(
topup_grid
)
# calculate second order deriv.
y_conv
=
np
.
convolve
(
y1
,
yp
,
mode
=
"same"
)
# best_vgrid = xp[np.where(y_conv == np.amin(y_conv))[0][0]]
# best_current = yp[np.where(y_conv == np.amin(y_conv))[0][0]]
peaks
,
_
=
find_peaks
(
y_conv
*-
1
)
#peaks, _ = find_peaks(y_conv*-1)
peaks
=
peakdetect
(
y_conv
*-
1
,
lookahead
=
5
)
#print(peaks)
current_peaks
=
[]
for
peak
in
peaks
:
current_peaks
.
append
(
yp
[
peak
])
for
subpeak
in
peak
:
#print(subpeak)
current_peaks
.
append
(
yp
[
subpeak
[
0
]])
#print(current_peaks)
max_current
=
max
(
current_peaks
)
max_index
=
current_peaks
.
index
(
max_current
)
best_vgrid
=
xp
[
peaks
[
max_index
]
-
4
]
best_current
=
yp
[
peaks
[
max_index
]
-
4
]
gun_dev
.
write_attribute
(
'FastGridVoltage'
,
best_vgrid
)
#max_index = yp.index(max_current)
max_index
=
np
.
where
(
yp
==
max_current
)[
0
]
best_vgrid
=
float
(
xp
[
max_index
])
best_current
=
float
(
yp
[
max_index
])
if
topup_test_mode
==
True
:
if
topup_grid
>
0
:
gun_dev
.
write_attribute
(
'FastGridVoltage'
,
topup_grid
)
else
:
gun_dev
.
write_attribute
(
'FastGridVoltage'
,
starting_gun
)
else
:
gun_dev
.
write_attribute
(
'FastGridVoltage'
,
best_vgrid
)
selfseq_dev
.
write_attribute
(
"best_vgrid_result"
,
float
(
best_vgrid
))
if
publish_to_elog
==
True
:
import
pygal
from
pygal.style
import
Style
...
...
src/__pycache__/peakdetect.cpython-36.pyc
0 → 100644
View file @
b298d6f5
File added
src/peakdetect.py
0 → 100755
View file @
b298d6f5
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment