From a7f3d91cbd9f858cbcea7c2a3af34918a7a24801 Mon Sep 17 00:00:00 2001 From: Pete R Jemian Date: Mon, 29 Nov 2021 15:45:33 -0600 Subject: [PATCH] MNT #594 SynPseudoVoigt --- CHANGES.rst | 2 + apstools/devices/__init__.py | 1 + apstools/devices/synth_pseudo_voigt.py | 163 +++++++ docs/source/resources/demo_tuneaxis.ipynb | 526 +++++++++++++--------- 4 files changed, 481 insertions(+), 211 deletions(-) create mode 100644 apstools/devices/synth_pseudo_voigt.py diff --git a/CHANGES.rst b/CHANGES.rst index b76ee87c5..f02a0526c 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -38,6 +38,8 @@ Reorganized all devices, including `synApps/`, into `devices/` subpackage. Moved ``snapshot`` application and related files to a subdirectory. +``signals.SynPseudoVoigt()`` moved to ``devices.SynPseudoVoigt()``. + Maintenance --------------- diff --git a/apstools/devices/__init__.py b/apstools/devices/__init__.py index 51ceda591..c92742dc5 100644 --- a/apstools/devices/__init__.py +++ b/apstools/devices/__init__.py @@ -46,6 +46,7 @@ from .shutters import SimulatedApsPssShutterWithStatus from .srs570_preamplifier import SRS570_PreAmplifier from .struck3820 import Struck3820 +from .synth_pseudo_voigt import SynPseudoVoigt from .tracking_signal import TrackingSignal from .xia_pf4 import DualPf4FilterBox from .xia_pf4 import Pf4FilterBank diff --git a/apstools/devices/synth_pseudo_voigt.py b/apstools/devices/synth_pseudo_voigt.py new file mode 100644 index 000000000..247b94e87 --- /dev/null +++ b/apstools/devices/synth_pseudo_voigt.py @@ -0,0 +1,163 @@ +""" +Synthetic pseudo-Voigt function ++++++++++++++++++++++++++++++++++++++++ + +EXAMPLES: + +.. code-block:: python + :caption: Simple example of SynPseudoVoigt(). + :linenos: + + from apstools.devices import SynPseudoVoigt + from ophyd.sim import motor + det = SynPseudoVoigt('det', motor, 'motor', + center=0, eta=0.5, scale=1, sigma=1, bkg=0) + + # scan the "det" peak with the "motor" positioner + # RE(bp.scan([det], motor, -2, 2, 41)) + + +.. code-block:: python + :caption: Example of SynPseudoVoigt() with randomized values. + :linenos: + + import numpy as np + from apstools.devices import SynPseudoVoigt + synthetic_pseudovoigt = SynPseudoVoigt( + 'synthetic_pseudovoigt', m1, 'm1', + center=-1.5 + 0.5*np.random.uniform(), + eta=0.2 + 0.5*np.random.uniform(), + sigma=0.001 + 0.05*np.random.uniform(), + scale=1e5, + bkg=0.01*np.random.uniform()) + + # scan the "synthetic_pseudovoigt" peak with the "m1" positioner + # RE(bp.scan([synthetic_pseudovoigt], m1, -2, 0, 219)) + +.. autosummary:: + + ~SynPseudoVoigt +""" + +import ophyd.sim +import numpy as np + + +class SynPseudoVoigt(ophyd.sim.SynSignal): # lgtm [py/missing-call-to-init] + """ + Evaluate a point on a pseudo-Voigt based on the value of a motor. + + .. index:: Ophyd Signal; SynPseudoVoigt + + Provides a signal to be measured. + Acts like a detector. + + :see: https://en.wikipedia.org/wiki/Voigt_profile + + PARAMETERS + + name + *str* : + name of detector signal + motor + ``Mover`` : + The independent coordinate + motor_field + *str* : + name of `Mover` field + center + *float* : + (optional) + location of maximum value, default=0 + eta + *float* : + (optional) + 0 <= eta < 1.0: Lorentzian fraction, default=0.5 + scale + *float* : + (optional) + scale >= 1 : scale factor, default=1 + sigma + *float* : + (optional) + sigma > 0 : width, default=1 + bkg + *float* : + (optional) + bkg >= 0 : constant background, default=0 + noise + ``"poisson"`` or ``"uniform"`` or ``None`` : + Add noise to the result. + noise_multiplier + *float* : + Only relevant for 'uniform' noise. Multiply the random amount of + noise by 'noise_multiplier' + """ + + def __init__( + # fmt: off + self, + name, motor, motor_field, + center=0, eta=0.5, scale=1, sigma=1, bkg=0, + noise=None, noise_multiplier=1, + **kwargs + # fmt: on + ): + if eta < 0.0 or eta > 1.0: + raise ValueError("eta={} must be between 0 and 1".format(eta)) + if scale < 1.0: + raise ValueError("scale must be >= 1") + if sigma <= 0.0: + raise ValueError("sigma must be > 0") + if bkg < 0.0: + raise ValueError("bkg must be >= 0") + + # remember these terms for later access by user + self.name = name + self.motor = motor + self.center = center + self.eta = eta + self.scale = scale + self.sigma = sigma + self.bkg = bkg + self.noise = noise + self.noise_multiplier = noise_multiplier + + def f_lorentzian(x, gamma): + # return gamma / np.pi / (x**2 + gamma**2) + return 1 / np.pi / gamma / (1 + (x / gamma) ** 2) + + def f_gaussian(x, sigma): + numerator = np.exp(-0.5 * (x / sigma) ** 2) + denominator = sigma * np.sqrt(2 * np.pi) + return numerator / denominator + + def pvoigt(): + m = motor.read()[motor_field]["value"] + g_max = f_gaussian(0, sigma) # peak normalization + l_max = f_lorentzian(0, sigma) + v = bkg + if eta > 0: + v += eta * f_lorentzian(m - center, sigma) / l_max + if eta < 1: + v += (1 - eta) * f_gaussian(m - center, sigma) / g_max + v *= scale + if noise == "poisson": + v = int(np.random.poisson(np.round(v), 1)) + elif noise == "uniform": + v += np.random.uniform(-1, 1) * noise_multiplier + return v + + ophyd.sim.SynSignal.__init__( + self, name=name, func=pvoigt, **kwargs + ) + +# ----------------------------------------------------------------------------- +# :author: Pete R. Jemian +# :email: jemian@anl.gov +# :copyright: (c) 2017-2022, UChicago Argonne, LLC +# +# Distributed under the terms of the Creative Commons Attribution 4.0 International Public License. +# +# The full license is in the file LICENSE.txt, distributed with this software. +# ----------------------------------------------------------------------------- diff --git a/docs/source/resources/demo_tuneaxis.ipynb b/docs/source/resources/demo_tuneaxis.ipynb index b0345c318..f3454cbbb 100644 --- a/docs/source/resources/demo_tuneaxis.ipynb +++ b/docs/source/resources/demo_tuneaxis.ipynb @@ -10,38 +10,24 @@ "\n", "We'll use a software-only (not connected to hardware) motor as a positioner. Here, we prepare a signal that is a computation based on the value of our positioner. The computed signal is a model of a realistic diffraction peak ([pseudo-Voigt](https://en.wikipedia.org/wiki/Voigt_profile), a mixture of a Gaussian and a Lorentzian) one might encounter in a powder diffraction scan. The model peak is a pseudo-voigt function to which some noise has been added. Random numbers are used to modify the ideal pseudo-voigt function so as to simulate a realistic signal.\n", "\n", - "For this demo, we do not need the databroker since we do not plan to review any of this data after collection. We'll display the data during the scan using the *BestEffortCallback()* code." + "For this demo, we do not need the databroker since we do not plan to review any of this data after collection. We'll display the data during the scan using the *LiveTable()* code." ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "0" - ] - }, - "execution_count": 1, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ - "from ophyd import EpicsMotor\n", - "from apstools.synApps_ophyd import swaitRecord, swait_setup_random_number\n", - "from apstools.signals import SynPseudoVoigt\n", + "from apstools.devices import SynPseudoVoigt\n", "from apstools.plans import TuneAxis\n", + "from bluesky import RunEngine\n", + "from bluesky import plans as bp\n", "from bluesky.callbacks import LiveTable\n", "import numpy as np\n", - "from databroker import Broker\n", - "from bluesky import RunEngine\n", + "from ophyd import EpicsMotor\n", "\n", - "RE = RunEngine({})\n", - "db = Broker.named(\"mongodb_config\")\n", - "RE.subscribe(db.insert)" + "RE = RunEngine({})\n" ] }, { @@ -57,11 +43,7 @@ "metadata": {}, "outputs": [], "source": [ - "import socket\n", - "if socket.gethostname().find(\"mint-vm\") >= 0:\n", - " prefix = \"vm7:\"\n", - "else:\n", - " prefix = \"xxx:\"" + "IOC = \"gp:\"" ] }, { @@ -77,7 +59,7 @@ "metadata": {}, "outputs": [], "source": [ - "m1 = EpicsMotor(prefix+\"m1\", name=\"m1\")\n", + "m1 = EpicsMotor(f\"{IOC}m1\", name=\"m1\")\n", "m1.wait_for_connection()" ] }, @@ -102,15 +84,88 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "## Setup the simulated detector signal. \n", - "\n", - "Randomize the values a bit so that we have something interesting to find with `TuneAxis()`." + "## Setup the simulated detector signal. " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Make a simple scan with a simulated motor and the `SynPseudoVoigt()` signal." ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "\n", + "+-----------+------------+------------+------------+\n", + "| seq_num | time | motor | det |\n", + "+-----------+------------+------------+------------+\n", + "| 1 | 15:32:07.1 | -3.000 | 0.056 |\n", + "| 2 | 15:32:07.1 | -2.667 | 0.076 |\n", + "| 3 | 15:32:07.1 | -2.333 | 0.110 |\n", + "| 4 | 15:32:07.1 | -2.000 | 0.168 |\n", + "| 5 | 15:32:07.1 | -1.667 | 0.257 |\n", + "| 6 | 15:32:07.1 | -1.333 | 0.386 |\n", + "| 7 | 15:32:07.1 | -1.000 | 0.553 |\n", + "| 8 | 15:32:07.1 | -0.667 | 0.747 |\n", + "| 9 | 15:32:07.1 | -0.333 | 0.923 |\n", + "| 10 | 15:32:07.1 | 0.000 | 1.000 |\n", + "| 11 | 15:32:07.1 | 0.333 | 0.923 |\n", + "| 12 | 15:32:07.1 | 0.667 | 0.747 |\n", + "| 13 | 15:32:07.1 | 1.000 | 0.553 |\n", + "| 14 | 15:32:07.1 | 1.333 | 0.386 |\n", + "| 15 | 15:32:07.1 | 1.667 | 0.257 |\n", + "| 16 | 15:32:07.1 | 2.000 | 0.168 |\n", + "| 17 | 15:32:07.1 | 2.333 | 0.110 |\n", + "| 18 | 15:32:07.2 | 2.667 | 0.076 |\n", + "| 19 | 15:32:07.2 | 3.000 | 0.056 |\n", + "+-----------+------------+------------+------------+\n", + "generator scan ['2d2bf557'] (scan num: 1)\n", + "\n", + "\n" + ] + }, + { + "data": { + "text/plain": [ + "('2d2bf557-4929-4ed3-8112-02de3e9b79ba',)" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "from ophyd.sim import motor\n", + "\n", + "det = SynPseudoVoigt('det', motor, 'motor',\n", + " center=0, eta=0.5, scale=1, sigma=1, bkg=0)\n", + "\n", + "live_table = LiveTable([\"motor\", \"det\"])\n", + "\n", + "RE(bp.scan([det], motor, -3, 3, 19), live_table)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Make a new signal with randomized values so that we have something interesting to find with `TuneAxis()`." + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, "outputs": [], "source": [ "spvoigt = SynPseudoVoigt(\n", @@ -131,27 +186,27 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 7, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "spvoigt.scale: 100000.0\n", - "spvoigt.center: -1.3940973681450914\n", - "spvoigt.sigma: 0.025534621641250733\n", - "spvoigt.eta: 0.2993015167776747\n", - "spvoigt.bkg: 0.0045580721055284755\n" + "spvoigt.scale = 100000.0\n", + "spvoigt.center = -1.3925351184258767\n", + "spvoigt.sigma = 0.023117195475099467\n", + "spvoigt.eta = 0.5002409281255817\n", + "spvoigt.bkg = 0.004540805634184992\n" ] } ], "source": [ - "print(\"spvoigt.scale: \", spvoigt.scale)\n", - "print(\"spvoigt.center: \", spvoigt.center)\n", - "print(\"spvoigt.sigma: \", spvoigt.sigma)\n", - "print(\"spvoigt.eta: \", spvoigt.eta)\n", - "print(\"spvoigt.bkg: \", spvoigt.bkg)" + "print(f\"{spvoigt.scale = }\")\n", + "print(f\"{spvoigt.center = }\")\n", + "print(f\"{spvoigt.sigma = }\")\n", + "print(f\"{spvoigt.eta = }\")\n", + "print(f\"{spvoigt.bkg = }\")" ] }, { @@ -163,7 +218,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 8, "metadata": {}, "outputs": [], "source": [ @@ -189,7 +244,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 9, "metadata": {}, "outputs": [], "source": [ @@ -202,17 +257,16 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Configure the *LiveTable* to also show the simulated detector signal." + "Reconfigure the *LiveTable* to also show the simulated detector signal." ] }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 10, "metadata": {}, "outputs": [], "source": [ - "live_table = LiveTable([\"m1\", \"spvoigt\"])\n", - "#spvoigt.read_attrs = [\"value\"]" + "live_table = LiveTable([\"m1\", \"spvoigt\"])" ] }, { @@ -227,133 +281,173 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 11, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ + "\n", + "\n", "+-----------+------------+------------+------------+\n", "| seq_num | time | m1 | spvoigt |\n", "+-----------+------------+------------+------------+\n", - "| 1 | 17:12:09.7 | -2.75000 | 466.418 |\n", - "| 2 | 17:12:10.2 | -2.47000 | 472.656 |\n", - "| 3 | 17:12:10.7 | -2.19000 | 486.582 |\n", - "| 4 | 17:12:11.2 | -1.92000 | 526.201 |\n", - "| 5 | 17:12:11.7 | -1.64000 | 775.096 |\n", - "| 6 | 17:12:12.2 | -1.36000 | 39939.541 |\n", - "| 7 | 17:12:12.7 | -1.08000 | 652.314 |\n", - "| 8 | 17:12:13.2 | -0.81000 | 512.898 |\n", - "| 9 | 17:12:13.7 | -0.53000 | 481.921 |\n", - "| 10 | 17:12:14.2 | -0.25000 | 470.709 |\n", + "| 1 | 15:32:09.0 | -2.75000 | 468.584 |\n", + "| 2 | 15:32:09.4 | -2.47200 | 477.012 |\n", + "| 3 | 15:32:09.9 | -2.19400 | 495.664 |\n", + "| 4 | 15:32:10.4 | -1.91700 | 551.081 |\n", + "| 5 | 15:32:10.9 | -1.63900 | 890.331 |\n", + "| 6 | 15:32:11.4 | -1.36100 | 37649.129 |\n", + "| 7 | 15:32:11.9 | -1.08300 | 731.549 |\n", + "| 8 | 15:32:12.4 | -0.80600 | 531.667 |\n", + "| 9 | 15:32:12.9 | -0.52800 | 489.822 |\n", + "| 10 | 15:32:13.4 | -0.25000 | 474.551 |\n", "+-----------+------------+------------+------------+\n", - "generator TuneAxis.multi_pass_tune ['7f7884bf'] (scan num: 1)\n", - "x : m1\n", - "y : spvoigt\n", - "cen : -1.3602204901822772\n", - "com : -1.3756508139688854\n", - "fwhm : 0.28176586200160525\n", - "min : [ -2.75 466.41822165]\n", - "max : [ -1.36000000e+00 3.99395408e+04]\n", - "crossings : [-1.50110342 -1.21933756]\n", - "tune_ok : True\n", - "center : -1.3602204901822772\n", - "initial_position : -1.5\n", - "final_position : -1.3602204901822772\n", + "generator TuneAxis.multi_pass_tune ['a4114e5d'] (scan num: 2)\n", + "\n", + "\n", + "PeakStats\n", + "================ =================================\n", + "key result \n", + "================ =================================\n", + "x m1 \n", + "y spvoigt \n", + "cen -1.3613023467014518 \n", + "com -1.377695169270274 \n", + "fwhm 0.2805848988995139 \n", + "min [ -2.75 468.5838482] \n", + "max [-1.36100000e+00 3.76491287e+04]\n", + "crossings [-1.5015948 -1.2210099] \n", + "tune_ok True \n", + "center -1.3613023467014518 \n", + "initial_position -1.5 \n", + "final_position -1.3613023467014518 \n", + "================ =================================\n", + "\n", + "\n", + "\n", "+-----------+------------+------------+------------+\n", "| seq_num | time | m1 | spvoigt |\n", "+-----------+------------+------------+------------+\n", - "| 1 | 17:12:16.3 | -1.05000 | 619.723 |\n", - "| 2 | 17:12:16.6 | -1.12000 | 713.324 |\n", - "| 3 | 17:12:16.9 | -1.19000 | 917.069 |\n", - "| 4 | 17:12:17.2 | -1.26000 | 1503.150 |\n", - "| 5 | 17:12:17.5 | -1.33000 | 7556.047 |\n", - "| 6 | 17:12:17.8 | -1.39000 | 98808.184 |\n", - "| 7 | 17:12:18.1 | -1.46000 | 6869.196 |\n", - "| 8 | 17:12:18.4 | -1.53000 | 1476.432 |\n", - "| 9 | 17:12:18.7 | -1.60000 | 909.138 |\n", - "| 10 | 17:12:19.0 | -1.67000 | 709.993 |\n", + "| 1 | 15:32:15.6 | -1.08000 | 726.277 |\n", + "| 2 | 15:32:15.9 | -1.14300 | 879.752 |\n", + "| 3 | 15:32:16.2 | -1.20500 | 1202.827 |\n", + "| 4 | 15:32:16.5 | -1.26700 | 2094.826 |\n", + "| 5 | 15:32:16.8 | -1.33000 | 7755.669 |\n", + "| 6 | 15:32:17.1 | -1.39200 | 100413.903 |\n", + "| 7 | 15:32:17.4 | -1.45500 | 7778.191 |\n", + "| 8 | 15:32:17.7 | -1.51700 | 2122.224 |\n", + "| 9 | 15:32:18.0 | -1.57900 | 1211.316 |\n", + "| 10 | 15:32:18.3 | -1.64200 | 879.990 |\n", "+-----------+------------+------------+------------+\n", - "generator TuneAxis.multi_pass_tune ['f0658421'] (scan num: 2)\n", - "x : m1\n", - "y : spvoigt\n", - "cen : -1.3925493564354836\n", - "com : -1.388063320223276\n", - "fwhm : 0.0696594765635481\n", - "min : [ -1.05 619.72273041]\n", - "max : [ -1.39000000e+00 9.88081842e+04]\n", - "crossings : [-1.35771962 -1.42737909]\n", - "tune_ok : True\n", - "center : -1.3925493564354836\n", - "initial_position : -1.36\n", - "final_position : -1.3925493564354836\n", + "generator TuneAxis.multi_pass_tune ['3d6676bd'] (scan num: 3)\n", + "\n", + "\n", + "PeakStats\n", + "================ =================================\n", + "key result \n", + "================ =================================\n", + "x m1 \n", + "y spvoigt \n", + "cen -1.3922730855240273 \n", + "com -1.3902511955043215 \n", + "fwhm 0.06724971768409405 \n", + "min [ -1.08 726.27690371] \n", + "max [-1.39200000e+00 1.00413903e+05]\n", + "crossings [-1.35864823 -1.42589794] \n", + "tune_ok True \n", + "center -1.3922730855240273 \n", + "initial_position -1.361 \n", + "final_position -1.3922730855240273 \n", + "================ =================================\n", + "\n", + "\n", + "\n", "+-----------+------------+------------+------------+\n", "| seq_num | time | m1 | spvoigt |\n", "+-----------+------------+------------+------------+\n", - "| 1 | 17:12:19.9 | -1.47000 | 4343.665 |\n", - "| 2 | 17:12:20.1 | -1.45000 | 12001.374 |\n", - "| 3 | 17:12:20.3 | -1.43000 | 36585.978 |\n", - "| 4 | 17:12:20.5 | -1.42000 | 57093.799 |\n", - "| 5 | 17:12:20.7 | -1.40000 | 97090.260 |\n", - "| 6 | 17:12:20.9 | -1.38000 | 83559.337 |\n", - "| 7 | 17:12:21.1 | -1.36000 | 39939.541 |\n", - "| 8 | 17:12:21.3 | -1.35000 | 23744.263 |\n", - "| 9 | 17:12:21.5 | -1.33000 | 7556.047 |\n", - "| 10 | 17:12:21.7 | -1.31000 | 3291.358 |\n", + "| 1 | 15:32:19.2 | -1.45900 | 6653.750 |\n", + "| 2 | 15:32:19.4 | -1.44400 | 13045.729 |\n", + "| 3 | 15:32:19.6 | -1.42900 | 29198.479 |\n", + "| 4 | 15:32:19.8 | -1.41400 | 59792.319 |\n", + "| 5 | 15:32:20.0 | -1.39900 | 94909.037 |\n", + "| 6 | 15:32:20.2 | -1.38500 | 93064.128 |\n", + "| 7 | 15:32:20.4 | -1.37000 | 57178.835 |\n", + "| 8 | 15:32:20.6 | -1.35500 | 27585.332 |\n", + "| 9 | 15:32:20.8 | -1.34000 | 12347.278 |\n", + "| 10 | 15:32:21.0 | -1.32500 | 6401.204 |\n", "+-----------+------------+------------+------------+\n", - "generator TuneAxis.multi_pass_tune ['37c188c0'] (scan num: 3)\n", - "x : m1\n", - "y : spvoigt\n", - "cen : -1.3940331552672007\n", - "com : -1.3946491706909672\n", - "fwhm : 0.05866574572145877\n", - "min : [ -1.31000000e+00 3.29135751e+03]\n", - "max : [ -1.40000000e+00 9.70902600e+04]\n", - "crossings : [-1.42336603 -1.36470028]\n", - "tune_ok : True\n", - "center : -1.3940331552672007\n", - "initial_position : -1.3900000000000001\n", - "final_position : -1.3940331552672007\n", + "generator TuneAxis.multi_pass_tune ['c1906b84'] (scan num: 4)\n", + "\n", + "\n", + "PeakStats\n", + "================ =================================\n", + "key result \n", + "================ =================================\n", + "x m1 \n", + "y spvoigt \n", + "cen -1.3925866293523317 \n", + "com -1.3924357886768364 \n", + "fwhm 0.051786583357105176 \n", + "min [-1.32500000e+00 6.40120353e+03]\n", + "max [-1.3990000e+00 9.4909037e+04] \n", + "crossings [-1.41847992 -1.36669334] \n", + "tune_ok True \n", + "center -1.3925866293523317 \n", + "initial_position -1.3920000000000001 \n", + "final_position -1.3925866293523317 \n", + "================ =================================\n", + "\n", + "\n", + "\n", "+-----------+------------+------------+------------+\n", "| seq_num | time | m1 | spvoigt |\n", "+-----------+------------+------------+------------+\n", - "| 1 | 17:12:22.4 | -1.37000 | 61175.978 |\n", - "| 2 | 17:12:22.4 | -1.37000 | 61175.978 |\n", - "| 3 | 17:12:22.4 | -1.38000 | 83559.337 |\n", - "| 4 | 17:12:22.4 | -1.38000 | 83559.337 |\n", - "| 5 | 17:12:22.5 | -1.39000 | 98808.184 |\n", - "| 6 | 17:12:22.6 | -1.39000 | 98808.184 |\n", - "| 7 | 17:12:22.6 | -1.40000 | 97090.260 |\n", - "| 8 | 17:12:22.7 | -1.40000 | 97090.260 |\n", - "| 9 | 17:12:22.7 | -1.41000 | 79738.952 |\n", - "| 10 | 17:12:22.8 | -1.41000 | 79738.952 |\n", + "| 1 | 15:32:21.7 | -1.34100 | 12998.398 |\n", + "| 2 | 15:32:21.9 | -1.35300 | 24778.142 |\n", + "| 3 | 15:32:22.1 | -1.36400 | 43605.376 |\n", + "| 4 | 15:32:22.3 | -1.37600 | 72243.068 |\n", + "| 5 | 15:32:22.5 | -1.38700 | 96329.463 |\n", + "| 6 | 15:32:22.7 | -1.39900 | 94909.037 |\n", + "| 7 | 15:32:22.9 | -1.41000 | 69869.076 |\n", + "| 8 | 15:32:23.1 | -1.42200 | 41695.396 |\n", + "| 9 | 15:32:23.3 | -1.43300 | 23563.252 |\n", + "| 10 | 15:32:23.5 | -1.44500 | 12391.646 |\n", "+-----------+------------+------------+------------+\n", - "generator TuneAxis.multi_pass_tune ['44f573de'] (scan num: 4)\n", - "x : m1\n", - "y : spvoigt\n", - "cen : -1.3941302031251124\n", - "com : -1.3900000000000001\n", - "fwhm : 0.031447823793166574\n", - "min : [ -1.37000000e+00 6.11759783e+04]\n", - "max : [ -1.39000000e+00 9.88081842e+04]\n", - "crossings : [-1.37840629 -1.40985412]\n", - "tune_ok : False\n", - "center : -1.3940331552672007\n", - "initial_position : -1.3900000000000001\n", - "final_position : -1.3900000000000001\n" + "generator TuneAxis.multi_pass_tune ['3d930020'] (scan num: 5)\n", + "\n", + "\n", + "PeakStats\n", + "================ =================================\n", + "key result \n", + "================ =================================\n", + "x m1 \n", + "y spvoigt \n", + "cen -1.3925561295137476 \n", + "com -1.3926093613000814 \n", + "fwhm 0.04809881301054353 \n", + "min [-1.44500000e+00 1.23916458e+04]\n", + "max [-1.38700000e+00 9.63294635e+04]\n", + "crossings [-1.36850672 -1.41660554] \n", + "tune_ok True \n", + "center -1.3925561295137476 \n", + "initial_position -1.393 \n", + "final_position -1.3925561295137476 \n", + "================ =================================\n", + "\n" ] }, { "data": { "text/plain": [ - "('7f7884bf-c59f-49d4-aa25-6e0c5019b813',\n", - " 'f0658421-7b7e-45ef-a724-0b10538ec98d',\n", - " '37c188c0-4f24-4e9b-b8ab-d610dc8797c5',\n", - " '44f573de-35d4-4dc2-98fd-a44bd585e30b')" + "('a4114e5d-57db-43f6-88e2-bafd54bb946b',\n", + " '3d6676bd-6314-4075-ae1f-5695fa4fb910',\n", + " 'c1906b84-52b0-443b-b184-f27a7aefdfb5',\n", + " '3d930020-ea23-437e-aef3-5d1c8f614777')" ] }, - "execution_count": 10, + "execution_count": 11, "metadata": {}, "output_type": "execute_result" } @@ -371,21 +465,21 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 12, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "final: -1.39403315527\n", - "max (-1.3900000000000001, 98808.184210417196)\n", - "min (-1.3700000000000001, 61175.978285094367)\n", - "-- -1.36022049018 0.281765862002\n", - "-- -1.39254935644 0.0696594765635\n", - "-- -1.39403315527 0.0586657457215\n", - "-- -1.39413020313 0.0314478237932\n", - "m1= -1.3900000000000001 det= 79738.9517242\n" + "final: -1.3925561295137476\n", + "max (-1.387, 96329.46348824805)\n", + "min (-1.445, 12391.645821650982)\n", + "-- Signal(name='PeakStats_cen', parent='PeakStats', value=-1.3613023467014518, timestamp=1638221533.4918845) Signal(name='PeakStats_fwhm', parent='PeakStats', value=0.2805848988995139, timestamp=1638221533.4918973)\n", + "-- Signal(name='PeakStats_cen', parent='PeakStats', value=-1.3922730855240273, timestamp=1638221538.3189716) Signal(name='PeakStats_fwhm', parent='PeakStats', value=0.06724971768409405, timestamp=1638221538.3190074)\n", + "-- Signal(name='PeakStats_cen', parent='PeakStats', value=-1.3925866293523317, timestamp=1638221541.0214105) Signal(name='PeakStats_fwhm', parent='PeakStats', value=0.051786583357105176, timestamp=1638221541.0214403)\n", + "-- Signal(name='PeakStats_cen', parent='PeakStats', value=-1.3925561295137476, timestamp=1638221543.5190797) Signal(name='PeakStats_fwhm', parent='PeakStats', value=0.04809881301054353, timestamp=1638221543.5190878)\n", + "m1.position=-1.393 det=12391.645821650982\n" ] } ], @@ -395,7 +489,7 @@ "print(\"min\", tuner.peaks.min)\n", "for stat in tuner.stats:\n", " print(\"--\", stat.cen, stat.fwhm)\n", - "print(\"m1=\", m1.position, \"\", \"det=\", spvoigt.get())" + "print(f\"{m1.position=} det={spvoigt.get()}\")" ] }, { @@ -416,69 +510,79 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 13, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ + "\n", + "\n", "+-----------+------------+------------+------------+\n", "| seq_num | time | m1 | spvoigt |\n", "+-----------+------------+------------+------------+\n", - "| 1 | 17:12:25.0 | -2.75000 | 466.418 |\n", - "| 2 | 17:12:25.2 | -2.66000 | 467.980 |\n", - "| 3 | 17:12:25.5 | -2.58000 | 469.677 |\n", - "| 4 | 17:12:25.8 | -2.49000 | 472.047 |\n", - "| 5 | 17:12:26.1 | -2.41000 | 474.704 |\n", - "| 6 | 17:12:26.4 | -2.32000 | 478.553 |\n", - "| 7 | 17:12:26.7 | -2.23000 | 483.710 |\n", - "| 8 | 17:12:27.0 | -2.15000 | 489.922 |\n", - "| 9 | 17:12:27.3 | -2.06000 | 499.752 |\n", - "| 10 | 17:12:27.6 | -1.97000 | 514.531 |\n", - "| 11 | 17:12:27.9 | -1.89000 | 534.952 |\n", - "| 12 | 17:12:28.2 | -1.80000 | 573.787 |\n", - "| 13 | 17:12:28.5 | -1.72000 | 638.421 |\n", - "| 14 | 17:12:28.8 | -1.63000 | 802.419 |\n", - "| 15 | 17:12:29.1 | -1.54000 | 1345.299 |\n", - "| 16 | 17:12:29.4 | -1.46000 | 6869.196 |\n", - "| 17 | 17:12:29.7 | -1.37000 | 61175.978 |\n", - "| 18 | 17:12:30.1 | -1.28000 | 1886.595 |\n", - "| 19 | 17:12:30.4 | -1.20000 | 964.993 |\n", - "| 20 | 17:12:30.7 | -1.11000 | 695.657 |\n", - "| 21 | 17:12:31.0 | -1.03000 | 602.295 |\n", - "| 22 | 17:12:31.3 | -0.94000 | 550.148 |\n", - "| 23 | 17:12:31.6 | -0.85000 | 521.582 |\n", - "| 24 | 17:12:31.9 | -0.77000 | 505.826 |\n", - "| 25 | 17:12:32.2 | -0.68000 | 494.028 |\n", - "| 26 | 17:12:32.5 | -0.59000 | 485.959 |\n", - "| 27 | 17:12:32.8 | -0.51000 | 480.753 |\n", - "| 28 | 17:12:33.1 | -0.42000 | 476.360 |\n", - "| 29 | 17:12:33.4 | -0.34000 | 473.360 |\n", - "| 30 | 17:12:33.7 | -0.25000 | 470.709 |\n", + "| 1 | 15:32:26.0 | -2.75000 | 468.584 |\n", + "| 2 | 15:32:26.3 | -2.66400 | 470.611 |\n", + "| 3 | 15:32:26.6 | -2.57800 | 473.096 |\n", + "| 4 | 15:32:26.9 | -2.49100 | 476.226 |\n", + "| 5 | 15:32:27.2 | -2.40500 | 480.146 |\n", + "| 6 | 15:32:27.5 | -2.31900 | 485.206 |\n", + "| 7 | 15:32:27.8 | -2.23300 | 491.897 |\n", + "| 8 | 15:32:28.1 | -2.14700 | 501.001 |\n", + "| 9 | 15:32:28.4 | -2.06000 | 514.014 |\n", + "| 10 | 15:32:28.7 | -1.97400 | 533.024 |\n", + "| 11 | 15:32:29.0 | -1.88800 | 562.743 |\n", + "| 12 | 15:32:29.3 | -1.80200 | 613.021 |\n", + "| 13 | 15:32:29.6 | -1.71600 | 708.285 |\n", + "| 14 | 15:32:29.9 | -1.62900 | 927.652 |\n", + "| 15 | 15:32:30.2 | -1.54300 | 1607.658 |\n", + "| 16 | 15:32:30.5 | -1.45700 | 7177.590 |\n", + "| 17 | 15:32:30.8 | -1.37100 | 59619.402 |\n", + "| 18 | 15:32:31.1 | -1.28400 | 2625.801 |\n", + "| 19 | 15:32:31.4 | -1.19800 | 1150.649 |\n", + "| 20 | 15:32:31.7 | -1.11200 | 791.473 |\n", + "| 21 | 15:32:32.0 | -1.02600 | 652.276 |\n", + "| 22 | 15:32:32.3 | -0.94000 | 584.281 |\n", + "| 23 | 15:32:32.6 | -0.85300 | 545.748 |\n", + "| 24 | 15:32:32.9 | -0.76700 | 522.307 |\n", + "| 25 | 15:32:33.2 | -0.68100 | 506.828 |\n", + "| 26 | 15:32:33.5 | -0.59500 | 496.074 |\n", + "| 27 | 15:32:33.8 | -0.50900 | 488.303 |\n", + "| 28 | 15:32:34.1 | -0.42200 | 482.445 |\n", + "| 29 | 15:32:34.4 | -0.33600 | 478.018 |\n", + "| 30 | 15:32:34.7 | -0.25000 | 474.551 |\n", "+-----------+------------+------------+------------+\n", - "generator TuneAxis.tune ['957d83c1'] (scan num: 5)\n", - "x : m1\n", - "y : spvoigt\n", - "cen : -1.3721138038388505\n", - "com : -1.399197379943788\n", - "fwhm : 0.09638340566154024\n", - "min : [ -2.75 466.41822165]\n", - "max : [ -1.37000000e+00 6.11759783e+04]\n", - "crossings : [-1.42030551 -1.3239221 ]\n", - "tune_ok : True\n", - "center : -1.3721138038388505\n", - "initial_position : -1.5\n", - "final_position : -1.3721138038388505\n" + "generator TuneAxis.tune ['b3666b8f'] (scan num: 6)\n", + "\n", + "\n", + "PeakStats\n", + "================ =================================\n", + "key result \n", + "================ =================================\n", + "x m1 \n", + "y spvoigt \n", + "cen -1.372677305136548 \n", + "com -1.3988438773310985 \n", + "fwhm 0.09364757525546175 \n", + "min [ -2.75 468.5838482] \n", + "max [-1.37100000e+00 5.96194017e+04]\n", + "crossings [-1.41950109 -1.32585352] \n", + "tune_ok True \n", + "center -1.372677305136548 \n", + "initial_position -1.5 \n", + "final_position -1.372677305136548 \n", + "================ =================================\n", + "\n" ] }, { "data": { "text/plain": [ - "('957d83c1-9f11-47df-936b-ce14a396cd76',)" + "('b3666b8f-df97-4f76-b353-c0f7f7716f99',)" ] }, - "execution_count": 12, + "execution_count": 13, "metadata": {}, "output_type": "execute_result" } @@ -500,19 +604,19 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 14, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "final: -1.37211380384\n", - "max (-1.3700000000000001, 61175.978285094367)\n", - "min (-2.75, 466.41822164640951)\n", - "centroid -1.37211380384\n", - "FWHM 0.0963834056615\n", - "m1= -1.37 det= 470.708557361\n" + "final: -1.372677305136548\n", + "max (-1.371, 59619.401745892595)\n", + "min (-2.75, 468.58384819985065)\n", + "centroid -1.372677305136548\n", + "FWHM 0.09364757525546175\n", + "m1.position=-1.373 det=474.5512608494155\n" ] } ], @@ -522,7 +626,7 @@ "print(\"min\", tuner.peaks.min)\n", "print(\"centroid\", tuner.peaks.cen)\n", "print(\"FWHM\", tuner.peaks.fwhm)\n", - "print(\"m1=\", m1.position, \"\", \"det=\", spvoigt.value)" + "print(f\"{m1.position=} det={spvoigt.get()}\")" ] } ], @@ -542,9 +646,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.6" + "version": "3.9.7" } }, "nbformat": 4, "nbformat_minor": 2 -} \ No newline at end of file +}