diff --git a/examples/LoadImageFromDB-execution.ipynb b/examples/LoadImageFromDB-execution.ipynb
new file mode 100644
index 0000000..00efe9e
--- /dev/null
+++ b/examples/LoadImageFromDB-execution.ipynb
@@ -0,0 +1,1084 @@
+{
+ "cells": [
+ {
+ "cell_type": "code",
+ "execution_count": 1,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "import os\n",
+ "import datetime\n",
+ "import h5py\n",
+ "import numpy as np\n",
+ "import imageio\n",
+ "import matplotlib.pyplot as plt\n",
+ "from matplotlib.colors import LogNorm\n",
+ "\n",
+ "from databroker import Broker\n",
+ "from eiger_io.fs_handler import EigerHandler"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 2,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "db = Broker.named('chx')\n",
+ "db.reg.register_handler('AD_EIGER2', EigerHandler, overwrite=True)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 3,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+ "source": [
+ "def save_hdf5(data, filename='data.h5', dataset='dataset', save_dir=None):\n",
+ " \"\"\"Saving data to an hdf5 file.\n",
+ " \n",
+ " Parameters\n",
+ " ----------\n",
+ " data: ndarray\n",
+ " data array to save into hdf5 file\n",
+ " filename: str\n",
+ " the name of the file\n",
+ " dataset: str\n",
+ " the name of the entry in the hdf5 layout\n",
+ " save_dir: None or str\n",
+ " a directory to save the file in\n",
+ " \n",
+ " Returns\n",
+ " -------\n",
+ " status: str\n",
+ " a status string\n",
+ " \"\"\"\n",
+ " if save_dir:\n",
+ " filename = os.path.join(save_dir, filename)\n",
+ " h5f = h5py.File(filename, 'w')\n",
+ " r = h5f.create_dataset(dataset, data=data)\n",
+ " status = '{} created: {}'.format(r, os.path.abspath(filename))\n",
+ " h5f.close()\n",
+ " return status"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Get data from Eiger detector"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 4,
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "time: 201707312119\n",
+ "uid: f4fe7c56-3c23-4445-8bec-9a373066ead2\n",
+ "scan_id: 5068\n"
+ ]
+ }
+ ],
+ "source": [
+ "eiger_uid = 'f4fe7c'\n",
+ "hdr_eiger = db[eiger_uid] # 'eiger4m_single_image' field for hdr.data()\n",
+ "time_e = datetime.datetime.fromtimestamp(timestamp=hdr_eiger['start']['time']).strftime('%Y%m%d%H%M')\n",
+ "uid_e = hdr_eiger['start']['uid']\n",
+ "scan_id_e = hdr_eiger['start']['scan_id']\n",
+ "print(f'time: {time_e}\\nuid: {uid_e}\\nscan_id: {scan_id_e}')"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 5,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "
\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " time | \n",
+ " eiger4m_single_image | \n",
+ " eiger4m_single_stats1_total | \n",
+ " eiger4m_single_stats2_total | \n",
+ " eiger4m_single_stats3_total | \n",
+ " eiger4m_single_stats4_total | \n",
+ " eiger4m_single_stats5_total | \n",
+ "
\n",
+ " \n",
+ " seq_num | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " 1 | \n",
+ " 2017-07-31 21:21:58.409980 | \n",
+ " aee074a3-2e4e-4295-854c-da0b7f919853 | \n",
+ " 648629050.0 | \n",
+ " 252040143.0 | \n",
+ " 8.590173e+10 | \n",
+ " 2.576998e+10 | \n",
+ " 2.130496e+15 | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
"
+ ],
+ "text/plain": [
+ " time eiger4m_single_image \\\n",
+ "seq_num \n",
+ "1 2017-07-31 21:21:58.409980 aee074a3-2e4e-4295-854c-da0b7f919853 \n",
+ "\n",
+ " eiger4m_single_stats1_total eiger4m_single_stats2_total \\\n",
+ "seq_num \n",
+ "1 648629050.0 252040143.0 \n",
+ "\n",
+ " eiger4m_single_stats3_total eiger4m_single_stats4_total \\\n",
+ "seq_num \n",
+ "1 8.590173e+10 2.576998e+10 \n",
+ "\n",
+ " eiger4m_single_stats5_total \n",
+ "seq_num \n",
+ "1 2.130496e+15 "
+ ]
+ },
+ "execution_count": 5,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "hdr_eiger.table()"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 6,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "{'eiger4m_single_image',\n",
+ " 'eiger4m_single_stats1_total',\n",
+ " 'eiger4m_single_stats2_total',\n",
+ " 'eiger4m_single_stats3_total',\n",
+ " 'eiger4m_single_stats4_total',\n",
+ " 'eiger4m_single_stats5_total'}"
+ ]
+ },
+ "execution_count": 6,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "hdr_eiger.fields()"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "### Use the field with an '_image' occurrence"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 7,
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "filepath : /XF11ID/data/2017/07/31/5c06c4d9-3743-4873-8ea9\n",
+ "got images_per_file\n"
+ ]
+ }
+ ],
+ "source": [
+ "imgs_eiger = list(hdr_eiger.data('eiger4m_single_image'))"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 8,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "(2167, 2070)"
+ ]
+ },
+ "execution_count": 8,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "imgs_eiger[0].shape"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 9,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "application/vnd.jupyter.widget-view+json": {
+ "model_id": "",
+ "version_major": 2,
+ "version_minor": 0
+ },
+ "text/plain": [
+ "FigureCanvasNbAgg()"
+ ]
+ },
+ "metadata": {},
+ "output_type": "display_data"
+ },
+ {
+ "data": {
+ "text/plain": [
+ ""
+ ]
+ },
+ "execution_count": 9,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "%matplotlib widget\n",
+ "plt.imshow(imgs_eiger[0][0], cmap='viridis', norm=LogNorm())"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Get data from xray eye camera"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 10,
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "time: 201801201715\n",
+ "uid: 44aae6fe-70b7-4fbf-a4ed-2297ea6b725f\n",
+ "scan_id: 10836\n"
+ ]
+ }
+ ],
+ "source": [
+ "xeye_uid = '44aae6fe'\n",
+ "hdr_xeye = db[xeye_uid] # 'xray_eye3_image' field for hdr.data\n",
+ "time_x = datetime.datetime.fromtimestamp(timestamp=hdr_xeye['start']['time']).strftime('%Y%m%d%H%M')\n",
+ "uid_x = hdr_xeye['start']['uid']\n",
+ "scan_id_x = hdr_xeye['start']['scan_id']\n",
+ "print(f'time: {time_x}\\nuid: {uid_x}\\nscan_id: {scan_id_x}')"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 11,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " time | \n",
+ " xray_eye3_stats1_total | \n",
+ " xray_eye3_stats2_total | \n",
+ " xray_eye3_stats3_total | \n",
+ " xray_eye3_stats4_total | \n",
+ " xray_eye3_stats5_total | \n",
+ " xray_eye3_image | \n",
+ "
\n",
+ " \n",
+ " seq_num | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " 1 | \n",
+ " 2018-01-20 17:17:00.270831 | \n",
+ " 125698.0 | \n",
+ " 64832.0 | \n",
+ " 237824.0 | \n",
+ " 18878.0 | \n",
+ " 11772860.0 | \n",
+ " 04de934d-9daa-4c1f-8890-4a9a4d55744e | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
"
+ ],
+ "text/plain": [
+ " time xray_eye3_stats1_total \\\n",
+ "seq_num \n",
+ "1 2018-01-20 17:17:00.270831 125698.0 \n",
+ "\n",
+ " xray_eye3_stats2_total xray_eye3_stats3_total \\\n",
+ "seq_num \n",
+ "1 64832.0 237824.0 \n",
+ "\n",
+ " xray_eye3_stats4_total xray_eye3_stats5_total \\\n",
+ "seq_num \n",
+ "1 18878.0 11772860.0 \n",
+ "\n",
+ " xray_eye3_image \n",
+ "seq_num \n",
+ "1 04de934d-9daa-4c1f-8890-4a9a4d55744e "
+ ]
+ },
+ "execution_count": 11,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "hdr_xeye.table()"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 12,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "{'xray_eye3_image',\n",
+ " 'xray_eye3_stats1_total',\n",
+ " 'xray_eye3_stats2_total',\n",
+ " 'xray_eye3_stats3_total',\n",
+ " 'xray_eye3_stats4_total',\n",
+ " 'xray_eye3_stats5_total'}"
+ ]
+ },
+ "execution_count": 12,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "hdr_xeye.fields()"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "### Use the field with an '_image' occurrence"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 13,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "imgs_xeye = list(hdr_xeye.data('xray_eye3_image'))"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 14,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "(100, 2050, 2448)"
+ ]
+ },
+ "execution_count": 14,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "imgs_xeye[0].shape"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 15,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "application/vnd.jupyter.widget-view+json": {
+ "model_id": "54da83baba3a4d218ee6f8041c2cb9e2",
+ "version_major": 2,
+ "version_minor": 0
+ },
+ "text/plain": [
+ "FigureCanvasNbAgg()"
+ ]
+ },
+ "metadata": {},
+ "output_type": "display_data"
+ },
+ {
+ "data": {
+ "text/plain": [
+ ""
+ ]
+ },
+ "execution_count": 15,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "%matplotlib widget\n",
+ "plt.imshow(np.mean(imgs_xeye[0], axis=0), cmap='gray')"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Get tabular data"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 16,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "hdr_tab = db['635f98ba']"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 17,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " time | \n",
+ " mca_xs_channel1_rois_roi01_value | \n",
+ " mca_xs_channel1_rois_roi01_value_sum | \n",
+ " smp_y | \n",
+ " smp_y_setpoint | \n",
+ " smp_y_actuate | \n",
+ "
\n",
+ " \n",
+ " seq_num | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " 1 | \n",
+ " 2018-01-20 16:56:52.655752 | \n",
+ " 8852.950130 | \n",
+ " 8852.950130 | \n",
+ " 1.63200 | \n",
+ " 1.632000 | \n",
+ " 1 | \n",
+ "
\n",
+ " \n",
+ " 2 | \n",
+ " 2018-01-20 16:56:54.752364 | \n",
+ " 9455.684040 | \n",
+ " 9455.684040 | \n",
+ " 1.63407 | \n",
+ " 1.634069 | \n",
+ " 1 | \n",
+ "
\n",
+ " \n",
+ " 3 | \n",
+ " 2018-01-20 16:56:56.320527 | \n",
+ " 9188.674397 | \n",
+ " 9188.674397 | \n",
+ " 1.63614 | \n",
+ " 1.636138 | \n",
+ " 1 | \n",
+ "
\n",
+ " \n",
+ " 4 | \n",
+ " 2018-01-20 16:56:58.668509 | \n",
+ " 9684.293795 | \n",
+ " 9684.293795 | \n",
+ " 1.63821 | \n",
+ " 1.638207 | \n",
+ " 1 | \n",
+ "
\n",
+ " \n",
+ " 5 | \n",
+ " 2018-01-20 16:57:01.070926 | \n",
+ " 10320.926364 | \n",
+ " 10320.926364 | \n",
+ " 1.64028 | \n",
+ " 1.640276 | \n",
+ " 1 | \n",
+ "
\n",
+ " \n",
+ " 6 | \n",
+ " 2018-01-20 16:57:02.616491 | \n",
+ " 11229.173725 | \n",
+ " 11229.173725 | \n",
+ " 1.64234 | \n",
+ " 1.642345 | \n",
+ " 1 | \n",
+ "
\n",
+ " \n",
+ " 7 | \n",
+ " 2018-01-20 16:57:07.248679 | \n",
+ " 11389.695753 | \n",
+ " 11389.695753 | \n",
+ " 1.64441 | \n",
+ " 1.644414 | \n",
+ " 1 | \n",
+ "
\n",
+ " \n",
+ " 8 | \n",
+ " 2018-01-20 16:57:10.695743 | \n",
+ " 12590.483663 | \n",
+ " 12590.483663 | \n",
+ " 1.64648 | \n",
+ " 1.646483 | \n",
+ " 1 | \n",
+ "
\n",
+ " \n",
+ " 9 | \n",
+ " 2018-01-20 16:57:14.327309 | \n",
+ " 16611.346002 | \n",
+ " 16611.346002 | \n",
+ " 1.64855 | \n",
+ " 1.648552 | \n",
+ " 1 | \n",
+ "
\n",
+ " \n",
+ " 10 | \n",
+ " 2018-01-20 16:57:20.603425 | \n",
+ " 20751.495839 | \n",
+ " 20751.495839 | \n",
+ " 1.65062 | \n",
+ " 1.650621 | \n",
+ " 1 | \n",
+ "
\n",
+ " \n",
+ " 11 | \n",
+ " 2018-01-20 16:57:25.915176 | \n",
+ " 25207.733610 | \n",
+ " 25207.733610 | \n",
+ " 1.65269 | \n",
+ " 1.652690 | \n",
+ " 1 | \n",
+ "
\n",
+ " \n",
+ " 12 | \n",
+ " 2018-01-20 16:57:27.634732 | \n",
+ " 38616.633253 | \n",
+ " 38616.633253 | \n",
+ " 1.65476 | \n",
+ " 1.654759 | \n",
+ " 1 | \n",
+ "
\n",
+ " \n",
+ " 13 | \n",
+ " 2018-01-20 16:57:31.626734 | \n",
+ " 79980.406192 | \n",
+ " 79980.406192 | \n",
+ " 1.65683 | \n",
+ " 1.656828 | \n",
+ " 1 | \n",
+ "
\n",
+ " \n",
+ " 14 | \n",
+ " 2018-01-20 16:57:33.480865 | \n",
+ " 155312.266491 | \n",
+ " 155312.266491 | \n",
+ " 1.65890 | \n",
+ " 1.658897 | \n",
+ " 1 | \n",
+ "
\n",
+ " \n",
+ " 15 | \n",
+ " 2018-01-20 16:57:35.916922 | \n",
+ " 227985.963766 | \n",
+ " 227985.963766 | \n",
+ " 1.66097 | \n",
+ " 1.660966 | \n",
+ " 1 | \n",
+ "
\n",
+ " \n",
+ " 16 | \n",
+ " 2018-01-20 16:57:37.890037 | \n",
+ " 256689.802487 | \n",
+ " 256689.802487 | \n",
+ " 1.66303 | \n",
+ " 1.663034 | \n",
+ " 1 | \n",
+ "
\n",
+ " \n",
+ " 17 | \n",
+ " 2018-01-20 16:57:39.938619 | \n",
+ " 215936.465360 | \n",
+ " 215936.465360 | \n",
+ " 1.66510 | \n",
+ " 1.665103 | \n",
+ " 1 | \n",
+ "
\n",
+ " \n",
+ " 18 | \n",
+ " 2018-01-20 16:57:42.086255 | \n",
+ " 136271.719730 | \n",
+ " 136271.719730 | \n",
+ " 1.66717 | \n",
+ " 1.667172 | \n",
+ " 1 | \n",
+ "
\n",
+ " \n",
+ " 19 | \n",
+ " 2018-01-20 16:57:53.622662 | \n",
+ " 73234.905911 | \n",
+ " 73234.905911 | \n",
+ " 1.66924 | \n",
+ " 1.669241 | \n",
+ " 1 | \n",
+ "
\n",
+ " \n",
+ " 20 | \n",
+ " 2018-01-20 16:57:58.384996 | \n",
+ " 39155.733105 | \n",
+ " 39155.733105 | \n",
+ " 1.67131 | \n",
+ " 1.671310 | \n",
+ " 1 | \n",
+ "
\n",
+ " \n",
+ " 21 | \n",
+ " 2018-01-20 16:58:00.092883 | \n",
+ " 28484.735369 | \n",
+ " 28484.735369 | \n",
+ " 1.67338 | \n",
+ " 1.673379 | \n",
+ " 1 | \n",
+ "
\n",
+ " \n",
+ " 22 | \n",
+ " 2018-01-20 16:58:02.589288 | \n",
+ " 24366.672081 | \n",
+ " 24366.672081 | \n",
+ " 1.67545 | \n",
+ " 1.675448 | \n",
+ " 1 | \n",
+ "
\n",
+ " \n",
+ " 23 | \n",
+ " 2018-01-20 16:58:04.892483 | \n",
+ " 19999.373753 | \n",
+ " 19999.373753 | \n",
+ " 1.67752 | \n",
+ " 1.677517 | \n",
+ " 1 | \n",
+ "
\n",
+ " \n",
+ " 24 | \n",
+ " 2018-01-20 16:58:08.038970 | \n",
+ " 16928.130224 | \n",
+ " 16928.130224 | \n",
+ " 1.67959 | \n",
+ " 1.679586 | \n",
+ " 1 | \n",
+ "
\n",
+ " \n",
+ " 25 | \n",
+ " 2018-01-20 16:58:09.778661 | \n",
+ " 16430.150998 | \n",
+ " 16430.150998 | \n",
+ " 1.68166 | \n",
+ " 1.681655 | \n",
+ " 1 | \n",
+ "
\n",
+ " \n",
+ " 26 | \n",
+ " 2018-01-20 16:58:11.927914 | \n",
+ " 15745.416235 | \n",
+ " 15745.416235 | \n",
+ " 1.68372 | \n",
+ " 1.683724 | \n",
+ " 1 | \n",
+ "
\n",
+ " \n",
+ " 27 | \n",
+ " 2018-01-20 16:58:13.620725 | \n",
+ " 14326.177558 | \n",
+ " 14326.177558 | \n",
+ " 1.68579 | \n",
+ " 1.685793 | \n",
+ " 1 | \n",
+ "
\n",
+ " \n",
+ " 28 | \n",
+ " 2018-01-20 16:58:15.724333 | \n",
+ " 14398.289874 | \n",
+ " 14398.289874 | \n",
+ " 1.68786 | \n",
+ " 1.687862 | \n",
+ " 1 | \n",
+ "
\n",
+ " \n",
+ " 29 | \n",
+ " 2018-01-20 16:58:17.358957 | \n",
+ " 14171.370792 | \n",
+ " 14171.370792 | \n",
+ " 1.68993 | \n",
+ " 1.689931 | \n",
+ " 1 | \n",
+ "
\n",
+ " \n",
+ " 30 | \n",
+ " 2018-01-20 16:58:23.899721 | \n",
+ " 14099.434124 | \n",
+ " 14099.434124 | \n",
+ " 1.69200 | \n",
+ " 1.692000 | \n",
+ " 1 | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
"
+ ],
+ "text/plain": [
+ " time mca_xs_channel1_rois_roi01_value \\\n",
+ "seq_num \n",
+ "1 2018-01-20 16:56:52.655752 8852.950130 \n",
+ "2 2018-01-20 16:56:54.752364 9455.684040 \n",
+ "3 2018-01-20 16:56:56.320527 9188.674397 \n",
+ "4 2018-01-20 16:56:58.668509 9684.293795 \n",
+ "5 2018-01-20 16:57:01.070926 10320.926364 \n",
+ "6 2018-01-20 16:57:02.616491 11229.173725 \n",
+ "7 2018-01-20 16:57:07.248679 11389.695753 \n",
+ "8 2018-01-20 16:57:10.695743 12590.483663 \n",
+ "9 2018-01-20 16:57:14.327309 16611.346002 \n",
+ "10 2018-01-20 16:57:20.603425 20751.495839 \n",
+ "11 2018-01-20 16:57:25.915176 25207.733610 \n",
+ "12 2018-01-20 16:57:27.634732 38616.633253 \n",
+ "13 2018-01-20 16:57:31.626734 79980.406192 \n",
+ "14 2018-01-20 16:57:33.480865 155312.266491 \n",
+ "15 2018-01-20 16:57:35.916922 227985.963766 \n",
+ "16 2018-01-20 16:57:37.890037 256689.802487 \n",
+ "17 2018-01-20 16:57:39.938619 215936.465360 \n",
+ "18 2018-01-20 16:57:42.086255 136271.719730 \n",
+ "19 2018-01-20 16:57:53.622662 73234.905911 \n",
+ "20 2018-01-20 16:57:58.384996 39155.733105 \n",
+ "21 2018-01-20 16:58:00.092883 28484.735369 \n",
+ "22 2018-01-20 16:58:02.589288 24366.672081 \n",
+ "23 2018-01-20 16:58:04.892483 19999.373753 \n",
+ "24 2018-01-20 16:58:08.038970 16928.130224 \n",
+ "25 2018-01-20 16:58:09.778661 16430.150998 \n",
+ "26 2018-01-20 16:58:11.927914 15745.416235 \n",
+ "27 2018-01-20 16:58:13.620725 14326.177558 \n",
+ "28 2018-01-20 16:58:15.724333 14398.289874 \n",
+ "29 2018-01-20 16:58:17.358957 14171.370792 \n",
+ "30 2018-01-20 16:58:23.899721 14099.434124 \n",
+ "\n",
+ " mca_xs_channel1_rois_roi01_value_sum smp_y smp_y_setpoint \\\n",
+ "seq_num \n",
+ "1 8852.950130 1.63200 1.632000 \n",
+ "2 9455.684040 1.63407 1.634069 \n",
+ "3 9188.674397 1.63614 1.636138 \n",
+ "4 9684.293795 1.63821 1.638207 \n",
+ "5 10320.926364 1.64028 1.640276 \n",
+ "6 11229.173725 1.64234 1.642345 \n",
+ "7 11389.695753 1.64441 1.644414 \n",
+ "8 12590.483663 1.64648 1.646483 \n",
+ "9 16611.346002 1.64855 1.648552 \n",
+ "10 20751.495839 1.65062 1.650621 \n",
+ "11 25207.733610 1.65269 1.652690 \n",
+ "12 38616.633253 1.65476 1.654759 \n",
+ "13 79980.406192 1.65683 1.656828 \n",
+ "14 155312.266491 1.65890 1.658897 \n",
+ "15 227985.963766 1.66097 1.660966 \n",
+ "16 256689.802487 1.66303 1.663034 \n",
+ "17 215936.465360 1.66510 1.665103 \n",
+ "18 136271.719730 1.66717 1.667172 \n",
+ "19 73234.905911 1.66924 1.669241 \n",
+ "20 39155.733105 1.67131 1.671310 \n",
+ "21 28484.735369 1.67338 1.673379 \n",
+ "22 24366.672081 1.67545 1.675448 \n",
+ "23 19999.373753 1.67752 1.677517 \n",
+ "24 16928.130224 1.67959 1.679586 \n",
+ "25 16430.150998 1.68166 1.681655 \n",
+ "26 15745.416235 1.68372 1.683724 \n",
+ "27 14326.177558 1.68579 1.685793 \n",
+ "28 14398.289874 1.68786 1.687862 \n",
+ "29 14171.370792 1.68993 1.689931 \n",
+ "30 14099.434124 1.69200 1.692000 \n",
+ "\n",
+ " smp_y_actuate \n",
+ "seq_num \n",
+ "1 1 \n",
+ "2 1 \n",
+ "3 1 \n",
+ "4 1 \n",
+ "5 1 \n",
+ "6 1 \n",
+ "7 1 \n",
+ "8 1 \n",
+ "9 1 \n",
+ "10 1 \n",
+ "11 1 \n",
+ "12 1 \n",
+ "13 1 \n",
+ "14 1 \n",
+ "15 1 \n",
+ "16 1 \n",
+ "17 1 \n",
+ "18 1 \n",
+ "19 1 \n",
+ "20 1 \n",
+ "21 1 \n",
+ "22 1 \n",
+ "23 1 \n",
+ "24 1 \n",
+ "25 1 \n",
+ "26 1 \n",
+ "27 1 \n",
+ "28 1 \n",
+ "29 1 \n",
+ "30 1 "
+ ]
+ },
+ "execution_count": 17,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "tbl = hdr_tab.table()\n",
+ "tbl"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 18,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "application/vnd.jupyter.widget-view+json": {
+ "model_id": "abca5475eb4e44e6ad63dfd375a52dcf",
+ "version_major": 2,
+ "version_minor": 0
+ },
+ "text/plain": [
+ "FigureCanvasNbAgg()"
+ ]
+ },
+ "metadata": {},
+ "output_type": "display_data"
+ },
+ {
+ "data": {
+ "text/plain": [
+ ""
+ ]
+ },
+ "execution_count": 18,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "tbl.plot(x='smp_y', y='mca_xs_channel1_rois_roi01_value_sum', grid=True)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 19,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "tbl.to_csv('/home/mrakitin/work/CHX/exported.csv')"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Save Eiger data to TIFF and HDF5 files"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 20,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "201707312119_f4fe7c_5068.tiff\n",
+ "201707312119_f4fe7c_5068.h5\n"
+ ]
+ }
+ ],
+ "source": [
+ "filename = '{}_{}_{}'.format(time_e, eiger_uid, scan_id_e)\n",
+ "filename_tiff= '{}.{}'.format(filename, 'tiff')\n",
+ "filename_h5 = '{}.{}'.format(filename, 'h5')\n",
+ "print(filename_tiff)\n",
+ "print(filename_h5)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 21,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "imageio.imwrite(os.path.join('/home/mrakitin/work/CHX/', filename_tiff), imgs_eiger[0][0])"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 22,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ " created: /home/mrakitin/work/CHX/201707312119_f4fe7c_5068.h5\n"
+ ]
+ }
+ ],
+ "source": [
+ "status = save_hdf5(imgs_eiger, filename=filename_h5, dataset='dataset',\n",
+ " save_dir='/home/mrakitin/work/CHX/')\n",
+ "print(status)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+ "source": []
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "CHX (current)",
+ "language": "python",
+ "name": "analysis-2018-2.1_srv1"
+ },
+ "language_info": {
+ "codemirror_mode": {
+ "name": "ipython",
+ "version": 3
+ },
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
+ "nbconvert_exporter": "python",
+ "pygments_lexer": "ipython3",
+ "version": "3.6.5"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 2
+}
diff --git a/examples/LoadImageFromDB-template.ipynb b/examples/LoadImageFromDB-template.ipynb
new file mode 100644
index 0000000..ae5456f
--- /dev/null
+++ b/examples/LoadImageFromDB-template.ipynb
@@ -0,0 +1,334 @@
+{
+ "cells": [
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "import os\n",
+ "import datetime\n",
+ "import h5py\n",
+ "import numpy as np\n",
+ "import imageio\n",
+ "import matplotlib.pyplot as plt\n",
+ "from matplotlib.colors import LogNorm\n",
+ "\n",
+ "from databroker import Broker\n",
+ "from eiger_io.fs_handler import EigerHandler"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "db = Broker.named('chx')\n",
+ "db.reg.register_handler('AD_EIGER2', EigerHandler, overwrite=True)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+ "source": [
+ "def save_hdf5(data, filename='data.h5', dataset='dataset', save_dir=None):\n",
+ " \"\"\"Saving data to an hdf5 file.\n",
+ " \n",
+ " Parameters\n",
+ " ----------\n",
+ " data: ndarray\n",
+ " data array to save into hdf5 file\n",
+ " filename: str\n",
+ " the name of the file\n",
+ " dataset: str\n",
+ " the name of the entry in the hdf5 layout\n",
+ " save_dir: None or str\n",
+ " a directory to save the file in\n",
+ " \n",
+ " Returns\n",
+ " -------\n",
+ " status: str\n",
+ " a status string\n",
+ " \"\"\"\n",
+ " if save_dir:\n",
+ " filename = os.path.join(save_dir, filename)\n",
+ " h5f = h5py.File(filename, 'w')\n",
+ " r = h5f.create_dataset(dataset, data=data)\n",
+ " status = '{} created: {}'.format(r, os.path.abspath(filename))\n",
+ " h5f.close()\n",
+ " return status"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Get data from Eiger detector"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "eiger_uid = 'f4fe7c'\n",
+ "hdr_eiger = db[eiger_uid] # 'eiger4m_single_image' field for hdr.data()\n",
+ "time_e = datetime.datetime.fromtimestamp(timestamp=hdr_eiger['start']['time']).strftime('%Y%m%d%H%M')\n",
+ "uid_e = hdr_eiger['start']['uid']\n",
+ "scan_id_e = hdr_eiger['start']['scan_id']\n",
+ "print(f'time: {time_e}\\nuid: {uid_e}\\nscan_id: {scan_id_e}')"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "hdr_eiger.table()"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "hdr_eiger.fields()"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "### Use the field with an '_image' occurrence"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "imgs_eiger = list(hdr_eiger.data('eiger4m_single_image'))"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "imgs_eiger[0].shape"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "%matplotlib widget\n",
+ "plt.imshow(imgs_eiger[0][0], cmap='viridis', norm=LogNorm())"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Get data from xray eye camera"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "xeye_uid = '44aae6fe'\n",
+ "hdr_xeye = db[xeye_uid] # 'xray_eye3_image' field for hdr.data\n",
+ "time_x = datetime.datetime.fromtimestamp(timestamp=hdr_xeye['start']['time']).strftime('%Y%m%d%H%M')\n",
+ "uid_x = hdr_xeye['start']['uid']\n",
+ "scan_id_x = hdr_xeye['start']['scan_id']\n",
+ "print(f'time: {time_x}\\nuid: {uid_x}\\nscan_id: {scan_id_x}')"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "hdr_xeye.table()"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "hdr_xeye.fields()"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "### Use the field with an '_image' occurrence"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "imgs_xeye = list(hdr_xeye.data('xray_eye3_image'))"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "imgs_xeye[0].shape"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "%matplotlib widget\n",
+ "plt.imshow(np.mean(imgs_xeye[0], axis=0), cmap='gray')"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Get tabular data"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "hdr_tab = db['635f98ba']"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "tbl = hdr_tab.table()\n",
+ "tbl"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "tbl.plot(x='smp_y', y='mca_xs_channel1_rois_roi01_value_sum', grid=True)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "tbl.to_csv('/home/mrakitin/work/CHX/exported.csv')"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Save Eiger data to TIFF and HDF5 files"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+ "source": [
+ "filename = '{}_{}_{}'.format(time_e, eiger_uid, scan_id_e)\n",
+ "filename_tiff= '{}.{}'.format(filename, 'tiff')\n",
+ "filename_h5 = '{}.{}'.format(filename, 'h5')\n",
+ "print(filename_tiff)\n",
+ "print(filename_h5)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "imageio.imwrite(os.path.join('/home/mrakitin/work/CHX/', filename_tiff), imgs_eiger[0][0])"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+ "source": [
+ "status = save_hdf5(imgs_eiger, filename=filename_h5, dataset='dataset',\n",
+ " save_dir='/home/mrakitin/work/CHX/')\n",
+ "print(status)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+ "source": []
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "CHX (current)",
+ "language": "python",
+ "name": "analysis-2018-2.1_srv1"
+ },
+ "language_info": {
+ "codemirror_mode": {
+ "name": "ipython",
+ "version": 3
+ },
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
+ "nbconvert_exporter": "python",
+ "pygments_lexer": "ipython3",
+ "version": "3.6.5"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 2
+}