AD and PVA¶
This section contains a python example of how to grab an image from AreaDetector using PVA.
Download file: example_01.py
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3
4"""
5How to grab images from AreaDetector using pva
6"""
7
8
9from epics import PV
10import pvaccess as pva
11import time
12import numpy as np
13import matplotlib.pyplot as plt
14
15
16def streaming(buff):
17 PVA_prefix = '2bmbPG1:Pva1:'
18
19 pva_data = pva.Channel(PVA_prefix + 'Image')
20 pva_data_type = pva.Channel(PVA_prefix + 'DataType_RBV')
21 pva_image = pva_data.get('')
22 pva_data_dict = pva_image.getStructureDict()
23
24 image = pva_image['value']
25 width = pva_image['dimension'][0]['size']
26 height = pva_image['dimension'][1]['size']
27
28 print(image[0]['ubyteValue'])
29 image_np = np.reshape(image[0]['ubyteValue'], (width, height))
30 print(width, height)
31 print(image_np.shape)
32
33 # plt.imshow(image_np)
34 # plt.show()
35
36 print(pva_data_dict)
37
38 ix = width//2
39 iy = width//2
40 iz = height//2
41
42 # buffer is continuously update with monitoring
43 # the detector pv (function addProjection), called inside pv monitor
44 databuffer = np.zeros([buff, height, width], dtype='float32')
45
46 def addProjection(pv):
47 curid = pv['uniqueId']
48 print(curid)
49 databuffer[np.mod(curid, buff)] = pv['value'][0]['ubyteValue'].reshape(
50 height, width).astype('float32')
51
52 pva_data.monitor(addProjection, '')
53
54 while(True):
55 datap = databuffer.copy()
56 # print('new image')
57if __name__ == "__main__":
58
59 buff = 50
60 streaming(buff)