From 8c7e568c25da551bb19264f9c00748c4d1886753 Mon Sep 17 00:00:00 2001 From: Laurent Mercadier <laurent.mercadier@xfel.eu> Date: Tue, 4 May 2021 21:38:21 +0200 Subject: [PATCH] Add mnemonic machinery to take into account mnemonics versions --- doc/Loading_data_in_memory.ipynb | 65 +- src/toolbox_scs/__init__.py | 4 +- src/toolbox_scs/constants.py | 718 +++++++++++---------- src/toolbox_scs/detectors/bam_detectors.py | 19 +- src/toolbox_scs/detectors/digitizers.py | 42 +- src/toolbox_scs/detectors/xgm.py | 26 +- src/toolbox_scs/load.py | 157 ++--- src/toolbox_scs/mnemonics_machinery.py | 145 +++++ 8 files changed, 657 insertions(+), 519 deletions(-) create mode 100644 src/toolbox_scs/mnemonics_machinery.py diff --git a/doc/Loading_data_in_memory.ipynb b/doc/Loading_data_in_memory.ipynb index b553347..20b40d9 100644 --- a/doc/Loading_data_in_memory.ipynb +++ b/doc/Loading_data_in_memory.ipynb @@ -31,9 +31,9 @@ { "data": { "text/plain": [ - "{'source': 'SCS_BLU_XGM/XGM/DOOCS:output',\n", - " 'key': 'data.intensityTD',\n", - " 'dim': ['XGMbunchId']}" + "({'source': 'SCS_BLU_XGM/XGM/DOOCS:output',\n", + " 'key': 'data.intensityTD',\n", + " 'dim': ['XGMbunchId']},)" ] }, "execution_count": 1, @@ -50,7 +50,28 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "The available mnemonics can be display with: `print(list(tb.mnemonics.keys()))`." + "The list of available mnemonics can vary from run to run, depending on what sources were recorded. The function `mnemonics_for_run` returns the mnemonics that correspond to actual data sources in a run (`extra_data` `DataCollection`):" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "run, _ = tb.load(2212, 213)\n", + "run_mnemonics = tb.mnemonics_for_run(run)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "<div class=\"alert alert-info\">\n", + "\n", + "The mnemonics are by no means an exhaustive list of the contents of a run, but rather convenience shortcuts to the mostly used data sources at SCS. Please refer to the [extra_data](https://extra-data.readthedocs.io/en/latest/) package to access the full list of data sources present in a run.\n", + "\n", + "</div>" ] }, { @@ -71,7 +92,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 3, "metadata": {}, "outputs": [ { @@ -439,8 +460,8 @@ " MCP3peaks (trainId, sa3_pId) float64 -197.7 -34.67 ... -1.213e+03\n", " SCS_SA3 (trainId, sa3_pId) float64 2.839e+03 897.9 ... 8.069e+03\n", "Attributes:\n", - " runFolder: /gpfs/exfel/exp/SCS/201901/p002212/raw/r0208</pre><div class='xr-wrap' hidden><div class='xr-header'><div class='xr-obj-type'>xarray.Dataset</div></div><ul class='xr-sections'><li class='xr-section-item'><input id='section-d190895c-429f-49c5-b6d3-a746eeba5ee7' class='xr-section-summary-in' type='checkbox' disabled ><label for='section-d190895c-429f-49c5-b6d3-a746eeba5ee7' class='xr-section-summary' title='Expand/collapse section'>Dimensions:</label><div class='xr-section-inline-details'><ul class='xr-dim-list'><li><span>pulse_slot</span>: 2700</li><li><span class='xr-has-index'>sa3_pId</span>: 125</li><li><span class='xr-has-index'>trainId</span>: 3066</li></ul></div><div class='xr-section-details'></div></li><li class='xr-section-item'><input id='section-4b85fc5e-de13-43f7-963b-b77286fd62b5' class='xr-section-summary-in' type='checkbox' checked><label for='section-4b85fc5e-de13-43f7-963b-b77286fd62b5' class='xr-section-summary' >Coordinates: <span>(2)</span></label><div class='xr-section-inline-details'></div><div class='xr-section-details'><ul class='xr-var-list'><li class='xr-var-item'><div class='xr-var-name'><span class='xr-has-index'>trainId</span></div><div class='xr-var-dims'>(trainId)</div><div class='xr-var-dtype'>uint64</div><div class='xr-var-preview xr-preview'>520069541 520069542 ... 520072606</div><input id='attrs-07fa6d2e-5dd2-4fed-9bc9-4bddb9616c4d' class='xr-var-attrs-in' type='checkbox' disabled><label for='attrs-07fa6d2e-5dd2-4fed-9bc9-4bddb9616c4d' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-3b328c4e-f541-4092-8778-ce46b92ce7e0' class='xr-var-data-in' type='checkbox'><label for='data-3b328c4e-f541-4092-8778-ce46b92ce7e0' title='Show/Hide data repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-var-attrs'><dl class='xr-attrs'></dl></div><div class='xr-var-data'><pre>array([520069541, 520069542, 520069543, ..., 520072604, 520072605, 520072606],\n", - " dtype=uint64)</pre></div></li><li class='xr-var-item'><div class='xr-var-name'><span class='xr-has-index'>sa3_pId</span></div><div class='xr-var-dims'>(sa3_pId)</div><div class='xr-var-dtype'>int64</div><div class='xr-var-preview xr-preview'>1040 1048 1056 ... 2016 2024 2032</div><input id='attrs-7e7b0279-e00c-4e72-b9b9-cf39b39185ac' class='xr-var-attrs-in' type='checkbox' disabled><label for='attrs-7e7b0279-e00c-4e72-b9b9-cf39b39185ac' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-e4074543-0528-49db-8695-cd0f8b95bab2' class='xr-var-data-in' type='checkbox'><label for='data-e4074543-0528-49db-8695-cd0f8b95bab2' title='Show/Hide data repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-var-attrs'><dl class='xr-attrs'></dl></div><div class='xr-var-data'><pre>array([1040, 1048, 1056, 1064, 1072, 1080, 1088, 1096, 1104, 1112, 1120, 1128,\n", + " runFolder: /gpfs/exfel/exp/SCS/201901/p002212/raw/r0208</pre><div class='xr-wrap' hidden><div class='xr-header'><div class='xr-obj-type'>xarray.Dataset</div></div><ul class='xr-sections'><li class='xr-section-item'><input id='section-5749d5d4-4669-43a9-bf34-bd10d1445694' class='xr-section-summary-in' type='checkbox' disabled ><label for='section-5749d5d4-4669-43a9-bf34-bd10d1445694' class='xr-section-summary' title='Expand/collapse section'>Dimensions:</label><div class='xr-section-inline-details'><ul class='xr-dim-list'><li><span>pulse_slot</span>: 2700</li><li><span class='xr-has-index'>sa3_pId</span>: 125</li><li><span class='xr-has-index'>trainId</span>: 3066</li></ul></div><div class='xr-section-details'></div></li><li class='xr-section-item'><input id='section-abec55c2-d5c0-4e22-82ba-37ea68bd1b34' class='xr-section-summary-in' type='checkbox' checked><label for='section-abec55c2-d5c0-4e22-82ba-37ea68bd1b34' class='xr-section-summary' >Coordinates: <span>(2)</span></label><div class='xr-section-inline-details'></div><div class='xr-section-details'><ul class='xr-var-list'><li class='xr-var-item'><div class='xr-var-name'><span class='xr-has-index'>trainId</span></div><div class='xr-var-dims'>(trainId)</div><div class='xr-var-dtype'>uint64</div><div class='xr-var-preview xr-preview'>520069541 520069542 ... 520072606</div><input id='attrs-e9c66ef0-ab66-4116-b9ab-c958ace198d4' class='xr-var-attrs-in' type='checkbox' disabled><label for='attrs-e9c66ef0-ab66-4116-b9ab-c958ace198d4' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-eef747e7-31e0-4cbc-9417-41afa22ac2ab' class='xr-var-data-in' type='checkbox'><label for='data-eef747e7-31e0-4cbc-9417-41afa22ac2ab' title='Show/Hide data repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-var-attrs'><dl class='xr-attrs'></dl></div><div class='xr-var-data'><pre>array([520069541, 520069542, 520069543, ..., 520072604, 520072605, 520072606],\n", + " dtype=uint64)</pre></div></li><li class='xr-var-item'><div class='xr-var-name'><span class='xr-has-index'>sa3_pId</span></div><div class='xr-var-dims'>(sa3_pId)</div><div class='xr-var-dtype'>int64</div><div class='xr-var-preview xr-preview'>1040 1048 1056 ... 2016 2024 2032</div><input id='attrs-375b6fcb-7273-4f21-9288-68533d2a75d5' class='xr-var-attrs-in' type='checkbox' disabled><label for='attrs-375b6fcb-7273-4f21-9288-68533d2a75d5' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-4dd1c96a-68b6-40d8-8e0f-bf7e75dbbd77' class='xr-var-data-in' type='checkbox'><label for='data-4dd1c96a-68b6-40d8-8e0f-bf7e75dbbd77' title='Show/Hide data repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-var-attrs'><dl class='xr-attrs'></dl></div><div class='xr-var-data'><pre>array([1040, 1048, 1056, 1064, 1072, 1080, 1088, 1096, 1104, 1112, 1120, 1128,\n", " 1136, 1144, 1152, 1160, 1168, 1176, 1184, 1192, 1200, 1208, 1216, 1224,\n", " 1232, 1240, 1248, 1256, 1264, 1272, 1280, 1288, 1296, 1304, 1312, 1320,\n", " 1328, 1336, 1344, 1352, 1360, 1368, 1376, 1384, 1392, 1400, 1408, 1416,\n", @@ -450,15 +471,15 @@ " 1712, 1720, 1728, 1736, 1744, 1752, 1760, 1768, 1776, 1784, 1792, 1800,\n", " 1808, 1816, 1824, 1832, 1840, 1848, 1856, 1864, 1872, 1880, 1888, 1896,\n", " 1904, 1912, 1920, 1928, 1936, 1944, 1952, 1960, 1968, 1976, 1984, 1992,\n", - " 2000, 2008, 2016, 2024, 2032])</pre></div></li></ul></div></li><li class='xr-section-item'><input id='section-0744a4dc-6a08-4bd6-a4ec-28ab10915d87' class='xr-section-summary-in' type='checkbox' checked><label for='section-0744a4dc-6a08-4bd6-a4ec-28ab10915d87' class='xr-section-summary' >Data variables: <span>(4)</span></label><div class='xr-section-inline-details'></div><div class='xr-section-details'><ul class='xr-var-list'><li class='xr-var-item'><div class='xr-var-name'><span>bunchPatternTable</span></div><div class='xr-var-dims'>(trainId, pulse_slot)</div><div class='xr-var-dtype'>uint32</div><div class='xr-var-preview xr-preview'>2139945 0 2129961 0 ... 0 0 0 0</div><input id='attrs-4a316316-f1a1-4c1c-9e40-6be175d58c3c' class='xr-var-attrs-in' type='checkbox' disabled><label for='attrs-4a316316-f1a1-4c1c-9e40-6be175d58c3c' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-3998e9f3-e48a-4d1b-80f6-3cdc00fab4c8' class='xr-var-data-in' type='checkbox'><label for='data-3998e9f3-e48a-4d1b-80f6-3cdc00fab4c8' title='Show/Hide data repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-var-attrs'><dl class='xr-attrs'></dl></div><div class='xr-var-data'><pre>array([[2139945, 0, 2129961, ..., 0, 0, 0],\n", + " 2000, 2008, 2016, 2024, 2032])</pre></div></li></ul></div></li><li class='xr-section-item'><input id='section-2bf2a4bf-5efc-4328-90f8-6434c99e0d82' class='xr-section-summary-in' type='checkbox' checked><label for='section-2bf2a4bf-5efc-4328-90f8-6434c99e0d82' class='xr-section-summary' >Data variables: <span>(4)</span></label><div class='xr-section-inline-details'></div><div class='xr-section-details'><ul class='xr-var-list'><li class='xr-var-item'><div class='xr-var-name'><span>bunchPatternTable</span></div><div class='xr-var-dims'>(trainId, pulse_slot)</div><div class='xr-var-dtype'>uint32</div><div class='xr-var-preview xr-preview'>2139945 0 2129961 0 ... 0 0 0 0</div><input id='attrs-c6f3163a-6ff8-46d0-896d-84f4a30a1274' class='xr-var-attrs-in' type='checkbox' disabled><label for='attrs-c6f3163a-6ff8-46d0-896d-84f4a30a1274' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-9f42782b-c07b-491c-aab0-bad6d85b08a5' class='xr-var-data-in' type='checkbox'><label for='data-9f42782b-c07b-491c-aab0-bad6d85b08a5' title='Show/Hide data repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-var-attrs'><dl class='xr-attrs'></dl></div><div class='xr-var-data'><pre>array([[2139945, 0, 2129961, ..., 0, 0, 0],\n", " [2141993, 0, 2129961, ..., 0, 0, 0],\n", " [2139945, 0, 2129961, ..., 0, 0, 0],\n", " ...,\n", " [2141993, 0, 2129961, ..., 0, 0, 0],\n", " [2139945, 0, 2129961, ..., 0, 0, 0],\n", " [2141993, 0, 2129961, ..., 0, 0, 0]],\n", - " dtype=uint32)</pre></div></li><li class='xr-var-item'><div class='xr-var-name'><span>nrj</span></div><div class='xr-var-dims'>(trainId)</div><div class='xr-var-dtype'>float64</div><div class='xr-var-preview xr-preview'>778.6 778.6 778.5 ... 783.4 783.4</div><input id='attrs-3133f05d-246a-498b-bbd1-a695804ca7aa' class='xr-var-attrs-in' type='checkbox' disabled><label for='attrs-3133f05d-246a-498b-bbd1-a695804ca7aa' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-8a408860-cf45-47b6-8d6c-bd86b50714b4' class='xr-var-data-in' type='checkbox'><label for='data-8a408860-cf45-47b6-8d6c-bd86b50714b4' title='Show/Hide data repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-var-attrs'><dl class='xr-attrs'></dl></div><div class='xr-var-data'><pre>array([778.62824057, 778.55124428, 778.52251822, ..., 783.36562112,\n", - " 783.3947057 , 783.37531574])</pre></div></li><li class='xr-var-item'><div class='xr-var-name'><span>MCP3peaks</span></div><div class='xr-var-dims'>(trainId, sa3_pId)</div><div class='xr-var-dtype'>float64</div><div class='xr-var-preview xr-preview'>-197.7 -34.67 ... -1.213e+03</div><input id='attrs-5734ac8d-335a-4815-9ee2-78fb4203170e' class='xr-var-attrs-in' type='checkbox' disabled><label for='attrs-5734ac8d-335a-4815-9ee2-78fb4203170e' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-ae539ba8-cec2-4f31-b1b7-2c3813777b7c' class='xr-var-data-in' type='checkbox'><label for='data-ae539ba8-cec2-4f31-b1b7-2c3813777b7c' title='Show/Hide data repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-var-attrs'><dl class='xr-attrs'></dl></div><div class='xr-var-data'><pre>array([[-1.97666667e+02, -3.46666667e+01, 1.83333333e+01, ...,\n", + " dtype=uint32)</pre></div></li><li class='xr-var-item'><div class='xr-var-name'><span>nrj</span></div><div class='xr-var-dims'>(trainId)</div><div class='xr-var-dtype'>float64</div><div class='xr-var-preview xr-preview'>778.6 778.6 778.5 ... 783.4 783.4</div><input id='attrs-160a6c0f-b0f4-436b-a1d7-e391ce9be176' class='xr-var-attrs-in' type='checkbox' disabled><label for='attrs-160a6c0f-b0f4-436b-a1d7-e391ce9be176' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-d7477817-0648-4b12-b543-4468c4bb0021' class='xr-var-data-in' type='checkbox'><label for='data-d7477817-0648-4b12-b543-4468c4bb0021' title='Show/Hide data repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-var-attrs'><dl class='xr-attrs'></dl></div><div class='xr-var-data'><pre>array([778.62824057, 778.55124428, 778.52251822, ..., 783.36562112,\n", + " 783.3947057 , 783.37531574])</pre></div></li><li class='xr-var-item'><div class='xr-var-name'><span>MCP3peaks</span></div><div class='xr-var-dims'>(trainId, sa3_pId)</div><div class='xr-var-dtype'>float64</div><div class='xr-var-preview xr-preview'>-197.7 -34.67 ... -1.213e+03</div><input id='attrs-aa041bc0-149c-49c6-b91a-5b1d2601beeb' class='xr-var-attrs-in' type='checkbox' disabled><label for='attrs-aa041bc0-149c-49c6-b91a-5b1d2601beeb' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-c711b983-98a1-4331-a8f6-cf6d597093fa' class='xr-var-data-in' type='checkbox'><label for='data-c711b983-98a1-4331-a8f6-cf6d597093fa' title='Show/Hide data repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-var-attrs'><dl class='xr-attrs'></dl></div><div class='xr-var-data'><pre>array([[-1.97666667e+02, -3.46666667e+01, 1.83333333e+01, ...,\n", " -4.95533333e+03, -2.58333333e+03, -3.64000000e+03],\n", " [-1.14000000e+02, -4.00000000e+02, -2.75000000e+02, ...,\n", " -1.89733333e+03, -1.63966667e+03, -9.57000000e+02],\n", @@ -470,7 +491,7 @@ " [-6.08666667e+02, -7.73333333e+01, 2.33333333e+00, ...,\n", " -1.58466667e+03, -9.06333333e+02, -1.04700000e+03],\n", " [-4.16666667e+01, -4.10333333e+02, 5.00000000e+01, ...,\n", - " -9.43666667e+02, -2.86800000e+03, -1.21266667e+03]])</pre></div></li><li class='xr-var-item'><div class='xr-var-name'><span>SCS_SA3</span></div><div class='xr-var-dims'>(trainId, sa3_pId)</div><div class='xr-var-dtype'>float64</div><div class='xr-var-preview xr-preview'>2.839e+03 897.9 ... 8.069e+03</div><input id='attrs-8d82e392-da97-41ca-83db-d29849d6dd1c' class='xr-var-attrs-in' type='checkbox' disabled><label for='attrs-8d82e392-da97-41ca-83db-d29849d6dd1c' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-49ac9135-f9d9-43a0-95da-0a48aff881c3' class='xr-var-data-in' type='checkbox'><label for='data-49ac9135-f9d9-43a0-95da-0a48aff881c3' title='Show/Hide data repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-var-attrs'><dl class='xr-attrs'></dl></div><div class='xr-var-data'><pre>array([[ 2838.68261719, 897.93481445, 1270.12817383, ...,\n", + " -9.43666667e+02, -2.86800000e+03, -1.21266667e+03]])</pre></div></li><li class='xr-var-item'><div class='xr-var-name'><span>SCS_SA3</span></div><div class='xr-var-dims'>(trainId, sa3_pId)</div><div class='xr-var-dtype'>float64</div><div class='xr-var-preview xr-preview'>2.839e+03 897.9 ... 8.069e+03</div><input id='attrs-a2a05ecd-eb49-4e87-9483-3a5bd014bcf6' class='xr-var-attrs-in' type='checkbox' disabled><label for='attrs-a2a05ecd-eb49-4e87-9483-3a5bd014bcf6' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-a20bc7cc-3de5-4cfd-ae37-0436989b734f' class='xr-var-data-in' type='checkbox'><label for='data-a20bc7cc-3de5-4cfd-ae37-0436989b734f' title='Show/Hide data repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-var-attrs'><dl class='xr-attrs'></dl></div><div class='xr-var-data'><pre>array([[ 2838.68261719, 897.93481445, 1270.12817383, ...,\n", " 33158.98046875, 19836.09570312, 27724.03515625],\n", " [ 2088.77197266, 861.36578369, 3565.16918945, ...,\n", " 16303.64941406, 12787.91503906, 6092.00097656],\n", @@ -482,7 +503,7 @@ " [ 3646.75048828, 2033.26245117, 569.56018066, ...,\n", " 9144.62402344, 7623.27978516, 4444.45361328],\n", " [ 708.95373535, 1963.84277344, 912.64025879, ...,\n", - " 5079.55371094, 12632.79003906, 8069.31152344]])</pre></div></li></ul></div></li><li class='xr-section-item'><input id='section-7ad05c3b-49ee-497e-9b89-5cd235a25de5' class='xr-section-summary-in' type='checkbox' checked><label for='section-7ad05c3b-49ee-497e-9b89-5cd235a25de5' class='xr-section-summary' >Attributes: <span>(1)</span></label><div class='xr-section-inline-details'></div><div class='xr-section-details'><dl class='xr-attrs'><dt><span>runFolder :</span></dt><dd>/gpfs/exfel/exp/SCS/201901/p002212/raw/r0208</dd></dl></div></li></ul></div></div>" + " 5079.55371094, 12632.79003906, 8069.31152344]])</pre></div></li></ul></div></li><li class='xr-section-item'><input id='section-cda1897f-d27d-40dd-a0fb-5ca7d116fb6b' class='xr-section-summary-in' type='checkbox' checked><label for='section-cda1897f-d27d-40dd-a0fb-5ca7d116fb6b' class='xr-section-summary' >Attributes: <span>(1)</span></label><div class='xr-section-inline-details'></div><div class='xr-section-details'><dl class='xr-attrs'><dt><span>runFolder :</span></dt><dd>/gpfs/exfel/exp/SCS/201901/p002212/raw/r0208</dd></dl></div></li></ul></div></div>" ], "text/plain": [ "<xarray.Dataset>\n", @@ -500,7 +521,7 @@ " runFolder: /gpfs/exfel/exp/SCS/201901/p002212/raw/r0208" ] }, - "execution_count": 2, + "execution_count": 3, "metadata": {}, "output_type": "execute_result" } @@ -548,7 +569,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 4, "metadata": {}, "outputs": [ { @@ -914,14 +935,14 @@ " [1499, 1502, 1508, ..., 1508, 1502, 1500]], dtype=int16)\n", "Coordinates:\n", " * trainId (trainId) uint64 520069541 520069542 ... 520072605 520072606\n", - "Dimensions without coordinates: samplesId</pre><div class='xr-wrap' hidden><div class='xr-header'><div class='xr-obj-type'>xarray.DataArray</div><div class='xr-array-name'>'SCS_UTC1_ADQ/ADC/1:network.digitizers.channel_1_C.raw.samples'</div><ul class='xr-dim-list'><li><span class='xr-has-index'>trainId</span>: 3066</li><li><span>samplesId</span>: 600000</li></ul></div><ul class='xr-sections'><li class='xr-section-item'><div class='xr-array-wrap'><input id='section-797922ee-1be5-4715-99a3-b1e48d2a750d' class='xr-array-in' type='checkbox' checked><label for='section-797922ee-1be5-4715-99a3-b1e48d2a750d' title='Show/hide data repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-array-preview xr-preview'><span>1515 1500 1507 1506 1497 1505 1510 ... 1506 1508 1513 1508 1502 1500</span></div><div class='xr-array-data'><pre>array([[1515, 1500, 1507, ..., 1505, 1498, 1500],\n", + "Dimensions without coordinates: samplesId</pre><div class='xr-wrap' hidden><div class='xr-header'><div class='xr-obj-type'>xarray.DataArray</div><div class='xr-array-name'>'SCS_UTC1_ADQ/ADC/1:network.digitizers.channel_1_C.raw.samples'</div><ul class='xr-dim-list'><li><span class='xr-has-index'>trainId</span>: 3066</li><li><span>samplesId</span>: 600000</li></ul></div><ul class='xr-sections'><li class='xr-section-item'><div class='xr-array-wrap'><input id='section-0d8dea0c-7010-4a3f-82b7-4dc59ecb6bb5' class='xr-array-in' type='checkbox' checked><label for='section-0d8dea0c-7010-4a3f-82b7-4dc59ecb6bb5' title='Show/hide data repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-array-preview xr-preview'><span>1515 1500 1507 1506 1497 1505 1510 ... 1506 1508 1513 1508 1502 1500</span></div><div class='xr-array-data'><pre>array([[1515, 1500, 1507, ..., 1505, 1498, 1500],\n", " [1500, 1502, 1498, ..., 1504, 1490, 1499],\n", " [1503, 1508, 1507, ..., 1512, 1500, 1496],\n", " ...,\n", " [1502, 1515, 1517, ..., 1503, 1498, 1509],\n", " [1512, 1511, 1513, ..., 1506, 1504, 1506],\n", - " [1499, 1502, 1508, ..., 1508, 1502, 1500]], dtype=int16)</pre></div></div></li><li class='xr-section-item'><input id='section-8a9e5391-7fe8-4d6a-9deb-c98f7b93332a' class='xr-section-summary-in' type='checkbox' checked><label for='section-8a9e5391-7fe8-4d6a-9deb-c98f7b93332a' class='xr-section-summary' >Coordinates: <span>(1)</span></label><div class='xr-section-inline-details'></div><div class='xr-section-details'><ul class='xr-var-list'><li class='xr-var-item'><div class='xr-var-name'><span class='xr-has-index'>trainId</span></div><div class='xr-var-dims'>(trainId)</div><div class='xr-var-dtype'>uint64</div><div class='xr-var-preview xr-preview'>520069541 520069542 ... 520072606</div><input id='attrs-9435069b-6d74-409c-aed3-ac5294cce5f7' class='xr-var-attrs-in' type='checkbox' disabled><label for='attrs-9435069b-6d74-409c-aed3-ac5294cce5f7' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-10417c8c-1a86-44b8-9e3b-d79d616b5eff' class='xr-var-data-in' type='checkbox'><label for='data-10417c8c-1a86-44b8-9e3b-d79d616b5eff' title='Show/Hide data repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-var-attrs'><dl class='xr-attrs'></dl></div><div class='xr-var-data'><pre>array([520069541, 520069542, 520069543, ..., 520072604, 520072605, 520072606],\n", - " dtype=uint64)</pre></div></li></ul></div></li><li class='xr-section-item'><input id='section-4020eff5-2cf5-4308-9874-0461d72a2239' class='xr-section-summary-in' type='checkbox' disabled ><label for='section-4020eff5-2cf5-4308-9874-0461d72a2239' class='xr-section-summary' title='Expand/collapse section'>Attributes: <span>(0)</span></label><div class='xr-section-inline-details'></div><div class='xr-section-details'><dl class='xr-attrs'></dl></div></li></ul></div></div>" + " [1499, 1502, 1508, ..., 1508, 1502, 1500]], dtype=int16)</pre></div></div></li><li class='xr-section-item'><input id='section-f974c2c1-cd6d-4d6f-929f-17f8ffe396ca' class='xr-section-summary-in' type='checkbox' checked><label for='section-f974c2c1-cd6d-4d6f-929f-17f8ffe396ca' class='xr-section-summary' >Coordinates: <span>(1)</span></label><div class='xr-section-inline-details'></div><div class='xr-section-details'><ul class='xr-var-list'><li class='xr-var-item'><div class='xr-var-name'><span class='xr-has-index'>trainId</span></div><div class='xr-var-dims'>(trainId)</div><div class='xr-var-dtype'>uint64</div><div class='xr-var-preview xr-preview'>520069541 520069542 ... 520072606</div><input id='attrs-adb662e7-d59a-4dcc-87bf-b4cb24492252' class='xr-var-attrs-in' type='checkbox' disabled><label for='attrs-adb662e7-d59a-4dcc-87bf-b4cb24492252' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-6a9f5877-8c70-4e0e-90f0-f06830c55b69' class='xr-var-data-in' type='checkbox'><label for='data-6a9f5877-8c70-4e0e-90f0-f06830c55b69' title='Show/Hide data repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-var-attrs'><dl class='xr-attrs'></dl></div><div class='xr-var-data'><pre>array([520069541, 520069542, 520069543, ..., 520072604, 520072605, 520072606],\n", + " dtype=uint64)</pre></div></li></ul></div></li><li class='xr-section-item'><input id='section-c90f8620-2a1d-4d41-9738-96bc8a4f4bc7' class='xr-section-summary-in' type='checkbox' disabled ><label for='section-c90f8620-2a1d-4d41-9738-96bc8a4f4bc7' class='xr-section-summary' title='Expand/collapse section'>Attributes: <span>(0)</span></label><div class='xr-section-inline-details'></div><div class='xr-section-details'><dl class='xr-attrs'></dl></div></li></ul></div></div>" ], "text/plain": [ "<xarray.DataArray 'SCS_UTC1_ADQ/ADC/1:network.digitizers.channel_1_C.raw.samples' (trainId: 3066, samplesId: 600000)>\n", @@ -937,13 +958,13 @@ "Dimensions without coordinates: samplesId" ] }, - "execution_count": 3, + "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "raw_traces = run.get_array(*tb.mnemonics['MCP2raw'].values())\n", + "raw_traces = run.get_array(*run_mnemonics['MCP2raw'].values())\n", "raw_traces" ] }, @@ -956,16 +977,16 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "[<matplotlib.lines.Line2D at 0x2ae2a8e23f60>]" + "[<matplotlib.lines.Line2D at 0x2aef559eed68>]" ] }, - "execution_count": 4, + "execution_count": 5, "metadata": {}, "output_type": "execute_result" }, diff --git a/src/toolbox_scs/__init__.py b/src/toolbox_scs/__init__.py index 47d2252..f1acd89 100644 --- a/src/toolbox_scs/__init__.py +++ b/src/toolbox_scs/__init__.py @@ -1,6 +1,6 @@ from .load import (load, concatenateRuns, get_array, run_by_path) - from .constants import mnemonics +from .mnemonics_machinery import mnemonics_for_run __all__ = ( # functions @@ -8,6 +8,7 @@ __all__ = ( "concatenateRuns", "get_array", "run_by_path", + "mnemonics_for_run", # Classes # Variables "mnemonics", @@ -22,6 +23,7 @@ __all__ = ( clean_ns = [ # filenames 'constants', + 'mnemonics_machinery' # folders 'misc', 'util', diff --git a/src/toolbox_scs/constants.py b/src/toolbox_scs/constants.py index 72eee76..b4ad8c0 100644 --- a/src/toolbox_scs/constants.py +++ b/src/toolbox_scs/constants.py @@ -1,281 +1,303 @@ mnemonics = { # Machine - "sase3": {'source': 'SCS_RR_UTC/MDL/BUNCH_DECODER', - 'key': 'sase3.pulseIds.value', - 'dim': ['bunchId']}, - "sase2": {'source': 'SCS_RR_UTC/MDL/BUNCH_DECODER', - 'key': 'sase2.pulseIds.value', - 'dim': ['bunchId']}, - "sase1": {'source': 'SCS_RR_UTC/MDL/BUNCH_DECODER', - 'key': 'sase1.pulseIds.value', - 'dim': ['bunchId']}, - "maindump": {'source': 'SCS_RR_UTC/MDL/BUNCH_DECODER', - 'key': 'maindump.pulseIds.value', - 'dim': ['bunchId']}, - "bunchpattern": {'source': 'SCS_RR_UTC/TSYS/TIMESERVER', - 'key': 'readBunchPatternTable.value', - 'dim': None}, - "bunchPatternTable": {'source': 'SCS_RR_UTC/TSYS/TIMESERVER', - 'key': 'bunchPatternTable.value', - 'dim': ['pulse_slot']}, - "npulses_sase3": {'source': 'SCS_RR_UTC/MDL/BUNCH_DECODER', - 'key': 'sase3.nPulses.value', - 'dim': None}, - "npulses_sase1": {'source': 'SCS_RR_UTC/MDL/BUNCH_DECODER', - 'key': 'sase1.nPulses.value', - 'dim': None}, - "bunchPatternTable_SA3": { - 'source': 'SA3_BR_UTC/TSYS/TIMESERVER:outputBunchPattern', - 'key': 'data.bunchPatternTable', - 'dim': ['pulse_slot']}, + "sase3": ({'source': 'SCS_RR_UTC/MDL/BUNCH_DECODER', + 'key': 'sase3.pulseIds.value', + 'dim': ['bunchId']},), + "sase2": ({'source': 'SCS_RR_UTC/MDL/BUNCH_DECODER', + 'key': 'sase2.pulseIds.value', + 'dim': ['bunchId']},), + "sase1": ({'source': 'SCS_RR_UTC/MDL/BUNCH_DECODER', + 'key': 'sase1.pulseIds.value', + 'dim': ['bunchId']},), + "maindump": ({'source': 'SCS_RR_UTC/MDL/BUNCH_DECODER', + 'key': 'maindump.pulseIds.value', + 'dim': ['bunchId']},), + "bunchpattern": ({'source': 'SCS_RR_UTC/TSYS/TIMESERVER', + 'key': 'readBunchPatternTable.value', + 'dim': None},), + "bunchPatternTable": ( + {'source': 'SCS_RR_UTC/TSYS/TIMESERVER:outputBunchPattern', + 'key': 'data.bunchPatternTable', + 'dim': ['pulse_slot']}, + {'source': 'SCS_RR_UTC/TSYS/TIMESERVER', + 'key': 'bunchPatternTable.value', + 'dim': ['pulse_slot']}), + "npulses_sase3": ({'source': 'SCS_RR_UTC/MDL/BUNCH_DECODER', + 'key': 'sase3.nPulses.value', + 'dim': None},), + "npulses_sase1": ({'source': 'SCS_RR_UTC/MDL/BUNCH_DECODER', + 'key': 'sase1.nPulses.value', + 'dim': None},), + "bunchPatternTable_SA3": ( + {'source': 'SA3_BR_UTC/TSYS/TIMESERVER:outputBunchPattern', + 'key': 'data.bunchPatternTable', + 'dim': ['pulse_slot']},), # Bunch Arrival Monitors - "BAM414": {'source': 'SCS_ILH_LAS/DOOCS/BAM_414_B2:output', - 'key': 'data.lowChargeArrivalTime', - 'dim': ['BAMbunchId']}, - "BAM1932M": {'source': 'SCS_ILH_LAS/DOOCS/BAM_1932M_TL:output', - 'key': 'data.lowChargeArrivalTime', - 'dim': ['BAMbunchId']}, - "BAM1932S": {'source': 'SCS_ILH_LAS/DOOCS/BAM_1932S_TL:output', - 'key': 'data.lowChargeArrivalTime', - 'dim': ['BAMbunchId']}, + "BAM414": ({'source': 'SCS_ILH_LAS/DOOCS/BAM_414_B2:output', + 'key': 'data.lowChargeArrivalTime', + 'dim': ['BAMbunchId']},), + "BAM1932M": ({'source': 'SCS_ILH_LAS/DOOCS/BAM_1932M_TL:output', + 'key': 'data.lowChargeArrivalTime', + 'dim': ['BAMbunchId']},), + "BAM1932S": ({'source': 'SCS_ILH_LAS/DOOCS/BAM_1932S_TL:output', + 'key': 'data.lowChargeArrivalTime', + 'dim': ['BAMbunchId']},), # SA3 - "nrj": {'source': 'SA3_XTD10_MONO/MDL/PHOTON_ENERGY', - 'key': 'actualEnergy.value', - 'dim': None}, + "nrj": ({'source': 'SA3_XTD10_MONO/MDL/PHOTON_ENERGY', + 'key': 'actualEnergy.value', + 'dim': None},), - "M2BEND": {'source': 'SA3_XTD10_MIRR-2/MOTOR/BENDER', - 'key': 'actualPosition.value', - 'dim': None}, - "VSLIT": {'source': 'SA3_XTD10_VSLIT/MDL/BLADE', - 'key': 'actualGap.value', - 'dim': None}, - "ESLIT": {'source': 'SCS_XTD10_ESLIT/MDL/MAIN', - 'key': 'actualGap.value', - 'dim': None}, - "HSLIT": {'source': 'SCS_XTD10_HSLIT/MDL/BLADE', - 'key': 'actualGap.value', - 'dim': None}, - "transmission": {'source': 'SA3_XTD10_GATT/MDL/GATT_TRANSMISSION_MONITOR', - 'key': 'Estimated_Tr.value', - 'dim': None}, - "GATT_pressure": {'source': 'P_GATT', - 'key': 'value.value', - 'dim': None}, - "navitar": {'source': 'SCS_XTD10_IMGES/CAM/BEAMVIEW_NAVITAR:daqOutput', - 'key': 'data.image.pixels', - 'dim': ['x', 'y']}, - "UND": {'source': 'SA3_XTD10_UND/DOOCS/PHOTON_ENERGY', - 'key': 'actualPosition.value', - 'dim': None}, - # DPS imagers - "DPS2CAM2": {'source': 'SCS_BLU_DPS-2/CAM/IMAGER2CAMERA:daqOutput', + "M2BEND": ({'source': 'SA3_XTD10_MIRR-2/MOTOR/BENDER', + 'key': 'actualPosition.value', + 'dim': None},), + "VSLIT": ({'source': 'SA3_XTD10_VSLIT/MDL/BLADE', + 'key': 'actualGap.value', + 'dim': None},), + "ESLIT": ({'source': 'SCS_XTD10_ESLIT/MDL/MAIN', + 'key': 'actualGap.value', + 'dim': None},), + "HSLIT": ({'source': 'SCS_XTD10_HSLIT/MDL/BLADE', + 'key': 'actualGap.value', + 'dim': None},), + "transmission": ({'source': 'SA3_XTD10_GATT/MDL/GATT_TRANSMISSION_MONITOR', + 'key': 'Estimated_Tr.value', + 'dim': None},), + "GATT_pressure": ({'source': 'P_GATT', + 'key': 'value.value', + 'dim': None},), + "navitar": ({'source': 'SCS_XTD10_IMGES/CAM/BEAMVIEW_NAVITAR:daqOutput', 'key': 'data.image.pixels', - 'dim': ['dps2cam2_y', 'dps2cam2_x']}, + 'dim': ['x', 'y']},), + "UND": ({'source': 'SA3_XTD10_UND/DOOCS/PHOTON_ENERGY', + 'key': 'actualPosition.value', + 'dim': None},), + # DPS imagers + "DPS1CAM2": ({'source': 'SCS_BLU_DPS-1/CAM/IMAGER2CAMERA:daqOutput', + 'key': 'data.image.pixels', + 'dim': ['dps1cam2_y', 'dps1cam2_x']},), + "DPS2CAM2": ({'source': 'SCS_BLU_DPS-2/CAM/IMAGER2CAMERA:daqOutput', + 'key': 'data.image.pixels', + 'dim': ['dps2cam2_y', 'dps2cam2_x']},), # XTD10 XGM # keithley - "XTD10_photonFlux": {'source': 'SA3_XTD10_XGM/XGM/DOOCS', - 'key': 'pulseEnergy.photonFlux.value', - 'dim': None}, - "XTD10_photonFlux_sigma": {'source': 'SA3_XTD10_XGM/XGM/DOOCS', - 'key': 'pulseEnergy.photonFluxSigma.value', - 'dim': None}, + "XTD10_photonFlux": ({'source': 'SA3_XTD10_XGM/XGM/DOOCS', + 'key': 'pulseEnergy.photonFlux.value', + 'dim': None},), + "XTD10_photonFlux_sigma": ({'source': 'SA3_XTD10_XGM/XGM/DOOCS', + 'key': 'pulseEnergy.photonFluxSigma.value', + 'dim': None},), # ADC - "XTD10_XGM": {'source': 'SA3_XTD10_XGM/XGM/DOOCS:output', - 'key': 'data.intensityTD', - 'dim': ['XGMbunchId']}, - "XTD10_XGM_sigma": {'source': 'SA3_XTD10_XGM/XGM/DOOCS:output', - 'key': 'data.intensitySigmaTD', - 'dim': ['XGMbunchId']}, - "XTD10_SA3": {'source': 'SA3_XTD10_XGM/XGM/DOOCS:output', - 'key': 'data.intensitySa3TD', - 'dim': ['XGMbunchId']}, - "XTD10_SA3_sigma": {'source': 'SA3_XTD10_XGM/XGM/DOOCS:output', - 'key': 'data.intensitySa3SigmaTD', - 'dim': ['XGMbunchId']}, - "XTD10_SA1": {'source': 'SA3_XTD10_XGM/XGM/DOOCS:output', - 'key': 'data.intensitySa1TD', - 'dim': ['XGMbunchId']}, - "XTD10_SA1_sigma": {'source': 'SA3_XTD10_XGM/XGM/DOOCS:output', - 'key': 'data.intensitySa1SigmaTD', - 'dim': ['XGMbunchId']}, + "XTD10_XGM": ({'source': 'SA3_XTD10_XGM/XGM/DOOCS:output', + 'key': 'data.intensityTD', + 'dim': ['XGMbunchId']},), + "XTD10_XGM_sigma": ({'source': 'SA3_XTD10_XGM/XGM/DOOCS:output', + 'key': 'data.intensitySigmaTD', + 'dim': ['XGMbunchId']},), + "XTD10_SA3": ({'source': 'SA3_XTD10_XGM/XGM/DOOCS:output', + 'key': 'data.intensitySa3TD', + 'dim': ['XGMbunchId']},), + "XTD10_SA3_sigma": ({'source': 'SA3_XTD10_XGM/XGM/DOOCS:output', + 'key': 'data.intensitySa3SigmaTD', + 'dim': ['XGMbunchId']},), + "XTD10_SA1": ({'source': 'SA3_XTD10_XGM/XGM/DOOCS:output', + 'key': 'data.intensitySa1TD', + 'dim': ['XGMbunchId']},), + "XTD10_SA1_sigma": ({'source': 'SA3_XTD10_XGM/XGM/DOOCS:output', + 'key': 'data.intensitySa1SigmaTD', + 'dim': ['XGMbunchId']},), # low pass averaged ADC - "XTD10_slowTrain": {'source': 'SA3_XTD10_XGM/XGM/DOOCS', - 'key': 'controlData.slowTrain.value', - 'dim': None}, - "XTD10_slowTrain_SA1": {'source': 'SA3_XTD10_XGM/XGM/DOOCS', - 'key': 'controlData.slowTrainSa1.value', - 'dim': None}, - "XTD10_slowTrain_SA3": {'source': 'SA3_XTD10_XGM/XGM/DOOCS', - 'key': 'controlData.slowTrainSa3.value', - 'dim': None}, + "XTD10_slowTrain": ({'source': 'SA3_XTD10_XGM/XGM/DOOCS', + 'key': 'controlData.slowTrain.value', + 'dim': None},), + "XTD10_slowTrain_SA1": ({'source': 'SA3_XTD10_XGM/XGM/DOOCS', + 'key': 'controlData.slowTrainSa1.value', + 'dim': None},), + "XTD10_slowTrain_SA3": ({'source': 'SA3_XTD10_XGM/XGM/DOOCS', + 'key': 'controlData.slowTrainSa3.value', + 'dim': None},), # SCS XGM # keithley - "SCS_photonFlux": {'source': 'SCS_BLU_XGM/XGM/DOOCS', - 'key': 'pulseEnergy.photonFlux.value', - 'dim': None}, - "SCS_photonFlux_sigma": {'source': 'SCS_BLU_XGM/XGM/DOOCS', - 'key': 'pulseEnergy.photonFluxSigma.value', - 'dim': None}, + "SCS_photonFlux": ({'source': 'SCS_BLU_XGM/XGM/DOOCS', + 'key': 'pulseEnergy.photonFlux.value', + 'dim': None},), + "SCS_photonFlux_sigma": ({'source': 'SCS_BLU_XGM/XGM/DOOCS', + 'key': 'pulseEnergy.photonFluxSigma.value', + 'dim': None},), # ADC - "SCS_XGM": {'source': 'SCS_BLU_XGM/XGM/DOOCS:output', - 'key': 'data.intensityTD', - 'dim': ['XGMbunchId']}, - "SCS_XGM_sigma": {'source': 'SCS_BLU_XGM/XGM/DOOCS:output', - 'key': 'data.intensitySigmaTD', - 'dim': ['XGMbunchId']}, - "SCS_SA1": {'source': 'SCS_BLU_XGM/XGM/DOOCS:output', - 'key': 'data.intensitySa1TD', - 'dim': ['XGMbunchId']}, - "SCS_SA1_sigma": {'source': 'SCS_BLU_XGM/XGM/DOOCS:output', - 'key': 'data.intensitySa1SigmaTD', - 'dim': ['XGMbunchId']}, - "SCS_SA3": {'source': 'SCS_BLU_XGM/XGM/DOOCS:output', - 'key': 'data.intensitySa3TD', - 'dim': ['XGMbunchId']}, - "SCS_SA3_sigma": {'source': 'SCS_BLU_XGM/XGM/DOOCS:output', - 'key': 'data.intensitySa3SigmaTD', - 'dim': ['XGMbunchId']}, + "SCS_XGM": ({'source': 'SCS_BLU_XGM/XGM/DOOCS:output', + 'key': 'data.intensityTD', + 'dim': ['XGMbunchId']},), + "SCS_XGM_sigma": ({'source': 'SCS_BLU_XGM/XGM/DOOCS:output', + 'key': 'data.intensitySigmaTD', + 'dim': ['XGMbunchId']},), + "SCS_SA1": ({'source': 'SCS_BLU_XGM/XGM/DOOCS:output', + 'key': 'data.intensitySa1TD', + 'dim': ['XGMbunchId']},), + "SCS_SA1_sigma": ({'source': 'SCS_BLU_XGM/XGM/DOOCS:output', + 'key': 'data.intensitySa1SigmaTD', + 'dim': ['XGMbunchId']},), + "SCS_SA3": ({'source': 'SCS_BLU_XGM/XGM/DOOCS:output', + 'key': 'data.intensitySa3TD', + 'dim': ['XGMbunchId']},), + "SCS_SA3_sigma": ({'source': 'SCS_BLU_XGM/XGM/DOOCS:output', + 'key': 'data.intensitySa3SigmaTD', + 'dim': ['XGMbunchId']},), # low pass averaged ADC - "SCS_slowTrain": {'source': 'SCS_BLU_XGM/XGM/DOOCS', - 'key': 'controlData.slowTrain.value', - 'dim': None}, - "SCS_slowTrain_SA1": {'source': 'SCS_BLU_XGM/XGM/DOOCS', - 'key': 'controlData.slowTrainSa1.value', - 'dim': None}, - "SCS_slowTrain_SA3": {'source': 'SCS_BLU_XGM/XGM/DOOCS', - 'key': 'controlData.slowTrainSa3.value', - 'dim': None}, + "SCS_slowTrain": ({'source': 'SCS_BLU_XGM/XGM/DOOCS', + 'key': 'controlData.slowTrain.value', + 'dim': None},), + "SCS_slowTrain_SA1": ({'source': 'SCS_BLU_XGM/XGM/DOOCS', + 'key': 'controlData.slowTrainSa1.value', + 'dim': None},), + "SCS_slowTrain_SA3": ({'source': 'SCS_BLU_XGM/XGM/DOOCS', + 'key': 'controlData.slowTrainSa3.value', + 'dim': None},), # KBS - "HFM_CAPB": {'source': 'SCS_KBS_HFM/ASENS/CAPB', - 'key': 'value.value', - 'dim': None}, - "HFM_CAPF": {'source': 'SCS_KBS_HFM/ASENS/CAPF', - 'key': 'value.value', - 'dim': None}, - "HFM_CAPM": {'source': 'SCS_KBS_HFM/ASENS/CAPM', - 'key': 'value.value', - 'dim': None}, - "HFM_BENDERB": {'source': 'SCS_KBS_HFM/MOTOR/BENDERB', - 'key': 'encoderPosition.value', - 'dim': None}, - "HFM_BENDERF": {'source': 'SCS_KBS_HFM/MOTOR/BENDERF', - 'key': 'encoderPosition.value', - 'dim': None}, - "VFM_CAPB": {'source': 'SCS_KBS_VFM/ASENS/CAPB', - 'key': 'value.value', - 'dim': None}, - "VFM_CAPF": {'source': 'SCS_KBS_VFM/ASENS/CAPF', - 'key': 'value.value', - 'dim': None}, - "VFM_CAPM": {'source': 'SCS_KBS_VFM/ASENS/CAPM', - 'key': 'value.value', - 'dim': None}, - "VFM_BENDERB": {'source': 'SCS_KBS_VFM/MOTOR/BENDERB', - 'key': 'encoderPosition.value', - 'dim': None}, - "VFM_BENDERF": {'source': 'SCS_KBS_VFM/MOTOR/BENDERF', - 'key': 'encoderPosition.value', - 'dim': None}, + "HFM_CAPB": ({'source': 'SCS_KBS_HFM/ASENS/CAPB', + 'key': 'value.value', + 'dim': None},), + "HFM_CAPF": ({'source': 'SCS_KBS_HFM/ASENS/CAPF', + 'key': 'value.value', + 'dim': None},), + "HFM_CAPM": ({'source': 'SCS_KBS_HFM/ASENS/CAPM', + 'key': 'value.value', + 'dim': None},), + "HFM_BENDERB": ({'source': 'SCS_KBS_HFM/MOTOR/BENDERB', + 'key': 'encoderPosition.value', + 'dim': None},), + "HFM_BENDERF": ({'source': 'SCS_KBS_HFM/MOTOR/BENDERF', + 'key': 'encoderPosition.value', + 'dim': None},), + "VFM_CAPB": ({'source': 'SCS_KBS_VFM/ASENS/CAPB', + 'key': 'value.value', + 'dim': None},), + "VFM_CAPF": ({'source': 'SCS_KBS_VFM/ASENS/CAPF', + 'key': 'value.value', + 'dim': None},), + "VFM_CAPM": ({'source': 'SCS_KBS_VFM/ASENS/CAPM', + 'key': 'value.value', + 'dim': None},), + "VFM_BENDERB": ({'source': 'SCS_KBS_VFM/MOTOR/BENDERB', + 'key': 'encoderPosition.value', + 'dim': None},), + "VFM_BENDERF": ({'source': 'SCS_KBS_VFM/MOTOR/BENDERF', + 'key': 'encoderPosition.value', + 'dim': None},), # AFS LASER - "AFS_PhaseShifter": {'source': 'SCS_ILH_LAS/PHASESHIFTER/DOOCS', - 'key': 'actualPosition.value', - 'dim': None}, - "AFS_DelayLine": {'source': 'SCS_ILH_LAS/MOTOR/LT3', - 'key': 'actualPosition.value', - 'dim': None}, - "AFS_HalfWP": {'source': 'SCS_ILH_LAS/MOTOR/ROT_OPA_BWP1', - 'key': 'actualPosition.value', - 'dim': None}, - "AFS_FocusLens": {'source': 'SCS_ILH_LAS/MOTOR/LT_SPARE1', - 'key': 'actualPosition.value', - 'dim': None}, + "AFS_PhaseShifter": ({'source': 'SCS_ILH_LAS/PHASESHIFTER/DOOCS', + 'key': 'actualPosition.value', + 'dim': None},), + "AFS_DelayLine": ({'source': 'SCS_ILH_LAS/MOTOR/LT3', + 'key': 'actualPosition.value', + 'dim': None},), + "AFS_HalfWP": ({'source': 'SCS_ILH_LAS/MOTOR/ROT_OPA_BWP1', + 'key': 'actualPosition.value', + 'dim': None},), + "AFS_FocusLens": ({'source': 'SCS_ILH_LAS/MOTOR/LT_SPARE1', + 'key': 'actualPosition.value', + 'dim': None},), # 2nd lens of telescope - "AFS_TeleLens": {'source': 'SCS_ILH_LAS/MOTOR/LT2', - 'key': 'actualPosition.value', - 'dim': None}, + "AFS_TeleLens": ({'source': 'SCS_ILH_LAS/MOTOR/LT2', + 'key': 'actualPosition.value', + 'dim': None},), # PP LASER 800 nm path - "PP800_PhaseShifter": {'source': 'SCS_ILH_LAS/DOOCS/PP800_PHASESHIFTER', - 'key': 'actualPosition.value', - 'dim': None}, - "PP800_SynchDelayLine": {'source': 'SCS_ILH_LAS/DOOCS/PPL_OPT_DELAY', - 'key': 'actualPosition.value', - 'dim': None}, - "PP800_DelayLine": {'source': 'SCS_ILH_LAS/MOTOR/LT3', + "PP800_PhaseShifter": ({'source': 'SCS_ILH_LAS/DOOCS/PP800_PHASESHIFTER', + 'key': 'actualPosition.value', + 'dim': None},), + "PP800_SynchDelayLine": ({'source': 'SCS_ILH_LAS/DOOCS/PPL_OPT_DELAY', + 'key': 'actualPosition.value', + 'dim': None},), + "PP800_DelayLine": ({'source': 'SCS_ILH_LAS/MOTOR/LT3', + 'key': 'actualPosition.value', + 'dim': None}, + {'source': 'SCS_ILH_LAS/MOTOR/LT3', + 'key': 'AActualPosition.value', + 'dim': None},), + "PP800_HalfWP": ({'source': 'SCS_ILH_LAS/MOTOR/ROT8WP1', + 'key': 'actualPosition.value', + 'dim': None},), + "PP800_FocusLens": ({'source': 'SCS_ILH_LAS/MOTOR/LT_SPARE1', + 'key': 'actualPosition.value', + 'dim': None},), + # 1st lens of telescope (setup of August 2019) + "PP800_TeleLens": ({'source': 'SCS_ILH_LAS/MOTOR/LT7', 'key': 'actualPosition.value', - 'dim': None}, - "PP800_HalfWP": {'source': 'SCS_ILH_LAS/MOTOR/ROT8WP1', + 'dim': None},), + "ILH_8CAM1": ({'source': 'SCS_ILH_LAS/CAM/8CAM1:daqOutput', + 'key': 'data.image.pixels', + 'dim': ['8cam1_y', '8cam1_x']},), + "ILH_10CAM1": ({'source': 'SCS_ILH_LAS/CAM/10CAM1:daqOutput', + 'key': 'data.image.pixels', + 'dim': ['10cam1_y', '10cam1_x']},), + "ILH_PIDelay": ({'source': 'SCS_ILH_LAS/MOTOR/PIDELAY', 'key': 'actualPosition.value', - 'dim': None}, - "PP800_FocusLens": {'source': 'SCS_ILH_LAS/MOTOR/LT_SPARE1', - 'key': 'actualPosition.value', - 'dim': None}, - # 1st lens of telescope (setup of August 2019) - "PP800_TeleLens": {'source': 'SCS_ILH_LAS/MOTOR/LT7', - 'key': 'actualPosition.value', - 'dim': None}, - "ILH_8CAM1": {'source': 'SCS_ILH_LAS/CAM/8CAM1:daqOutput', - 'key': 'data.image.pixels', - 'dim': ['8cam1_y', '8cam1_x']}, + 'dim': None},), # GPC - "GPC_EOS_DelayLine": {'source': 'SCS_CDIDET_GRD/MOTOR/IMAGER', - 'key': 'actualPosition.value', - 'dim': None}, - "GPC_X": {'source': 'SCS_GPC_MOV/MOTOR/X', - 'key': 'actualPosition.value', - 'dim': None}, - "GPC_Y": {'source': 'SCS_GPC_MOV/MOTOR/Y', - 'key': 'actualPosition.value', - 'dim': None}, - "GPC_THETA": {'source': 'SCS_GPC_MOV/MOTOR/THETA', - 'key': 'actualPosition.value', - 'dim': None}, - "GPC_THETAMAG": {'source': 'SCS_GPC_MOV/MOTOR/THETAMAG', - 'key': 'actualPosition.value', - 'dim': None}, + "GPC_EOS_DelayLine": ({'source': 'SCS_CDIDET_GRD/MOTOR/IMAGER', + 'key': 'actualPosition.value', + 'dim': None},), + "GPC_X": ({'source': 'SCS_GPC_MOV/MOTOR/X', + 'key': 'actualPosition.value', + 'dim': None},), + "GPC_Y": ({'source': 'SCS_GPC_MOV/MOTOR/Y', + 'key': 'actualPosition.value', + 'dim': None},), + "GPC_THETA": ({'source': 'SCS_GPC_MOV/MOTOR/THETA', + 'key': 'actualPosition.value', + 'dim': None},), + "GPC_THETAMAG": ({'source': 'SCS_GPC_MOV/MOTOR/THETAMAG', + 'key': 'actualPosition.value', + 'dim': None},), # FFT - "scannerX": {'source': 'SCS_CDIFFT_SAM/LMOTOR/SCANNERX', - 'key': 'actualPosition.value', - 'dim': None}, - "scannerY": {'source': 'SCS_CDIFFT_SAM/MOTOR/SCANNERY', - 'key': 'actualPosition.value', - 'dim': None}, - "scannerY_enc": {'source': 'SCS_CDIFFT_SAM/ENC/SCANNERY', - 'key': 'value.value', - 'dim': None}, - "SAM-Z": {'source': 'SCS_CDIFFT_MOV/ENC/SAM_Z', - 'key': 'value.value', - 'dim': None}, - "magnet": {'source': 'SCS_CDIFFT_MAG/ASENS/CURRENT', + "scannerX": ({'source': 'SCS_CDIFFT_SAM/LMOTOR/SCANNERX', + 'key': 'actualPosition.value', + 'dim': None},), + "scannerY": ({'source': 'SCS_CDIFFT_SAM/MOTOR/SCANNERY', + 'key': 'actualPosition.value', + 'dim': None},), + "scannerY_enc": ({'source': 'SCS_CDIFFT_SAM/ENC/SCANNERY', + 'key': 'value.value', + 'dim': None},), + "SAM-Z": ({'source': 'SCS_CDIFFT_MOV/ENC/SAM_Z', 'key': 'value.value', - 'dim': None}, - "magnet_old": {'source': 'SCS_CDIFFT_MAG/SUPPLY/CURRENT', - 'key': 'actualCurrent.value', - 'dim': None}, - "Vertical_FDM": {'source': 'SCS_CDIFFT_LDM/CAM/CAMERA1A:daqOutput', + 'dim': None},), + "magnet": ({'source': 'SCS_CDIFFT_MAG/ASENS/PSU_CMON', + 'key': 'value.value', + 'dim': None}, + {'source': 'SCS_CDIFFT_MAG/ASENS/CURRENT', + 'key': 'value.value', + 'dim': None}, + {'source': 'SCS_CDIFFT_MAG/SUPPLY/CURRENT', + 'key': 'actualCurrent.value', + 'dim': None}), + "Vertical_FDM": ({'source': 'SCS_CDIFFT_LDM/CAM/CAMERA1A:daqOutput', + 'key': 'data.image.pixels', + 'dim': ['vfdm_y', 'vfdm_x']},), + "LLC_webcam2": ({'source': 'SCS_CDILLC_VAC/CAM/WEBCAMERA2:daqOutput', 'key': 'data.image.pixels', - 'dim': ['vfdm_y', 'vfdm_x']}, + 'dim': ['llc2_y', 'llc2_x']},), # FastCCD, if in raw folder, raw images # if in proc folder, dark substracted and relative gain corrected - "fastccd": {'source': 'SCS_CDIDET_FCCD2M/DAQ/FCCD:daqOutput', - 'key': 'data.image.pixels', - 'dim': ['x', 'y']}, + "fastccd": ({'source': 'SCS_CDIDET_FCCD2M/DAQ/FCCD:daqOutput', + 'key': 'data.image.pixels', + 'dim': ['x', 'y']},), # FastCCD with common mode correction - "fastccd_cm": {'source': 'SCS_CDIDET_FCCD2M/DAQ/FCCD:daqOutput', - 'key': 'data.image.pixels_cm', - 'dim': ['x', 'y']}, + "fastccd_cm": ({'source': 'SCS_CDIDET_FCCD2M/DAQ/FCCD:daqOutput', + 'key': 'data.image.pixels_cm', + 'dim': ['x', 'y']},), # FastCCD charge split correction in very low photon count regime - "fastccd_classified": {'source': 'SCS_CDIDET_FCCD2M/DAQ/FCCD:daqOutput', - 'key': 'data.image.pixels_classified', - 'dim': ['x', 'y']}, + "fastccd_classified": ({'source': 'SCS_CDIDET_FCCD2M/DAQ/FCCD:daqOutput', + 'key': 'data.image.pixels_classified', + 'dim': ['x', 'y']},), # FastCCD event multiplicity from the charge split correction: # 0: no events # 100, 101: single events @@ -284,116 +306,126 @@ mnemonics = { # 400-403: charge split into four pixels in four different orientations # 1000: charge in more than four neighboring pixels. Cannot be produced # by a single photon alone. - "fastccd_patterns": {'source': 'SCS_CDIDET_FCCD2M/DAQ/FCCD:daqOutput', - 'key': 'data.image.patterns', - 'dim': ['x', 'y']}, + "fastccd_patterns": ({'source': 'SCS_CDIDET_FCCD2M/DAQ/FCCD:daqOutput', + 'key': 'data.image.patterns', + 'dim': ['x', 'y']},), # FastCCD gain map, 0 high gain, 1 medium gain, 2 low gain - "fastccd_gain": {'source': 'SCS_CDIDET_FCCD2M/DAQ/FCCD:daqOutput', - 'key': 'data.image.gain', - 'dim': ['x', 'y']}, + "fastccd_gain": ({'source': 'SCS_CDIDET_FCCD2M/DAQ/FCCD:daqOutput', + 'key': 'data.image.gain', + 'dim': ['x', 'y']},), # FastCCD mask, bad pixel map to be ignored if > 0 - "fastccd_mask": {'source': 'SCS_CDIDET_FCCD2M/DAQ/FCCD:daqOutput', - 'key': 'data.image.mask', - 'dim': ['x', 'y']}, + "fastccd_mask": ({'source': 'SCS_CDIDET_FCCD2M/DAQ/FCCD:daqOutput', + 'key': 'data.image.mask', + 'dim': ['x', 'y']},), # TIM - "MCP1apd": {'source': 'SCS_UTC1_ADQ/ADC/1:network', - 'key': 'digitizers.channel_1_D.apd.pulseIntegral', - 'dim': ['apdId']}, - "MCP1raw": {'source': 'SCS_UTC1_ADQ/ADC/1:network', - 'key': 'digitizers.channel_1_D.raw.samples', - 'dim': ['samplesId']}, - "MCP2apd": {'source': 'SCS_UTC1_ADQ/ADC/1:network', - 'key': 'digitizers.channel_1_C.apd.pulseIntegral', - 'dim': ['apdId']}, - "MCP2raw": {'source': 'SCS_UTC1_ADQ/ADC/1:network', - 'key': 'digitizers.channel_1_C.raw.samples', - 'dim': ['samplesId']}, - "MCP3apd": {'source': 'SCS_UTC1_ADQ/ADC/1:network', - 'key': 'digitizers.channel_1_B.apd.pulseIntegral', - 'dim': ['apdId']}, - "MCP3raw": {'source': 'SCS_UTC1_ADQ/ADC/1:network', - 'key': 'digitizers.channel_1_B.raw.samples', - 'dim': ['samplesId']}, - "MCP4apd": {'source': 'SCS_UTC1_ADQ/ADC/1:network', - 'key': 'digitizers.channel_1_A.apd.pulseIntegral', - 'dim': ['apdId']}, - "MCP4raw": {'source': 'SCS_UTC1_ADQ/ADC/1:network', - 'key': 'digitizers.channel_1_A.raw.samples', - 'dim': ['samplesId']}, + "MCP1apd": ({'source': 'SCS_UTC1_ADQ/ADC/1:network', + 'key': 'digitizers.channel_1_D.apd.pulseIntegral', + 'dim': ['apdId']},), + "MCP1raw": ({'source': 'SCS_UTC1_ADQ/ADC/1:network', + 'key': 'digitizers.channel_1_D.raw.samples', + 'dim': ['samplesId']},), + "MCP2apd": ({'source': 'SCS_UTC1_ADQ/ADC/1:network', + 'key': 'digitizers.channel_1_C.apd.pulseIntegral', + 'dim': ['apdId']},), + "MCP2raw": ({'source': 'SCS_UTC1_ADQ/ADC/1:network', + 'key': 'digitizers.channel_1_C.raw.samples', + 'dim': ['samplesId']},), + "MCP3apd": ({'source': 'SCS_UTC1_ADQ/ADC/1:network', + 'key': 'digitizers.channel_1_B.apd.pulseIntegral', + 'dim': ['apdId']},), + "MCP3raw": ({'source': 'SCS_UTC1_ADQ/ADC/1:network', + 'key': 'digitizers.channel_1_B.raw.samples', + 'dim': ['samplesId']},), + "MCP4apd": ({'source': 'SCS_UTC1_ADQ/ADC/1:network', + 'key': 'digitizers.channel_1_A.apd.pulseIntegral', + 'dim': ['apdId']},), + "MCP4raw": ({'source': 'SCS_UTC1_ADQ/ADC/1:network', + 'key': 'digitizers.channel_1_A.raw.samples', + 'dim': ['samplesId']},), # FastADC - "FastADC0peaks": {'source': 'SCS_UTC1_MCP/ADC/1:channel_0.output', - 'key': 'data.peaks', - 'dim': ['peakId']}, - "FastADC0raw": {'source': 'SCS_UTC1_MCP/ADC/1:channel_0.output', - 'key': 'data.rawData', - 'dim': ['fadc_samplesId']}, - "FastADC1peaks": {'source': 'SCS_UTC1_MCP/ADC/1:channel_1.output', - 'key': 'data.peaks', - 'dim': ['peakId']}, - "FastADC1raw": {'source': 'SCS_UTC1_MCP/ADC/1:channel_1.output', - 'key': 'data.rawData', - 'dim': ['fadc_samplesId']}, - "FastADC2peaks": {'source': 'SCS_UTC1_MCP/ADC/1:channel_2.output', - 'key': 'data.peaks', - 'dim': ['peakId']}, - "FastADC2raw": {'source': 'SCS_UTC1_MCP/ADC/1:channel_2.output', - 'key': 'data.rawData', - 'dim': ['fadc_samplesId']}, - "FastADC3peaks": {'source': 'SCS_UTC1_MCP/ADC/1:channel_3.output', - 'key': 'data.peaks', - 'dim': ['peakId']}, - "FastADC3raw": {'source': 'SCS_UTC1_MCP/ADC/1:channel_3.output', - 'key': 'data.rawData', - 'dim': ['fadc_samplesId']}, - "FastADC4peaks": {'source': 'SCS_UTC1_MCP/ADC/1:channel_4.output', - 'key': 'data.peaks', - 'dim': ['peakId']}, - "FastADC4raw": {'source': 'SCS_UTC1_MCP/ADC/1:channel_4.output', - 'key': 'data.rawData', - 'dim': ['fadc_samplesId']}, - "FastADC5peaks": {'source': 'SCS_UTC1_MCP/ADC/1:channel_5.output', - 'key': 'data.peaks', - 'dim': ['peakId']}, - "FastADC5raw": {'source': 'SCS_UTC1_MCP/ADC/1:channel_5.output', - 'key': 'data.rawData', - 'dim': ['fadc_samplesId']}, - "FastADC6peaks": {'source': 'SCS_UTC1_MCP/ADC/1:channel_6.output', - 'key': 'data.peaks', - 'dim': ['peakId']}, - "FastADC6raw": {'source': 'SCS_UTC1_MCP/ADC/1:channel_6.output', - 'key': 'data.rawData', - 'dim': ['fadc_samplesId']}, - "FastADC7peaks": {'source': 'SCS_UTC1_MCP/ADC/1:channel_7.output', - 'key': 'data.peaks', - 'dim': ['peakId']}, - "FastADC7raw": {'source': 'SCS_UTC1_MCP/ADC/1:channel_7.output', - 'key': 'data.rawData', - 'dim': ['fadc_samplesId']}, - "FastADC8peaks": {'source': 'SCS_UTC1_MCP/ADC/1:channel_8.output', - 'key': 'data.peaks', - 'dim': ['peakId']}, - "FastADC8raw": {'source': 'SCS_UTC1_MCP/ADC/1:channel_8.output', - 'key': 'data.rawData', - 'dim': ['fadc_samplesId']}, - "FastADC9peaks": {'source': 'SCS_UTC1_MCP/ADC/1:channel_9.output', - 'key': 'data.peaks', - 'dim': ['peakId']}, - "FastADC9raw": {'source': 'SCS_UTC1_MCP/ADC/1:channel_9.output', - 'key': 'data.rawData', - 'dim': ['fadc_samplesId']}, + "FastADC0peaks": ({'source': 'SCS_UTC1_MCP/ADC/1:channel_0.output', + 'key': 'data.peaks', + 'dim': ['peakId']},), + "FastADC0raw": ({'source': 'SCS_UTC1_MCP/ADC/1:channel_0.output', + 'key': 'data.rawData', + 'dim': ['fadc_samplesId']},), + "FastADC1peaks": ({'source': 'SCS_UTC1_MCP/ADC/1:channel_1.output', + 'key': 'data.peaks', + 'dim': ['peakId']},), + "FastADC1raw": ({'source': 'SCS_UTC1_MCP/ADC/1:channel_1.output', + 'key': 'data.rawData', + 'dim': ['fadc_samplesId']},), + "FastADC2peaks": ({'source': 'SCS_UTC1_MCP/ADC/1:channel_2.output', + 'key': 'data.peaks', + 'dim': ['peakId']},), + "FastADC2raw": ({'source': 'SCS_UTC1_MCP/ADC/1:channel_2.output', + 'key': 'data.rawData', + 'dim': ['fadc_samplesId']},), + "FastADC3peaks": ({'source': 'SCS_UTC1_MCP/ADC/1:channel_3.output', + 'key': 'data.peaks', + 'dim': ['peakId']},), + "FastADC3raw": ({'source': 'SCS_UTC1_MCP/ADC/1:channel_3.output', + 'key': 'data.rawData', + 'dim': ['fadc_samplesId']},), + "FastADC4peaks": ({'source': 'SCS_UTC1_MCP/ADC/1:channel_4.output', + 'key': 'data.peaks', + 'dim': ['peakId']},), + "FastADC4raw": ({'source': 'SCS_UTC1_MCP/ADC/1:channel_4.output', + 'key': 'data.rawData', + 'dim': ['fadc_samplesId']},), + "FastADC5peaks": ({'source': 'SCS_UTC1_MCP/ADC/1:channel_5.output', + 'key': 'data.peaks', + 'dim': ['peakId']},), + "FastADC5raw": ({'source': 'SCS_UTC1_MCP/ADC/1:channel_5.output', + 'key': 'data.rawData', + 'dim': ['fadc_samplesId']},), + "FastADC6peaks": ({'source': 'SCS_UTC1_MCP/ADC/1:channel_6.output', + 'key': 'data.peaks', + 'dim': ['peakId']},), + "FastADC6raw": ({'source': 'SCS_UTC1_MCP/ADC/1:channel_6.output', + 'key': 'data.rawData', + 'dim': ['fadc_samplesId']},), + "FastADC7peaks": ({'source': 'SCS_UTC1_MCP/ADC/1:channel_7.output', + 'key': 'data.peaks', + 'dim': ['peakId']},), + "FastADC7raw": ({'source': 'SCS_UTC1_MCP/ADC/1:channel_7.output', + 'key': 'data.rawData', + 'dim': ['fadc_samplesId']},), + "FastADC8peaks": ({'source': 'SCS_UTC1_MCP/ADC/1:channel_8.output', + 'key': 'data.peaks', + 'dim': ['peakId']},), + "FastADC8raw": ({'source': 'SCS_UTC1_MCP/ADC/1:channel_8.output', + 'key': 'data.rawData', + 'dim': ['fadc_samplesId']},), + "FastADC9peaks": ({'source': 'SCS_UTC1_MCP/ADC/1:channel_9.output', + 'key': 'data.peaks', + 'dim': ['peakId']},), + "FastADC9raw": ({'source': 'SCS_UTC1_MCP/ADC/1:channel_9.output', + 'key': 'data.rawData', + 'dim': ['fadc_samplesId']},), # KARABACON - "KARABACON": {'source': 'SCS_DAQ_SCAN/MDL/KARABACON', - 'key': 'actualStep.value', - 'dim': None}, + "KARABACON": ({'source': 'SCS_DAQ_SCAN/MDL/KARABACON', + 'key': 'actualStep.value', + 'dim': None},), # GOTTHARD - "Gotthard1": {'source': 'SCS_PAM_XOX/DET/GOTTHARD_RECEIVER1:daqOutput', - 'key': 'data.adc', - 'dim': ['gott_pId', 'pixelId']}, - "Gotthard2": {'source': 'SCS_PAM_XOX/DET/GOTTHARD_RECEIVER2:daqOutput', - 'key': 'data.adc', - 'dim': ['gott_pId', 'pixelId']} + "Gotthard1": ({'source': 'SCS_PAM_XOX/DET/GOTTHARD_RECEIVER1:daqOutput', + 'key': 'data.adc', + 'dim': ['gott_pId', 'pixelId']},), + "Gotthard2": ({'source': 'SCS_PAM_XOX/DET/GOTTHARD_RECEIVER2:daqOutput', + 'key': 'data.adc', + 'dim': ['gott_pId', 'pixelId']},), + + # BASLER RACER + "Racer1": ({'source': 'SCS_PAM_XOX/CAM/RACER1:daqOutput', + 'key': 'data.image.pixels', + 'dim': ['racer1_pId', 'racer1_x']},), + + # BBO2 RY (interferometric timing tool, Nov 2020, p2711) + "BBO_RY": ({'source': 'SCS_CDIDET_GRD/MOTOR/IMAGER', + 'key': 'actualPosition.value', + 'dim': None},) } diff --git a/src/toolbox_scs/detectors/bam_detectors.py b/src/toolbox_scs/detectors/bam_detectors.py index 4b0d77f..12d6ef1 100644 --- a/src/toolbox_scs/detectors/bam_detectors.py +++ b/src/toolbox_scs/detectors/bam_detectors.py @@ -11,9 +11,9 @@ import logging import numpy as np import xarray as xr -from ..constants import mnemonics as _mnemonics from ..misc.bunch_pattern_external import is_pulse_at -import toolbox_scs.load as tbload +from ..mnemonics_machinery import (mnemonics_to_process, + mnemonics_for_run) log = logging.getLogger(__name__) @@ -56,7 +56,7 @@ def get_bam(run, mnemonics=None, merge_with=None, bunchPattern='sase3'): """ # get the list of mnemonics to process - mnemonics = tbload.mnemonics_to_process(mnemonics, merge_with, 'BAM') + mnemonics = mnemonics_to_process(mnemonics, merge_with, 'BAM') if len(mnemonics) == 0: log.info('No array with unaligned BAM data to extract. Skipping.') @@ -70,25 +70,26 @@ def get_bam(run, mnemonics=None, merge_with=None, bunchPattern='sase3'): else: mw_ds = xr.Dataset() + run_mnemonics = mnemonics_for_run(run) # extract the XFEL pulses: slice(0,5400,2) roi = np.s_[:5400:2] ds = xr.Dataset() for m in mnemonics: if bool(merge_with) and m in merge_with: - val = merge_with[m].isel({_mnemonics[m]['dim'][0]: roi}) + val = merge_with[m].isel({run_mnemonics[m]['dim'][0]: roi}) log.debug(f'Using {m} from merge_with dataset.') else: - val = run.get_array(*_mnemonics[m].values(), roi=roi, name=m) + val = run.get_array(*run_mnemonics[m].values(), roi=roi, name=m) log.debug(f'Loading {m} from DataCollection.') - val[_mnemonics[m]['dim'][0]] = np.arange(2700) + val[run_mnemonics[m]['dim'][0]] = np.arange(2700) ds = ds.merge(val, join='inner') # check if bunch pattern table exists if bool(merge_with) and 'bunchPatternTable' in merge_with: bpt = merge_with['bunchPatternTable'] log.debug('Using bpt from merge_with dataset.') - elif _mnemonics['bunchPatternTable']['source'] in run.all_sources: - bpt = run.get_array(*_mnemonics['bunchPatternTable'].values()) + elif 'bunchPatternTable' in run_mnemonics: + bpt = run.get_array(*run_mnemonics['bunchPatternTable'].values()) log.debug('Loaded bpt from extra_data run.') else: bpt = None @@ -99,7 +100,7 @@ def get_bam(run, mnemonics=None, merge_with=None, bunchPattern='sase3'): 'scs_ppl': 'ol_pId'} mask = is_pulse_at(bpt, bunchPattern) mask = mask.rename({'pulse_slot': dim_names[bunchPattern]}) - ds = ds.rename({_mnemonics['BAM1932M']['dim'][0]: + ds = ds.rename({run_mnemonics['BAM1932M']['dim'][0]: dim_names[bunchPattern]}) ds = ds.where(mask, drop=True) diff --git a/src/toolbox_scs/detectors/digitizers.py b/src/toolbox_scs/detectors/digitizers.py index d412cbf..b677323 100644 --- a/src/toolbox_scs/detectors/digitizers.py +++ b/src/toolbox_scs/detectors/digitizers.py @@ -13,10 +13,10 @@ import xarray as xr import matplotlib.pyplot as plt from scipy.signal import find_peaks -from ..constants import mnemonics as _mnemonics from ..misc.bunch_pattern_external import is_pulse_at from ..util.exceptions import ToolBoxValueError -import toolbox_scs.load as tbload +from ..mnemonics_machinery import (mnemonics_to_process, + mnemonics_for_run) log = logging.getLogger(__name__) @@ -223,14 +223,15 @@ def get_peaks(run, 'are required.') # Load data arr = None + run_mnemonics = mnemonics_for_run(run) if data is None: log.debug(f'Loading array from DataCollection with {source}, {key}') arr = run.get_array(source, key) if isinstance(data, str): log.debug(f'Loading array from mnemonic {data}') - arr = run.get_array(*_mnemonics[data].values()) - source = _mnemonics[data]['source'] - key = _mnemonics[data]['key'] + arr = run.get_array(*run_mnemonics[data].values()) + source = run_mnemonics[data]['source'] + key = run_mnemonics[data]['key'] if arr is None: log.debug('Using array provided in data argument.') if source is None or key is None: @@ -244,8 +245,8 @@ def get_peaks(run, bpt = run.get_array(bunchPattern['source'], bunchPattern['key'], extra_dims=['pulse_slot']) pattern = bunchPattern['pattern'] - if _mnemonics['bunchPatternTable']['source'] in run.all_sources: - bpt = run.get_array(*_mnemonics['bunchPatternTable'].values()) + if 'bunchPatternTable' in run_mnemonics: + bpt = run.get_array(*run_mnemonics['bunchPatternTable'].values()) pattern = bunchPattern else: pattern = bunchPattern @@ -375,8 +376,9 @@ def channel_peak_params(run, source, key=None, digitizer=None, ------- dict with peak integration parameters. """ - if source in _mnemonics: - m = _mnemonics[source] + run_mnemonics = mnemonics_for_run(run) + if source in run_mnemonics: + m = run_mnemonics[source] source = m['source'] key = m['key'] if key is not None: @@ -510,7 +512,8 @@ def get_peak_params(run, mnemonic, raw_trace=None, ntrains=200): Only used if raw_trace is None. Number of trains used to calculate the average raw trace of the corresponding channel. """ - if mnemonic not in _mnemonics: + run_mnemonics = mnemonics_for_run(run) + if mnemonic not in run_mnemonics: raise ToolBoxValueError("mnemonic must be a ToolBox mnemonics") if "raw" not in mnemonic: mnemo_raw = mnemonic.replace('peaks', 'raw').replace('apd', 'raw') @@ -524,7 +527,7 @@ def get_peak_params(run, mnemonic, raw_trace=None, ntrains=200): title = 'Auto-find peak params' if raw_trace is None: sel = run.select_trains(np.s_[:ntrains]) - raw_trace = sel.get_array(*_mnemonics[mnemo_raw].values()) + raw_trace = sel.get_array(*run_mnemonics[mnemo_raw].values()) raw_trace = raw_trace.mean(dim='trainId') params = find_integ_params(raw_trace, min_distance=min_distance) log.debug(f'{title} for {mnemonic}: {params}') @@ -569,6 +572,7 @@ def check_peak_params(run, mnemonic, raw_trace=None, ntrains=200, params=None, ------- dictionnary of peak integration parameters """ + run_mnemonics = mnemonics_for_run(run) if "raw" in mnemonic: mnemo_raw = mnemonic title = 'Auto-find peak params' @@ -577,7 +581,7 @@ def check_peak_params(run, mnemonic, raw_trace=None, ntrains=200, params=None, title = 'Digitizer peak params' if raw_trace is None: sel = run.select_trains(np.s_[:ntrains]) - raw_trace = sel.get_array(*_mnemonics[mnemo_raw].values()) + raw_trace = sel.get_array(*run_mnemonics[mnemo_raw].values()) raw_trace = raw_trace.mean(dim='trainId') if params is None: params = get_peak_params(run, mnemonic, raw_trace) @@ -586,11 +590,10 @@ def check_peak_params(run, mnemonic, raw_trace=None, ntrains=200, params=None, if not plot: return params min_distance = 24 if "FastADC" in mnemonic else 440 - if _mnemonics['bunchPatternTable']['source'] in sel.all_sources \ - and bunchPattern != 'None': + if 'bunchPatternTable' in run_mnemonics and bunchPattern != 'None': sel = run.select_trains(np.s_[:ntrains]) bp_params = {} - bpt = sel.get_array(*_mnemonics['bunchPatternTable'].values()) + bpt = sel.get_array(*run_mnemonics['bunchPatternTable'].values()) mask = is_pulse_at(bpt, bunchPattern) pid = np.sort(np.unique(np.where(mask)[1])) bp_params['npulses'] = len(pid) @@ -816,7 +819,7 @@ def get_digitizer_peaks(run, mnemonics, digitizer, merge_with=None, # get the list of mnemonics to process def to_processed_name(name): return name.replace('raw', 'peaks').replace('apd', 'peaks') - mnemonics = tbload.mnemonics_to_process(mnemonics, merge_with, + mnemonics = mnemonics_to_process(mnemonics, merge_with, digitizer, to_processed_name) if len(mnemonics) == 0: @@ -826,12 +829,13 @@ def get_digitizer_peaks(run, mnemonics, digitizer, merge_with=None, else: log.info(f'Extracting {digitizer} peaks from {mnemonics}.') + run_mnemonics = mnemonics_for_run(run) # check if bunch pattern table exists if bool(merge_with) and 'bunchPatternTable' in merge_with: bpt = merge_with['bunchPatternTable'] log.debug('Using bpt from merge_with dataset.') - elif _mnemonics['bunchPatternTable']['source'] in run.all_sources: - bpt = run.get_array(*_mnemonics['bunchPatternTable'].values()) + elif 'bunchPatternTable' in run_mnemonics: + bpt = run.get_array(*run_mnemonics['bunchPatternTable'].values()) log.debug('Loaded bpt from DataCollection.') else: bpt = None @@ -846,7 +850,7 @@ def get_digitizer_peaks(run, mnemonics, digitizer, merge_with=None, vals = [] for k in mnemonics: useRaw = True if 'raw' in k else False - m = _mnemonics[k] + m = run_mnemonics[k] if bool(merge_with) and k in merge_with: data = merge_with[k] else: diff --git a/src/toolbox_scs/detectors/xgm.py b/src/toolbox_scs/detectors/xgm.py index bed5941..cdb84dc 100644 --- a/src/toolbox_scs/detectors/xgm.py +++ b/src/toolbox_scs/detectors/xgm.py @@ -12,9 +12,9 @@ import numpy as np import xarray as xr import matplotlib.pyplot as plt -from ..constants import mnemonics as _mnemonics from ..misc.bunch_pattern_external import is_sase_1, is_sase_3 -import toolbox_scs.load as tbload +from ..mnemonics_machinery import (mnemonics_to_process, + mnemonics_for_run) log = logging.getLogger(__name__) @@ -59,7 +59,7 @@ def get_xgm(run, mnemonics=None, merge_with=None, keepAllSase=False, """ # get the list of mnemonics to process - mnemonics = tbload.mnemonics_to_process(mnemonics, merge_with, 'XGM') + mnemonics = mnemonics_to_process(mnemonics, merge_with, 'XGM') if len(mnemonics) == 0: log.info('No array with unaligned XGM peaks to extract. Skipping.') @@ -73,12 +73,13 @@ def get_xgm(run, mnemonics=None, merge_with=None, keepAllSase=False, else: ds = xr.Dataset() + run_mnemonics = mnemonics_for_run(run) # check if bunch pattern table exists if bool(merge_with) and 'bunchPatternTable' in merge_with: bpt = merge_with['bunchPatternTable'] log.debug('Using bpt from merge_with dataset.') - elif _mnemonics['bunchPatternTable']['source'] in run.all_sources: - bpt = run.get_array(*_mnemonics['bunchPatternTable'].values()) + elif 'bunchPatternTable' in run_mnemonics: + bpt = run.get_array(*run_mnemonics['bunchPatternTable'].values()) log.debug('Loaded bpt from DataCollection.') else: bpt = None @@ -89,7 +90,7 @@ def get_xgm(run, mnemonics=None, merge_with=None, keepAllSase=False, arr = merge_with[m] log.debug(f'Using {m} from merge_with dataset.') else: - arr = run.get_array(*_mnemonics[m].values(), name=m) + arr = run.get_array(*run_mnemonics[m].values(), name=m) log.debug(f'Loading {m} from DataCollection.') if bpt is not None: arr = align_xgm_array(arr, bpt) @@ -226,13 +227,14 @@ def calibrate_xgm(run, data, xgm='SCS', plot=False): >>> ds['SCS_SA3_uJ'] = F * ds['SCS_SA3'] """ + run_mnemonics = mnemonics_for_run(run) + # check if bunch pattern table exists if 'bunchPatternTable' in data: bpt = data['bunchPatternTable'] - log.debug('Using bpt from provided dataset.') - elif _mnemonics['bunchPatternTable']['source'] in run.all_sources: - bpt = run.get_array(*_mnemonics['bunchPatternTable'].values()) - elif _mnemonics['bunchPatternTable_SA3']['source'] in run.all_sources: - bpt = run.get_array(*_mnemonics['bunchPatternTable_SA3'].values()) + elif 'bunchPatternTable' in run_mnemonics: + bpt = run.get_array(*run_mnemonics['bunchPatternTable'].values()) + elif 'bunchPatternTable_SA3' in run_mnemonics: + bpt = run.get_array(*run_mnemonics['bunchPatternTable_SA3'].values()) else: raise ValueError('Bunch pattern missing. Cannot calibrate XGM.') mask_sa3 = is_sase_3(bpt.sel(trainId=data.trainId)) @@ -254,7 +256,7 @@ def calibrate_xgm(run, data, xgm='SCS', plot=False): if pflux_key in data: pflux = data[pflux_key] else: - pflux = run.get_array(*_mnemonics[pflux_key].values()) + pflux = run.get_array(*run_mnemonics[pflux_key].values()) pflux = pflux.sel(trainId=data.trainId) pflux_sa3 = (npulses_sa1 + npulses_sa3) * pflux / npulses_sa3 avg_fast = data[f'{xgm}_SA3'].rolling(trainId=200).mean().mean(axis=1) diff --git a/src/toolbox_scs/load.py b/src/toolbox_scs/load.py index 19021e7..5ebac8b 100644 --- a/src/toolbox_scs/load.py +++ b/src/toolbox_scs/load.py @@ -15,6 +15,7 @@ import xarray as xr import extra_data as ed from .constants import mnemonics as _mnemonics +from .mnemonics_machinery import mnemonics_for_run from .util.exceptions import ToolBoxValueError, ToolBoxPathError from .util.data_access import find_run_dir import toolbox_scs.detectors as tbdet @@ -75,17 +76,21 @@ def load(proposalNB=None, runNB=None, 'MCP3apd') and aligns the pulse Id with the sase3 bunch pattern. extract_laser: bool If True, extracts the peaks from FastADC variables (e.g. 'FastADC5raw', - 'FastADC3peaks') and aligns the pulse Id with the PP laser bunch pattern. + 'FastADC3peaks') and aligns the pulse Id with the PP laser bunch + pattern. extract_xgm: bool If True, extracts the values from XGM variables (e.g. 'SCS_SA3', - 'XTD10_XGM') and aligns the pulse Id with the sase1 / sase3 bunch pattern. + 'XTD10_XGM') and aligns the pulse Id with the sase1 / sase3 bunch + pattern. extract_bam: bool If True, extracts the values from BAM variables (e.g. 'BAM1932M') and aligns the pulse Id with the sase3 bunch pattern. tim_bp: str - bunch pattern used to extract the TIM pulses. Ignored if extract_tim=False. + bunch pattern used to extract the TIM pulses. + Ignored if extract_tim=False. laser_bp: str - bunch pattern used to extract the TIM pulses. Ignored if extract_tim=False. + bunch pattern used to extract the TIM pulses. + Ignored if extract_tim=False. Returns ------- @@ -116,23 +121,22 @@ def load(proposalNB=None, runNB=None, print('Loading data from {}'.format(runFolder)) run.info() - keys = [] - vals = [] + data_arrays = [] + run_mnemonics = mnemonics_for_run(run) # load pulse pattern info - if _mnemonics['bunchPatternTable']['source'] in run.all_sources: - bpt = run.get_array(*_mnemonics['bunchPatternTable'].values()) - keys.append("bunchPatternTable") - vals.append(bpt) - elif _mnemonics['bunchPatternTable_SA3']['source'] in run.all_sources: + if 'bunchPatternTable' in run_mnemonics: + bpt = run.get_array(*run_mnemonics['bunchPatternTable'].values(), + name='bunchPatternTable') + data_arrays.append(bpt) + elif 'bunchPatternTable_SA3' in run_mnemonics: log.info('Did not find SCS bunch pattern table but found the SA3 one.') - bpt = run.get_array(*_mnemonics['bunchPatternTable_SA3'].values()) - keys.append("bunchPatternTable") - vals.append(bpt) + bpt = run.get_array(*run_mnemonics['bunchPatternTable_SA3'].values(), + name='bunchPatternTable') + data_arrays.append(bpt) else: - log.warning('Source {} and {} not found in run. Skipping!'.format( - _mnemonics['bunchPatternTable']['source'], - _mnemonics['bunchPatternTable_SA3']['source'],)) + log.warning('Bunch pattern table not found in run. Skipping!') + for f in fields: if type(f) == dict: # extracting mnemomic defined on the spot @@ -143,13 +147,18 @@ def load(proposalNB=None, runNB=None, v = f[k] else: # extracting mnemomic from the table - if f in _mnemonics: - v = _mnemonics[f] + if f in run_mnemonics: + v = run_mnemonics[f] k = f else: - print(f'Unknow mnemonic "{f}". Skipping!') + if f in _mnemonics: + log.warning(f'Mnemonic "{f}" not found in run. Skipping!') + print(f'Mnemonic "{f}" not found in run. Skipping!') + else: + log.warning(f'Unknow mnemonic "{f}". Skipping!') + print(f'Unknow mnemonic "{f}". Skipping!') continue - if k in keys: + if k in [d.name for d in data_arrays]: continue # already loaded, skip if display: print(f'Loading {k}') @@ -159,53 +168,51 @@ def load(proposalNB=None, runNB=None, continue if k not in rois: # no ROIs selection, we read everything - arr = run.get_array(*v.values()) + arr = run.get_array(*v.values(), name=k) if len(arr) == 0: log.warning(f'Empty array for {f}: {v["source"]}, {v["key"]}. ' 'Skipping!') print(f'Empty array for {f}: {v["source"]}, {v["key"]}. ' 'Skipping!') continue - vals.append(arr) - keys.append(k) + data_arrays.append(arr) else: # ROIs selection, for each ROI we select a region of the data and # save it with new name and dimensions for nk, nv in rois[k].items(): arr = run.get_array(v['source'], v['key'], extra_dims=nv['dim'], - roi=nv['roi']) + roi=nv['roi'], + name=nk) if len(arr) == 0: - log.warning(f'Empty array for {f}: {v["source"]}, {v["key"]}. ' - 'Skipping!') + log.warning(f'Empty array for {f}: {v["source"]}, ' + f'{v["key"]}. Skipping!') print(f'Empty array for {f}: {v["source"]}, {v["key"]}. ' 'Skipping!') continue - vals.append(arr) - keys.append(nk) - aligned_vals = xr.align(*vals, join='inner') - data = dict(zip(keys, aligned_vals)) - data = xr.Dataset(data) + data_arrays.append(arr) + + data = xr.merge(data_arrays, join='inner') data.attrs['runFolder'] = runFolder - tim = [k for k in _mnemonics if 'MCP' in k and k in data] + tim = [k for k in run_mnemonics if 'MCP' in k and k in data] if extract_tim and len(tim) > 0: data = tbdet.get_tim_peaks(run, mnemonics=tim, merge_with=data, bunchPattern=tim_bp) - laser = [k for k in _mnemonics if 'FastADC' in k and k in data] + laser = [k for k in run_mnemonics if 'FastADC' in k and k in data] if extract_laser and len(laser) > 0: data = tbdet.get_laser_peaks(run, mnemonics=laser, merge_with=data, bunchPattern=laser_bp) - xgm = ['XTD10_XGM', 'XTD10_XGM_sigma', 'XTD10_SA3', 'XTD10_SA3_sigma', - 'XTD10_SA1', 'XTD10_SA1_sigma', 'SCS_XGM', 'SCS_XGM_sigma', + xgm = ['XTD10_XGM', 'XTD10_XGM_sigma', 'XTD10_SA3', 'XTD10_SA3_sigma', + 'XTD10_SA1', 'XTD10_SA1_sigma', 'SCS_XGM', 'SCS_XGM_sigma', 'SCS_SA1', 'SCS_SA1_sigma', 'SCS_SA3', 'SCS_SA3_sigma'] xgm = [k for k in xgm if k in data] if extract_xgm and len(xgm) > 0: data = tbdet.get_xgm(run, mnemonics=xgm, merge_with=data) - bam = [k for k in _mnemonics if 'BAM' in k and k in data] + bam = [k for k in run_mnemonics if 'BAM' in k and k in data] if extract_bam and len(bam) > 0: data = tbdet.get_bam(run, mnemonics=bam, merge_with=data) @@ -314,79 +321,3 @@ def get_array(run, mnemonic_key=None, stepsize=None): raise return data - - -def mnemonics_to_process(mnemo_list, merge_with, detector, func=None): - """ - Finds the list of mnemonics, within mnemo_list and merge_with, that - correspond to arrays that are not yet loaded and/or processed by a - detector function. Removes the mnemonics of the already processed - arrays from the list. - - Parameters - ---------- - mnemo_list: str or list of str - ToolBox mnemonics of pulse-resolved detector arrays - merge_with: xarray Dataset - Dataset that may contain non-processed arrays - detector: str - One in {'ADQ412', 'FastADC', 'XGM', 'BAM'} - func: function - function that takes one argument, an unprocessed mnemonic string, - and converts it into a processed one, i.e. from 'MCP2apd' to - 'MCP2peaks'. If None, the function returns the input mnemonic. - - Returns - ------- - mnemonics: list of str - the mnemonics to process - """ - if func is None: - def func(x): - return x - - if detector == 'BAM': - det_mnemos = [m for m in _mnemonics if 'BAM' in m] - default_mnemo = 'BAM1932M' - default_processed = 'BAM1932M' - if detector == 'XGM': - det_mnemos = ['XTD10_XGM', 'XTD10_XGM_sigma', 'XTD10_SA3', - 'XTD10_SA3_sigma', 'XTD10_SA1', 'XTD10_SA1_sigma', - 'SCS_XGM', 'SCS_XGM_sigma', 'SCS_SA1', 'SCS_SA1_sigma', - 'SCS_SA3', 'SCS_SA3_sigma'] - default_mnemo = 'SCS_SA3' - default_processed = 'SCS_SA3' - if detector == 'ADQ412': - det_mnemos = [m for m in _mnemonics if 'MCP' in m] - default_mnemo = 'MCP2apd' - default_processed = 'MCP2peaks' - if detector == 'FastADC': - det_mnemos = [m for m in _mnemonics if 'FastADC' in m] - default_mnemo = 'FastADC5raw' - default_processed = 'FastADC5peaks' - - dig_dims = list(set([_mnemonics[m]['dim'][0] for m in det_mnemos])) - processed_mnemos = list(set([func(m) for m in det_mnemos])) - - # create a list of mnemonics to process from the provided mnemonics and - # merge_with Dataset - mw_mnemos = [] - mw_processed = [] - if bool(merge_with): - mw_mnemos = [m for m in merge_with if m in det_mnemos and - any(dim in merge_with[m].dims for dim in dig_dims)] - mw_processed = [m for m in merge_with if m in processed_mnemos and - any(dim in merge_with[m].dims for dim in dig_dims) - is False] - if mnemo_list is None: - mnemonics = [] - if len(mw_mnemos) == 0 and default_processed not in mw_processed: - mnemonics = [default_mnemo] - else: - mnemonics = [mnemo_list] if isinstance(mnemo_list, str) else mnemo_list - mnemonics = list(set(mnemonics + mw_mnemos)) - for m in mnemonics[:]: - if func(m) in mw_processed: - mnemonics.remove(m) - - return mnemonics diff --git a/src/toolbox_scs/mnemonics_machinery.py b/src/toolbox_scs/mnemonics_machinery.py new file mode 100644 index 0000000..dac8d1a --- /dev/null +++ b/src/toolbox_scs/mnemonics_machinery.py @@ -0,0 +1,145 @@ +""" Handling ToolBox mnemonics sub-routines + + Copyright (2021) SCS Team. + + (contributions preferrably comply with pep8 code structure + guidelines.) +""" + +import logging + +from .constants import mnemonics as _mnemonics + +log = logging.getLogger(__name__) + + +def mnemonics_for_run(run): + """ + Returns the availble ToolBox mnemonics for a give extra_data + DataCollection + + Parameters + ---------- + run: extra_data DataCollection + The run to check for mnemonics + + Returns + ------- + mnemonics: dict + The dictionnary of mnemonics that are available in the run. + + Example + ------- + >>> import toolbox_scs as tb + >>> run, _ = tb.load(2212, 213) + >>> tb.mnemonics_for_run(run) + """ + result = {} + for m in _mnemonics: + version = mnemo_version_index(run, m) + if version != -1: + result[m] = _mnemonics[m][version] + return result + + +def mnemo_version_index(run, mnemonic): + """ + Given a mnemonic and a DataCollection, checks the existence of the + mnemonic versions within the tuple value of the mnemonic and returns the + valid version index. + + Parameters + ---------- + run: extra_data DataCollection + The run that contains the data source corresponding to the mnemonic + menmonic: str + A ToolBox mnemonic + + Returns + ------- + index: int + The index of the tuple. If no valid version is found, returns -1. + + """ + for i, v in enumerate(_mnemonics[mnemonic]): + if (v['source'] in run.all_sources and + v['key'] in run.keys_for_source(v['source'])): + log.debug(f'Found version {i} for mnemonic "{mnemonic}": {v}') + return i + return -1 + + +def mnemonics_to_process(mnemo_list, merge_with, detector, func=None): + """ + Finds the list of mnemonics, within mnemo_list and merge_with, that + correspond to arrays that are not yet loaded and/or processed by a + detector function. Removes the mnemonics of the already processed + arrays from the list. + + Parameters + ---------- + mnemo_list: str or list of str + ToolBox mnemonics of pulse-resolved detector arrays + merge_with: xarray Dataset + Dataset that may contain non-processed arrays + detector: str + One in {'ADQ412', 'FastADC', 'XGM', 'BAM'} + func: function + function that takes one argument, an unprocessed mnemonic string, + and converts it into a processed one, i.e. from 'MCP2apd' to + 'MCP2peaks'. If None, the function returns the input mnemonic. + + Returns + ------- + mnemonics: list of str + the mnemonics to process + """ + if func is None: + def func(x): + return x + + if detector == 'BAM': + det_mnemos = [m for m in _mnemonics if 'BAM' in m] + default_mnemo = 'BAM1932M' + default_processed = 'BAM1932M' + if detector == 'XGM': + det_mnemos = ['XTD10_XGM', 'XTD10_XGM_sigma', 'XTD10_SA3', + 'XTD10_SA3_sigma', 'XTD10_SA1', 'XTD10_SA1_sigma', + 'SCS_XGM', 'SCS_XGM_sigma', 'SCS_SA1', 'SCS_SA1_sigma', + 'SCS_SA3', 'SCS_SA3_sigma'] + default_mnemo = 'SCS_SA3' + default_processed = 'SCS_SA3' + if detector == 'ADQ412': + det_mnemos = [m for m in _mnemonics if 'MCP' in m] + default_mnemo = 'MCP2apd' + default_processed = 'MCP2peaks' + if detector == 'FastADC': + det_mnemos = [m for m in _mnemonics if 'FastADC' in m] + default_mnemo = 'FastADC5raw' + default_processed = 'FastADC5peaks' + + dig_dims = list(set([_mnemonics[m][0]['dim'][0] for m in det_mnemos])) + processed_mnemos = list(set([func(m) for m in det_mnemos])) + + # create a list of mnemonics to process from the provided mnemonics and + # merge_with Dataset + mw_mnemos = [] + mw_processed = [] + if bool(merge_with): + mw_mnemos = [m for m in merge_with if m in det_mnemos and + any(dim in merge_with[m].dims for dim in dig_dims)] + mw_processed = [m for m in merge_with if m in processed_mnemos and + any(dim in merge_with[m].dims for dim in dig_dims) + is False] + if mnemo_list is None: + mnemonics = [] + if len(mw_mnemos) == 0 and default_processed not in mw_processed: + mnemonics = [default_mnemo] + else: + mnemonics = [mnemo_list] if isinstance(mnemo_list, str) else mnemo_list + mnemonics = list(set(mnemonics + mw_mnemos)) + for m in mnemonics[:]: + if func(m) in mw_processed: + mnemonics.remove(m) + + return mnemonics -- GitLab