Skip to content

Instantly share code, notes, and snippets.

@habi
Created February 16, 2016 15:04
Show Gist options
  • Save habi/ad03e1d48605ef03c759 to your computer and use it in GitHub Desktop.
Save habi/ad03e1d48605ef03c759 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
GetCurrentImage.py | David Haberthür <david.haberthuer@psi.ch>
Minimal script to get current camera image from EPICS and display it
"""
# Import necessary modules
from epicsPV import epicsPV
import numpy
import matplotlib.pyplot as plt
# Initialize EPICS channels. The channel names have been found in
# /import/work/sls/java/ImageJ/plugins/EPICS_ccdconnection/EPICS_CC_Viewer.java
chImage = epicsPV('X02DA-CCDCAM:FPICTURE')
chImageWidth = epicsPV('X02DA-CCDCAM:WIDTH')
chImageHeight = epicsPV('X02DA-CCDCAM:HEIGHT')
# Read image size and put the values into a list
ImageSize = [int(chImageHeight.getw()), int(chImageWidth.getw())]
# Read the EPICS image channel. This is a stream of numbers, which we put into
# an array and reshape this array to the image size. The image values should
# then be unsigned integers (0 to 65535), we thus convert the array to 'uint16'
Image = numpy.asarray(chImage.getw()).reshape(ImageSize).astype('uint16')
plt.imshow(Image, cmap='gray', interpolation='nearest')
plt.show()
@simongregorebner
Copy link

Just a side mark, when coding python you should try to somehow stick with https://www.python.org/dev/peps/pep-0008/

@habi
Copy link
Author

habi commented Mar 27, 2016

@simon: I absolutely agree. My pep8 only complains about "W292 no newline at end of file" in this case...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment