Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Bliss
bliss
Commits
17d79d78
Commit
17d79d78
authored
May 07, 2021
by
Valentin Valls
Browse files
Normalize numpy import
parent
7f73b1c2
Changes
1
Hide whitespace changes
Inline
Side-by-side
bliss/controllers/simulation_counter.py
View file @
17d79d78
...
...
@@ -5,7 +5,7 @@
# Copyright (c) 2015-2020 Beamline Control Unit, ESRF
# Distributed under the GNU LGPLv3. See LICENSE for more info.
import
numpy
as
np
import
numpy
from
scipy
import
signal
from
scipy.special
import
erf
...
...
@@ -221,14 +221,14 @@ class SimulationCounterAcquisitionSlave(AcquisitionSlave):
#### Generation of the distribution
if
self
.
distribution
==
"FLAT"
:
self
.
data
=
n
p
.
ones
(
nbpoints
)
*
self
.
shape_param
[
"height_factor"
]
self
.
data
=
n
umpy
.
ones
(
nbpoints
)
*
self
.
shape_param
[
"height_factor"
]
elif
self
.
distribution
==
"LINEAR"
:
xdata
=
n
p
.
linspace
(
scan_start
,
scan_stop
,
nbpoints
)
xdata
=
n
umpy
.
linspace
(
scan_start
,
scan_stop
,
nbpoints
)
self
.
data
=
(
xdata
*
self
.
shape_param
[
"sigma_factor"
]
+
self
.
shape_param
[
"mu_offset"
]
)
else
:
xdata
=
n
p
.
linspace
(
scan_start
,
scan_stop
,
nbpoints
)
xdata
=
n
umpy
.
linspace
(
scan_start
,
scan_stop
,
nbpoints
)
self
.
data
=
self
.
gauss
(
xdata
,
self
.
shape_param
[
"mu_offset"
],
self
.
shape_param
[
"sigma_factor"
]
)
...
...
@@ -239,9 +239,9 @@ class SimulationCounterAcquisitionSlave(AcquisitionSlave):
# applying noise
if
self
.
timescan_or_ct
():
noise
=
(
n
p
.
random
.
rand
(
1
)[
0
]
*
self
.
noise_factor
)
+
1
noise
=
(
n
umpy
.
random
.
rand
(
1
)[
0
]
*
self
.
noise_factor
)
+
1
else
:
noise
=
(
n
p
.
random
.
rand
(
nbpoints
)
*
self
.
noise_factor
)
+
1
noise
=
(
n
umpy
.
random
.
rand
(
nbpoints
)
*
self
.
noise_factor
)
+
1
self
.
data
=
self
.
data
*
noise
log_debug_data
(
self
,
"SIMULATION_COUNTER_ACQ_DEV -- prepare() -- data+noise="
,
self
.
data
...
...
@@ -252,8 +252,8 @@ class SimulationCounterAcquisitionSlave(AcquisitionSlave):
log_debug
(
self
,
"SIMULATION_COUNTER_ACQ_DEV -- prepare() END"
)
def
calc_gaussian
(
self
,
x
,
mu
,
sigma
):
one_over_sqtr
=
1.0
/
n
p
.
sqrt
(
2.0
*
n
p
.
pi
*
n
p
.
square
(
sigma
))
exp
=
n
p
.
exp
(
-
n
p
.
square
(
x
-
mu
)
/
(
2.0
*
n
p
.
square
(
sigma
)))
one_over_sqtr
=
1.0
/
n
umpy
.
sqrt
(
2.0
*
n
umpy
.
pi
*
n
umpy
.
square
(
sigma
))
exp
=
n
umpy
.
exp
(
-
n
umpy
.
square
(
x
-
mu
)
/
(
2.0
*
n
umpy
.
square
(
sigma
)))
_val
=
one_over_sqtr
*
exp
...
...
@@ -283,7 +283,7 @@ class SimulationCounterAcquisitionSlave(AcquisitionSlave):
sigma
=
sigma_factor
*
(
xmax
-
xmin
)
/
6.0
self
.
sigma
=
sigma
self
.
fwhm
=
2
*
n
p
.
sqrt
(
2
*
n
p
.
log
(
2
))
*
sigma
# ~ 2.35 * sigma
self
.
fwhm
=
2
*
n
umpy
.
sqrt
(
2
*
n
umpy
.
log
(
2
))
*
sigma
# ~ 2.35 * sigma
log_debug
(
self
,
...
...
@@ -408,19 +408,23 @@ class _Signal:
def
_missing_edge_of_gaussian_left
(
npoints
,
frac_missing
):
p
=
npoints
//
2
p2
=
int
(
p
*
frac_missing
)
return
np
.
concatenate
(
(
signal
.
gaussian
(
p
,
.
1
*
npoints
)[
p2
:],
np
.
zeros
(
p2
),
np
.
zeros
(
npoints
-
p
))
return
numpy
.
concatenate
(
(
signal
.
gaussian
(
p
,
.
1
*
npoints
)[
p2
:],
numpy
.
zeros
(
p2
),
numpy
.
zeros
(
npoints
-
p
),
)
)
SIGNALS
=
{
"sawtooth"
:
lambda
npoints
:
signal
.
sawtooth
(
n
p
.
arange
(
0
,
2
*
n
p
.
pi
*
1.1
,
2
*
n
p
.
pi
*
1.1
/
npoints
),
width
=
.
9
n
umpy
.
arange
(
0
,
2
*
n
umpy
.
pi
*
1.1
,
2
*
n
umpy
.
pi
*
1.1
/
npoints
),
width
=
.
9
),
"gaussian"
:
lambda
npoints
:
signal
.
gaussian
(
npoints
,
.
2
*
npoints
),
"flat"
:
lambda
npoints
:
n
p
.
ones
(
npoints
),
"off_center_gaussian"
:
lambda
npoints
:
n
p
.
concatenate
(
"flat"
:
lambda
npoints
:
n
umpy
.
ones
(
npoints
),
"off_center_gaussian"
:
lambda
npoints
:
n
umpy
.
concatenate
(
(
n
p
.
zeros
(
npoints
-
npoints
//
2
),
n
umpy
.
zeros
(
npoints
-
npoints
//
2
),
signal
.
gaussian
(
npoints
//
2
,
.
1
*
npoints
),
)
),
...
...
@@ -438,35 +442,35 @@ class _Signal:
"half_gaussian_left"
:
lambda
npoints
:
_Signal
.
_missing_edge_of_gaussian_left
(
npoints
,
0.4
)[::
-
1
],
"triangle"
:
lambda
npoints
:
n
p
.
concatenate
(
"triangle"
:
lambda
npoints
:
n
umpy
.
concatenate
(
(
n
p
.
arange
(
0
,
1
,
1
/
(
npoints
//
2
)),
n
p
.
flip
(
n
p
.
arange
(
0
,
1
,
1
/
(
npoints
-
npoints
//
2
))),
n
umpy
.
arange
(
0
,
1
,
1
/
(
npoints
//
2
)),
n
umpy
.
flip
(
n
umpy
.
arange
(
0
,
1
,
1
/
(
npoints
-
npoints
//
2
))),
)
),
"square"
:
lambda
npoints
:
n
p
.
concatenate
(
"square"
:
lambda
npoints
:
n
umpy
.
concatenate
(
(
n
p
.
zeros
(
npoints
//
3
),
n
p
.
ones
(
npoints
//
3
),
n
p
.
zeros
(
npoints
-
2
*
(
npoints
//
3
)),
n
umpy
.
zeros
(
npoints
//
3
),
n
umpy
.
ones
(
npoints
//
3
),
n
umpy
.
zeros
(
npoints
-
2
*
(
npoints
//
3
)),
)
),
"bimodal"
:
lambda
npoints
:
n
p
.
concatenate
(
"bimodal"
:
lambda
npoints
:
n
umpy
.
concatenate
(
(
signal
.
gaussian
(
npoints
-
npoints
//
2
,
.
15
*
npoints
)
*
1.5
,
signal
.
gaussian
(
npoints
//
2
,
.
15
*
npoints
),
)
),
"step_down"
:
lambda
npoints
:
n
p
.
concatenate
(
(
n
p
.
ones
(
npoints
//
2
),
n
p
.
zeros
(
npoints
-
npoints
//
2
))
"step_down"
:
lambda
npoints
:
n
umpy
.
concatenate
(
(
n
umpy
.
ones
(
npoints
//
2
),
n
umpy
.
zeros
(
npoints
-
npoints
//
2
))
),
"step_up"
:
lambda
npoints
:
n
p
.
concatenate
(
(
n
p
.
zeros
(
npoints
//
2
),
n
p
.
ones
(
npoints
-
npoints
//
2
))
"step_up"
:
lambda
npoints
:
n
umpy
.
concatenate
(
(
n
umpy
.
zeros
(
npoints
//
2
),
n
umpy
.
ones
(
npoints
-
npoints
//
2
))
),
"erf_down"
:
lambda
npoints
:
1
-
erf
(
n
p
.
arange
(
-
3
,
3
,
6
/
(
npoints
))),
"erf_up"
:
lambda
npoints
:
erf
(
n
p
.
arange
(
-
3
,
3
,
6
/
(
npoints
))),
"erf_down"
:
lambda
npoints
:
1
-
erf
(
n
umpy
.
arange
(
-
3
,
3
,
6
/
(
npoints
))),
"erf_up"
:
lambda
npoints
:
erf
(
n
umpy
.
arange
(
-
3
,
3
,
6
/
(
npoints
))),
"inverted_gaussian"
:
lambda
npoints
:
1
-
signal
.
gaussian
(
npoints
,
.
2
*
npoints
),
"expo_gaussian"
:
lambda
npoints
:
n
p
.
exp
(
"expo_gaussian"
:
lambda
npoints
:
n
umpy
.
exp
(
signal
.
gaussian
(
npoints
,
.
1
*
npoints
)
*
30
),
}
...
...
@@ -477,7 +481,7 @@ class _Signal:
self
.
name
=
name
self
.
npoints
=
npoints
def
compute
(
self
)
->
n
p
.
ndarray
:
def
compute
(
self
)
->
n
umpy
.
ndarray
:
return
self
.
SIGNALS
[
self
.
name
](
self
.
npoints
)
...
...
@@ -610,7 +614,7 @@ class AutoFilterDetMon:
def
init_signal
(
self
):
n
=
self
.
_npoints
+
1
stdev
=
.
1
*
self
.
_npoints
+
1
self
.
_data
=
n
p
.
exp
(
signal
.
gaussian
(
n
,
stdev
)
*
10
)
self
.
_data
=
n
umpy
.
exp
(
signal
.
gaussian
(
n
,
stdev
)
*
10
)
@
property
def
npoints
(
self
):
...
...
Write
Preview
Supports
Markdown
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