Commit 803de542 authored by Valentin Valls's avatar Valentin Valls
Browse files

Create a OneDimSimulationCounter

parent b3129b65
Pipeline #46753 passed with stages
in 136 minutes and 36 seconds
......@@ -10,8 +10,8 @@ from scipy import signal
from scipy.special import erf
from bliss.scanning.chain import AcquisitionSlave
from bliss.common.counter import Counter, SoftCounter
from bliss.controllers.counter import CounterController
from bliss.common.counter import Counter, SoftCounter, SamplingMode, SamplingCounter
from bliss.controllers.counter import CounterController, SamplingCounterController
from bliss.common.soft_axis import SoftAxis
from bliss.common.protocols import counter_namespace
......@@ -589,6 +589,55 @@ class FixedShapeCounter:
return self._axis
class OneDimSimulationController(SamplingCounterController):
"""Controller to handle `OneDimSimulationCounter`"""
def read(self, counter):
return counter._get_data()
class OneDimSimulationCounter(SamplingCounter):
"""Create a 1D simulated counter.
signal: Name of the signal shape to generate. See `_Signal.SIGNALS`
size: Number of points to generate
coef: Coefficient applied to the generator
poissonian: If true the signal is randomized with poissonian filter
def __init__(
name: str,
controller: OneDimSimulationController,
signal: str = "sawtooth",
coef: float = 1.0,
poissonian: bool = False,
size: int = 32,
self._size = size
self._signal = _Signal(
name=signal, npoints=size, poissonian=poissonian, coef=coef
def _get_data(self):
return self._signal.compute()
def shape(self):
return (self._size,)
class AutoFilterDetMon:
"""Simulated monitor (flat signal) and detector counter with
has a gaussian shape with maximum :code:`monitor * transmission`.
# -*- coding: utf-8 -*-
# This file is part of the bliss project
# Copyright (c) 2015-2020 Beamline Control Unit, ESRF
# Distributed under the GNU LGPLv3. See LICENSE for more info.
import numpy
from bliss.controllers.simulation_counter import (
from bliss.common.counter import SamplingMode
from bliss.common.scans import loopscan
def test_onedim_simulation_counter__linear_up():
controller = OneDimSimulationController(name="onedim")
c1 = OneDimSimulationCounter(
"c1", controller=controller, signal="linear_up", coef=10, size=5
data =
expected = numpy.array([0, 2.5, 5, 7.5, 10])
numpy.testing.assert_array_equal(data, expected)
def test_onedim_simulation_counter__gaussian():
controller = OneDimSimulationController(name="onedim")
c1 = OneDimSimulationCounter(
"c1", controller=controller, signal="gaussian", coef=10, size=5
data =
expected = numpy.array([1.35, 6.07, 10., 6.07, 1.35])
numpy.testing.assert_array_almost_equal(data, expected, decimal=2)
def test_onedim_simulation_counter__acquisition(session):
"""Check acaquisition from a OneDimSimulationCounter"""
controller = OneDimSimulationController(name="onedim")
counter = OneDimSimulationCounter(
"onedim", controller, signal="linear_up", coef=10, size=5
assert counter.mode == SamplingMode.SINGLE
loops = loopscan(5, .1, counter, save=False)
data = loops.get_data()["onedim"]
expected = numpy.array([0., 2.5, 5., 7.5, 10.])
assert len(data) == 5
numpy.testing.assert_array_equal(data[0], expected)
numpy.testing.assert_array_equal(data[-1], expected)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment