def readSurveyPositions(filename):
    # label1, label2, z, x, y
    positions = readFile(filename, hasLabels=False, headerLines=1)

    label = positions[0]
    #id = np.array(map(float, positions[0]))
    #id = np.array(map(int, id))
    x = np.array(map(float, positions[3]))
    y = np.array(map(float, positions[4]))
    z = np.array(map(float, positions[2]))

    # this is an intentional truncation of the information in the file
    # the values of the front and back planes do not make sense together
    # arbitrarily pick one of the sets
    id = []
    id.extend(getCornersSpecial(90))
    id.extend(getCornersSpecial(91))
    id.extend(getCorners(92))
    id.extend(getCorners(93))
    id.extend(getCorners(94))

    positions = {}
    for i, x_i,y_i,z_i in zip(id, x,y,z):
        if x_i == 0. and y_i == 0. and z_i == 0:
            continue
        positions[i] = Vector(x_i, y_i, z_i)
    return positions
Пример #2
0
def addGroup(corners, columns, labels):
    # setup the relation between labels and columns
    labels_in_col = {}
    for column in columns:
        labels_in_col[column] = []
    for label in labels:
        column = label[0]
        labels_in_col[column].append(label)

    # add the panels
    for column in columns:
        letter = "ABCDEFGHIJKL".index(column) + 1
        col = instr.makeTypeElement("Column%d" % letter)
        for label in labels_in_col[column]:
            (name, offset) = getBankNameAndOffset(label)
            panel_name="panel_v2"
            idstepbyrow=y_num2
            if label in v3_panels:
                panel_name="panel_v3"
                idstepbyrow=y_num3
            extra_attrs={"idstart":offset, 'idfillbyfirst':'y', 'idstepbyrow':idstepbyrow}
            det = instr.makeDetectorElement(panel_name, root=col, extra_attrs=extra_attrs)
            try:
              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))
def readEngineeringPositions(filename):
    positions = readFile(filename, hasLabels=False)

    tube = np.array(map(int, positions[0]))
    pixel = np.array(map(int, positions[1]))
    id = tube*128+pixel

    x = -1. * np.array(map(float, positions[6]))
    x[x == -0.] = 0.
    y = np.array(map(float, positions[5]))
    z = np.array(map(float, positions[7]))

    positions = {}
    for i, x_i,y_i,z_i in zip(id, x,y,z):
        positions[i] = Vector(x_i, y_i, z_i)

    return positions
def readEngineeringPositions(filename):
    positions = readFile(filename, hasLabels=False)

    tube = np.fromiter(map(int, positions[0]), dtype=int)
    pixel = np.fromiter(map(int, positions[1]), dtype=int)
    id = tube * 128 + pixel

    x = -1. * np.fromiter(map(float, positions[6]), dtype=float)
    x[x == -0.] = 0.
    y = np.fromiter(map(float, positions[5]), dtype=float)
    z = np.fromiter(map(float, positions[7]), dtype=float)

    positions = {}
    for i, x_i, y_i, z_i in zip(id, x, y, z):
        positions[i] = Vector(x_i, y_i, z_i)

    return positions
Пример #5
0
def readPositionsLeft(filename):
    positions = readFile(filename)
    x = np.array(map(float, positions['X']))
    y = np.array(map(float, positions['Elevation']))
    z = np.array(map(float, positions['Z']))
    positions['position'] = []
    for x_i,y_i,z_i in zip(x,y,z):
        positions['position'].append(Vector(x_i, y_i, z_i))

    del positions['X']
    del positions['Elevation']
    del positions['Z']

    names = {'D596':79,
             'D579':76,
             'D261':73,
             'D585':70,
             'D586':67,
             'D573':64,
             'D571':61,
             'D574':58,
             'D225':55,
             'D565':52,
             'D551':48,
             'D594':43}
    columnnames = {43:13, 48:14, 52:15, 55:16, 58:17, 61:18, 64:19, 67:20, 70:21, 73:22, 76:23, 79:24}
    banks = {}
    for i, (det, position) in enumerate(zip(positions['Detector'], positions['position'])):
        bank = names[det[:4]]
        i = i%4
        if i == 0:
            three = position
        elif i == 1:
            four = position
        elif i == 2:
            one = position
        elif i == 3:
            two = position
        else:
            raise ValueError("Inconceivable! i = %d" % i)

        if i == 3:
            column = 'Column%d' % columnnames[bank]
            banks[bank] = (column, Rectangle(four, one, two, three, tolerance_len=0.006))

    return banks
def readSurveyPositions(filename):
    # label1, label2, z, x, y
    positions = readFile(filename, hasLabels=False, headerLines=1)

    labels = positions[0]
    # NOTE: label2 column is empty on latest survey, so these indices are shifted back one
    x = np.fromiter(map(float, positions[2]), dtype=float)
    y = np.fromiter(map(float, positions[3]), dtype=float)
    z = np.fromiter(map(float, positions[1]), dtype=float)

    ids = []

    for i in range(0, len(labels), 4):
        det = labels[i]

        # this assumes the label column is in the format "Det#_[1U,2U,1D,2D]"
        [bank, _] = det.split("_")
        bank = int(bank.lstrip("Det"))

        # mapping between survey points to getCorner indices
        # this allows survey measurements to be in any ordering in the file
        # getCorners returns in order: LL, UL, UR, LR
        mapping = {"1U": 3, "2U": 0, "2D": 1, "1D": 2}

        # loop over each measurement for this bank and find the correct
        # detector id it corresponds to
        corners = getCorners(bank)
        for j in range(0, 4):
            [b, pos] = labels[i + j].split("_")
            b = int(b.lstrip("Det"))
            # print("bank {} - {} --> {} ({})".format(b, pos, mapping[pos], corners[mapping[pos]]))
            # verify that this bank is the one we are working on
            assert (b == bank)
            ids.append(corners[mapping[pos]])

    positions = {}
    for i, x_i, y_i, z_i in zip(ids, x, y, z):
        if x_i == 0. and y_i == 0. and z_i == 0:
            continue
        # subtract off distance to source from z values
        positions[i] = Vector(x_i, y_i, z_i - 19.5)
    return positions
Пример #7
0
def readPositionsRight(filename):
    positions = readFile(filename)
    del positions['Position']
    del positions['DetectorNum']

    x = np.array(map(float, positions['X']))
    y = np.array(map(float, positions['Elevation']))
    z = np.array(map(float, positions['Z'])) - 60.
    positions['bank'] = np.array(map(int, positions['bank']))

    positions['position'] = []
    for x_i,y_i,z_i in zip(x,y,z):
        positions['position'].append(Vector(x_i, y_i, z_i))

    del positions['X']
    del positions['Elevation']
    del positions['Z']

    columnnames = {'SA':1, 'SB':2, 'SC':3, 'SD':4, 'SE':5, 'SF':6,
                   'SG':7, 'SH':8, 'SI':9, 'SJ':10, 'SK':11, 'SL':12}

    banks = {}
    for i, (column, row, bank, position) in enumerate(zip(positions['column'], positions['row'], positions['bank'], positions['position'])):
        i = i%4
        if i == 0:
            one = position
        elif i == 1:
            two = position
        elif i == 2:
            three = position
        elif i == 3:
            four = position
        else:
            raise ValueError("Inconceivable! i = %d" % i)

        if i == 3:
            column = 'Column%d' % columnnames[column]
            banks[int(bank)] = (column, Rectangle(four, one, two, three, tolerance_len=0.006))

    return banks
Пример #8
0
def addGroup(corners, columns, labels):
    # setup the relation between labels and columns
    labels_in_col = {}
    for column in columns:
        labels_in_col[column] = []
    for label in labels:
        column = label[0]
        labels_in_col[column].append(label)

    # add the panels
    for column in columns:
        letter = "ABCDEFGHIJKL".index(column) + 1
        col = instr.makeTypeElement("Column%d" % letter)
        for label in labels_in_col[column]:
            (name, offset) = getBankNameAndOffset(label)
            panel_name = "panel_v2"
            idstepbyrow = y_num2
            if label in v3_panels:
                panel_name = "panel_v3"
                idstepbyrow = y_num3
            extra_attrs = {
                "idstart": offset,
                'idfillbyfirst': 'y',
                'idstepbyrow': idstepbyrow
            }
            det = instr.makeDetectorElement(panel_name,
                                            root=col,
                                            extra_attrs=extra_attrs)
            try:
                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))
Пример #9
0
    from helper import MantidGeom
    from sns_ncolumn import readFile

    try:
        geom_input_file = sys.argv[1]
    except IndexError:
        geom_input_file = "SNS/CNCS/CNCS_geom_2016B.txt"
        
    # Set header information
    comment = "Created by Michael Reuter"
    # Time needs to be in UTC?
    valid_from = "2016-07-14 00:00:00"

    # Get geometry information file
    inst_name = "CNCS"
    detinfo = readFile(geom_input_file)
    num_dets = len(detinfo.values()[0])
    xml_outfile = inst_name+"_Definition.xml"
 
    det = MantidGeom(inst_name, comment=comment, valid_from=valid_from)
    det.addSnsDefaults()
    det.addComment("SOURCE AND SAMPLE POSITION")
    det.addModerator(-36.262)
    det.addSamplePosition()
    det.addComment("MONITORS")
    det.addMonitors(names=["monitor1", "monitor2", "monitor3"],
                    distance=["-29.949", "-28.706", "-1.416"])

    label = "detectors"
    det.addComponent(label, label)
    doc_handle = det.makeTypeElement(label)
Пример #10
0
 def __init__(self, filename, L1=0.):
     self._detinfo = readFile(filename)
     self._L1 = L1
    from helper import MantidGeom
    from sns_ncolumn import readFile

    try:
        geom_input_file = sys.argv[1]
    except IndexError:
        geom_input_file = "SNS/SEQ/SEQ_geom_19890-.txt"

    # Set header information
    comment = "Created by Michael Reuter"
    # Time needs to be in UTC?
    valid_from = "2012-04-04 14:15:46"

    # Get geometry information file

    detinfo = readFile(geom_input_file)
    num_dets = len(detinfo.values()[0])
    xml_outfile = INST_NAME + "_Definition.xml"

    det = MantidGeom(INST_NAME, comment=comment, valid_from=valid_from)
    det.addSnsDefaults()
    det.addComment("SOURCE AND SAMPLE POSITION")
    det.addModerator(-20.0114)
    det.addSamplePosition()
    det.addComment("CHOPPERS")
    det.addChopper("t0-chopper", -10.51)
    det.addVerticalAxisT0Chopper("t0-chopper")
    det.addChopper("fermi-chopper", -2.00180)
    det.addFermiChopper("fermi-chopper")
    det.addComment("MONITORS")
    det.addMonitors(names=["monitor1", "monitor2"],
Пример #12
0
 def __init__(self, filename, L1=0.):
     self._detinfo = readFile(filename)
     self._L1 = L1