Created
December 2, 2011 00:03
-
-
Save omsai/1420851 to your computer and use it in GitHub Desktop.
Test Micropoint calibration with configurable pattern for e.g. 365nm objective
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
Generate an Andor iQ .rgn file with a scalable and repositionable pattern of | |
FRAPPA points | |
''' | |
# User variables | |
SENSOR_SIZE = [512, 512] | |
CENTER = [255,255] | |
SIDE_LENGTH = 360 | |
POINT_SPACING = 20 | |
##FILE_PATH = r'Kinetic Imaging/iQx/Default' | |
FILE_PATH = r'Desktop' | |
FILE_NAME = 'micropoint_pattern' | |
LOG_FILE_NAME = r'micropoint_pattern.log' | |
P = POINT_SPACING | |
LINE_POINTS = SIDE_LENGTH / POINT_SPACING | |
LOCAL_STAR_PATTERN = [ | |
[0,0], | |
[-P, -P], | |
[-P, P], | |
[P, P], | |
[P, -P] | |
] | |
from os import path | |
import logging | |
logging.basicConfig(filename=LOG_FILE_NAME, level=logging.DEBUG) | |
def line(start, end): | |
''' | |
Return [x, y] array between start and end; both inclusive | |
''' | |
logging.info('Making line: ' + repr(start) + ' ' + repr(end)) | |
negative_x = False | |
negative_y = False | |
if start[0] > end[0]: negative_x = True | |
if start[1] > end[1]: negative_y = True | |
if negative_x: | |
spacing_x = (start[0] - end[0]) / LINE_POINTS | |
if spacing_x == 0: | |
x = [start[0]] * (LINE_POINTS + 1) | |
else: | |
x = range(start[0], end[0] -spacing_x, -spacing_x) | |
logging.debug('x: ' + repr(x)) | |
else: | |
spacing_x = (end[0] - start[0]) / LINE_POINTS | |
if spacing_x == 0: | |
x = [start[0]] * (LINE_POINTS + 1) | |
else: | |
x = range(start[0], end[0] +spacing_x, +spacing_x) | |
logging.debug('x: ' + repr(x)) | |
if negative_y: | |
spacing_y = (start[1] - end[1]) / LINE_POINTS | |
if spacing_y == 0: | |
y = [start[1]] * (LINE_POINTS + 1) | |
else: | |
y = range(start[1], end[1] -spacing_y, -spacing_y) | |
logging.debug('y: ' + repr(y)) | |
else: | |
spacing_y = (end[1] - start[1]) / LINE_POINTS | |
if spacing_y == 0: | |
y = [start[1]] * (LINE_POINTS + 1) | |
else: | |
y = range(start[1], end[1] +spacing_y, +spacing_y) | |
logging.debug('y: ' + repr(y)) | |
return zip(x, y) | |
def point_generator(center = CENTER, | |
side_length = SIDE_LENGTH): | |
''' | |
Create cross hair pattern, and star patterns around cross hair | |
''' | |
points = [] | |
h = SIDE_LENGTH / 2 | |
cx = CENTER[0] | |
cy = CENTER[1] | |
# Draw diagonals | |
top_left = [cx-h, cy-h] | |
top_right = [cx+h, cy-h] | |
bottom_left = [cx-h, cy+h] | |
bottom_right = [cx+h, cy+h] | |
points += line(top_left, bottom_right) | |
points += line(bottom_left, top_right) | |
# Draw straights | |
v1 = cx - 2*POINT_SPACING | |
v2 = cx + 2*POINT_SPACING | |
h1 = cy - 2*POINT_SPACING | |
h2 = cy + 2*POINT_SPACING | |
points += line([v1, cy-h], [v1, cy+h]) | |
points += line([v2, cy-h], [v2, cy+h]) | |
points += line([cx-h, h1], [cx+h, h1]) | |
points += line([cx-h, h2], [cx+h, h2]) | |
# prune duplicate points | |
points = list(set(points)) | |
return points | |
def existspath(mypath): | |
''' | |
Return 1 if file or path exists, else return 0 | |
''' | |
if path.exists(mypath): | |
logging.info('Found path %s' % mypath) | |
return 1 | |
else: | |
logging.error('Could not find path %s' % mypath) | |
return 0 | |
def main(): | |
points = point_generator() | |
n = len(points) | |
## FIXME: Set date and time to current | |
HEADER = \ | |
'''[Phase List 5.0] | |
Number Of Phases=4 | |
Date=12/1/2011 | |
Time=2:18:28 PM | |
Phase0 Name=_Background | |
Phase0 Colour=255 | |
Phase0 Grey Min=255 | |
Phase0 Grey Max=0 | |
Phase0 Red Min=255 | |
Phase0 Red Max=0 | |
Phase0 Green Min=255 | |
Phase0 Green Max=0 | |
Phase0 Blue Min=255 | |
Phase0 Blue Max=0 | |
Phase0 Enabled=1 | |
Phase1 Name=_Crop | |
Phase1 Colour=16711680 | |
Phase1 Grey Min=255 | |
Phase1 Grey Max=0 | |
Phase1 Red Min=255 | |
Phase1 Red Max=0 | |
Phase1 Green Min=255 | |
Phase1 Green Max=0 | |
Phase1 Blue Min=255 | |
Phase1 Blue Max=0 | |
Phase1 Enabled=1 | |
Phase2 Name=_Cycle | |
Phase2 Colour=16777215 | |
Phase2 Grey Min=255 | |
Phase2 Grey Max=0 | |
Phase2 Red Min=255 | |
Phase2 Red Max=0 | |
Phase2 Green Min=255 | |
Phase2 Green Max=0 | |
Phase2 Blue Min=255 | |
Phase2 Blue Max=0 | |
Phase2 Enabled=1 | |
Phase3 Name=_FRAPPA | |
Phase3 Colour=65535 | |
Phase3 Grey Min=255 | |
Phase3 Grey Max=0 | |
Phase3 Red Min=255 | |
Phase3 Red Max=0 | |
Phase3 Green Min=255 | |
Phase3 Green Max=0 | |
Phase3 Blue Min=255 | |
Phase3 Blue Max=0 | |
Phase3 Enabled=1 | |
[Region List 4.0] | |
''' | |
# Change as appropriate | |
NUMBER_OF_REGIONS = 'Number Of Regions={0}\n'.format(n) | |
## FIME: Set date and time to current | |
DATE_TIME = \ | |
'''Date=12/1/2011 | |
Time=2:18:28 PM''' | |
# Create zip file name | |
logging.debug('Creating region file name') | |
##desktop_path = path.join(path.expandvars("%ALLUSERSAPPDATA%"), FILE_PATH) | |
desktop_path = path.join(path.expanduser("~"), FILE_PATH) | |
FILE = path.join(desktop_path, FILE_NAME) | |
FILE = ''.join([FILE, '.rgn']) | |
logging.info('Writing to region file: ' + FILE) | |
## FIXME: prevent file collision! | |
rfile = open(FILE, 'w') | |
rfile.write(HEADER + \ | |
NUMBER_OF_REGIONS + \ | |
DATE_TIME) | |
label = 1 | |
for point in points: | |
REGION = ''' | |
Region{0} Label={0} | |
Region{0} Class Name=_FRAPPA | |
Region{0} Overlay Type=1 | |
Region{0} Overlay Colour=65535 | |
Region{0} Overlay Line Width=0 | |
Region{0} Number Of Points=1 | |
Region{0} Region Points={1},{2};'''.format(label, point[0], point[1]) | |
label = label + 1 | |
rfile.write(REGION) | |
rfile.write('\n') | |
rfile.close() | |
if __name__ == '__main__': | |
print "Creating regions file..." | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment