Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
ToolBox
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
SCS
ToolBox
Commits
1bd27bbe
Commit
1bd27bbe
authored
5 years ago
by
Laurent Mercadier
Browse files
Options
Downloads
Patches
Plain Diff
Improved autoFindFastAdcPeaks()
parent
686e2947
No related branches found
No related tags found
1 merge request
!73
Improved autoFindFastAdcPeaks()
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
xgm.py
+33
-14
33 additions, 14 deletions
xgm.py
with
33 additions
and
14 deletions
xgm.py
+
33
−
14
View file @
1bd27bbe
...
@@ -863,18 +863,18 @@ def fastAdcPeaks(data, channel, intstart, intstop, bkgstart, bkgstop, period=Non
...
@@ -863,18 +863,18 @@ def fastAdcPeaks(data, channel, intstart, intstop, bkgstart, bkgstop, period=Non
results
[:,
i
]
=
integ
results
[:,
i
]
=
integ
return
results
return
results
def
autoFindFastAdcPeaks
(
data
,
channel
=
5
,
threshold
=
35000
,
display
=
False
,
plot
=
False
):
def
autoFindFastAdcPeaks
(
data
,
channel
=
5
,
window
=
'
small
'
,
display
=
False
,
plot
=
False
):
'''
Automatically finds positive peaks in channel of Fast ADC trace, assuming
'''
Automatically finds peaks in channel of Fast ADC trace, a minimum width of 4
a minimum absolute height of
'
threshold
'
counts and a minimum width of 4
samples. The find_peaks function and determination of the peak integration
samples. The find_peaks function and determination of the peak region and
region and baseline subtraction is optimized for typical photodiode signals
baseline subtraction is optimized for typical photodiode signals of the
of the SCS instrument (ILH, FFT reflectometer, FFT diag stage).
SCS instrument (ILH, FFT reflectometer, FFT diag stage).
Inputs:
Inputs:
data: xarray Dataset containing Fast ADC traces
data: xarray Dataset containing Fast ADC traces
key: data key of the array of traces
key: data key of the array of traces
threshold: minimum height of the peaks
window:
'
small
'
or
'
large
'
: defines the width of the integration region
centered on the peak.
display: bool, displays info on the pulses found
display: bool, displays info on the pulses found
plot: plots regions of integration of the first pulse in the trace
plot:
bool,
plots regions of integration of the first pulse in the trace
Output:
Output:
peaks: DataArray of the integrated peaks
peaks: DataArray of the integrated peaks
'''
'''
...
@@ -882,25 +882,44 @@ def autoFindFastAdcPeaks(data, channel=5, threshold=35000, display=False, plot=F
...
@@ -882,25 +882,44 @@ def autoFindFastAdcPeaks(data, channel=5, threshold=35000, display=False, plot=F
key
=
f
'
FastADC
{
channel
}
raw
'
key
=
f
'
FastADC
{
channel
}
raw
'
if
key
not
in
data
:
if
key
not
in
data
:
raise
ValueError
(
f
'
{
key
}
not found in data set
'
)
raise
ValueError
(
f
'
{
key
}
not found in data set
'
)
tid
=
data
[
key
].
where
(
data
[
key
]
>
threshold
,
drop
=
True
).
trainId
[
0
]
#average over the 100 first traces to get at least one train with signal
trace
=
data
[
key
].
sel
(
trainId
=
tid
)
trace
=
data
[
key
].
isel
(
trainId
=
slice
(
0
,
100
)).
mean
(
dim
=
'
trainId
'
).
values
if
plot
:
trace_plot
=
np
.
copy
(
trace
)
#subtract baseline and check if peaks are positive or negative
bl
=
np
.
median
(
trace
)
trace_no_bl
=
trace
-
bl
if
np
.
max
(
trace_no_bl
)
>=
np
.
abs
(
np
.
min
(
trace_no_bl
)):
posNeg
=
'
positive
'
else
:
posNeg
=
'
negative
'
trace_no_bl
*=
-
1
trace
=
bl
+
trace_no_bl
threshold
=
bl
+
np
.
max
(
trace_no_bl
)
/
2
#find peaks
centers
,
peaks
=
find_peaks
(
trace
,
height
=
threshold
,
width
=
(
4
,
None
))
centers
,
peaks
=
find_peaks
(
trace
,
height
=
threshold
,
width
=
(
4
,
None
))
c
=
centers
[
0
]
c
=
centers
[
0
]
w
=
np
.
average
(
peaks
[
'
widths
'
]).
astype
(
int
)
w
=
np
.
average
(
peaks
[
'
widths
'
]).
astype
(
int
)
period
=
np
.
median
(
np
.
diff
(
centers
)).
astype
(
int
)
period
=
np
.
median
(
np
.
diff
(
centers
)).
astype
(
int
)
npulses
=
centers
.
shape
[
0
]
npulses
=
centers
.
shape
[
0
]
intstart
=
int
(
c
-
w
/
4
)
+
1
if
window
not
in
[
'
small
'
,
'
large
'
]:
intstop
=
int
(
c
+
w
/
4
)
+
1
raise
ValueError
(
f
"'
window argument should be either
'
small
'
or
'
large
'
, not
{
window
}
"
)
if
window
==
'
small
'
:
intstart
=
int
(
c
-
w
/
4
)
+
1
intstop
=
int
(
c
+
w
/
4
)
+
1
if
window
==
'
large
'
:
intstart
=
int
(
peaks
[
'
left_ips
'
][
0
])
intstop
=
int
(
peaks
[
'
right_ips
'
][
0
])
+
w
bkgstop
=
int
(
peaks
[
'
left_ips
'
][
0
])
-
5
bkgstop
=
int
(
peaks
[
'
left_ips
'
][
0
])
-
5
bkgstart
=
bkgstop
-
10
bkgstart
=
bkgstop
-
10
if
display
:
if
display
:
print
(
f
'
Found
{
npulses
}
pulses, avg. width=
{
w
}
, period=
{
period
}
samples,
'
+
print
(
f
'
Found
{
npulses
}
{
posNeg
}
pulses, avg. width=
{
w
}
, period=
{
period
}
samples,
'
+
f
'
rep. rate=
{
1e6
/
(
9.230769
*
period
)
:
.
3
f
}
kHz
'
)
f
'
rep. rate=
{
1e6
/
(
9.230769
*
period
)
:
.
3
f
}
kHz
'
)
fAdcPeaks
=
fastAdcPeaks
(
data
,
channel
=
channel
,
intstart
=
intstart
,
intstop
=
intstop
,
fAdcPeaks
=
fastAdcPeaks
(
data
,
channel
=
channel
,
intstart
=
intstart
,
intstop
=
intstop
,
bkgstart
=
bkgstart
,
bkgstop
=
bkgstop
,
period
=
period
,
npulses
=
npulses
)
bkgstart
=
bkgstart
,
bkgstop
=
bkgstop
,
period
=
period
,
npulses
=
npulses
)
if
plot
:
if
plot
:
plt
.
figure
()
plt
.
figure
()
plt
.
plot
(
trace
,
'
o-
'
,
ms
=
3
)
plt
.
plot
(
trace
_plot
,
'
o-
'
,
ms
=
3
)
for
i
in
range
(
npulses
):
for
i
in
range
(
npulses
):
plt
.
axvline
(
intstart
+
i
*
period
,
ls
=
'
--
'
,
color
=
'
g
'
)
plt
.
axvline
(
intstart
+
i
*
period
,
ls
=
'
--
'
,
color
=
'
g
'
)
plt
.
axvline
(
intstop
+
i
*
period
,
ls
=
'
--
'
,
color
=
'
r
'
)
plt
.
axvline
(
intstop
+
i
*
period
,
ls
=
'
--
'
,
color
=
'
r
'
)
...
...
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