Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
calc-stats
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
cs
util
sequencer
calc-stats
Commits
6b90d430
Commit
6b90d430
authored
3 years ago
by
Giulio Gaio
Browse files
Options
Downloads
Patches
Plain Diff
Fixed scipy stats import
parent
7975a23a
No related branches found
Branches containing commit
Tags
1.0.4
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/CalcStats.py
+37
-20
37 additions, 20 deletions
src/CalcStats.py
with
37 additions
and
20 deletions
src/CalcStats.py
+
37
−
20
View file @
6b90d430
...
...
@@ -8,7 +8,7 @@
from
tango
import
*
#import matplotlib.pyplot as plt
import
numpy
as
np
import
scipy
as
sp
import
scipy
.stats
as
sp
import
time
,
datetime
import
sys
,
os
import
math
...
...
@@ -252,6 +252,7 @@ class DeviceObj:
else
:
self
.
acq_state
&=
~
STATE_ERR
self
.
acq_state
&=
~
TANGO_ERR
self
.
acq_state
&=
~
SAMPLES_ERR
# A=np.array([1,2, 3, 4, 5]) A[2:]=array([3, 4, 5]) B=np.array([6,7]) A=np.append(A[2:],B)
# sample_shift recovers the data shift in respect the bunch number
...
...
@@ -267,7 +268,7 @@ class DeviceObj:
# plt.pause(0.0001)
if
DATA_DBG
:
print
(
'
Acquired
'
,
self
.
device_name
,
self
.
command
)
print
(
'
Acquired
'
,
self
.
device_name
,
self
.
command
,
self
.
data
[
0
]
)
self
.
bn_start
=
new_bn_start
self
.
bn_end
=
new_bn_end
...
...
@@ -277,11 +278,14 @@ class DeviceObj:
self
.
last_bn_start
=
bn_start
self
.
last_bn_end
=
bn_end
if
DATA_DBG
:
print
(
"
Start Device state
"
,
self
.
acq_state
)
except
DevFailed
as
df
:
self
.
bn_error
=
new_bn_end
self
.
acq_state
|=
ACQ_ERR
if
ERR_DBG
:
print
(
'
E
rror reading
'
,
self
.
device_name
,
'
/
'
,
self
.
command
,
'
bn=
'
,
int
(
bn_start
),
'
bnend=
'
,
int
(
bn_end
))
print
(
'
TANGO ERROR: e
rror reading
'
,
self
.
device_name
,
'
/
'
,
self
.
command
,
'
bn=
'
,
int
(
bn_start
),
'
bnend=
'
,
int
(
bn_end
))
print
(
str
(
df
))
# recovery data strategy, ask data once at a time, accept at maximum 5 errors
...
...
@@ -289,6 +293,9 @@ class DeviceObj:
data_tmp
=
np
.
array
([])
if
self
.
bn_error
==
new_bn_end
:
if
DATA_DBG
:
print
(
'
Recovering device
'
,
self
.
device_name
,
self
.
command
,
self
.
data
[
0
])
self
.
acq_state
|=
RECOV_RUN
...
...
@@ -312,11 +319,15 @@ class DeviceObj:
consec_error
=
0
except
:
if
ERR_DBG
:
print
(
'
Max recovery error
'
,
self
.
device_name
,
'
/
'
,
self
.
command
)
print
(
'
ERROR: get_data(), max recovery error
'
,
self
.
device_name
,
'
/
'
,
self
.
command
)
tango_error
=
tango_error
+
1
consec_error
=
consec_error
+
1
tmp
=
last_valid_val
# if more then 10 % of errors, stop recovery
if
tango_error
>
(
bn_end
-
bn_start
+
1
)
*
0.1
:
error_flag
=
True
...
...
@@ -343,6 +354,8 @@ class DeviceObj:
self
.
acq_state
&=
~
TANGO_ERR
self
.
acq_state
&=
~
ACQ_ERR
if
DATA_DBG
:
print
(
"
End Device state
"
,
self
.
acq_state
)
...
...
@@ -424,11 +437,11 @@ class DeviceObj:
except
DevFailed
as
df
:
if
ERR_DBG
:
print
(
'
C
onfiguration reading error
'
,
self
.
device_name
,
'
/
'
,
command
)
print
(
'
TANGO ERROR: get_configuration(), c
onfiguration reading error
'
,
self
.
device_name
,
'
/
'
,
command
)
print
(
str
(
df
))
except
:
if
ERR_DBG
:
print
(
'
C
onfiguration reading error
'
,
self
.
device_name
,
'
/
'
,
command
)
print
(
'
ERROR: get_configuration(), c
onfiguration reading error
'
,
self
.
device_name
,
'
/
'
,
command
)
#
...
...
@@ -589,11 +602,11 @@ class DeviceObj:
except
DevFailed
as
df
:
if
ERR_DBG
:
print
(
'
S
etting sequencer error
'
,
self
.
device_name
)
print
(
'
ERROR: set_sequencer(), s
etting sequencer error
'
,
self
.
device_name
)
print
(
str
(
df
))
except
:
if
ERR_DBG
:
print
(
'
S
etting sequencer error
'
,
self
.
device_name
)
print
(
'
ERROR: set_sequencer(),
etting sequencer error
'
,
self
.
device_name
)
#
...
...
@@ -610,7 +623,7 @@ class DeviceObj:
if
(
self
.
acq_state
&
(
STATE_ERR
|
ACQ_ERR
|
TANGO_ERR
|
SAMPLES_ERR
))
or
((
self
.
acq_state
&
ACQ_RUN
)
==
0
):
if
ERR_DBG
:
print
(
'
Skip filtering
'
,
self
.
device_name
,
self
.
command
,
'
, state
'
,
self
.
acq_state
)
print
(
'
ERROR: filter_data(),
Skip filtering
'
,
self
.
device_name
,
self
.
command
,
'
, state
'
,
self
.
acq_state
)
return
# sort the array and get the indexes of the sorted array
...
...
@@ -641,6 +654,8 @@ class DeviceObj:
# get the indexes of the elements above the maximum threshold
self
.
max_thres_thres_idx
=
np
.
nonzero
(
self
.
data
>
self
.
max_thres_val_tmp
)[
0
]
# remove NaN (np.nan)
self
.
nan_idx
=
np
.
argwhere
(
np
.
isnan
(
self
.
sort_data
));
...
...
@@ -655,14 +670,18 @@ class DeviceObj:
self
.
sort_filt_data
=
[
self
.
data
[
index
]
for
index
in
self
.
sort_data_idx
]
if
len
(
self
.
sort_filt_data
)
<=
self
.
min_process_samples
:
if
ERR_DBG
:
print
(
'
ERROR: filter_data(), number of valid samples under threshold
'
,
self
.
device_name
)
self
.
acq_state
|=
EMPTY_ERR
else
:
self
.
acq_state
&=
~
EMPTY_ERR
self
.
acq_state
&=
~
EMPTY_ERR
except
:
if
ERR_DBG
:
print
(
'
ERROR: filter_data(),
'
,
self
.
device_name
)
self
.
acq_state
|=
EMPTY_ERR
return
#
...
...
@@ -717,15 +736,14 @@ class DeviceObj:
#[self.valid_samples,self.minmax,self.avg,self.std,self.skew,self.kurt] = stats.describe(self.sort_filt_data)
#self.median = self.sort_filt_data[int(len(self.valid_samplest) / 2) - 1];
self
.
valid_samples
=
len
(
self
.
sort_filt_data
)
self
.
minmax
=
np
.
ptp
(
self
.
sort_filt_data
)
self
.
mean
=
np
.
mean
(
self
.
sort_filt_data
)
self
.
min
=
np
.
min
(
self
.
sort_filt_data
)
self
.
max
=
np
.
max
(
self
.
sort_filt_data
)
self
.
median
=
self
.
sort_filt_data
[
int
(
self
.
valid_samples
/
2
)
-
1
];
self
.
std
=
np
.
std
(
self
.
sort_filt_data
)
self
.
skew
=
sp
.
stats
.
skew
(
self
.
sort_filt_data
)
self
.
kurt
=
sp
.
stats
.
kurtosis
(
self
.
sort_filt_data
)
self
.
minmax
=
np
.
ptp
(
self
.
sort_filt_data
)
self
.
mean
=
np
.
mean
(
self
.
sort_filt_data
)
self
.
min
=
np
.
min
(
self
.
sort_filt_data
)
self
.
max
=
np
.
max
(
self
.
sort_filt_data
)
self
.
median
=
self
.
sort_filt_data
[
int
(
self
.
valid_samples
/
2
)
-
1
];
self
.
std
=
np
.
std
(
self
.
sort_filt_data
)
self
.
skew
=
sp
.
skew
(
self
.
sort_filt_data
)
self
.
kurt
=
sp
.
kurtosis
(
self
.
sort_filt_data
)
if
DATA_DBG
:
print
(
self
.
device_name
,
'
/
'
,
self
.
command
,
'
valid samples
'
,
self
.
valid_samples
)
...
...
@@ -980,7 +998,6 @@ while 1:
# exit from acquisition
if
abort_flag
:
break
# pause acquisition
while
pause_flag
:
pause_flag
=
selfseq_dev
.
read_attribute
(
'
PauseFlag
'
).
value
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
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