Skip to content

Commit

Permalink
Merge pull request #5 from mantidproject/feature/7070_pg3_upgrade
Browse files Browse the repository at this point in the history
New POWGEN instrument
  • Loading branch information
stuartcampbell committed Aug 6, 2013
2 parents d26db74 + 2144ae9 commit 43fd05a
Show file tree
Hide file tree
Showing 5 changed files with 245 additions and 25 deletions.
125 changes: 125 additions & 0 deletions PG3_geom_2013_txt.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
Point_ID Z X Y
B2_3 57.967496 1.163795 -1.045114
B2_4 57.855079 1.213720 -0.668273
B2_1 58.171034 1.925040 -0.669014
B2_2 58.284018 1.874960 -1.045148
B3_3 57.846064 1.219319 -0.626904
B3_4 57.789431 1.244210 -0.236872
B3_1 58.108122 1.955365 -0.237555
B3_2 58.164590 1.929225 -0.627407
B4_3 57.786293 1.244037 -0.193533
B4_4 57.786088 1.245507 0.203120
B4_1 58.103564 1.955930 0.201390
B4_2 58.104137 1.955246 -0.194677
B5_3 57.791118 1.243313 0.243675
B5_4 57.847730 1.217441 0.635344
B5_1 58.165061 1.929125 0.635866
B5_2 58.108648 1.953542 0.246110
B6_3 57.856388 1.215041 0.678236
B6_4 57.968583 1.165708 1.053728
B6_1 58.285106 1.875597 1.052865
B6_2 58.171197 1.920101 0.676977
C2_3 58.353231 1.857034 -1.038249
C2_4 58.262246 1.939072 -0.662325
C2_1 58.774453 2.525435 -0.662660
C2_2 58.865438 2.443397 -1.038584
C3_3 58.252970 1.945852 -0.621365
C3_4 58.205673 1.987325 -0.230481
C3_1 58.719164 2.573067 -0.232528
C3_2 58.766462 2.531593 -0.623412
C4_3 58.204235 1.988630 -0.187544
C4_4 58.204590 1.989986 0.208182
C4_1 58.716171 2.576886 0.207212
C4_2 58.716478 2.575910 -0.188270
C5_3 58.205482 1.988943 0.250522
C5_4 58.250217 1.947402 0.642238
C5_1 58.762779 2.533804 0.641609
C5_2 58.717450 2.573489 0.252607
C6_3 58.259819 1.940003 0.683660
C6_4 58.351955 1.862152 1.059428
C6_1 58.862555 2.447635 1.060251
C6_2 58.770418 2.525485 0.684484
D2_3 58.879125 2.453227 -1.040371
D2_4 58.812259 2.554795 -0.665644
D2_1 59.462929 2.972239 -0.670055
D2_2 59.529795 2.870671 -1.044783
D3_3 58.806885 2.561998 -0.622348
D3_4 58.773634 2.614802 -0.231675
D3_1 59.427063 3.037178 -0.233351
D3_2 59.460314 2.984374 -0.624024
D4_3 58.770616 2.620194 -0.190515
D4_4 58.769166 2.619645 0.205687
D4_1 59.422589 3.040731 0.203468
D4_2 59.424040 3.041280 -0.192735
D5_3 58.777027 2.619699 0.250721
D5_4 58.803435 2.566876 0.639942
D5_1 59.458763 2.988972 0.639948
D5_2 59.425015 3.037799 0.250632
D6_3 58.812780 2.557521 0.682507
D6_4 58.876842 2.455350 1.055137
D6_1 59.529622 2.875519 1.055690
D6_2 59.465560 2.977690 0.683060
E2_3 59.545305 2.881937 -1.037930
E2_4 59.506829 2.993218 -0.668423
E2_1 60.243968 3.228587 -0.673212
E2_2 60.282444 3.117306 -1.042719
E3_3 59.502302 3.002985 -0.626142
E3_4 59.484208 3.061121 -0.234547
E3_1 60.225992 3.298972 -0.236037
E3_2 60.242018 3.240790 -0.625368
E4_3 59.488078 3.064539 -0.181767
E4_4 59.482653 3.062635 0.204573
E4_1 60.224161 3.300433 0.202082
E4_2 60.223816 3.301432 -0.192066
E5_3 59.483822 3.059766 0.248087
E5_4 59.506678 3.002140 0.636063
E5_1 60.236634 3.236060 0.636615
E5_2 60.226333 3.298214 0.247084
F2_3 60.291970 3.115583 -1.042385
F2_4 60.282160 3.237517 -0.666388
F2_1 61.058905 3.295846 -0.665958
F2_2 61.068263 3.173808 -1.042332
F3_3 60.281563 3.246755 -0.623651
F3_4 60.277548 3.309078 -0.233095
F3_1 61.053670 3.368084 -0.233111
F3_2 61.057624 3.305625 -0.624038
F4_3 60.276625 3.311038 -0.188752
F4_4 60.277950 3.311212 0.204441
F4_1 61.053154 3.369677 0.204427
F4_2 61.052500 3.369881 -0.189343
F5_3 60.275944 3.307985 0.248928
F5_4 60.281419 3.244850 0.638005
F5_1 61.058206 3.304663 0.637689
F5_2 61.050230 3.366787 0.248123
G3_3 61.083825 3.178938 -0.610081
G3_4 61.087569 3.187928 -0.216658
G3_1 61.859743 3.092149 -0.221739
G3_2 61.855975 3.082364 -0.615210
G4_3 61.083289 3.171548 -0.195333
G4_4 61.087888 3.169649 0.199201
G4_1 61.857521 3.077450 0.195221
G4_2 61.855369 3.078851 -0.198490
H3_3 61.883526 3.071899 -0.608548
H3_4 61.884556 3.066601 -0.213786
H3_1 62.616036 2.802013 -0.221960
H3_2 62.614460 2.807628 -0.614325
H4_3 61.880764 3.061826 -0.202408
H4_4 61.882144 3.056929 0.192679
H4_1 62.615590 2.798041 0.189847
H4_2 62.615580 2.803614 -0.206488
I4_3 62.603107 2.765000 -0.206922
I4_4 62.606223 2.765190 0.188266
I4_1 63.279071 2.371883 0.183147
I4_2 63.275791 2.371580 -0.213436
J4_3 63.285682 2.348077 -0.210754
J4_4 63.281420 2.343852 0.184341
J4_1 63.846931 1.809552 0.186169
J4_2 63.851097 1.812698 -0.207430
K4_3 63.863003 1.807522 -0.212620
K4_4 63.864620 1.807786 0.184897
K4_1 64.323014 1.177160 0.180570
K4_2 64.321620 1.178278 -0.214724
L4_3 64.331100 1.157380 -0.217920
L4_4 64.329768 1.154085 0.178306
L4_1 64.681894 0.461046 0.175652
L4_2 64.683188 0.464324 -0.221097
85 changes: 85 additions & 0 deletions pg3_compare_csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#!/usr/bin/env python

import logging
from pg3_geometry import CornersFile, L1
from rectangle import Rectangle, Vector

LOGLEVEL = "WARNING"

def diffRect(left, right, order, tolerance):
left = left.points
right = createRect(right, order, tolerance).points
diff = 0.
for i in range(4):
diff += (left[i] - right[i]).length
return diff

def createRect(points, order, tolerance):
mypoints = [ points[i] for i in order]
return Rectangle(mypoints[0], mypoints[1], mypoints[2], mypoints[3],
tolerance)

if __name__ == "__main__":
logging.basicConfig(format='%(levelname)s:%(message)s',
level=LOGLEVEL)
import sys
if len(sys.argv) != 3:
print "usage: %s <left> <right>"

left = sys.argv[1]
right = sys.argv[2]

left = CornersFile(left, L1)
right = CornersFile(right, L1)

banks = [
"B2", "B3", "B4", "B5",# "B6",
"C2", "C3", "C4", #"C5", "C6"
"D2", "D3", "D4", #"D5", "D6",
"E2", "E3", #"E4", "E5",
"F2", "F3", "F4", "F5",
"G3", "G4",
"H3", "H4",
"I4",
"J4",
"K4"
]
tol = .006
orders = [[0,1,2,3], [1,2,3,0], [2,3,0,1], [3,0,1,2], # keep order
[3,2,1,0], [2,1,0,3], [1,0,3,2], [0,3,2,1]] # reverse order

totalToReorder = 0

# go through all banks
for bank in banks:
# stupid starting values
minDiff = 100000.
orderBest = []

# generate the starting rectangles
logging.info("***** %s" % bank)
lftRect = left.rectangle(bank, tol)
rgtRect = right.rectangle(bank, tol)

# go through all orders
for order in orders:
diff = diffRect(lftRect, rgtRect.points, order, tol)
logging.debug("%s %f" % (str(order), diff))
if diff < minDiff:
minDiff = diff
orderBest = order

if orderBest == [0,1,2,3]:
logging.info("%s current order is the best" % bank)
continue
else:
totalToReorder += 1

# easier to understand 1-indexed arrays
orderBest = [ i+1 for i in orderBest]
# print out the best
print "%3s %s - diff=%.3f centerDiff=%.3f" % (bank, \
str(orderBest), minDiff, \
(lftRect.center - rgtRect.center).length)
if totalToReorder == 0:
print "No banks need to be reordered"
53 changes: 29 additions & 24 deletions pg3_geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
x_num3 = 308
y_num3 = 16

# primary flight path - negative b/c it is upstream
L1 = -60.0

def toEasier(label):
letter = "ABCDEFGHIJKL".index(label[0])
number = int(label[1:])
Expand Down Expand Up @@ -74,14 +77,15 @@ def addGroup(corners, columns, labels):
extra_attrs={"idstart":offset, 'idfillbyfirst':'y', 'idstepbyrow':idstepbyrow}
det = instr.makeDetectorElement(panel_name, root=col, extra_attrs=extra_attrs)
try:
corners.rectangle(label, .006).makeLocation(instr, det, name, technique="uv")
corners.rectangle(label, .014).makeLocation(instr, det, name, technique="uv")
except ValueError, e:
print "Failed to generate '" + label \
+ "' from corners. Trying from engineered centers."
detinfo = readFile("PG3_geom.txt")
addCenterRectangle(instr, det, name, detinfo, detinfo["label"].index(label))

v3_panels = ['B2', 'B3', 'B4', 'B5', 'B6', 'K4', 'L4']
# for the next cycle they will all be low resolution
v3_panels = []#'B2', 'B3', 'B4', 'B5', 'B6', 'K4', 'L4']

class CornersFile:
def __init__(self, filename, L1=0.):
Expand Down Expand Up @@ -120,7 +124,6 @@ def rectangle(self, label, tolerance_len):
"Vickie Lynch",
"Peter Peterson",
"Janik Zikovsky"]
L1 = -60.0

# boiler plate stuff
instr = MantidGeom(inst_name,
Expand Down Expand Up @@ -186,10 +189,10 @@ def rectangle(self, label, tolerance_len):
instr.addComponent(name, root=group)

# the actual work of adding the detectors
corners = CornersFile("PG3_geom_2011_txt.csv", abs(L1))
corners = CornersFile("PG3_geom_2013_txt.csv", abs(L1))
addGroup(corners, cols[4], ["B2", "B3", "B4", "B5", "B6"])
addGroup(corners, cols[3], ['C2', 'C3', 'C4', 'C5', 'D2', 'D3', 'D4'])
addGroup(corners, cols[2], ['E2', 'E3', 'E4', 'F2', 'F3', 'F4'])
addGroup(corners, cols[3], ['C2', 'C3', 'C4', 'C5', 'C6', 'D2', 'D3', 'D4', 'D5', 'D6'])
addGroup(corners, cols[2], ['E2', 'E3', 'E4', 'E5', 'F2', 'F3', 'F4', 'F5'])
addGroup(corners, cols[1], ['G3', 'G4', 'H3', 'H4', 'I4', 'J4', 'K4', 'L4'])

# add the panel shape
Expand All @@ -204,17 +207,18 @@ def rectangle(self, label, tolerance_len):
"ypixels":y_num2, "ystart":y_offset2, "ystep":y_delta2
})
le.SubElement(det, "properties")
instr.addComment(" Version 3 Detector Panel (16x308)")
x_delta3 = x_extent/float(x_num3)
x_offset3 = x_delta3*(1.-float(x_num3))/2.
y_delta3 = y_extent/float(y_num3)
y_offset3 = y_delta3*(1.-float(y_num3))/2.
det = instr.makeTypeElement("panel_v3",
extra_attrs={"is":"rectangular_detector", "type":"pixel_v3",
"xpixels":x_num3, "xstart":x_offset3, "xstep":x_delta3,
"ypixels":y_num3, "ystart":y_offset3, "ystep":y_delta3
})
le.SubElement(det, "properties")
if len(v3_panels) > 0:
instr.addComment(" Version 3 Detector Panel (16x308)")
x_delta3 = x_extent/float(x_num3)
x_offset3 = x_delta3*(1.-float(x_num3))/2.
y_delta3 = y_extent/float(y_num3)
y_offset3 = y_delta3*(1.-float(y_num3))/2.
det = instr.makeTypeElement("panel_v3",
extra_attrs={"is":"rectangular_detector", "type":"pixel_v3",
"xpixels":x_num3, "xstart":x_offset3, "xstep":x_delta3,
"ypixels":y_num3, "ystart":y_offset3, "ystep":y_delta3
})
le.SubElement(det, "properties")

# shape for monitors
instr.addComment(" Shape for Monitors")
Expand All @@ -229,13 +233,14 @@ def rectangle(self, label, tolerance_len):
[-.5*x_delta2, -.5*y_delta2, -0.0001],
[ .5*x_delta2, -.5*y_delta2, 0.0],
shape_id="pixel-shape")
instr.addComment(" Pixel for Version 3 Detectors (16x308)")
instr.addCuboidPixel("pixel_v3",
[-.5*x_delta3, -.5*y_delta3, 0.0],
[-.5*x_delta3, .5*y_delta3, 0.0],
[-.5*x_delta3, -.5*y_delta3, -0.0001],
[ .5*x_delta3, -.5*y_delta3, 0.0],
shape_id="pixel-shape")
if len(v3_panels) > 0:
instr.addComment(" Pixel for Version 3 Detectors (16x308)")
instr.addCuboidPixel("pixel_v3",
[-.5*x_delta3, -.5*y_delta3, 0.0],
[-.5*x_delta3, .5*y_delta3, 0.0],
[-.5*x_delta3, -.5*y_delta3, -0.0001],
[ .5*x_delta3, -.5*y_delta3, 0.0],
shape_id="pixel-shape")

# monitor ids
instr.addComment("MONITOR IDs")
Expand Down
2 changes: 1 addition & 1 deletion rectangle.py
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ def __height(self):

width = property(__width, doc="Width of the rectangle")
height = property(__height, doc="Height of the rectangle")
center = property(lambda self: self.__center[:],
center = property(lambda self: Vector(self.__center[:]),
doc="Center of the rectangle")
orientation = property(lambda self: self.__orient[:],
doc="Orientation as a set of three basis vectors")
Expand Down
5 changes: 5 additions & 0 deletions sns_ncolumn.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
#!/usr/bin/env python

import os

def readFile(filename, hasLabels=True):
"""This loads in a n-column ascii file and converts it into a dictionary
where the column headings are the keys, and the columns are as a list in
the value. If the "hasLabels" variable is False then the keys are the
column numbers."""

if not os.path.exists(filename):
raise RuntimeError("File '%s' does not exist" % filename)

# load the file
datafile = open(filename, "r")
lines = []
Expand Down

0 comments on commit 43fd05a

Please sign in to comment.