Last active
August 29, 2015 14:14
-
-
Save hirokai/749a259f57cff1cb45f1 to your computer and use it in GitHub Desktop.
MicroManager grid positions
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
#!/usr/bin/env ruby | |
require 'json' | |
include Math | |
# User parameters | |
# a: origin (in um) | |
# b: the 2nd point to define an axis | |
# Two axes will be (1) b-a and (2) 90 deg clockwise rotation of b-a. | |
# len: grid interval | |
# xlimit, ylimit: Allowed range (possible maximum absolute value) of x and y. | |
a = [-1663,-4787] | |
b = [1029,-4826] | |
len = 500 | |
xlimit = 8000 | |
ylimit = 5000 | |
def norm2(v) | |
v[0]*v[0] + v[1]*v[1] | |
end | |
v = [b[0]-a[0],b[1]-a[1]] | |
n = sqrt(norm2(v)) | |
v1 = [v[0]/n*len,v[1]/n*len] | |
v2 = [-v1[1],v1[0]] | |
count = 0 | |
col = 10 | |
row = 6 | |
moves = ([1] + [[1]*(col-2) + [2] + [3]*(col-2) + [2]]*(row/2)).flatten | |
xi = 0 | |
yi = 0 | |
poss = [] | |
moves.each{|m| | |
x = a[0] + xi*v1[0] + yi*v2[0] | |
y = a[1] + xi*v1[1] + yi*v2[1] | |
if x.abs > xlimit or y.abs > ylimit | |
raise "Coordinate out of bound.#{x}" | |
end | |
count += 1 | |
poss << {:GRID_COL => 0, :GRID_ROW => 0, :LABEL => "Pos#{count}", | |
:DEFAULT_Z_STAGE => "ASI ZStage", :DEFAULT_XY_STAGE => "ASI XYStage", | |
:PROPERTIES => {}, | |
:DEVICES => [{:DEVICE => "ASI XYStage", :AXES => 2, :Y => ("%.1f" % y).to_f, :X => ("%.1f" % x).to_f, :Z => 0}] | |
} | |
xi += (m == 1 ? 1 : (m == 3 ? -1 : 0)) | |
yi += (m == 2 ? 1 : (m == 4 ? -1 : 0)) | |
} | |
obj = {:VERSION => 3, :ID => "Micro-Manager XY-position list",:POSITIONS => poss} | |
puts JSON.pretty_generate(obj) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment