From 0ac6a3138e19a3405519114d9e00769964706aa1 Mon Sep 17 00:00:00 2001
From: Laurent Mercadier <laurent.mercadier@xfel.eu>
Date: Mon, 19 Jun 2023 13:24:03 +0200
Subject: [PATCH] Add documentation about missing trains check

---
 doc/Loading_data_in_memory.ipynb | 235 ++++++++++++++++++++++++++++---
 1 file changed, 213 insertions(+), 22 deletions(-)

diff --git a/doc/Loading_data_in_memory.ipynb b/doc/Loading_data_in_memory.ipynb
index 3e99a99..6fe6e33 100644
--- a/doc/Loading_data_in_memory.ipynb
+++ b/doc/Loading_data_in_memory.ipynb
@@ -28,6 +28,13 @@
    "execution_count": 1,
    "metadata": {},
    "outputs": [
+    {
+     "name": "stdout",
+     "output_type": "stream",
+     "text": [
+      "Cupy is not installed in this environment, no access to the GPU\n"
+     ]
+    },
     {
      "data": {
       "text/plain": [
@@ -642,17 +649,19 @@
        "  fill: currentColor;\n",
        "}\n",
        "</style><pre class='xr-text-repr-fallback'>&lt;xarray.Dataset&gt;\n",
-       "Dimensions:    (sa3_pId: 125, trainId: 3066)\n",
+       "Dimensions:            (pulse_slot: 2700, sa3_pId: 125, trainId: 3066)\n",
        "Coordinates:\n",
-       "  * trainId    (trainId) uint64 520069541 520069542 ... 520072605 520072606\n",
-       "  * sa3_pId    (sa3_pId) int64 1040 1048 1056 1064 1072 ... 2008 2016 2024 2032\n",
+       "  * trainId            (trainId) uint64 520069541 520069542 ... 520072606\n",
+       "  * sa3_pId            (sa3_pId) int64 1040 1048 1056 1064 ... 2016 2024 2032\n",
+       "Dimensions without coordinates: pulse_slot\n",
        "Data variables:\n",
-       "    nrj        (trainId) float64 778.6 778.6 778.5 778.5 ... 783.4 783.4 783.4\n",
-       "    MCP3peaks  (trainId, sa3_pId) float64 -197.7 -34.67 ... -1.213e+03\n",
-       "    SCS_SA3    (trainId, sa3_pId) float32 2838.6826 897.9348 ... 8069.3115\n",
+       "    nrj                (trainId) float64 778.6 778.6 778.5 ... 783.4 783.4 783.4\n",
+       "    MCP3peaks          (trainId, sa3_pId) float64 -197.7 -34.67 ... -1.213e+03\n",
+       "    bunchPatternTable  (trainId, pulse_slot) uint32 2139945 0 2129961 ... 0 0 0\n",
+       "    SCS_SA3            (trainId, sa3_pId) float32 2838.6826 ... 8069.3115\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-74989f5f-0be4-449b-803f-9a0056aecb89' class='xr-section-summary-in' type='checkbox' disabled ><label for='section-74989f5f-0be4-449b-803f-9a0056aecb89' class='xr-section-summary'  title='Expand/collapse section'>Dimensions:</label><div class='xr-section-inline-details'><ul class='xr-dim-list'><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-99327648-08f1-4329-aa2a-fcd0c6d46f47' class='xr-section-summary-in' type='checkbox'  checked><label for='section-99327648-08f1-4329-aa2a-fcd0c6d46f47' 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-47b77359-053e-4be2-9f54-ad18db57e4c6' class='xr-var-attrs-in' type='checkbox' disabled><label for='attrs-47b77359-053e-4be2-9f54-ad18db57e4c6' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-59ce29ac-459f-4a85-921b-d359f86d30b5' class='xr-var-data-in' type='checkbox'><label for='data-59ce29ac-459f-4a85-921b-d359f86d30b5' 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-50765c88-a568-4024-9894-8e72afe40ead' class='xr-var-attrs-in' type='checkbox' disabled><label for='attrs-50765c88-a568-4024-9894-8e72afe40ead' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-f4b89896-c2d2-40bf-ade4-38c0fbd2f38e' class='xr-var-data-in' type='checkbox'><label for='data-f4b89896-c2d2-40bf-ade4-38c0fbd2f38e' 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-085f0aef-4a12-4e03-94c3-f23bc89a5708' class='xr-section-summary-in' type='checkbox' disabled ><label for='section-085f0aef-4a12-4e03-94c3-f23bc89a5708' 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-f8e70b2a-dbce-421a-9ace-4807c81f9f30' class='xr-section-summary-in' type='checkbox'  checked><label for='section-f8e70b2a-dbce-421a-9ace-4807c81f9f30' 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-84ffe86d-fdd5-4425-8dd7-373ec691404f' class='xr-var-attrs-in' type='checkbox' disabled><label for='attrs-84ffe86d-fdd5-4425-8dd7-373ec691404f' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-0c1a5095-02cd-4f9f-9f05-5c531e70fed9' class='xr-var-data-in' type='checkbox'><label for='data-0c1a5095-02cd-4f9f-9f05-5c531e70fed9' 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-286f892a-39b5-43aa-b5d0-d276259522af' class='xr-var-attrs-in' type='checkbox' disabled><label for='attrs-286f892a-39b5-43aa-b5d0-d276259522af' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-dd118a90-596f-4134-9870-ef0040a08660' class='xr-var-data-in' type='checkbox'><label for='data-dd118a90-596f-4134-9870-ef0040a08660' 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",
@@ -662,8 +671,8 @@
        "       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-21892919-8222-4f6d-82dc-3e3bf7a3516b' class='xr-section-summary-in' type='checkbox'  checked><label for='section-21892919-8222-4f6d-82dc-3e3bf7a3516b' class='xr-section-summary' >Data variables: <span>(3)</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>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-aa6b48a6-bce2-4843-a5bb-6bfbbafab4cb' class='xr-var-attrs-in' type='checkbox' disabled><label for='attrs-aa6b48a6-bce2-4843-a5bb-6bfbbafab4cb' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-af204f67-7ed6-4c56-92f5-72d3bff80ebb' class='xr-var-data-in' type='checkbox'><label for='data-af204f67-7ed6-4c56-92f5-72d3bff80ebb' 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-6ddd9669-affa-4245-9bb6-aecd3d6c1c2e' class='xr-var-attrs-in' type='checkbox' disabled><label for='attrs-6ddd9669-affa-4245-9bb6-aecd3d6c1c2e' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-bc46b69e-3629-442a-9b70-d1c578ed6b50' class='xr-var-data-in' type='checkbox'><label for='data-bc46b69e-3629-442a-9b70-d1c578ed6b50' 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",
+       "       2000, 2008, 2016, 2024, 2032])</pre></div></li></ul></div></li><li class='xr-section-item'><input id='section-f0a952b4-1168-434a-9338-9535809448bf' class='xr-section-summary-in' type='checkbox'  checked><label for='section-f0a952b4-1168-434a-9338-9535809448bf' 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>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-fcd2e5c8-3c5d-4cc1-8738-63595d7d9bc4' class='xr-var-attrs-in' type='checkbox' disabled><label for='attrs-fcd2e5c8-3c5d-4cc1-8738-63595d7d9bc4' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-f80a84a5-1a36-468a-b8d1-6563f0cb8385' class='xr-var-data-in' type='checkbox'><label for='data-f80a84a5-1a36-468a-b8d1-6563f0cb8385' 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-c6941b0a-d79b-427d-95d4-92f2e8a853ef' class='xr-var-attrs-in' type='checkbox' disabled><label for='attrs-c6941b0a-d79b-427d-95d4-92f2e8a853ef' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-eb8a6249-9bdf-4f3a-89b2-61837021d89b' class='xr-var-data-in' type='checkbox'><label for='data-eb8a6249-9bdf-4f3a-89b2-61837021d89b' 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",
@@ -675,7 +684,14 @@
        "       [-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'>float32</div><div class='xr-var-preview xr-preview'>2838.6826 897.9348 ... 8069.3115</div><input id='attrs-bcf81088-196b-48ed-9810-4f50fc98bae0' class='xr-var-attrs-in' type='checkbox' disabled><label for='attrs-bcf81088-196b-48ed-9810-4f50fc98bae0' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-e1fcb774-2cc6-4712-a136-cc8ff4fe87f5' class='xr-var-data-in' type='checkbox'><label for='data-e1fcb774-2cc6-4712-a136-cc8ff4fe87f5' 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.6826 ,   897.9348 ,  1270.1282 , ..., 33158.98   ,\n",
+       "        -9.43666667e+02, -2.86800000e+03, -1.21266667e+03]])</pre></div></li><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-c243e3f0-24b7-4099-a967-4521fc95c948' class='xr-var-attrs-in' type='checkbox' disabled><label for='attrs-c243e3f0-24b7-4099-a967-4521fc95c948' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-3d0b532c-9ab9-4972-b2b0-0e3d5280338b' class='xr-var-data-in' type='checkbox'><label for='data-3d0b532c-9ab9-4972-b2b0-0e3d5280338b' 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>SCS_SA3</span></div><div class='xr-var-dims'>(trainId, sa3_pId)</div><div class='xr-var-dtype'>float32</div><div class='xr-var-preview xr-preview'>2838.6826 897.9348 ... 8069.3115</div><input id='attrs-637e1e15-03bd-40f0-b511-f1ff3c3b39e1' class='xr-var-attrs-in' type='checkbox' disabled><label for='attrs-637e1e15-03bd-40f0-b511-f1ff3c3b39e1' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-64f41dac-8de6-4729-8b1c-2d4a89a532c9' class='xr-var-data-in' type='checkbox'><label for='data-64f41dac-8de6-4729-8b1c-2d4a89a532c9' 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.6826 ,   897.9348 ,  1270.1282 , ..., 33158.98   ,\n",
        "        19836.096  , 27724.035  ],\n",
        "       [ 2088.772  ,   861.3658 ,  3565.1692 , ..., 16303.649  ,\n",
        "        12787.915  ,  6092.001  ],\n",
@@ -687,18 +703,20 @@
        "       [ 3646.7505 ,  2033.2625 ,   569.5602 , ...,  9144.624  ,\n",
        "         7623.28   ,  4444.4536 ],\n",
        "       [  708.95374,  1963.8428 ,   912.64026, ...,  5079.5537 ,\n",
-       "        12632.79   ,  8069.3115 ]], dtype=float32)</pre></div></li></ul></div></li><li class='xr-section-item'><input id='section-879a5c15-d357-443c-87c6-0f61a4de2456' class='xr-section-summary-in' type='checkbox'  checked><label for='section-879a5c15-d357-443c-87c6-0f61a4de2456' 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>"
+       "        12632.79   ,  8069.3115 ]], dtype=float32)</pre></div></li></ul></div></li><li class='xr-section-item'><input id='section-d305a1ba-6ccb-4976-9868-e80e5eddcd4b' class='xr-section-summary-in' type='checkbox'  checked><label for='section-d305a1ba-6ccb-4976-9868-e80e5eddcd4b' 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",
-       "Dimensions:    (sa3_pId: 125, trainId: 3066)\n",
+       "Dimensions:            (pulse_slot: 2700, sa3_pId: 125, trainId: 3066)\n",
        "Coordinates:\n",
-       "  * trainId    (trainId) uint64 520069541 520069542 ... 520072605 520072606\n",
-       "  * sa3_pId    (sa3_pId) int64 1040 1048 1056 1064 1072 ... 2008 2016 2024 2032\n",
+       "  * trainId            (trainId) uint64 520069541 520069542 ... 520072606\n",
+       "  * sa3_pId            (sa3_pId) int64 1040 1048 1056 1064 ... 2016 2024 2032\n",
+       "Dimensions without coordinates: pulse_slot\n",
        "Data variables:\n",
-       "    nrj        (trainId) float64 778.6 778.6 778.5 778.5 ... 783.4 783.4 783.4\n",
-       "    MCP3peaks  (trainId, sa3_pId) float64 -197.7 -34.67 ... -1.213e+03\n",
-       "    SCS_SA3    (trainId, sa3_pId) float32 2838.6826 897.9348 ... 8069.3115\n",
+       "    nrj                (trainId) float64 778.6 778.6 778.5 ... 783.4 783.4 783.4\n",
+       "    MCP3peaks          (trainId, sa3_pId) float64 -197.7 -34.67 ... -1.213e+03\n",
+       "    bunchPatternTable  (trainId, pulse_slot) uint32 2139945 0 2129961 ... 0 0 0\n",
+       "    SCS_SA3            (trainId, sa3_pId) float32 2838.6826 ... 8069.3115\n",
        "Attributes:\n",
        "    runFolder:  /gpfs/exfel/exp/SCS/201901/p002212/raw/r0208"
       ]
@@ -1118,14 +1136,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-7d0c7184-25b1-4288-bfd9-47f3e9b4f93a' class='xr-array-in' type='checkbox' checked><label for='section-7d0c7184-25b1-4288-bfd9-47f3e9b4f93a' 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-1fd34062-4cbb-4858-bb09-b40506ef9c17' class='xr-array-in' type='checkbox' checked><label for='section-1fd34062-4cbb-4858-bb09-b40506ef9c17' 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-d123789c-c419-49e2-bf55-ef97bf2d6c34' class='xr-section-summary-in' type='checkbox'  checked><label for='section-d123789c-c419-49e2-bf55-ef97bf2d6c34' 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-fc637dab-4e94-4478-8fe2-dd6fc460902d' class='xr-var-attrs-in' type='checkbox' disabled><label for='attrs-fc637dab-4e94-4478-8fe2-dd6fc460902d' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-a0b67c0b-bef9-42f0-95df-4489f4aed951' class='xr-var-data-in' type='checkbox'><label for='data-a0b67c0b-bef9-42f0-95df-4489f4aed951' 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-a9abdb8f-8036-48fe-bdb2-659be323c556' class='xr-section-summary-in' type='checkbox' disabled ><label for='section-a9abdb8f-8036-48fe-bdb2-659be323c556' 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-de014c49-eb43-4e5c-9ff7-271d6ff8bdd0' class='xr-section-summary-in' type='checkbox'  checked><label for='section-de014c49-eb43-4e5c-9ff7-271d6ff8bdd0' 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-7e5da8ce-be8e-4ba7-a590-2900d1db7fd8' class='xr-var-attrs-in' type='checkbox' disabled><label for='attrs-7e5da8ce-be8e-4ba7-a590-2900d1db7fd8' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-910371ff-d98e-4d80-9517-c0f8e20a5fe4' class='xr-var-data-in' type='checkbox'><label for='data-910371ff-d98e-4d80-9517-c0f8e20a5fe4' 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-3f1800f0-d78d-47eb-9663-9f013925a821' class='xr-section-summary-in' type='checkbox' disabled ><label for='section-3f1800f0-d78d-47eb-9663-9f013925a821' 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",
@@ -1166,7 +1184,7 @@
     {
      "data": {
       "text/plain": [
-       "[<matplotlib.lines.Line2D at 0x2b08f97ab748>]"
+       "[<matplotlib.lines.Line2D at 0x2af2127a4f28>]"
       ]
      },
      "execution_count": 7,
@@ -1189,6 +1207,179 @@
    "source": [
     "raw_traces.isel(trainId=0).plot()"
    ]
+  },
+  {
+   "cell_type": "markdown",
+   "metadata": {},
+   "source": [
+    "# Missing trains"
+   ]
+  },
+  {
+   "cell_type": "markdown",
+   "metadata": {},
+   "source": [
+    "The data rate, or percentage of trains containing data, is checked in the `load` function, and a warning is displayed if less than 95% of data is present. This can be useful to identify DAQ problems during a beamtime."
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 8,
+   "metadata": {},
+   "outputs": [
+    {
+     "name": "stderr",
+     "output_type": "stream",
+     "text": [
+      "SCS_SA3: only 85.6% of trains (2122 out of 2479) contain data.\n"
+     ]
+    }
+   ],
+   "source": [
+    "fields = ['SCS_HAMP_HV', 'SCS_SA3']\n",
+    "run, ds = tb.load(5836, 162, fields)"
+   ]
+  },
+  {
+   "cell_type": "markdown",
+   "metadata": {},
+   "source": [
+    "A function `check_data_rate` allows to extract the fraction of trains containing data for given mnemonics:"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 9,
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "text/plain": [
+       "{'SCS_HAMP_HV': 1.0, 'SCS_SA3': 0.8559903186768858}"
+      ]
+     },
+     "execution_count": 9,
+     "metadata": {},
+     "output_type": "execute_result"
+    }
+   ],
+   "source": [
+    "tb.check_data_rate(run, fields)"
+   ]
+  },
+  {
+   "cell_type": "markdown",
+   "metadata": {},
+   "source": [
+    "It will return the data rate for all mnemonics in the run if `fields` is omitted"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 10,
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "text/plain": [
+       "{'sase3': 1.0,\n",
+       " 'sase2': 1.0,\n",
+       " 'sase1': 1.0,\n",
+       " 'laser': 1.0,\n",
+       " 'maindump': 1.0,\n",
+       " 'bunchpattern': 1.0,\n",
+       " 'bunchPatternTable': 1.0,\n",
+       " 'npulses_sase3': 1.0,\n",
+       " 'npulses_sase1': 1.0,\n",
+       " 'npulses_laser': 1.0,\n",
+       " 'BAM414': 0.9693424768051634,\n",
+       " 'BAM1932M': 0.982654296087132,\n",
+       " 'BAM1932S': 0.9669221460266236,\n",
+       " 'DPS2CAM2': 0.0,\n",
+       " 'XTD10_photonFlux': 1.0,\n",
+       " 'XTD10_photonFlux_sigma': 1.0,\n",
+       " 'XTD10_XGM': 0.9983864461476402,\n",
+       " 'XTD10_XGM_sigma': 0.9983864461476402,\n",
+       " 'XTD10_SA3': 0.9983864461476402,\n",
+       " 'XTD10_SA3_sigma': 0.9983864461476402,\n",
+       " 'XTD10_SA1': 0.9983864461476402,\n",
+       " 'XTD10_SA1_sigma': 0.9983864461476402,\n",
+       " 'XTD10_slowTrain': 1.0,\n",
+       " 'XTD10_slowTrain_SA1': 1.0,\n",
+       " 'XTD10_slowTrain_SA3': 1.0,\n",
+       " 'SCS_photonFlux': 1.0,\n",
+       " 'SCS_photonFlux_sigma': 1.0,\n",
+       " 'SCS_HAMP_HV': 1.0,\n",
+       " 'SCS_XGM': 0.8559903186768858,\n",
+       " 'SCS_XGM_sigma': 0.8559903186768858,\n",
+       " 'SCS_SA1': 0.8559903186768858,\n",
+       " 'SCS_SA1_sigma': 0.8559903186768858,\n",
+       " 'SCS_SA3': 0.8559903186768858,\n",
+       " 'SCS_SA3_sigma': 0.8559903186768858,\n",
+       " 'SCS_slowTrain': 1.0,\n",
+       " 'SCS_slowTrain_SA1': 1.0,\n",
+       " 'SCS_slowTrain_SA3': 1.0,\n",
+       " 'AFS_DelayLine': 1.0,\n",
+       " 'AFS_FocusLens': 1.0,\n",
+       " 'PP800_PhaseShifter': 1.0,\n",
+       " 'PP800_SynchDelayLine': 1.0,\n",
+       " 'PP800_DelayLine': 1.0,\n",
+       " 'PP800_HalfWP': 1.0,\n",
+       " 'PP800_FocusLens': 1.0,\n",
+       " 'FFT_FocusLens': 1.0,\n",
+       " 'ZABER110_ODL': 1.0,\n",
+       " 'FastADC0peaks': 0.0,\n",
+       " 'FastADC0raw': 0.0,\n",
+       " 'FastADC1peaks': 0.0,\n",
+       " 'FastADC1raw': 0.0,\n",
+       " 'FastADC2peaks': 0.0,\n",
+       " 'FastADC2raw': 0.0,\n",
+       " 'FastADC3peaks': 1.0,\n",
+       " 'FastADC3raw': 1.0,\n",
+       " 'FastADC4peaks': 0.0,\n",
+       " 'FastADC4raw': 0.0,\n",
+       " 'FastADC5peaks': 1.0,\n",
+       " 'FastADC5raw': 1.0,\n",
+       " 'FastADC6peaks': 0.0,\n",
+       " 'FastADC6raw': 0.0,\n",
+       " 'FastADC7peaks': 0.0,\n",
+       " 'FastADC7raw': 0.0,\n",
+       " 'FastADC8peaks': 0.0,\n",
+       " 'FastADC8raw': 0.0,\n",
+       " 'FastADC9peaks': 1.0,\n",
+       " 'FastADC9raw': 1.0,\n",
+       " 'FastADC2_0peaks': 0.0,\n",
+       " 'FastADC2_0raw': 0.0,\n",
+       " 'FastADC2_1peaks': 0.0,\n",
+       " 'FastADC2_1raw': 0.0,\n",
+       " 'FastADC2_2peaks': 0.0,\n",
+       " 'FastADC2_2raw': 0.0,\n",
+       " 'FastADC2_3peaks': 0.0,\n",
+       " 'FastADC2_3raw': 0.0,\n",
+       " 'FastADC2_4peaks': 0.0,\n",
+       " 'FastADC2_4raw': 0.0,\n",
+       " 'FastADC2_5peaks': 0.0,\n",
+       " 'FastADC2_5raw': 0.0,\n",
+       " 'FastADC2_6peaks': 1.0,\n",
+       " 'FastADC2_6raw': 1.0,\n",
+       " 'FastADC2_7peaks': 1.0,\n",
+       " 'FastADC2_7raw': 1.0,\n",
+       " 'FastADC2_8peaks': 0.0,\n",
+       " 'FastADC2_8raw': 0.0,\n",
+       " 'FastADC2_9peaks': 0.0,\n",
+       " 'FastADC2_9raw': 0.0,\n",
+       " 'Gotthard1': 1.0,\n",
+       " 'Gotthard2': 0.0}"
+      ]
+     },
+     "execution_count": 10,
+     "metadata": {},
+     "output_type": "execute_result"
+    }
+   ],
+   "source": [
+    "tb.check_data_rate(run)"
+   ]
   }
  ],
  "metadata": {
-- 
GitLab