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
7f73b1c2
Commit
7f73b1c2
authored
May 05, 2021
by
Valentin Valls
Browse files
Extract a _Signal class from FixedShapeCounter
parent
c8abff25
Changes
1
Hide whitespace changes
Inline
Side-by-side
bliss/controllers/simulation_counter.py
View file @
7f73b1c2
...
...
@@ -401,13 +401,8 @@ class SimulationCounter(Counter):
self
.
config
=
config
class
FixedShapeCounter
:
"""Counter which generates a signal of predefined shape.
The predefined shape can be obtained by scanning the
associated software axis from 0 to 1:
s = ascan(self.axis, 0, 1, self.npoints, expo, self.counter)
"""
class
_Signal
:
"""Helper to provide a set of predefined signals"""
@
staticmethod
def
_missing_edge_of_gaussian_left
(
npoints
,
frac_missing
):
...
...
@@ -429,22 +424,20 @@ class FixedShapeCounter:
signal
.
gaussian
(
npoints
//
2
,
.
1
*
npoints
),
)
),
"missing_edge_of_gaussian_left"
:
lambda
npoints
:
FixedShapeCounter
.
_missing_edge_of_gaussian_left
(
"missing_edge_of_gaussian_left"
:
lambda
npoints
:
_Signal
.
_missing_edge_of_gaussian_left
(
npoints
,
0.25
),
"missing_edge_of_gaussian_right"
:
lambda
npoints
:
FixedShapeCounter
.
_missing_edge_of_gaussian_left
(
"missing_edge_of_gaussian_right"
:
lambda
npoints
:
_Signal
.
_missing_edge_of_gaussian_left
(
npoints
,
0.25
)[
::
-
1
],
"half_gaussian_right"
:
lambda
npoints
:
FixedShapeCounter
.
_missing_edge_of_gaussian_left
(
"half_gaussian_right"
:
lambda
npoints
:
_Signal
.
_missing_edge_of_gaussian_left
(
npoints
,
0.4
),
"half_gaussian_left"
:
lambda
npoints
:
FixedShapeCounter
.
_missing_edge_of_gaussian_left
(
"half_gaussian_left"
:
lambda
npoints
:
_Signal
.
_missing_edge_of_gaussian_left
(
npoints
,
0.4
)[
::
-
1
],
)[::
-
1
],
"triangle"
:
lambda
npoints
:
np
.
concatenate
(
(
np
.
arange
(
0
,
1
,
1
/
(
npoints
//
2
)),
...
...
@@ -478,11 +471,35 @@ class FixedShapeCounter:
),
}
def
__init__
(
self
,
signal
=
"sawtooth"
,
npoints
=
50
):
def
__init__
(
self
,
name
:
str
=
"sawtooth"
,
npoints
:
int
=
50
):
if
name
not
in
self
.
SIGNALS
:
raise
RuntimeError
(
f
"Signal name '
{
name
}
' undefined"
)
self
.
name
=
name
self
.
npoints
=
npoints
def
compute
(
self
)
->
np
.
ndarray
:
return
self
.
SIGNALS
[
self
.
name
](
self
.
npoints
)
class
FixedShapeCounter
:
"""Counter which generates a signal of predefined shape.
The predefined shape can be obtained by scanning the
associated software axis from 0 to 1:
.. code-block:: python
dev = FixedShapeCounter()
s = ascan(dev.axis, 0, 1, dev.npoints, expo, dev.counter)
"""
SIGNALS
=
set
(
_Signal
.
SIGNALS
.
keys
())
def
__init__
(
self
,
signal
:
str
=
"sawtooth"
,
npoints
:
int
=
50
):
self
.
_axis
=
SoftAxis
(
"TestAxis"
,
self
)
self
.
_counter
=
SoftCounter
(
self
)
self
.
_npoints
=
npoints
self
.
signal
=
signal
self
.
_
signal
=
_Signal
(
name
=
signal
,
npoints
=
npoints
)
self
.
_position
=
0
@
property
...
...
@@ -508,16 +525,16 @@ class FixedShapeCounter:
ascan of the associated axis between 0 and 1. This ensures
the predefined signal shape.
"""
self
.
_data
=
self
.
SIGNALS
[
self
.
_signal
](
self
.
_npoints
)
self
.
_data
=
self
.
_signal
.
compute
(
)
@
property
def
signal
(
self
):
return
self
.
_signal
return
self
.
_signal
.
name
@
signal
.
setter
def
signal
(
self
,
value
):
assert
value
in
self
.
SIGNALS
self
.
_signal
=
value
self
.
_signal
.
name
=
value
self
.
init_signal
()
@
property
...
...
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