{ "cells": [ { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "# Area Detector, Single mode, HDF5 file" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "**Objective**\n", "\n", "The [EPICS area detector](https://areadetector.github.io/master/index.html) software has a `Single` mode that reduces the configuration steps needed to acquire image frame(s) and output file(s). (EPICS Area Detector will write each frame to a separate file.)\n", "\n", "Here, we show how to configure the EPICS controls, then acquire an image with [bluesky](https://blueskyproject.io/) and write it to an [HDF5](https://www.hdfgroup.org/solutions/hdf5) file.\n", "\n", "**Contents**\n", "\n", "- [EPICS Area Detector IOC](#EPICS-Area-Detector-IOC) is pre-built\n", "- [File Directories](#File-Directories) are different on IOC and bluesky workstation\n", "- [ophyd](#ophyd) to describe the hardware\n", "- [bluesky](#bluesky) for the measurement\n", "- [databroker](#databroker) to view the image\n", "- [punx](#punx) (not part of Bluesky) to look at the HDF5 file\n", "- [Recapitulation](#Recapitulation) - rendition with no explanations\n", "\n", "In other examples (such as AD with [default file names](./de_0_adsim_hdf5_basic.ipynb) or [custom file names](./de_1_adsim_hdf5_custom_names.ipynb)), we described the details of the area detector support. Refer to those examples for the details. Here, following the same general outline, we leverage that knowledge and proceed to the specifics for this example." ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "## EPICS Area Detector IOC\n", "\n", "This example uses a prebuilt [ADSimDetector](https://areadetector.github.io/master/ADSimDetector/simDetector.html) driver, packaged in a [docker](https://www.docker.com/) image\n", "([prjemian/synapps](https://hub.docker.com/r/prjemian/synapps/tags)). The [EPICS IOC](https://docs.epics-controls.org/projects/how-tos/en/latest/getting-started/creating-ioc.html) is configured with prefix `ad:` using the [bash shell script](https://raw.githubusercontent.com/prjemian/epics-docker/main/resources/iocmgr.sh):\n", "\n", "
\n", "user@workstation:~$ iocmgr.sh start ADSIM ad\n", "" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "IOC = \"ad:\"" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "## File Directories\n", "\n", "Files from the IOC are mounted on the docker host in the directory `/tmp/docker_ioc/iocad`. The bluesky session runs on the docker host.\n", "\n", "system | file directory\n", "--- | ---\n", "area detector IOC | `/tmp`\n", "bluesky | `/tmp/docker_ioc/iocad/tmp`" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "import pathlib\n", "\n", "# These paths are specific to how this IOC is implemented.\n", "AD_IOC_MOUNT_PATH = pathlib.Path(\"/tmp\")\n", "BLUESKY_MOUNT_PATH = pathlib.Path(\"/tmp/docker_ioc/iocad/tmp\")" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "Next, define some structures that we will use when constructing the detector object. The `IMAGE_DIR` describes our default choice for where to store image files. We can change this at run time by changing thearea detector file writer's `FilePath` PV (before starting image acquisition)." ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "IMAGE_DIR = \"example/%Y/%m/%d\" # our choice for file arrangement\n", "\n", "# MUST end with a `/`, pathlib will NOT provide it\n", "WRITE_PATH_TEMPLATE = f\"{AD_IOC_MOUNT_PATH / IMAGE_DIR}/\"\n", "READ_PATH_TEMPLATE = f\"{BLUESKY_MOUNT_PATH / IMAGE_DIR}/\"" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "## ophyd\n", "\n", "Here's a screen view of the configuration we want (`HDF` plugin on the left,\n", "`cam` plugin on the right):\n", "\n", "![Area Detector configuration for writing HDF5 files in Single mode](ad_hdf5_single_mode.png)" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "### Preparation\n", "\n", "Configure how [matplotlib](https://matplotlib.org/) charts will be displayed in the notebook.\n", "\n", "We'll import additional libraries as needed by each of the following steps." ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "
<xarray.DataArray 'adsimdet_image' (dim_1: 1024, dim_2: 1024)> Size: 1MB\n", "array([[ 8, 12, 17, ..., 13, 10, 19],\n", " [12, 18, 15, ..., 15, 13, 17],\n", " [18, 8, 8, ..., 20, 12, 19],\n", " ...,\n", " [15, 16, 16, ..., 25, 30, 35],\n", " [ 8, 11, 18, ..., 35, 33, 25],\n", " [ 7, 13, 14, ..., 22, 29, 26]], dtype=uint8)\n", "Coordinates:\n", " time float64 8B 1.725e+09\n", "Dimensions without coordinates: dim_1, dim_2\n", "Attributes:\n", " object: adsimdet