{ "cells": [ { "cell_type": "markdown", "id": "4a03e7e9-5884-4158-8ff2-f890ce1415ed", "metadata": {}, "source": [ "# DataMap examples\n", "\n", "`DataMaps` are configurable objects with the purpose of translating PV values to simulation inputs. They do *not* retain any values. Rather, they provide methods `.to_tao(pvdata)`, `.to_bmad(pvdata)` that will produce input for Tao and Bmad, respectively, from a dict-like `pvdata` object with the actual PV names and values. " ] }, { "cell_type": "code", "execution_count": 1, "id": "d064fd74-f9d2-4c17-8c55-04e44a294c0c", "metadata": {}, "outputs": [], "source": [ "# Useful for debugging\n", "%load_ext autoreload\n", "%autoreload 2\n", "\n", "%config InlineBackend.figure_format = 'retina'" ] }, { "cell_type": "markdown", "id": "7591a99a-86f6-4b7a-883d-7e1c6f6d4155", "metadata": {}, "source": [ "## PVDATA\n", "\n", "Get some actual data that we will use to map" ] }, { "cell_type": "code", "execution_count": 2, "id": "d546b044-bec2-430e-a2bc-b3a397096d58", "metadata": {}, "outputs": [], "source": [ "import json\n", "import os" ] }, { "cell_type": "code", "execution_count": 3, "id": "1a76f3a1-d471-432a-be5b-c91700a12393", "metadata": { "tags": [] }, "outputs": [ { "data": { "text/plain": [ "740" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "PVDATA = json.load(open('data/PVDATA-2021-04-21T08:10:25.000000-07:00.json'))\n", "len(PVDATA)" ] }, { "cell_type": "markdown", "id": "a5969162-c237-41c1-a47c-a8c336b53166", "metadata": {}, "source": [ "# Tabular\n", "\n", "Often PVs have a simple linear mapping to simulation inputs. The `TabularDataMap` helps with this" ] }, { "cell_type": "code", "execution_count": 4, "id": "fbfe1532-8716-4fbd-8ce7-cf9e7a3aa08a", "metadata": {}, "outputs": [], "source": [ "from lcls_live.datamaps.tabular import TabularDataMap\n", "\n", "import pandas as pd\n", "import dataclasses " ] }, { "cell_type": "code", "execution_count": 5, "id": "289fffaf-9942-42d1-8654-830d754404e8", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
namepvnamebmad_factorbmad_namebmad_attributedescriptionbmad_offset
0BC1_offsetBMLN:LI21:235:MOTR0.001O_BC1_OFFSEToffsetNaNNaN
1BC2_offsetBMLN:LI24:805:MOTR0.001O_BC2_OFFSEToffsetNaNNaN
2L1_phaseACCL:LI21:1:L1S_S_PV0.000O_L1phase_degControls the L1 phase, which is the single kly...NaN
3L2_phaseACCL:LI22:1:PDES1.000O_L2phase_degNaNNaN
4L3_phaseACCL:LI25:1:PDESNaNO_L3phase_degNaN0.0
\n", "
" ], "text/plain": [ " name pvname bmad_factor bmad_name bmad_attribute \\\n", "0 BC1_offset BMLN:LI21:235:MOTR 0.001 O_BC1_OFFSET offset \n", "1 BC2_offset BMLN:LI24:805:MOTR 0.001 O_BC2_OFFSET offset \n", "2 L1_phase ACCL:LI21:1:L1S_S_PV 0.000 O_L1 phase_deg \n", "3 L2_phase ACCL:LI22:1:PDES 1.000 O_L2 phase_deg \n", "4 L3_phase ACCL:LI25:1:PDES NaN O_L3 phase_deg \n", "\n", " description bmad_offset \n", "0 NaN NaN \n", "1 NaN NaN \n", "2 Controls the L1 phase, which is the single kly... NaN \n", "3 NaN NaN \n", "4 NaN 0.0 " ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Make some tabular data\n", "dat0 = [\n", " \n", " {'name': 'BC1_offset',\n", " 'pvname':'BMLN:LI21:235:MOTR', # mm\n", " 'bmad_factor': 0.001,\n", " 'bmad_name': 'O_BC1_OFFSET',\n", " 'bmad_attribute': 'offset'\n", " },\n", " \n", " {'name': 'BC2_offset',\n", " 'pvname':'BMLN:LI24:805:MOTR', # mm\n", " 'bmad_factor': 0.001,\n", " 'bmad_name': 'O_BC2_OFFSET',\n", " 'bmad_attribute': 'offset'\n", " },\n", " \n", " {\n", " 'name': 'L1_phase',\n", " 'description': 'Controls the L1 phase, which is the single klystron L21_1. We will disable this for now, because the KlystronDataMap handles the phase directly.',\n", " 'pvname': 'ACCL:LI21:1:L1S_S_PV',\n", " 'bmad_name':'O_L1',\n", " 'bmad_factor': 0, # We'll disable this for now. The Klystron handles it. \n", " 'bmad_attribute':'phase_deg'\n", " \n", "}\n", "]\n", "\n", "dat_hxr = [\n", " {\n", " 'name': 'L2_phase',\n", " 'pvname': 'ACCL:LI22:1:PDES',\n", " 'bmad_name':'O_L2',\n", " 'bmad_factor': 1,\n", " 'bmad_attribute':'phase_deg'\n", " \n", "},\n", " {\n", " 'name': 'L3_phase',\n", " 'pvname': 'ACCL:LI25:1:PDES',\n", " 'bmad_name':'O_L3',\n", " 'bmad_attribute':'phase_deg',\n", " 'bmad_offset': 0\n", " \n", "}, \n", "]\n", "\n", "# SXR has different PVs\n", "dat_sxr = [\n", " {\n", " 'name': 'L2_phase',\n", " 'pvname': 'ACCL:LI22:1:PDES:SETDATA_1',\n", " 'bmad_name':'O_L2',\n", " 'bmad_factor': 1,\n", " 'bmad_attribute':'phase_deg'\n", " \n", "},\n", " {\n", " 'name': 'L3_phase',\n", " 'pvname': 'ACCL:LI25:1:PDES:SETDATA_1',\n", " 'bmad_name':'O_L3',\n", " 'bmad_attribute':'phase_deg',\n", " 'bmad_offset': 0\n", " \n", "}, \n", "]\n", "\n", "\n", "#Note that there are sone NaNs here. That's okay.\n", "df = pd.DataFrame(dat0+dat_hxr)\n", "df" ] }, { "cell_type": "code", "execution_count": 6, "id": "1b64ebeb-9b23-4fd0-8035-275030f22f13", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['BMLN:LI21:235:MOTR',\n", " 'BMLN:LI24:805:MOTR',\n", " 'ACCL:LI21:1:L1S_S_PV',\n", " 'ACCL:LI22:1:PDES',\n", " 'ACCL:LI25:1:PDES']" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Make the DataMap object, identifying the columns to be used\n", "DM = TabularDataMap(df, pvname='pvname', element='bmad_name', attribute='bmad_attribute', factor='bmad_factor', offset='bmad_offset')\n", "\n", "DM.pvlist" ] }, { "cell_type": "code", "execution_count": 7, "id": "f16aeca9-2e50-4751-9f4c-b0f8e331c065", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['O_BC1_OFFSET[offset] = 0.001 * 247.85581047127175',\n", " 'O_BC2_OFFSET[offset] = 0.001 * 385.0',\n", " 'O_L1[phase_deg] = 0.0 * -22.43420088792822',\n", " 'O_L2[phase_deg] = -36.284427384073055',\n", " 'O_L3[phase_deg] = 0.0']" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Process the data for Bmad commands\n", "DM.as_bmad(PVDATA)" ] }, { "cell_type": "code", "execution_count": 8, "id": "efde17a8-fadb-4883-af48-9413af2432d7", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['set ele O_BC1_OFFSET offset = 0.001 * 247.85581047127175',\n", " 'set ele O_BC2_OFFSET offset = 0.001 * 385.0',\n", " 'set ele O_L1 phase_deg = 0.0 * -22.43420088792822',\n", " 'set ele O_L2 phase_deg = -36.284427384073055',\n", " 'set ele O_L3 phase_deg = 0.0']" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# or Tao commands\n", "DM.as_tao(PVDATA)" ] }, { "cell_type": "code", "execution_count": 9, "id": "26063c63-ced3-4ffb-8eb1-edf2af6459ca", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
namepvnamebmad_factorbmad_namebmad_attributedescriptionbmad_offset
0BC1_offsetBMLN:LI21:235:MOTR0.001O_BC1_OFFSEToffsetNoneNaN
1BC2_offsetBMLN:LI24:805:MOTR0.001O_BC2_OFFSEToffsetNoneNaN
2L1_phaseACCL:LI21:1:L1S_S_PV0.000O_L1phase_degControls the L1 phase, which is the single kly...NaN
3L2_phaseACCL:LI22:1:PDES1.000O_L2phase_degNoneNaN
4L3_phaseACCL:LI25:1:PDESNaNO_L3phase_degNone0.0
\n", "
" ], "text/plain": [ " name pvname bmad_factor bmad_name bmad_attribute \\\n", "0 BC1_offset BMLN:LI21:235:MOTR 0.001 O_BC1_OFFSET offset \n", "1 BC2_offset BMLN:LI24:805:MOTR 0.001 O_BC2_OFFSET offset \n", "2 L1_phase ACCL:LI21:1:L1S_S_PV 0.000 O_L1 phase_deg \n", "3 L2_phase ACCL:LI22:1:PDES 1.000 O_L2 phase_deg \n", "4 L3_phase ACCL:LI25:1:PDES NaN O_L3 phase_deg \n", "\n", " description bmad_offset \n", "0 None NaN \n", "1 None NaN \n", "2 Controls the L1 phase, which is the single kly... NaN \n", "3 None NaN \n", "4 None 0.0 " ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Save, and reload\n", "JSON_OUT = 'linac_TabularDataMap.json'\n", "\n", "DM.to_json(JSON_OUT)\n", "\n", "DM2 = TabularDataMap.from_json(open(JSON_OUT).read())\n", "DM2.data" ] }, { "cell_type": "code", "execution_count": 10, "id": "0715e857-f90f-4f5e-ae70-93ff8f6df776", "metadata": {}, "outputs": [], "source": [ "# cleanup\n", "os.remove(JSON_OUT)" ] }, { "cell_type": "markdown", "id": "c26059a7-e3e0-408d-a83f-b3ea2d060c5b", "metadata": {}, "source": [ "## from CSV" ] }, { "cell_type": "code", "execution_count": 11, "id": "7838105c-eb4a-49b8-bb02-ac18000aef96", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Index(['device_name', 'attribute', 'unit', 'bmad_ele_name', 'bmad_factor',\n", " 'bmad_attribute', 'example_value'],\n", " dtype='object')" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Read a previously made csv file. This has slightly different columns\n", "df2 = pd.read_csv('../lcls_live/data/cu_hxr/quad_mapping.csv')[0:10]\n", "df2.columns" ] }, { "cell_type": "code", "execution_count": 12, "id": "8512b523-f963-4dd7-9ec9-e4dfde35d548", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['QUAD:LI21:211:BDES',\n", " 'QUAD:LI21:221:BDES',\n", " 'QUAD:LI21:243:BDES',\n", " 'QUAD:LI21:251:BDES',\n", " 'QUAD:LI21:271:BDES',\n", " 'QUAD:LI21:335:BDES',\n", " 'QUAD:LI24:713:BDES',\n", " 'QUAD:LI24:740:BDES',\n", " 'QUAD:LI24:860:BDES',\n", " 'QUAD:LI24:892:BDES']" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df2['pvname'] = df2['device_name']+':'+df2['attribute']\n", "\n", "DM2 = TabularDataMap(df2, pvname='pvname', element='bmad_ele_name', attribute='bmad_attribute', factor='bmad_factor', offset='')\n", "DM2.pvlist" ] }, { "cell_type": "code", "execution_count": 13, "id": "cede21e7-edeb-482f-877f-e9f6fd57b52e", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['set ele QM11 b1_gradient = -1/(10.0*0.108) * 4.2315152',\n", " 'set ele CQ11 b1_gradient = -1/(10.0*0.108) * -0.0204323',\n", " 'set ele SQ13 b1_gradient = -1/(10.0*0.160) * 0.0',\n", " 'set ele CQ12 b1_gradient = -1/(10.0*0.108) * -0.2459959',\n", " 'set ele QM12 b1_gradient = -1/(10.0*0.108) * -6.1242668',\n", " 'set ele QM15 b1_gradient = -1/(10.0*0.108) * -5.47263',\n", " 'set ele QM21 b1_gradient = -1/(10.0*0.461) * 35.4159609',\n", " 'set ele CQ21 b1_gradient = -1/(10.0*0.108) * -0.0621288',\n", " 'set ele CQ22 b1_gradient = -1/(10.0*0.108) * 1.35389',\n", " 'set ele QM22 b1_gradient = -1/(10.0*0.461) * -40.7820027']" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Here these aren't in our PVDATA\n", "DM2.as_tao(PVDATA)" ] }, { "cell_type": "code", "execution_count": 14, "id": "15361e67-7afa-49e3-94fc-d79e522f9339", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# We could check beforehand:\n", "missing = [name for name in DM2.pvlist if name not in PVDATA]\n", "len(missing)" ] }, { "cell_type": "markdown", "id": "bfbd6b49-9b00-4f6e-9b8a-f7d1a44e015c", "metadata": {}, "source": [ "## Quads from Pytao" ] }, { "cell_type": "code", "execution_count": 15, "id": "ebfef8ad-6fa5-4af0-bc8b-526393df047c", "metadata": {}, "outputs": [], "source": [ "from pytao import Tao\n", "tao = Tao('-init $LCLS_LATTICE/bmad/models/cu_hxr/tao.init -slice OTR2:END -noplot')" ] }, { "cell_type": "code", "execution_count": 16, "id": "bd978025-8388-4162-b065-077d33f78cc3", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'bmad_name': 'QM01',\n", " 'pvname_rbv': 'QUAD:IN20:631:BACT',\n", " 'pvname': 'QUAD:IN20:631:BDES',\n", " 'bmad_factor': -0.9259259259259259,\n", " 'bmad_attribute': 'b1_gradient'}" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "def quad_pvinfo(tao, ele):\n", " \"\"\"\n", " Returns dict of PV information for use in a DataMap\n", " \"\"\"\n", " head = tao.ele_head(ele)\n", " attrs = tao.ele_gen_attribs(ele)\n", " device = head['alias']\n", " \n", " d = {}\n", " d['bmad_name'] = ele\n", " d['pvname_rbv'] = device+':BACT'\n", " d['pvname'] = device+':BDES' \n", " d['bmad_factor'] = -1/attrs['L']/10\n", " d['bmad_attribute'] = 'b1_gradient'\n", " return d\n", "\n", "quad_pvinfo(tao, 'QM01')" ] }, { "cell_type": "code", "execution_count": 17, "id": "7df071bb-ce45-4026-b4c6-2ab1653f98d5", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
bmad_namepvname_rbvpvnamebmad_factorbmad_attribute
0QM01QUAD:IN20:631:BACTQUAD:IN20:631:BDES-0.925926b1_gradient
1QM02QUAD:IN20:651:BACTQUAD:IN20:651:BDES-0.925926b1_gradient
2QBQUAD:IN20:731:BACTQUAD:IN20:731:BDES-0.936330b1_gradient
3QM03QUAD:IN20:771:BACTQUAD:IN20:771:BDES-0.925926b1_gradient
4QM04QUAD:IN20:781:BACTQUAD:IN20:781:BDES-0.925926b1_gradient
..................
180QHXH47QUAD:UNDH:4780:BACTQUAD:UNDH:4780:BDES-1.190476b1_gradient
181QUE1QUAD:DMPH:300:BACTQUAD:DMPH:300:BDES-0.181818b1_gradient
182QUE2QUAD:DMPH:380:BACTQUAD:DMPH:380:BDES-0.181818b1_gradient
183QDMP1QUAD:DMPH:500:BACTQUAD:DMPH:500:BDES-0.232558b1_gradient
184QDMP2QUAD:DMPH:600:BACTQUAD:DMPH:600:BDES-0.232558b1_gradient
\n", "

185 rows × 5 columns

\n", "
" ], "text/plain": [ " bmad_name pvname_rbv pvname bmad_factor \\\n", "0 QM01 QUAD:IN20:631:BACT QUAD:IN20:631:BDES -0.925926 \n", "1 QM02 QUAD:IN20:651:BACT QUAD:IN20:651:BDES -0.925926 \n", "2 QB QUAD:IN20:731:BACT QUAD:IN20:731:BDES -0.936330 \n", "3 QM03 QUAD:IN20:771:BACT QUAD:IN20:771:BDES -0.925926 \n", "4 QM04 QUAD:IN20:781:BACT QUAD:IN20:781:BDES -0.925926 \n", ".. ... ... ... ... \n", "180 QHXH47 QUAD:UNDH:4780:BACT QUAD:UNDH:4780:BDES -1.190476 \n", "181 QUE1 QUAD:DMPH:300:BACT QUAD:DMPH:300:BDES -0.181818 \n", "182 QUE2 QUAD:DMPH:380:BACT QUAD:DMPH:380:BDES -0.181818 \n", "183 QDMP1 QUAD:DMPH:500:BACT QUAD:DMPH:500:BDES -0.232558 \n", "184 QDMP2 QUAD:DMPH:600:BACT QUAD:DMPH:600:BDES -0.232558 \n", "\n", " bmad_attribute \n", "0 b1_gradient \n", "1 b1_gradient \n", "2 b1_gradient \n", "3 b1_gradient \n", "4 b1_gradient \n", ".. ... \n", "180 b1_gradient \n", "181 b1_gradient \n", "182 b1_gradient \n", "183 b1_gradient \n", "184 b1_gradient \n", "\n", "[185 rows x 5 columns]" ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "quad_names = tao.lat_list('quad::*', 'ele.name', flags='-no_slaves')\n", "\n", "dfq = pd.DataFrame([quad_pvinfo(tao, ele) for ele in quad_names])\n", "dfq" ] }, { "cell_type": "code", "execution_count": 18, "id": "370926df-9299-40c8-bbb5-f520de5330ce", "metadata": {}, "outputs": [], "source": [ "QUAD_DATAMAP = TabularDataMap(dfq, pvname='pvname', element='bmad_name', attribute = 'bmad_attribute', factor='bmad_factor')" ] }, { "cell_type": "code", "execution_count": 19, "id": "af85dd1a-2a37-4b7c-ba66-75831b1dda02", "metadata": {}, "outputs": [], "source": [ "#JSONFILE = os.path.join(data_dir, 'cu_hxr/quad_TabularDataMap.json')\n", "#QUAD_DATAMAP.to_json(JSONFILE)" ] }, { "cell_type": "markdown", "id": "d1877eec-f5e5-4186-93e7-704f918e6733", "metadata": {}, "source": [ "## Measurements for Tao" ] }, { "cell_type": "code", "execution_count": 20, "id": "0a2754f3-3efe-414f-83ff-82215f49cd32", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['set data BC1.energy[1]|meas = 1000000000.0 * 0.22',\n", " 'set data BC2.energy[1]|meas = 1000000000.0 * 4.5',\n", " 'set data L3.energy[2]|meas = 1000000000.0 * 11.0']" ] }, "execution_count": 20, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# The syntax is flexible enough to use for getting measurements for Tao\n", "ENERGY_MEAS = [\n", " {\n", " 'name': 'L1_energy',\n", " 'pvname': 'BEND:LI21:231:EDES', # or EDES\n", " 'tao_datum': 'BC1.energy[1]', \n", " 'factor': 1e9\n", " },\n", " {\n", " 'name': 'L2_energy',\n", " 'pvname': 'BEND:LI24:790:EDES', # or EDES\n", " 'tao_datum': 'BC2.energy[1]',\n", " 'factor': 1e9\n", " },\n", " {\n", " 'name': 'L3_HXR_energy',\n", " 'pvname': 'BEND:DMPH:400:EDES', # or EDES\n", " 'tao_datum': 'L3.energy[2]',\n", " 'factor': 1e9\n", " }\n", " #{\n", " #'name': 'L3_SXR_energy',\n", " #'pvname': 'BEND:DMPS:400:EDES', # or EDES\n", " #'factor': 1e9\n", " #}, \n", "]\n", "df = pd.DataFrame(ENERGY_MEAS)\n", "DM = TabularDataMap(df, pvname='pvname', element='tao_datum', factor='factor',\n", " tao_format = 'set data {element}|meas = {value}',\n", " bmad_format = '! No equivalent Bmad format for: set data {element}|meas = {value}'\n", " )\n", "DM.as_tao(PVDATA)" ] }, { "cell_type": "code", "execution_count": 21, "id": "795ad7e9-3e58-4fe1-9a38-70b893f3cba2", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['! No equivalent Bmad format for: set data BC1.energy[1]|meas = 1000000000.0 * 0.22',\n", " '! No equivalent Bmad format for: set data BC2.energy[1]|meas = 1000000000.0 * 4.5',\n", " '! No equivalent Bmad format for: set data L3.energy[2]|meas = 1000000000.0 * 11.0']" ] }, "execution_count": 21, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# and this will produce\n", "DM.as_bmad(PVDATA)" ] }, { "cell_type": "code", "execution_count": 22, "id": "288ab169-22e9-4dc9-ac55-720bb92e5819", "metadata": {}, "outputs": [], "source": [ "# Save\n", "#JSON_OUT = os.path.join(data_dir, 'cu_hxr/tao_energy_measurements_TabularDataMap.json')\n", "#DM.to_json(JSON_OUT)" ] }, { "cell_type": "markdown", "id": "f9a7886b-9059-4c64-b35b-1092d783c2a9", "metadata": {}, "source": [ "## Subboosters" ] }, { "cell_type": "code", "execution_count": 23, "id": "d4312122-eabb-4d7e-a0dd-e828a7e98810", "metadata": {}, "outputs": [], "source": [ "from lcls_live.datamaps.klystron import subbooster_pvinfo, SUBBOOSTER_SECTORS" ] }, { "cell_type": "code", "execution_count": 24, "id": "0f068b41-6e96-448c-804d-9fe9f352a242", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
namephase_pvnamedesciptionbmad_namebmad_attribute
0SBST_21SBST:LI21:1:PHASNormal subboosterSBST_21phase_deg
1SBST_22SBST:LI22:1:PHASNormal subboosterSBST_22phase_deg
2SBST_23SBST:LI23:1:PHASNormal subboosterSBST_23phase_deg
3SBST_24SBST:LI24:1:PHASNormal subboosterSBST_24phase_deg
4SBST_25SBST:LI25:1:PHASNormal subboosterSBST_25phase_deg
5SBST_26SBST:LI26:1:PHASNormal subboosterSBST_26phase_deg
6SBST_27SBST:LI27:1:PHASNormal subboosterSBST_27phase_deg
7SBST_28SBST:LI28:1:PHASNormal subboosterSBST_28phase_deg
8SBST_29ACCL:LI29:0:KLY_PDESSpecial feedback subbooster, beamcode 1SBST_29phase_deg
9SBST_30ACCL:LI30:0:KLY_PDESSpecial feedback subbooster, beamcode 1SBST_30phase_deg
\n", "
" ], "text/plain": [ " name phase_pvname desciption \\\n", "0 SBST_21 SBST:LI21:1:PHAS Normal subbooster \n", "1 SBST_22 SBST:LI22:1:PHAS Normal subbooster \n", "2 SBST_23 SBST:LI23:1:PHAS Normal subbooster \n", "3 SBST_24 SBST:LI24:1:PHAS Normal subbooster \n", "4 SBST_25 SBST:LI25:1:PHAS Normal subbooster \n", "5 SBST_26 SBST:LI26:1:PHAS Normal subbooster \n", "6 SBST_27 SBST:LI27:1:PHAS Normal subbooster \n", "7 SBST_28 SBST:LI28:1:PHAS Normal subbooster \n", "8 SBST_29 ACCL:LI29:0:KLY_PDES Special feedback subbooster, beamcode 1 \n", "9 SBST_30 ACCL:LI30:0:KLY_PDES Special feedback subbooster, beamcode 1 \n", "\n", " bmad_name bmad_attribute \n", "0 SBST_21 phase_deg \n", "1 SBST_22 phase_deg \n", "2 SBST_23 phase_deg \n", "3 SBST_24 phase_deg \n", "4 SBST_25 phase_deg \n", "5 SBST_26 phase_deg \n", "6 SBST_27 phase_deg \n", "7 SBST_28 phase_deg \n", "8 SBST_29 phase_deg \n", "9 SBST_30 phase_deg " ] }, "execution_count": 24, "metadata": {}, "output_type": "execute_result" } ], "source": [ "SUBBOOSTERS = []\n", "for sector in SUBBOOSTER_SECTORS:\n", " \n", " dat = subbooster_pvinfo(sector, beamcode=1) # beamcode=1 => HXR, beamcode=2 => SXR\n", " dat['bmad_name'] = f'SBST_{sector}'\n", " dat['bmad_attribute'] = 'phase_deg'\n", " SUBBOOSTERS.append(dat)\n", "df = pd.DataFrame(SUBBOOSTERS) \n", "df " ] }, { "cell_type": "markdown", "id": "54902628-49e2-42b0-82f7-b163fd350d28", "metadata": {}, "source": [ "## Beginning Twiss measurements" ] }, { "cell_type": "code", "execution_count": 25, "id": "a3aeb0e1-19dd-4806-825d-9a768c23a84f", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
namepvnamebmad_namebmad_attribute
0OTR2_beta_x_measOTRS:IN20:571:BETA_Xbeginningbeta_a
1OTR2_beta_y_measOTRS:IN20:571:BETA_Ybeginningbeta_b
2OTR2_alpha_x_measOTRS:IN20:571:ALPHA_Xbeginningalpha_a
3OTR2_alpha_y_measOTRS:IN20:571:ALPHA_Ybeginningalpha_b
\n", "
" ], "text/plain": [ " name pvname bmad_name bmad_attribute\n", "0 OTR2_beta_x_meas OTRS:IN20:571:BETA_X beginning beta_a\n", "1 OTR2_beta_y_meas OTRS:IN20:571:BETA_Y beginning beta_b\n", "2 OTR2_alpha_x_meas OTRS:IN20:571:ALPHA_X beginning alpha_a\n", "3 OTR2_alpha_y_meas OTRS:IN20:571:ALPHA_Y beginning alpha_b" ] }, "execution_count": 25, "metadata": {}, "output_type": "execute_result" } ], "source": [ "def beginning_meas(name, pvprefix):\n", " dat = [\n", " {\n", " 'name': f'{name}_beta_x_meas',\n", " 'pvname': f'{pvprefix}:BETA_X', \n", " 'bmad_name': 'beginning', \n", " 'bmad_attribute': 'beta_a'\n", " },\n", " {\n", " 'name': f'{name}_beta_y_meas',\n", " 'pvname': f'{pvprefix}:BETA_Y', \n", " 'bmad_name': 'beginning', \n", " 'bmad_attribute': 'beta_b'\n", " },\n", " {\n", " 'name': f'{name}_alpha_x_meas',\n", " 'pvname': f'{pvprefix}:ALPHA_X', \n", " 'bmad_name': 'beginning', \n", " 'bmad_attribute': 'alpha_a'\n", " },\n", " {\n", " 'name': f'{name}_alpha_y_meas',\n", " 'pvname': f'{pvprefix}:ALPHA_Y', \n", " 'bmad_name': 'beginning', \n", " 'bmad_attribute': 'alpha_b'\n", " }, \n", " ]\n", " \n", " df= pd.DataFrame(dat)\n", "\n", " return TabularDataMap(df, pvname='pvname', element='bmad_name', attribute = 'bmad_attribute')\n", "\n", "OTR2_BEGINNING = beginning_meas('OTR2', 'OTRS:IN20:571')\n", "OTR2_BEGINNING.data\n" ] }, { "cell_type": "code", "execution_count": 26, "id": "fd841dcc-fbcb-4e15-bb7f-6067d6deb4a5", "metadata": {}, "outputs": [], "source": [ "WS02_BEGINNING = beginning_meas('WS02', 'WIRE:IN20:561')" ] }, { "cell_type": "markdown", "id": "f2a0116c-0fe8-42c3-b189-dd351a5b8403", "metadata": {}, "source": [ "# KlystronDataMap" ] }, { "cell_type": "code", "execution_count": 27, "id": "e414ca02-675c-4e5b-9dbf-b3eaca83edfc", "metadata": {}, "outputs": [], "source": [ "from lcls_live.datamaps.klystron import KlystronDataMap, klystron_pvinfo, existing_LCLS_klystrons_sector_station" ] }, { "cell_type": "code", "execution_count": 28, "id": "70a5d22f-fae1-4e94-b98f-54951d2d7a70", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "((20, 6),\n", " (20, 7),\n", " (20, 8),\n", " (21, 1),\n", " (21, 2),\n", " (21, 3),\n", " (21, 4),\n", " (21, 5),\n", " (21, 6),\n", " (21, 7),\n", " (21, 8),\n", " (22, 1),\n", " (22, 2),\n", " (22, 3),\n", " (22, 4),\n", " (22, 5),\n", " (22, 6),\n", " (22, 7),\n", " (22, 8),\n", " (23, 1),\n", " (23, 2),\n", " (23, 3),\n", " (23, 4),\n", " (23, 5),\n", " (23, 6),\n", " (23, 7),\n", " (23, 8),\n", " (24, 1),\n", " (24, 2),\n", " (24, 3),\n", " (24, 4),\n", " (24, 5),\n", " (24, 6),\n", " (25, 1),\n", " (25, 2),\n", " (25, 3),\n", " (25, 4),\n", " (25, 5),\n", " (25, 6),\n", " (25, 7),\n", " (25, 8),\n", " (26, 1),\n", " (26, 2),\n", " (26, 4),\n", " (26, 5),\n", " (26, 6),\n", " (26, 7),\n", " (26, 8),\n", " (27, 1),\n", " (27, 2),\n", " (27, 3),\n", " (27, 4),\n", " (27, 5),\n", " (27, 6),\n", " (27, 7),\n", " (27, 8),\n", " (28, 1),\n", " (28, 2),\n", " (28, 3),\n", " (28, 4),\n", " (28, 5),\n", " (28, 6),\n", " (28, 7),\n", " (28, 8),\n", " (29, 1),\n", " (29, 2),\n", " (29, 3),\n", " (29, 4),\n", " (29, 5),\n", " (29, 6),\n", " (29, 7),\n", " (29, 8),\n", " (30, 1),\n", " (30, 2),\n", " (30, 3),\n", " (30, 4),\n", " (30, 5),\n", " (30, 6),\n", " (30, 7),\n", " (30, 8))" ] }, "execution_count": 28, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Get a sector, station that exists\n", "existing_LCLS_klystrons_sector_station" ] }, { "cell_type": "code", "execution_count": 29, "id": "3c52e276-51b9-4422-ae7f-68c8187158e5", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'name': 'K30_6',\n", " 'sector': 30,\n", " 'station': 6,\n", " 'description': 'Klystron in sector 30, station 6, beamcode 1',\n", " 'enld_pvname': 'KLYS:LI30:61:ENLD',\n", " 'phase_pvname': 'KLYS:LI30:61:PHAS',\n", " 'accelerate_pvname': 'KLYS:LI30:61:BEAMCODE1_STAT',\n", " 'swrd_pvname': 'KLYS:LI30:61:SWRD',\n", " 'stat_pvname': 'KLYS:LI30:61:STAT',\n", " 'hdsc_pvname': 'KLYS:LI30:61:HDSC',\n", " 'dsta_pvname': 'KLYS:LI30:61:DSTA'}" ] }, "execution_count": 29, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# This will return a flat dict of info\n", "klystron_pvinfo(30, 6)" ] }, { "cell_type": "code", "execution_count": 30, "id": "ddcdfa73-581a-4d6b-bba3-fb168ff4c58d", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "\u001b[0;31mInit signature:\u001b[0m\n", "\u001b[0mKlystronDataMap\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0mname\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mstr\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0msector\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mint\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0mstation\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mint\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0mdescription\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mstr\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m''\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0menld_pvname\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mstr\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m''\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0mphase_pvname\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mstr\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m''\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0maccelerate_pvname\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mstr\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m''\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0mswrd_pvname\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mstr\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m''\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0mstat_pvname\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mstr\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m''\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0mhdsc_pvname\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mstr\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m''\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0mdsta_pvname\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mstr\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m''\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m->\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;31mDocstring:\u001b[0m \n", "Attributes\n", "----------\n", "bmad_name : str\n", "pvlist : list[str]\n", "\n", "Methods\n", "-------\n", "evaluate(pvdata) :\n", " Returns\n", " -------\n", " dict of:\n", " enld : float\n", " energy gain in MeV\n", " phase : float\n", " phase in deg\n", " in_use : bool\n", " \n", "as_bmad(pvdata)\n", " Returns\n", " -------\n", " list of str:\n", " Bmad lattice strings to set values extracted from pvdata\n", " \n", "as_tao(pvdata)\n", " Returns\n", " -------\n", " list of str:\n", " Tao command strings \n", " \n", "to_json(file=None)\n", " Returns\n", " -------\n", " JSON string, or writes to file if given. \n", "\n", "@classmethod\n", "from_json(s):\n", " Returns a new KlystronDataMap from a JSON string or file\n", " \n", "\u001b[0;31mFile:\u001b[0m ~/Code/GitHub/lcls-live/lcls_live/datamaps/klystron.py\n", "\u001b[0;31mType:\u001b[0m type\n", "\u001b[0;31mSubclasses:\u001b[0m \n" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "?KlystronDataMap" ] }, { "cell_type": "code", "execution_count": 31, "id": "164e79d0-c5e1-40c6-b734-469cff9e1434", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "KlystronDataMap(name='K21_6', sector=21, station=6, description='Klystron in sector 21, station 6, beamcode 1', enld_pvname='KLYS:LI21:61:ENLD', phase_pvname='KLYS:LI21:61:PHAS', accelerate_pvname='KLYS:LI21:61:BEAMCODE1_STAT', swrd_pvname='KLYS:LI21:61:SWRD', stat_pvname='KLYS:LI21:61:STAT', hdsc_pvname='KLYS:LI21:61:HDSC', dsta_pvname='KLYS:LI21:61:DSTA')" ] }, "execution_count": 31, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# This makes an object\n", "KlystronDataMap(**klystron_pvinfo(21, 6, beamcode=1))" ] }, { "cell_type": "code", "execution_count": 32, "id": "1d1ecc7e-0490-4fb5-91b8-5244e234cfa7", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['KLYS:LI21:61:ENLD',\n", " 'KLYS:LI21:61:PHAS',\n", " 'KLYS:LI21:61:BEAMCODE1_STAT',\n", " 'KLYS:LI21:61:SWRD',\n", " 'KLYS:LI21:61:STAT',\n", " 'KLYS:LI21:61:HDSC',\n", " 'KLYS:LI21:61:DSTA']" ] }, "execution_count": 32, "metadata": {}, "output_type": "execute_result" } ], "source": [ "k = KlystronDataMap(**klystron_pvinfo(21, 6, beamcode=1))\n", "\n", "# These are the PV names needed to mapping data\n", "k.pvlist\n" ] }, { "cell_type": "code", "execution_count": 33, "id": "12bd693b-b44f-4096-a787-5edcc91023f7", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'enld': 249.342, 'phase': -0.2623023986816406, 'in_use': True}" ] }, "execution_count": 33, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# This will extract those and produce useful information\n", "k.evaluate(PVDATA)" ] }, { "cell_type": "code", "execution_count": 34, "id": "a65a46a1-4014-492d-b834-5d7c9b91e7f4", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['K21_6[ENLD_MeV] = 249.342',\n", " 'K21_6[phase_deg] = -0.2623023986816406',\n", " 'K21_6[in_use] = 1']" ] }, "execution_count": 34, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Actual inputs for a simulation\n", "k.as_bmad(PVDATA)" ] }, { "cell_type": "code", "execution_count": 35, "id": "6f4d62de-d562-41c8-abbc-a5d2e90a0d41", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'{\"name\": \"K21_6\", \"sector\": 21, \"station\": 6, \"description\": \"Klystron in sector 21, station 6, beamcode 1\", \"enld_pvname\": \"KLYS:LI21:61:ENLD\", \"phase_pvname\": \"KLYS:LI21:61:PHAS\", \"accelerate_pvname\": \"KLYS:LI21:61:BEAMCODE1_STAT\", \"swrd_pvname\": \"KLYS:LI21:61:SWRD\", \"stat_pvname\": \"KLYS:LI21:61:STAT\", \"hdsc_pvname\": \"KLYS:LI21:61:HDSC\", \"dsta_pvname\": \"KLYS:LI21:61:DSTA\"}'" ] }, "execution_count": 35, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# A complete JSON string for serialization\n", "k.to_json()" ] }, { "cell_type": "code", "execution_count": 36, "id": "d5c560fe-6c77-40ed-bebf-fb10ada628f2", "metadata": {}, "outputs": [], "source": [ "# Make a large list\n", "\n", "KLYSTRON_DATAMAPS = []\n", "for sector, station in existing_LCLS_klystrons_sector_station:\n", " #print(sector, station) \n", " info = klystron_pvinfo(sector, station)\n", " k = KlystronDataMap(**info)\n", "\n", " KLYSTRON_DATAMAPS.append(k)" ] }, { "cell_type": "code", "execution_count": 37, "id": "a8b2fc9a-e3b6-4a2d-8fb3-3b66b90a061f", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "K20_6 GUN:IN20:1:GN1_AAVG\n", "K20_6 GUN:IN20:1:GN1_PAVG\n", "K20_7 ACCL:IN20:300:L0A_AACT_DS0\n", "K20_7 ACCL:IN20:300:L0A_PACT_DS0\n", "K20_8 ACCL:IN20:400:L0B_AACT_DS0\n", "K20_8 ACCL:IN20:400:L0B_PACT_DS0\n", "K21_1 ACCL:LI21:1:L1S_AACT_DS0\n", "K21_1 ACCL:LI21:1:L1S_PACT_DS0\n", "K21_2 ACCL:LI21:180:L1X_AACT_DS0\n", "K21_2 ACCL:LI21:180:L1X_PACT_DS0\n", "K24_1 ACCL:LI24:100:KLY_PDES:SETDATA_1\n", "K24_2 ACCL:LI24:200:KLY_PDES:SETDATA_1\n", "K24_3 ACCL:LI24:300:KLY_PDES:SETDATA_1\n" ] } ], "source": [ "# Check that our data is sufficient \n", "\n", "for k in KLYSTRON_DATAMAPS:\n", " for pv in k.pvlist:\n", " if pv not in PVDATA:\n", " print(k.name, pv)" ] }, { "cell_type": "code", "execution_count": 38, "id": "eef142e0-4a03-4f79-a2aa-67d5b41a7204", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'{\"name\": \"K20_6\", \"sector\": 20, \"station\": 6, \"description\": \"Klystron in sector 20, station 6, beamcode 1 for the GUN\", \"enld_pvname\": \"GUN:IN20:1:GN1_AAVG\", \"phase_pvname\": \"GUN:IN20:1:GN1_PAVG\", \"accelerate_pvname\": \"\", \"swrd_pvname\": \"\", \"stat_pvname\": \"\", \"hdsc_pvname\": \"\", \"dsta_pvname\": \"\"}'" ] }, "execution_count": 38, "metadata": {}, "output_type": "execute_result" } ], "source": [ "s = KLYSTRON_DATAMAPS[0].to_json()\n", "s" ] }, { "cell_type": "code", "execution_count": 39, "id": "cc672dd2-8b3d-495e-8e76-3c13debe8a4d", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "KlystronDataMap(name='K20_6', sector=20, station=6, description='Klystron in sector 20, station 6, beamcode 1 for the GUN', enld_pvname='GUN:IN20:1:GN1_AAVG', phase_pvname='GUN:IN20:1:GN1_PAVG', accelerate_pvname='', swrd_pvname='', stat_pvname='', hdsc_pvname='', dsta_pvname='')" ] }, "execution_count": 39, "metadata": {}, "output_type": "execute_result" } ], "source": [ "KlystronDataMap.from_json(s)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.13" } }, "nbformat": 4, "nbformat_minor": 5 }