Skip to content

Instantly share code, notes, and snippets.

@omsai
Created October 16, 2012 15:55
Show Gist options
  • Save omsai/3900135 to your computer and use it in GitHub Desktop.
Save omsai/3900135 to your computer and use it in GitHub Desktop.
Andor iQ Python IDE script to calculate Yokogawa excitation uniformity
#SHELL
"""
Calculate Spinning Disk uniformity and compare with Andor's specification.
Usage:
Start the Python IDE from iQ from under Plugins. Run this Plugin from
the iQ menu and select the "Progress" tab.
Run a protocol with just "Snap" and loop protocol enabled to collect images.
The bar will update to show how close the image drop-off.
Note if you are using the Clara, you have to edit the baseline
variable below.
Installation:
Copy this file to the Python Plugins directory, usually:
c:/Program Files/Andor Bioimaging/PythonEngine/Plugins/
Written by Pariksheet Nanda <p.nanda@andor.com> October 10, 2012
"""
from iqapp.observers import AcquisitionObserver
from iqtools.dialogs import progressSet
from numpy import array
class UniformityCheck(AcquisitionObserver):
# FIXME: Need a way of finding the active camera model is a Clara
# to set the baseline to 500
# Baseline for iXon and CMOS cameras are 100. Clara is the odd
# one out at 500
baseline = 100
def event_newFrame(self, n):
self.imf = self.im.frame(n) # Get current frame
center = self.roi_mean_intensity()
top_left = self.roi_mean_intensity([0.1, 0.1])
top_right = self.roi_mean_intensity([0.9, 0.1])
bottom_left = self.roi_mean_intensity([0.1, 0.9])
bottom_right = self.roi_mean_intensity([0.9, 0.9])
sides = (top_left + top_right +
bottom_right + bottom_right) /4
drop_off = (center - sides) / center * 100 # percent
output = "C:{0} S:{1} TL:{2} TR:{3} BL:{4} " + \
"BR:{5}"
print output.format(center, sides, top_left, top_right,
bottom_left, bottom_right)
status = '{0:6.2f}%'.format(drop_off)
progressSet("Drop Off", percentage=drop_off,
status=status)
def roi_mean_intensity(self, position_percent=(0.5,0.5)):
"""
Get the mean value of a 5% rectangle ROI at a specific image
position.
@param position_percent: relative x and y position in image
@type: tuple
@rtype: float
"""
imf_shape = array(self.imf.shape)
roi_shape = imf_shape * 0.05
roi_shape = roi_shape.astype(int)
x, y = roi_shape
roi_center = imf_shape * position_percent
x_offset, y_offset = roi_center - roi_shape / 2
roi = self.imf[x_offset:x_offset+x, y_offset:y_offset+y]
return roi.mean() - self.baseline
obs = UniformityCheck()
obs.register()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment