analyser_wavelength = nfile["/entry/instrument/analyzer%d/wavelength" % (i+1)].value[remove_ghosts] analyser_energy = 81.8042051/analyser_wavelength**2 bank_id = "bank%d" % (i+1) det.addComponent(bank_id, bank_id) #doc_handle = det.makeTypeElement(bank_id) det.addDetectorPixels(bank_id, r=distance, theta=polar_angle, phi=azimuthal_angle, names=pixel_id, energy=analyser_energy) det.addDetectorPixelsIdList(bank_id, r=distance, names=pixel_id) # Create the diffraction bank information det.addComponent("elastic", "elastic") handle = det.makeTypeElement("elastic") idlist = [] detector_z = [-2.1474825,-1.704594,-1.108373,-0.4135165,0.3181,1.0218315,1.6330115,2.0993535,2.376999] detector_x = [1.1649855,1.7484015,2.175541,2.408594,2.422933,2.216378,1.8142005,1.247867,0.5687435] detector_y = [-0.001807,-0.001801,-0.0011845,-0.0006885,-0.0013145,-0.001626,-0.001397,0.0003465,-0.0001125] for i in range(ELASTIC_BANK_START, ELASTIC_BANK_END+1): bank_name = "bank%d" % i det.addComponent(bank_name, root=handle) k = i - ELASTIC_BANK_START x_coord = detector_x[k] y_coord = detector_y[k]
Right detector: Same orientation of tubes, same size of pixels Only 96 tubes instead of 128 tubes in the main detector For more information, please visit https://www.ill.eu/instruments-support/instruments-groups/instruments/d22/characteristics/ """ d22 = MantidGeom(instrumentName, comment=comment, valid_from=validFrom) d22.addSnsDefaults(default_view='3D',axis_view_3d='z-') d22.addComment("SOURCE") d22.addComponentILL("moderator", 0., 0., moderator_source, "Source") d22.addComment("Sample position") d22.addComponentILL("sample_position", 0., 0., 0., "SamplePos") d22.addComment("MONITORS") d22.addMonitors(names=["monitor1", "monitor2"], distance=[zMon1, zMon2]) d22.addComment("MONITOR SHAPE") d22.addDummyMonitor(0.01, 0.03) d22.addComment("MONITOR IDs") d22.addMonitorIds([repr(100000), repr(100001)]) d22.addComment("DETECTOR") d22.addComponentILL("detector", 0., 0., 0.) detector = d22.makeTypeElement("detector") d22.addComponentRectangularDetector(detector0, 0., 0., zPos, idstart=id0, idfillbyfirst=FF, idstepbyrow=SR, root=detector) d22.addComponentRectangularDetector(detector1, -right_center_offset, 0., zPos-z_gap, idstart=id1, idfillbyfirst=FF, idstepbyrow=SR, root=detector) d22.addRectangularDetector(detector0, pixelName, xstart, xstep, xpixels, ystart, ystep, ypixels) d22.addRectangularDetector(detector1, pixelName, xstart_right, xstep, xpixels_right, ystart, ystep, ypixels) d22.addComment("PIXEL, EACH PIXEL IS A DETECTOR") d22.addCuboidPixel(pixelName, [-x, -y, thickness/2.], [-x, y, thickness/2.], [-x, -y, -thickness/2.], [x, -y, thickness/2.], shape_id="pixel-shape") d22.writeGeom("./ILL/IDF/" + instrumentName + "_Definition.xml")
#################### # add the id lists for groups - [start, stop, step] start, stop = -1, -1 for i, num_banks_in_pack in enumerate(num_banks): start = stop+1 stop = start + num_banks_in_pack*8*128-1 info = instr.addDetectorIds('Group%d' % (i+1), [start, stop, None]) for i, _ in enumerate(num_banks): group = 'Group%d' % (i+1) group = instr.addComponent(group, idlist=group) #################### # group 1 is banks 1-14 (inclusive) bank_offset = 0 group = instr.makeTypeElement('Group1') for i in range(num_banks[0]): bank_num = bank_offset + i + 1 bank = "bank%d" % bank_num corners = getCorners(bank_num) rect = getRectangle(bank_num, positions, corners) det = instr.makeDetectorElement('pack', root=group) rect.makeLocation(instr, det, bank) # group 2 is banks 15-37 (inclusive) bank_offset += num_banks[0] group = instr.makeTypeElement('Group2') for i in range(num_banks[1]): bank_num = bank_offset+i+1 bank = "bank%d" % bank_num corners = getCorners(bank_num)
for k in range(128): k = float(k) x.append(x0j + xextent *(1.-k/128.)) y.append(y0j + yextent *(1.-k/128.)) z.append(z0_first + dz_first*(1.-k/128.)) pack1 = DetPack(tuberadius = .5*.0254, airgap = AIR_GAP, xstartdiff = (.0254+AIR_GAP), ysize = -1.*TUBE_LENGTH, ystartdiff = -1.*TUBE_LENGTH/128., debug=False) pack1.setNames(pixel="onepixel", tube="tubedecreasing", pack="packdecreasing") group1 = instr.makeTypeElement("Group1") for i in range(n_first): offset = i*8*128 bank = "bank%d" % (i+1) rect = Rectangle( (-y[offset+UL], x[offset+UL], z[offset+UL]), (-y[offset+LL], x[offset+LL], z[offset+LL]), (-y[offset+LR], x[offset+LR], z[offset+LR]), (-y[offset+UR], x[offset+UR], z[offset+UR]) ) det = instr.makeDetectorElement(pack1.namepack, root=group1) rect.makeLocation(instr, det, bank) # ---------- add in group2 """ ;;; source idl code
""" # guides - not even copying the text # mapping of groups to column names cols = {4:['B'], 3:['C', 'D'], 2:['E', 'F'], 1:['G', 'H', 'I', 'J', 'K', 'L']} # add the empty components for i in cols.keys(): name = "Group%d" % i group = instr.addComponent(name)#, idlist=name) # add the columns to the group for groupNum in cols.keys(): name = "Group%d" % groupNum group = instr.makeTypeElement(name) for column in cols[groupNum]: name = "Column%d" % ("ABCDEFGHIJKL".index(column) + 1) instr.addComponent(name, root=group) # the actual work of adding the detectors 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', '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 instr.addComment(" Version 2 Detector Panel (7x154)") x_delta2 = x_extent/float(x_num2)
row_id = "" row_id_list = [] doc_handle = None for i in range(num_dets): location = detinfo["Location"][i] # REMOVE ME: when A and E rows are filled if location.startswith("A") or \ location.startswith("E"): continue if row_id != location[0]: row_id = location[0] row_id_list.append(row_id) row_id_str = row_id + " row" det.addComponent(row_id_str, row_id_str) doc_handle = det.makeTypeElement(row_id_str) det.addComponent(location, root=doc_handle) xpos = convert(detinfo["X"][i]) ypos = convert(detinfo["Y"][i]) zpos = convert(detinfo["Z"][i]) roty = float(detinfo["Angle"][i]) + FLIPY det_type = "eightpack" if location.startswith("C"): if location.endswith("T"): det_type = "eightpack-top" elif location.endswith("B"): det_type = "eightpack-bottom"
xml_outfile = inst_name+"_Definition.xml" nfile = h5py.File(nexusfile, 'r') det = MantidGeom(inst_name, comment=comment, valid_from=valid_from) det.addSnsDefaults(indirect=True) det.addComment("SOURCE AND SAMPLE POSITION") det.addModerator(-84.0) det.addSamplePosition() det.addComment("MONITORS") det.addMonitors(names=["monitor1"], distance=["-0.23368"], neutronic=True) # Create the inelastic banks information det.addComment("INELASTIC DECTECTORS") det.addComponent("silicon") handle_silicon = det.makeTypeElement("silicon") # Slicer for removing ghosts. Due to the mapping, the ghost tubes sit # on the same sides of the arrays for all banks. remove_ghosts = slice(-INELASTIC_TUBES_NGHOST) for i in range(banks): pixel_id = nfile["/entry/instrument/bank%d/pixel_id" % (i+1)].value[remove_ghosts] distance = nfile["/entry/instrument/bank%d/distance" % (i+1)].value[remove_ghosts] polar_angle = nfile["/entry/instrument/bank%d/polar_angle" % (i+1)].value[remove_ghosts] polar_angle *= (180.0/math.pi) azimuthal_angle = nfile["/entry/instrument/bank%d/azimuthal_angle" % (i+1)].value[remove_ghosts] azimuthal_angle *= (180.0/math.pi) analyser_wavelength = nfile["/entry/instrument/analyzer%d/wavelength" % (i+1)].value[remove_ghosts] analyser_energy = 81.8042051/analyser_wavelength**2
banks[bank] = banksL[bank] del banksL # delete the banks that are no longer installed for bank in [1,5,6,10,32,35,38,28,31,34,37,40]: del banks[bank] # create north and south sides sides = {'North':['Column%d' % i for i in range(13,25)], 'South':['Column%d' % i for i in range(1,13)]} # add the empty components for name in sides.keys(): group = instr.addComponent(name) # add the columns to the groups for side in sides.keys(): group = instr.makeTypeElement(side) for column in sides[side]: instr.addComponent(column, root=group) # create an ordered list of all columns columns = set() for name in banks.keys(): column, _ = banks[name] columns.add(column) columns = list(columns) columns.sort() createdcolumns = dict() for name in banks.keys(): offset = (int(name)-1) * 15000
cols = { 4: ['B'], 3: ['C', 'D'], 2: ['E', 'F'], 1: ['G', 'H', 'I', 'J', 'K', 'L'] } # add the empty components for i in cols.keys(): name = "Group%d" % i group = instr.addComponent(name) #, idlist=name) # add the columns to the group for groupNum in cols.keys(): name = "Group%d" % groupNum group = instr.makeTypeElement(name) for column in cols[groupNum]: name = "Column%d" % ("ABCDEFGHIJKL".index(column) + 1) instr.addComponent(name, root=group) # the actual work of adding the detectors 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', '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'])
d33 = MantidGeom(instrumentName, comment=comment, valid_from=validFrom) d33.addSnsDefaults() d33.addComment("SOURCE") d33.addComponentILL("moderator", 0., 0., moderator_source, "Source") d33.addComment("Sample position") d33.addComponentILL("sample_position", 0., 0., 0., "SamplePos") d33.addComment("MONITORS") d33.addMonitors(names=["monitor1", "monitor2"], distance=[zMon1, zMon2]) d33.addComment("MONITOR SHAPE") d33.addComment("FIXME: Do something real here.") d33.addDummyMonitor(0.01, 0.03) d33.addComment("MONITOR IDs") d33.addMonitorIds([repr(500000), repr(500001)]) d33.addComment("DETECTORS") d33.addComponentILL("detector", 0., 0., 0.) detector = d33.makeTypeElement("detector") d33.addComponentRectangularDetector(detector0, 0., 0., zPosRear, idstart=id0, idfillbyfirst=FF, idstepbyrow=SR, root=detector) d33.addComponentILL("front_detector", 0., 0., 0., root=detector) front_detector = d33.makeTypeElement("front_detector") d33.addComponentRectangularDetector(detector1, dF+dR, 0., zFront, idstart=id1, idfillbyfirst="x", idstepbyrow=SRF, rotz=90., roty=180., root=front_detector) d33.addComponentRectangularDetector(detector2, -dR-dF, 0., zFront, idstart=id2, idfillbyfirst="x", idstepbyrow=SRF, rotz=90., roty=180., root=front_detector) d33.addComponentRectangularDetector(detector3, 0., -dF-dR, zFront, idstart=id3, idfillbyfirst=FF, idstepbyrow=SRF, root=front_detector) d33.addComponentRectangularDetector(detector4, 0., dR+dF, zFront, idstart=id4, idfillbyfirst=FF, idstepbyrow=SRF, root=front_detector) d33.addComment("REAR DETECTOR") d33.addRectangularDetector(detector0, pixelName, xstart, xstep, xpixels, ystart, ystep, ypixels) d33.addComment("4 FRONT DETECTORS, from detector to sample in +Z direction") d33.addComment("RIGHT") d33.addRectangularDetector(detector1, pixelName, xstart, xstep, xpixels, startFront, ystep, pixelsFront) d33.addComment("LEFT")
For more information, please visit https://www.ill.eu/instruments-support/instruments-groups/instruments/d17/characteristics/ """ d17 = MantidGeom(instrumentName, comment=comment, valid_from=validFrom) d17.addSnsDefaults(theta_sign_axis='x') d17.addComment("SOURCE") d17.addComponentILL("chopper1", 0.0, 0.0, chop1_source, "Source") d17.addComment("Sample position") d17.addComponentILL("sample_position", 0.0, 0.0, 0.0, "SamplePos") d17.addComment("MONITORS") d17.addMonitors(names=["monitor1", "monitor2"], distance=[zMon1, zMon2]) d17.addComment("MONITOR SHAPE") d17.addComment("FIXME: Do something real here.") d17.addDummyMonitor(0.01, 0.03) d17.addComment("MONITOR IDs") d17.addMonitorIds(["100000", "100001"]) d17.addComment("2 Slits") d17.addComponentILL("slit2", 0.0, 0.0, slit2Centre) d17.makeTypeElement("slit2") d17.addComponentILL("slit3", 0.0, 0.0, slit3Centre) d17.makeTypeElement("slit3") d17.addComment("DETECTORS") d17.addComment("64 TUBES FORM ONE DETECTOR") d17.addComponentRectangularDetector("detector", 0.0, 0.0, detValue, idstart="1", idfillbyfirst="x", idstepbyrow="1") d17.addComment("PIXEL, EACH PIXEL IS A DETECTOR") d17.addRectangularDetector("detector", "pixel", xstart, xstep, xpixels, ystart, ystep, ypixels) d17.addCuboidPixel("pixel", [-x, -y, z], [x, y, z], [-x, -y, thickness], [x, -y, z], shape_id="pixel-shape") d17.writeGeom("./ILL/IDF/" + instrumentName + "_Definition.xml")
""" d11b = MantidGeom(instrument_name, comment=comment, valid_from=valid_from) d11b.addSnsDefaults(default_view='3D', axis_view_3d='z-') d11b.addComment("SOURCE") d11b.addComponentILL("monochromator", 0., 0., monochromator_source, "source") d11b.addComment("Sample position") d11b.addComponentILL("sample_position", 0., 0., 0., "SamplePos") d11b.addComment("MONITORS") d11b.addMonitors(names=["monitor1", "monitor2"], distance=[zMon1, zMon2]) d11b.addComment("MONITOR SHAPE") d11b.addDummyMonitor(0.01, 0.03) d11b.addComment("MONITOR IDs") d11b.addMonitorIds([repr(100000), repr(100001)]) d11b.addComment("DETECTORS") d11b.addComponentILL("detector", 0., 0., 0.) detector = d11b.makeTypeElement("detector") d11b.addComponentRectangularDetector(detector0, 0., 0., distance, idstart=id0, rotz=90., idfillbyfirst="x", idstepbyrow=str(number_of_tubes_center), root=detector) d11b.addComponentRectangularDetector( detector1, 0., 0., distance - z_gap, idstart=id1,
return tocartesian(r, t, p) geometry = MantidGeom(instrument_name, comment=comment, valid_from=valid_from) geometry.addSnsDefaults(indirect=args.geometrytype != 'N') geometry.addSamplePosition() geometry.addModerator(distance=ch12, name="chopper") geometry.addMonitors(names=["monitor"], distance=[mon], neutronic=args.geometrytype != 'N') geometry.addDummyMonitor(0.001, 0.001) geometry.addMonitorIds([0]) geometry.addComponent("single_detectors", "single_detectors", blank_location=False) sds = geometry.makeTypeElement("single_detectors") sdc = geometry.addComponent("single_pixel", root=sds) for i in range(len(SD_azimuths)): t = SD_azimuths[i] * pi / 180. x = sd * sin(t) y = 0. z = -sd * cos(t) nx, ny, nz = mirror(x, y, z, sd_analyser) if args.geometrytype == 'N': geometry.addLocation(root=sdc, x=nx, y=ny, z=nz, name="single_tube_{0}".format(i + 1)) else: geometry.addLocation(root=sdc,
def main(): from helper import MantidGeom inst_name = "VISION" xml_outfile = inst_name+"_Definition.xml" det = MantidGeom(inst_name, comment=" Created by Stuart Campbell ") det.addSnsDefaults(indirect=True) det.addComment("SOURCE AND SAMPLE POSITION") det.addModerator(-16.0) det.addSamplePosition() # Backscattering Banks are 21-100 BACKSCATTERING_NTUBES = 80 det.addComponent("elastic-backscattering", "elastic-backscattering") handle = det.makeTypeElement("elastic-backscattering") idlist = [] for k in range(BACKSCATTERING_NTUBES): id_start = 26624+(256*k) id_end = 26624 + (256*k) + 255 angle = -(2.25 + 4.5*k) bankid = 21 + k bank_name = "bank%d" % bankid det.addComponent(bank_name, root=handle) z_coord = -0.998 if k%2 == 0: # Even tube number (long) centre_offset = BS_ELASTIC_LONG_TUBE_INNER_RADIUS + (BS_ELASTIC_LONG_TUBE_LENGTH/2.0) #centre_offset = BS_ELASTIC_LONG_TUBE_INNER_RADIUS component_name = "tube-long-bs-elastic" else: # Odd tube number (short) centre_offset = BS_ELASTIC_SHORT_TUBE_INNER_RADIUS + (BS_ELASTIC_SHORT_TUBE_LENGTH/2.0) component_name = "tube-short-bs-elastic" x_coord = centre_offset * math.cos(math.radians(90-angle)) y_coord = centre_offset * math.sin(math.radians(90-angle)) det.addDetector(x_coord, y_coord, z_coord, 0, 0, -angle, bank_name, component_name) idlist.append(id_start) idlist.append(id_end) idlist.append(None) det.addDetectorIds("elastic-backscattering", idlist) # 90 elastic banks elastic_banklist = [3,6,9,12,15,18] elastic_bank_start = [2048,6144,10240,14336,18432,22528] elastic_angle = [22.5,-22.5,-67.5,-112.5,-157.5,157.5] sample_elastic_distance = 0.635 det.addComponent("elastic", "elastic") handle = det.makeTypeElement("elastic") idlist = [] elastic_index = 0 for i in elastic_banklist: bank_name = "bank%d" % i det.addComponent(bank_name, root=handle) z_coord = 0.0 x_coord = sample_elastic_distance * math.cos(math.radians(elastic_angle[elastic_index])) y_coord = sample_elastic_distance * math.sin(math.radians(elastic_angle[elastic_index])) det.addDetector(x_coord, y_coord, z_coord, -90.0, 0, 0., bank_name, "eightpack-elastic", facingSample=True) idlist.append(elastic_bank_start[elastic_index]) idlist.append(elastic_bank_start[elastic_index]+2047) idlist.append(None) elastic_index += 1 det.addDetectorIds("elastic", idlist) # Inelastic inelastic_banklist = [1,2,4,5,7,8,10,11,13,14,16,17,19,20] inelastic_bank_start=[0,1024,4096,5120,8192,9216,12288,13312,16384,17408,20480,21504,24576,25600] inelastic_angle = [45.0,45.0,0.0,0.0,-45.0,-45.0,-90.0,-90.0,-135.0,-135.0,180.0,180.0,135.0,135.0] inelastic_angle_for_rotation = [-45.0,-45.0,180.0,180.0,-135.0,-135.0,-90.0,-90.0,-225.0,-225.0,0.0,0.0,45.0,45.0] sample_inelastic_distance = 0.5174 det.addComponent("inelastic", "inelastic") handle = det.makeTypeElement("inelastic") idlist = [] inelastic_index = 0 for i in inelastic_banklist: bank_name = "bank%d" % i bank_comp = det.addComponent(bank_name, root=handle, blank_location=True) # location_element = le.SubElement(bank_comp, "location") # le.SubElement(location_element, "rot", **{"val":"90", "axis-x":"0", # "axis-y":"0", "axis-z":"1"}) # Neutronic Positions z_coord_neutronic = sample_inelastic_distance * math.tan(math.radians(45.0)) if inelastic_index % 2 == 0: # Facing Downstream z_coord = 0.01 else: # Facing to Moderator z_coord = -0.01 z_coord_neutronic = -z_coord_neutronic # Physical Positions x_coord = sample_inelastic_distance * math.cos(math.radians(inelastic_angle[inelastic_index])) y_coord = sample_inelastic_distance * math.sin(math.radians(inelastic_angle[inelastic_index])) det.addDetector(-x_coord, y_coord, z_coord, 0, 0, inelastic_angle_for_rotation[inelastic_index]-90.0, bank_name, "eightpack-inelastic", neutronic=True, nx=-x_coord, ny=y_coord, nz=z_coord_neutronic) efixed = ("Efixed", "3.64", "meV") det.addDetectorParameters(bank_name, efixed ) idlist.append(inelastic_bank_start[inelastic_index]) idlist.append(inelastic_bank_start[inelastic_index]+1023) idlist.append(None) inelastic_index += 1 det.addDetectorIds("inelastic", idlist) # 8 packs det.addComment("INELASTIC 8-PACK") det.addNPack("eightpack-inelastic", INELASTIC_TUBES_PER_BANK, INELASTIC_TUBE_WIDTH, INELASTIC_AIR_GAP, "tube-inelastic", neutronic=True) det.addComment("ELASTIC 8-PACK") det.addNPack("eightpack-elastic", ELASTIC_TUBES_PER_BANK, ELASTIC_TUBE_WIDTH, ELASTIC_AIR_GAP, "tube-elastic", neutronic=True, neutronicIsPhysical=True) # TUBES det.addComment("INELASTIC TUBE") det.addPixelatedTube("tube-inelastic", INELASTIC_TUBE_NPIXELS, INELASTIC_TUBE_LENGTH, "pixel-inelastic-tube", neutronic=True) det.addComment("BACKSCATTERING LONG TUBE") det.addPixelatedTube("tube-long-bs-elastic", BS_ELASTIC_LONG_TUBE_NPIXELS, BS_ELASTIC_LONG_TUBE_LENGTH, "pixel-bs-elastic-long-tube", neutronic=True, neutronicIsPhysical=True) det.addComment("BACKSCATTERING SHORT TUBE") det.addPixelatedTube("tube-short-bs-elastic", BS_ELASTIC_SHORT_TUBE_NPIXELS, BS_ELASTIC_SHORT_TUBE_LENGTH, "pixel-bs-elastic-short-tube", neutronic=True, neutronicIsPhysical=True) det.addComment("ELASTIC TUBE (90 degrees)") det.addPixelatedTube("tube-elastic", ELASTIC_TUBE_NPIXELS, ELASTIC_TUBE_LENGTH, "pixel-elastic-tube", neutronic=True, neutronicIsPhysical=True) # PIXELS det.addComment("PIXEL FOR INELASTIC TUBES") det.addCylinderPixel("pixel-inelastic-tube", (0.0, 0.0, 0.0), (0.0, 1.0, 0.0), (INELASTIC_TUBE_WIDTH/2.0), (INELASTIC_TUBE_LENGTH/INELASTIC_TUBE_NPIXELS)) det.addComment("PIXEL FOR BACKSCATTERING ELASTIC TUBES (LONG)") det.addCylinderPixel("pixel-bs-elastic-long-tube", (0.0, 0.0, 0.0), (0.0, 1.0, 0.0), (BS_ELASTIC_LONG_TUBE_WIDTH/2.0), (BS_ELASTIC_LONG_TUBE_LENGTH/BS_ELASTIC_LONG_TUBE_NPIXELS)) det.addComment("PIXEL FOR BACKSCATTERING ELASTIC TUBES (SHORT)") det.addCylinderPixel("pixel-bs-elastic-short-tube", (0.0, 0.0, 0.0), (0.0, 1.0, 0.0), (BS_ELASTIC_SHORT_TUBE_WIDTH/2.0), (BS_ELASTIC_SHORT_TUBE_LENGTH/BS_ELASTIC_SHORT_TUBE_NPIXELS)) det.addComment("PIXEL FOR ELASTIC TUBES (90 degrees)") det.addCylinderPixel("pixel-elastic-tube", (0.0, 0.0, 0.0), (0.0, 1.0, 0.0), (ELASTIC_TUBE_WIDTH/2.0), (ELASTIC_TUBE_LENGTH/ELASTIC_TUBE_NPIXELS)) det.addComment(" ##### MONITORS ##### ") det.addMonitors(names=["monitor1"], distance=["-6.71625"], neutronic=True) # MONITORS det.addComment("MONITOR SHAPE") det.addComment("FIXME: Do something real here.") det.addDummyMonitor(0.01, 0.03) det.addComment("MONITOR IDs") det.addMonitorIds(["-1"]) det.showGeom() det.writeGeom(xml_outfile)
# add the id lists for groups - [start, stop, step] start, stop = -1, -1 for i, num_banks_in_pack in enumerate(num_banks): start = stop + 1 stop = start + num_banks_in_pack * 8 * 128 - 1 info = instr.addDetectorIds('Group%d' % (i + 1), [start, stop, None]) for i, _ in enumerate(num_banks): group = 'Group%d' % (i + 1) # set blank_location=False to add <location/> tag to component group = instr.addComponent(group, idlist=group, blank_location=False) #################### # group 1 is banks 1-14 (inclusive) bank_offset = 0 group = instr.makeTypeElement('Group1') for i in range(num_banks[0]): bank_num = bank_offset + i + 1 bank = "bank%d" % bank_num corners = getCorners(bank_num) rect = getRectangle(bank_num, positions, corners) det = instr.makeDetectorElement('pack', root=group) rect.makeLocation(instr, det, bank) # group 2 is banks 15-37 (inclusive) bank_offset += num_banks[0] group = instr.makeTypeElement('Group2') for i in range(num_banks[1]): bank_num = bank_offset + i + 1 bank = "bank%d" % bank_num corners = getCorners(bank_num)
def main(): from helper import MantidGeom inst_name = "VISION" xml_outfile = inst_name+"_Definition.xml" comment = " Created by Stuart Campbell " valid_from = "2013-10-21 00:00:01" det = MantidGeom(inst_name, comment=comment, valid_from=valid_from) det.addSnsDefaults(indirect=True) det.addComment("SOURCE AND SAMPLE POSITION") det.addModerator(-16.0) det.addSamplePosition() # Backscattering Banks are 21-100 BACKSCATTERING_NTUBES = 80 BACKSCATTERING_SECTORS = 10 TUBES_PER_SECTOR = BACKSCATTERING_NTUBES / BACKSCATTERING_SECTORS PIXELS_PER_SECTOR = TUBES_PER_SECTOR * 256 det.addComponent("elastic-backscattering", "elastic-backscattering") handle = det.makeTypeElement("elastic-backscattering") idlist = [] for k in range(BACKSCATTERING_SECTORS): bankid = 15 + k bank_name = "bank%d" % bankid #doc_handle = det.makeDetectorElement(bank_name, root=handle) z_coord = -0.998 id_start = 14336 + (PIXELS_PER_SECTOR * k) id_end = 14336 + (PIXELS_PER_SECTOR * k) + PIXELS_PER_SECTOR - 1 for l in range(TUBES_PER_SECTOR): tube_index = (k*TUBES_PER_SECTOR) + l tube_name = bank_name + "-tube" + str(tube_index+1) #det.addComponent(tube_name, root=doc_handle) det.addComponent(tube_name, root=handle) angle = -(2.25 + 4.5*tube_index) if tube_index%2 == 0: # Even tube number (long) centre_offset = BS_ELASTIC_LONG_TUBE_INNER_RADIUS + (BS_ELASTIC_LONG_TUBE_LENGTH/2.0) #centre_offset = BS_ELASTIC_LONG_TUBE_INNER_RADIUS component_name = "tube-long-bs-elastic" else: # Odd tube number (short) centre_offset = BS_ELASTIC_SHORT_TUBE_INNER_RADIUS + (BS_ELASTIC_SHORT_TUBE_LENGTH/2.0) component_name = "tube-short-bs-elastic" x_coord = centre_offset * math.cos(math.radians(90-angle)) y_coord = centre_offset * math.sin(math.radians(90-angle)) det.addDetector( x_coord, y_coord, z_coord, 0, 0, -angle, tube_name, component_name) idlist.append(id_start) idlist.append(id_end) idlist.append(None) det.addDetectorIds("elastic-backscattering", idlist) # 90 elastic banks elastic_banklist = [25,26,27,28,29,30] elastic_bank_start = [34816,36864,38912,40960,43008,45056] elastic_angle = [157.5,-157.5,-67.5,-112.5,-22.5,22.5] sample_elastic_distance = 0.635 det.addComponent("elastic", "elastic") handle = det.makeTypeElement("elastic") idlist = [] elastic_index = 0 for i in elastic_banklist: bank_name = "bank%d" % i det.addComponent(bank_name, root=handle) z_coord = 0.0 x_coord = sample_elastic_distance * math.cos(math.radians(elastic_angle[elastic_index])) y_coord = sample_elastic_distance * math.sin(math.radians(elastic_angle[elastic_index])) det.addDetector(x_coord, y_coord, z_coord, -90.0, 180, 0., bank_name, "eightpack-elastic", facingSample=True) idlist.append(elastic_bank_start[elastic_index]) idlist.append(elastic_bank_start[elastic_index]+2047) idlist.append(None) elastic_index += 1 det.addDetectorIds("elastic", idlist) # Inelastic inelastic_banklist = [1,2,3,4,5,6,7,8,9,10,11,12,13,14] inelastic_bank_start=[0,1024,2048,3072,4096,5120,6144,7168,8192,9216,10240,11264,12288,13312] inelastic_angle = [45.0,0.0,-45.0,-90.0,-135.0,-180.0,135.0,45.0,0.0,-45.0,-90.0,-135.0,-180.0,135.0] inelastic_angle_for_rotation = [-45.0,180.0,-135.0,-90.0,-225.0,0.0,45.0,-45.0,180.0,-135.0,-90.0,-225.0,0.0,45.0] sample_inelastic_distance = 0.5174 det.addComponent("inelastic", "inelastic") handle = det.makeTypeElement("inelastic") idlist = [] inelastic_index = 0 for i in inelastic_banklist: bank_name = "bank%d" % i bank_comp = det.addComponent(bank_name, root=handle, blank_location=True) # location_element = le.SubElement(bank_comp, "location") # le.SubElement(location_element, "rot", **{"val":"90", "axis-x":"0", # "axis-y":"0", "axis-z":"1"}) # Neutronic Positions z_coord_neutronic = sample_inelastic_distance * math.tan(math.radians(45.0)) if inelastic_index+1 > 7: # Facing Downstream z_coord = -0.01 else: # Facing to Moderator z_coord = 0.01 z_coord_neutronic = -z_coord_neutronic # Physical Positions x_coord = sample_inelastic_distance * math.cos(math.radians(inelastic_angle[inelastic_index])) y_coord = sample_inelastic_distance * math.sin(math.radians(inelastic_angle[inelastic_index])) det.addDetector(-x_coord, y_coord, z_coord, 0, 0, inelastic_angle_for_rotation[inelastic_index]-90.0, bank_name, "eightpack-inelastic", neutronic=True, nx=-x_coord, ny=y_coord, nz=z_coord_neutronic) efixed = ("Efixed", "3.64", "meV") det.addDetectorParameters(bank_name, efixed ) idlist.append(inelastic_bank_start[inelastic_index]) idlist.append(inelastic_bank_start[inelastic_index]+1023) idlist.append(None) inelastic_index += 1 det.addDetectorIds("inelastic", idlist) # 8 packs det.addComment("INELASTIC 8-PACK") det.addNPack("eightpack-inelastic", INELASTIC_TUBES_PER_BANK, INELASTIC_TUBE_WIDTH, INELASTIC_AIR_GAP, "tube-inelastic", neutronic=True) det.addComment("ELASTIC 8-PACK") det.addNPack("eightpack-elastic", ELASTIC_TUBES_PER_BANK, ELASTIC_TUBE_WIDTH, ELASTIC_AIR_GAP, "tube-elastic", neutronic=True, neutronicIsPhysical=True) # TUBES det.addComment("INELASTIC TUBE") det.addPixelatedTube("tube-inelastic", INELASTIC_TUBE_NPIXELS, INELASTIC_TUBE_LENGTH, "pixel-inelastic-tube", neutronic=True) det.addComment("BACKSCATTERING LONG TUBE") det.addPixelatedTube("tube-long-bs-elastic", BS_ELASTIC_LONG_TUBE_NPIXELS, BS_ELASTIC_LONG_TUBE_LENGTH, "pixel-bs-elastic-long-tube", neutronic=True, neutronicIsPhysical=True) det.addComment("BACKSCATTERING SHORT TUBE") det.addPixelatedTube("tube-short-bs-elastic", BS_ELASTIC_SHORT_TUBE_NPIXELS, BS_ELASTIC_SHORT_TUBE_LENGTH, "pixel-bs-elastic-short-tube", neutronic=True, neutronicIsPhysical=True) det.addComment("ELASTIC TUBE (90 degrees)") det.addPixelatedTube("tube-elastic", ELASTIC_TUBE_NPIXELS, ELASTIC_TUBE_LENGTH, "pixel-elastic-tube", neutronic=True, neutronicIsPhysical=True) # PIXELS det.addComment("PIXEL FOR INELASTIC TUBES") det.addCylinderPixel("pixel-inelastic-tube", (0.0, 0.0, 0.0), (0.0, 1.0, 0.0), (INELASTIC_TUBE_WIDTH/2.0), (INELASTIC_TUBE_LENGTH/INELASTIC_TUBE_NPIXELS)) det.addComment("PIXEL FOR BACKSCATTERING ELASTIC TUBES (LONG)") det.addCylinderPixel("pixel-bs-elastic-long-tube", (0.0, 0.0, 0.0), (0.0, 1.0, 0.0), (BS_ELASTIC_LONG_TUBE_WIDTH/2.0), (BS_ELASTIC_LONG_TUBE_LENGTH/BS_ELASTIC_LONG_TUBE_NPIXELS)) det.addComment("PIXEL FOR BACKSCATTERING ELASTIC TUBES (SHORT)") det.addCylinderPixel("pixel-bs-elastic-short-tube", (0.0, 0.0, 0.0), (0.0, 1.0, 0.0), (BS_ELASTIC_SHORT_TUBE_WIDTH/2.0), (BS_ELASTIC_SHORT_TUBE_LENGTH/BS_ELASTIC_SHORT_TUBE_NPIXELS)) det.addComment("PIXEL FOR ELASTIC TUBES (90 degrees)") det.addCylinderPixel("pixel-elastic-tube", (0.0, 0.0, 0.0), (0.0, 1.0, 0.0), (ELASTIC_TUBE_WIDTH/2.0), (ELASTIC_TUBE_LENGTH/ELASTIC_TUBE_NPIXELS)) det.addComment(" ##### MONITORS ##### ") det.addMonitors(names=["monitor1","monitor4"], distance=["-6.71625","0.287"], neutronic=True) # MONITORS det.addComment("MONITOR SHAPE") det.addComment("FIXME: All monitors share the dimensions of monitor4.") det.addCuboidMonitor(0.051,0.054,0.013) det.addComment("MONITOR IDs") det.addMonitorIds(["-1","-4"]) #det.showGeom() det.writeGeom(xml_outfile)
def main(): from helper import MantidGeom inst_name = "VISION" xml_outfile = inst_name + "_Definition.xml" det = MantidGeom(inst_name, comment=" Created by Stuart Campbell ") det.addSnsDefaults(indirect=True) det.addComment("SOURCE AND SAMPLE POSITION") det.addModerator(-16.0) det.addSamplePosition() # Backscattering Banks are 21-100 BACKSCATTERING_NTUBES = 80 det.addComponent("elastic-backscattering", "elastic-backscattering") handle = det.makeTypeElement("elastic-backscattering") idlist = [] for k in range(BACKSCATTERING_NTUBES): id_start = 26624 + (256 * k) id_end = 26624 + (256 * k) + 255 angle = -(2.25 + 4.5 * k) bankid = 21 + k bank_name = "bank%d" % bankid det.addComponent(bank_name, root=handle) z_coord = -0.998 if k % 2 == 0: # Even tube number (long) centre_offset = BS_ELASTIC_LONG_TUBE_INNER_RADIUS + ( BS_ELASTIC_LONG_TUBE_LENGTH / 2.0) #centre_offset = BS_ELASTIC_LONG_TUBE_INNER_RADIUS component_name = "tube-long-bs-elastic" else: # Odd tube number (short) centre_offset = BS_ELASTIC_SHORT_TUBE_INNER_RADIUS + ( BS_ELASTIC_SHORT_TUBE_LENGTH / 2.0) component_name = "tube-short-bs-elastic" x_coord = centre_offset * math.cos(math.radians(90 - angle)) y_coord = centre_offset * math.sin(math.radians(90 - angle)) det.addDetector(x_coord, y_coord, z_coord, 0, 0, -angle, bank_name, component_name) idlist.append(id_start) idlist.append(id_end) idlist.append(None) det.addDetectorIds("elastic-backscattering", idlist) # 90 elastic banks elastic_banklist = [3, 6, 9, 12, 15, 18] elastic_bank_start = [2048, 6144, 10240, 14336, 18432, 22528] elastic_angle = [22.5, -22.5, -67.5, -112.5, -157.5, 157.5] sample_elastic_distance = 0.635 det.addComponent("elastic", "elastic") handle = det.makeTypeElement("elastic") idlist = [] elastic_index = 0 for i in elastic_banklist: bank_name = "bank%d" % i det.addComponent(bank_name, root=handle) z_coord = 0.0 x_coord = sample_elastic_distance * math.cos( math.radians(elastic_angle[elastic_index])) y_coord = sample_elastic_distance * math.sin( math.radians(elastic_angle[elastic_index])) det.addDetector(x_coord, y_coord, z_coord, -90.0, 0, 0., bank_name, "eightpack-elastic", facingSample=True) idlist.append(elastic_bank_start[elastic_index]) idlist.append(elastic_bank_start[elastic_index] + 2047) idlist.append(None) elastic_index += 1 det.addDetectorIds("elastic", idlist) # Inelastic inelastic_banklist = [1, 2, 4, 5, 7, 8, 10, 11, 13, 14, 16, 17, 19, 20] inelastic_bank_start = [ 0, 1024, 4096, 5120, 8192, 9216, 12288, 13312, 16384, 17408, 20480, 21504, 24576, 25600 ] inelastic_angle = [ 45.0, 45.0, 0.0, 0.0, -45.0, -45.0, -90.0, -90.0, -135.0, -135.0, 180.0, 180.0, 135.0, 135.0 ] inelastic_angle_for_rotation = [ -45.0, -45.0, 180.0, 180.0, -135.0, -135.0, -90.0, -90.0, -225.0, -225.0, 0.0, 0.0, 45.0, 45.0 ] sample_inelastic_distance = 0.5174 det.addComponent("inelastic", "inelastic") handle = det.makeTypeElement("inelastic") idlist = [] inelastic_index = 0 for i in inelastic_banklist: bank_name = "bank%d" % i bank_comp = det.addComponent(bank_name, root=handle, blank_location=True) # location_element = le.SubElement(bank_comp, "location") # le.SubElement(location_element, "rot", **{"val":"90", "axis-x":"0", # "axis-y":"0", "axis-z":"1"}) # Neutronic Positions z_coord_neutronic = sample_inelastic_distance * math.tan( math.radians(45.0)) if inelastic_index % 2 == 0: # Facing Downstream z_coord = 0.01 else: # Facing to Moderator z_coord = -0.01 z_coord_neutronic = -z_coord_neutronic # Physical Positions x_coord = sample_inelastic_distance * math.cos( math.radians(inelastic_angle[inelastic_index])) y_coord = sample_inelastic_distance * math.sin( math.radians(inelastic_angle[inelastic_index])) det.addDetector(-x_coord, y_coord, z_coord, 0, 0, inelastic_angle_for_rotation[inelastic_index] - 90.0, bank_name, "eightpack-inelastic", neutronic=True, nx=-x_coord, ny=y_coord, nz=z_coord_neutronic) efixed = ("Efixed", "3.64", "meV") det.addDetectorParameters(bank_name, efixed) idlist.append(inelastic_bank_start[inelastic_index]) idlist.append(inelastic_bank_start[inelastic_index] + 1023) idlist.append(None) inelastic_index += 1 det.addDetectorIds("inelastic", idlist) # 8 packs det.addComment("INELASTIC 8-PACK") det.addNPack("eightpack-inelastic", INELASTIC_TUBES_PER_BANK, INELASTIC_TUBE_WIDTH, INELASTIC_AIR_GAP, "tube-inelastic", neutronic=True) det.addComment("ELASTIC 8-PACK") det.addNPack("eightpack-elastic", ELASTIC_TUBES_PER_BANK, ELASTIC_TUBE_WIDTH, ELASTIC_AIR_GAP, "tube-elastic", neutronic=True, neutronicIsPhysical=True) # TUBES det.addComment("INELASTIC TUBE") det.addPixelatedTube("tube-inelastic", INELASTIC_TUBE_NPIXELS, INELASTIC_TUBE_LENGTH, "pixel-inelastic-tube", neutronic=True) det.addComment("BACKSCATTERING LONG TUBE") det.addPixelatedTube("tube-long-bs-elastic", BS_ELASTIC_LONG_TUBE_NPIXELS, BS_ELASTIC_LONG_TUBE_LENGTH, "pixel-bs-elastic-long-tube", neutronic=True, neutronicIsPhysical=True) det.addComment("BACKSCATTERING SHORT TUBE") det.addPixelatedTube("tube-short-bs-elastic", BS_ELASTIC_SHORT_TUBE_NPIXELS, BS_ELASTIC_SHORT_TUBE_LENGTH, "pixel-bs-elastic-short-tube", neutronic=True, neutronicIsPhysical=True) det.addComment("ELASTIC TUBE (90 degrees)") det.addPixelatedTube("tube-elastic", ELASTIC_TUBE_NPIXELS, ELASTIC_TUBE_LENGTH, "pixel-elastic-tube", neutronic=True, neutronicIsPhysical=True) # PIXELS det.addComment("PIXEL FOR INELASTIC TUBES") det.addCylinderPixel("pixel-inelastic-tube", (0.0, 0.0, 0.0), (0.0, 1.0, 0.0), (INELASTIC_TUBE_WIDTH / 2.0), (INELASTIC_TUBE_LENGTH / INELASTIC_TUBE_NPIXELS)) det.addComment("PIXEL FOR BACKSCATTERING ELASTIC TUBES (LONG)") det.addCylinderPixel( "pixel-bs-elastic-long-tube", (0.0, 0.0, 0.0), (0.0, 1.0, 0.0), (BS_ELASTIC_LONG_TUBE_WIDTH / 2.0), (BS_ELASTIC_LONG_TUBE_LENGTH / BS_ELASTIC_LONG_TUBE_NPIXELS)) det.addComment("PIXEL FOR BACKSCATTERING ELASTIC TUBES (SHORT)") det.addCylinderPixel( "pixel-bs-elastic-short-tube", (0.0, 0.0, 0.0), (0.0, 1.0, 0.0), (BS_ELASTIC_SHORT_TUBE_WIDTH / 2.0), (BS_ELASTIC_SHORT_TUBE_LENGTH / BS_ELASTIC_SHORT_TUBE_NPIXELS)) det.addComment("PIXEL FOR ELASTIC TUBES (90 degrees)") det.addCylinderPixel("pixel-elastic-tube", (0.0, 0.0, 0.0), (0.0, 1.0, 0.0), (ELASTIC_TUBE_WIDTH / 2.0), (ELASTIC_TUBE_LENGTH / ELASTIC_TUBE_NPIXELS)) det.addComment(" ##### MONITORS ##### ") det.addMonitors(names=["monitor1"], distance=["-6.71625"], neutronic=True) # MONITORS det.addComment("MONITOR SHAPE") det.addComment("FIXME: Do something real here.") det.addDummyMonitor(0.01, 0.03) det.addComment("MONITOR IDs") det.addMonitorIds(["-1"]) det.showGeom() det.writeGeom(xml_outfile)
k = float(k) x.append(x0j + xextent * (1. - k / 128.)) y.append(y0j + yextent * (1. - k / 128.)) z.append(z0_first + dz_first * (1. - k / 128.)) pack1 = DetPack(tuberadius=.5 * .0254, airgap=AIR_GAP, xstartdiff=(.0254 + AIR_GAP), ysize=-1. * TUBE_LENGTH, ystartdiff=-1. * TUBE_LENGTH / 128., debug=False) pack1.setNames(pixel="onepixel", tube="tubedecreasing", pack="packdecreasing") group1 = instr.makeTypeElement("Group1") for i in range(n_first): offset = i * 8 * 128 bank = "bank%d" % (i + 1) rect = Rectangle((-y[offset + UL], x[offset + UL], z[offset + UL]), (-y[offset + LL], x[offset + LL], z[offset + LL]), (-y[offset + LR], x[offset + LR], z[offset + LR]), (-y[offset + UR], x[offset + UR], z[offset + UR])) det = instr.makeDetectorElement(pack1.namepack, root=group1) rect.makeLocation(instr, det, bank) # ---------- add in group2 """ ;;; source idl code N_second=23 ;z0_second=5.05/8.45*3.2
d33 = MantidGeom(instrumentName, comment=comment, valid_from=validFrom) d33.addSnsDefaults(default_view='3D', axis_view_3d='z-') d33.addComment("SOURCE") d33.addComponentILL("moderator", 0., 0., moderator_source, "Source") d33.addComment("Sample position") d33.addComponentILL("sample_position", 0., 0., 0., "SamplePos") d33.addComment("MONITORS") d33.addMonitors(names=["monitor1", "monitor2"], distance=[zMon1, zMon2]) d33.addComment("MONITOR SHAPE") d33.addComment("FIXME: Do something real here.") d33.addDummyMonitor(0.01, 0.03) d33.addComment("MONITOR IDs") d33.addMonitorIds([repr(500000), repr(500001)]) d33.addComment("DETECTORS") d33.addComponentILL("detector", 0., 0., 0.) detector = d33.makeTypeElement("detector") d33.addComponentRectangularDetector(detector0, 0., 0., zPosRear, idstart=id0, idfillbyfirst="x", idstepbyrow=SR, rotz=90., root=detector) d33.addComponentILL("front_detector", 0., 0., 0., root=detector) front_detector = d33.makeTypeElement("front_detector") d33.addComponentRectangularDetector(detector1, -dF - dR, 0., zFront,
def generate_reflection_file(reflection_key): r""" Parameters ---------- reflection_key: str Returns ------- """ refl = reflections[reflection_key] if not os.path.exists(refl['nexus']): message = '{} not found. Not creating geometry'.format(refl['nexus']) raise FileExistsError(message) inst_name = "BASIS" # Set header information comment = "Created by Michael Reuter and Jose Borreguero" # Time needs to be in UTC? valid_from = "2014-01-01 00:00:00" xml_outfile = '{}_Definition_Si{}.xml'.format(inst_name, reflection_key) nfile = h5py.File(refl['nexus'], 'r') det = MantidGeom(inst_name, comment=comment, valid_from=valid_from) det.addSnsDefaults(indirect=True) det.addComment("SOURCE AND SAMPLE POSITION") det.addModerator(-84.0) det.addSamplePosition() det.addComment("MONITORS") det.addMonitors(names=["monitor1"], distance=["-0.23368"], neutronic=True) # Create the inelastic banks information det.addComment('INELASTIC DECTECTORS') det.addComponent('silicon') handle_silicon = det.makeTypeElement("silicon") # Slicer for removing ghosts. Due to the mapping, the ghost tubes sit # on the same sides of the arrays for all banks. remove_ghosts = slice(-INELASTIC_TUBES_NGHOST) for i in range(n_inelastic_banks): bank_id = "bank%d" % (i + 1) pixel_id = nfile["/entry/instrument/bank%d/pixel_id" % (i + 1)].value[remove_ghosts] distance = nfile["/entry/instrument/bank%d/distance" % (i + 1)].value[remove_ghosts] # theta or polar_angle: angle from the Z-axis towards the X-axis polar_angle = nfile["/entry/instrument/bank%d/polar_angle" % (i + 1)].value[remove_ghosts] polar_angle *= (180.0 / math.pi) # phi or azimuthal_angle: angle in the XY-plane azimuthal_angle = nfile["/entry/instrument/bank%d/azimuthal_angle" % (i + 1)].value[remove_ghosts] azimuthal_angle *= (180.0 / math.pi) analyser_wavelength = nfile["/entry/instrument/analyzer%d/wavelength" % (i + 1)].value[remove_ghosts] analyser_wavelength *= refl['ratio_to_irreducible_hkl'] analyser_energy = 81.8042051 / analyser_wavelength**2 det.addComponent(bank_id, idlist=bank_id, root=handle_silicon) xbank, ybank, zbank = pixels_physical_xyz(i) det.addDetectorPixels(bank_id, x=xbank, y=ybank, z=zbank, names=pixel_id, energy=analyser_energy, nr=distance, ntheta=polar_angle, nphi=azimuthal_angle, output_efixed=refl['efixed']) det.addDetectorPixelsIdList(bank_id, r=distance, names=pixel_id, elg="multiple_ranges") # Create the diffraction bank information det.addComponent("elastic", "elastic") handle = det.makeTypeElement("elastic") idlist = [] detector_z = [ -2.1474825, -1.704594, -1.108373, -0.4135165, 0.3181, 1.0218315, 1.6330115, 2.0993535, 2.376999 ] detector_x = [ 1.1649855, 1.7484015, 2.175541, 2.408594, 2.422933, 2.216378, 1.8142005, 1.247867, 0.5687435 ] detector_y = [ -0.001807, -0.001801, -0.0011845, -0.0006885, -0.0013145, -0.001626, -0.001397, 0.0003465, -0.0001125 ] for i in range(ELASTIC_BANK_START, ELASTIC_BANK_END + 1): bank_name = "bank%d" % i det.addComponent(bank_name, root=handle) k = i - ELASTIC_BANK_START x_coord = detector_x[k] y_coord = detector_y[k] z_coord = detector_z[k] det.addDetector(x_coord, y_coord, z_coord, 0.0, 0., 90., bank_name, "tube-elastic", facingSample=True) idlist.append(ELASTIC_DETECTORID_START + ELASTIC_TUBE_NPIXELS * (i - ELASTIC_BANK_START)) idlist.append(ELASTIC_DETECTORID_START + ELASTIC_TUBE_NPIXELS * (i - ELASTIC_BANK_START) + ELASTIC_TUBE_NPIXELS - 1) idlist.append(None) # Diffraction tube information det.addComment("ELASTIC TUBE (90 degrees)") det.addPixelatedTube("tube-elastic", ELASTIC_TUBE_NPIXELS, ELASTIC_TUBE_LENGTH, "pixel-elastic-tube", neutronic=True, neutronicIsPhysical=True) # Set the diffraction pixel Ids det.addDetectorIds("elastic", idlist) # Creating diffraction pixel det.addComment("PIXEL FOR DIFFRACTION TUBES") det.addCylinderPixel("pixel-elastic-tube", (0.0, 0.0, 0.0), (0.0, 1.0, 0.0), (ELASTIC_TUBE_WIDTH / 2.0), (ELASTIC_TUBE_LENGTH / ELASTIC_TUBE_NPIXELS)) det.addComment("PIXEL FOR INELASTIC TUBES") det.addCylinderPixel( "pixel", (0.0, 0.0, 0.0), (0.0, 1.0, 0.0), INELASTIC_TUBE_WIDTH * (1.0 - INELASTIC_PIXEL_RADIUS_GAP_RATIO) / 2.0, INELASTIC_TUBE_LENGTH * (1.0 - INELASTIC_PIXEL_HEIGHT_GAP_RATIO) / INELASTIC_TUBE_NPIXEL, is_type="detector", algebra="cyl-approx") det.addComment("MONITOR SHAPE") det.addComment("FIXME: Do something real here.") det.addDummyMonitor(0.01, 0.03) det.addComment("MONITOR IDs") det.addMonitorIds(["-1"]) det.writeGeom(xml_outfile) # Always clean after yourself nfile.close()
in16b.addSnsDefaults(default_view='3D', axis_view_3d='z-', theta_sign_axis="x") in16b.addComment("Sample position") in16b.addSamplePosition() in16b.addComment("Chopper position") in16b.addModerator(distance=chopper_to_sample, name="chopper") in16b.addComment("MONITOR") in16b.addMonitors(names=["monitor"], distance=[monitor_to_sample]) in16b.addDummyMonitor(0.001, 0.001) in16b.addMonitorIds([0]) in16b.addComment("Detector") in16b.addComponentILL("detector", 0, 0, 0) detector = in16b.makeTypeElement("detector") # create tubes id lists for i in range(number_of_tubes): in16b.addDetectorIds("tube_{0}_ids".format(i + 1), [pixel_per_tube * i + 1, pixel_per_tube * (i + 1), 1]) # create standard tube component and place them tube = in16b.makeTypeElement("tube") for i in range(number_of_tubes): current_tube = in16b.addComponent('tube', idlist="tube_{0}_ids".format(i + 1), root=detector) in16b.addLocation(root=current_tube, x=0, y=pow(-1, i) * vertical_offset,
def mirror(x, y, z): r, t, p = topolar(x, y, z) r += 2*analyser t = pi - t p += pi return tocartesian(r, t, p) geometry = MantidGeom(instrument_name, comment=comment, valid_from=valid_from) geometry.addSnsDefaults(indirect=args.geometrytype != 'N') geometry.addSamplePosition() geometry.addModerator(distance=ch12, name="chopper") geometry.addMonitors(names=["monitor"], distance=[mon], neutronic=args.geometrytype != 'N') geometry.addDummyMonitor(0.001, 0.001) geometry.addMonitorIds([0]) geometry.addComponent("single_detectors", "single_detectors") sds = geometry.makeTypeElement("single_detectors") sdc = geometry.addComponent("single_pixel", root=sds, blank_location=False) r = 2*analyser+psd for i in range(len(SD_azimuths)): t=SD_azimuths[i]* pi/180. x = - psd * sin(t) y = 0. z = - psd * cos(t) nx, ny, nz = mirror(x, y, z) if args.geometrytype == 'N': geometry.addLocation(root=sdc, x=nx, y=ny, z=nz, name="single_tube_{0}".format(i+1)) else: geometry.addLocation(root=sdc, x=x, y=y, z=z, nx=nx, ny=ny, nz=nz, name="single_tube_{0}".format(i+1), neutronic=True) geometry.addComponent("psds", "psds") psds = geometry.makeTypeElement("psds") psdc = geometry.addComponent("single_pixel", root=psds, blank_location=False)
figaro = MantidGeom(instrumentName, comment=comment, valid_from=validFrom) figaro.addSnsDefaults(theta_sign_axis='y') figaro.addComment("SOURCE") figaro.addComponentILL("chopper1", 0.0, 0.0, zSource, "Source") figaro.addComment("Sample position") figaro.addComponentILL("sample_position", 0.0, 0.0, 0.0, "SamplePos") figaro.addComment("MONITORS") figaro.addMonitors(names=["monitor1", "monitor2"], distance=[zMon1, zMon2]) figaro.addComment("MONITOR SHAPE") figaro.addComment("FIXME: Do something real here.") figaro.addDummyMonitor(0.01, 0.03) figaro.addComment("MONITOR IDs") figaro.addMonitorIds(["100000", "100001"]) figaro.addComment("2 Slits") figaro.addComponentILL("slit2", 0.0, 0.0, slit2Centre) figaro.makeTypeElement("slit2") figaro.addComponentILL("slit3", 0.0, 0.0, slit3Centre) figaro.makeTypeElement("slit3") figaro.addComment("DETECTORS") figaro.addComment("64 tubes form the detector") figaro.addComponentRectangularDetector("detector", 0.0, 0.0, zDetector, idstart="1", idfillbyfirst="x", idstepbyrow="1") figaro.addComment("PIXEL, EACH PIXEL IS A DETECTOR") figaro.addRectangularDetector("detector", "pixel", xstart, xstep, xpixels, ystart, ystep, ypixels) figaro.addCuboidPixel("pixel", [-x, -y, z], [x, y, z], [-x, -y, -z],
lb_pos = ["X", "Y", "Z"] for bank_id in bank_ids: elem_bank = vulcan_geom.addComponent(type_name=f"bank{bank_id}", idlist=f"bank{bank_id}") vulcan_geom.addLocation(elem_bank, x=0, y=0, z=0, rot_y=0) # -- ADD 8PACKS -- # NOTE: # Assume that the given csv files contains measurements for all eight-packs in each bank logging.info(f"Add 8-packs") for bank_id in bank_ids: # select bank bk = df[df["bank"] == bank_id] # make top element elem_bank = vulcan_geom.makeTypeElement(f"bank{bank_id}") # add individual eight packs based on measurements eightpack_ids = bk["eightpack"].unique() type_name = "eightpackshort" if bank_id == 5 else "eightpack" for eightpack_id in eightpack_ids: ep = bk[bk["eightpack"] == eightpack_id].sort_values( by=["eightpack vertice idx"]) vertices = ep[["X", "Y", "Z"]].to_numpy() # build the rectangle # NOTE: # this will set both the position and orientation of the 8-pack rectangle = Rectangle(*vertices, tolerance_len=REC_TOL_LENS) elem_eightpack = vulcan_geom.addComponent( type_name=type_name, root=elem_bank, name=f"pack{eightpack_id:02d}")
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) for i in range(num_dets): detname = BANKFMT % (i+1) roty = float(detinfo["BankAngle"][i]) + FLIPY xpos = convert(detinfo["Bank_xpos"][i]) ypos = convert(detinfo["Bank_ypos"][i]) zpos = convert(detinfo["Bank_zpos"][i]) det.addComponent(detname, root=doc_handle) det.addDetector(xpos, ypos, zpos, ROTX, roty, ROTZ, detname, "eightpack") det.addComment("STANDARD 8-PACK") det.addNPack("eightpack", NUM_TUBES_PER_BANK, TUBE_WIDTH, AIR_GAP_WIDTH) det.addComment("STANDARD 2m 128 PIXEL TUBE") det.addPixelatedTube("tube", NUM_PIXELS_PER_TUBE, TUBE_SIZE)
def generate_reflection_file(reflection_key): r""" Parameters ---------- reflection_key: str Returns ------- """ refl = reflections[reflection_key] if not os.path.exists(refl['nexus']): message = '{} not found. Not creating geometry'.format(refl['nexus']) raise FileExistsError(message) inst_name = "BASIS" # Set header information comment = "Created by Michael Reuter and Jose Borreguero" # Time needs to be in UTC? valid_from = "2014-01-01 00:00:00" xml_outfile = '{}_Definition_Si{}.xml'.format(inst_name, reflection_key) nfile = h5py.File(refl['nexus'], 'r') det = MantidGeom(inst_name, comment=comment, valid_from=valid_from) det.addSnsDefaults(indirect=True) det.addComment("SOURCE AND SAMPLE POSITION") det.addModerator(-84.0) det.addSamplePosition() det.addComment("MONITORS") det.addMonitors(names=["monitor1"], distance=["-0.23368"], neutronic=True) # Create the inelastic banks information det.addComment('INELASTIC DECTECTORS') det.addComponent('silicon') handle_silicon = det.makeTypeElement("silicon") # Slicer for removing ghosts. Due to the mapping, the ghost tubes sit # on the same sides of the arrays for all banks. remove_ghosts = slice(-INELASTIC_TUBES_NGHOST) for i in range(n_inelastic_banks): bank_id = "bank%d" % (i+1) pixel_id = nfile["/entry/instrument/bank%d/pixel_id" % (i+1)].value[remove_ghosts] distance = nfile["/entry/instrument/bank%d/distance" % (i+1)].value[remove_ghosts] # theta or polar_angle: angle from the Z-axis towards the X-axis polar_angle = nfile["/entry/instrument/bank%d/polar_angle" % (i+1)].value[remove_ghosts] polar_angle *= (180.0/math.pi) # phi or azimuthal_angle: angle in the XY-plane azimuthal_angle = nfile["/entry/instrument/bank%d/azimuthal_angle" % (i+1)].value[remove_ghosts] azimuthal_angle *= (180.0/math.pi) analyser_wavelength = nfile["/entry/instrument/analyzer%d/wavelength" % (i+1)].value[remove_ghosts] analyser_wavelength *= refl['ratio_to_irreducible_hkl'] analyser_energy = 81.8042051/analyser_wavelength**2 det.addComponent(bank_id, idlist=bank_id, root=handle_silicon) xbank, ybank, zbank = pixels_physical_xyz(i) det.addDetectorPixels(bank_id, x=xbank, y=ybank, z=zbank, names=pixel_id, energy=analyser_energy, nr=distance, ntheta=polar_angle, nphi=azimuthal_angle, output_efixed=refl['efixed']) det.addDetectorPixelsIdList(bank_id, r=distance, names=pixel_id, elg="multiple_ranges") # Create the diffraction bank information det.addComponent("elastic", "elastic") handle = det.makeTypeElement("elastic") idlist = [] detector_z = [-2.1474825, -1.704594, -1.108373, -0.4135165, 0.3181, 1.0218315, 1.6330115, 2.0993535, 2.376999] detector_x = [1.1649855, 1.7484015, 2.175541, 2.408594, 2.422933, 2.216378, 1.8142005, 1.247867, 0.5687435] detector_y = [-0.001807, -0.001801, -0.0011845, -0.0006885, -0.0013145, -0.001626, -0.001397, 0.0003465, -0.0001125] for i in range(ELASTIC_BANK_START, ELASTIC_BANK_END+1): bank_name = "bank%d" % i det.addComponent(bank_name, root=handle) k = i - ELASTIC_BANK_START x_coord = detector_x[k] y_coord = detector_y[k] z_coord = detector_z[k] det.addDetector(x_coord, y_coord, z_coord, 0.0, 0., 90., bank_name, "tube-elastic", facingSample=True) idlist.append(ELASTIC_DETECTORID_START + ELASTIC_TUBE_NPIXELS*(i-ELASTIC_BANK_START)) idlist.append(ELASTIC_DETECTORID_START + ELASTIC_TUBE_NPIXELS*(i-ELASTIC_BANK_START) + ELASTIC_TUBE_NPIXELS-1) idlist.append(None) # Diffraction tube information det.addComment("ELASTIC TUBE (90 degrees)") det.addPixelatedTube("tube-elastic", ELASTIC_TUBE_NPIXELS, ELASTIC_TUBE_LENGTH, "pixel-elastic-tube", neutronic=True, neutronicIsPhysical=True) # Set the diffraction pixel Ids det.addDetectorIds("elastic", idlist) # Creating diffraction pixel det.addComment("PIXEL FOR DIFFRACTION TUBES") det.addCylinderPixel("pixel-elastic-tube", (0.0, 0.0, 0.0), (0.0, 1.0, 0.0), (ELASTIC_TUBE_WIDTH/2.0), (ELASTIC_TUBE_LENGTH/ELASTIC_TUBE_NPIXELS)) det.addComment("PIXEL FOR INELASTIC TUBES") det.addCylinderPixel("pixel", (0.0, 0.0, 0.0), (0.0, 1.0, 0.0), INELASTIC_TUBE_WIDTH * (1.0-INELASTIC_PIXEL_RADIUS_GAP_RATIO) / 2.0, INELASTIC_TUBE_LENGTH * (1.0-INELASTIC_PIXEL_HEIGHT_GAP_RATIO) / INELASTIC_TUBE_NPIXEL, is_type="detector", algebra="cyl-approx") det.addComment("MONITOR SHAPE") det.addComment("FIXME: Do something real here.") det.addDummyMonitor(0.01, 0.03) det.addComment("MONITOR IDs") det.addMonitorIds(["-1"]) det.writeGeom(xml_outfile) # Always clean after yourself nfile.close()
For more information, please visit https://www.ill.eu/instruments-support/instruments-groups/instruments/figaro/characteristics/ """ figaro = MantidGeom(instrumentName, comment=comment, valid_from=validFrom) figaro.addSnsDefaults(theta_sign_axis='y') figaro.addComment("SOURCE") figaro.addComponentILL("chopper1", 0.0, 0.0, zSource, "Source") figaro.addComment("Sample position") figaro.addComponentILL("sample_position", 0.0, 0.0, 0.0, "SamplePos") figaro.addComment("MONITORS") figaro.addMonitors(names=["monitor1", "monitor2"], distance=[zMon1, zMon2]) figaro.addComment("MONITOR SHAPE") figaro.addComment("FIXME: Do something real here.") figaro.addDummyMonitor(0.01, 0.03) figaro.addComment("MONITOR IDs") figaro.addMonitorIds(["100000", "100001"]) figaro.addComment("2 Slits") figaro.addComponentILL("slit2", 0.0, 0.0, slit2Centre) figaro.makeTypeElement("slit2") figaro.addComponentILL("slit3", 0.0, 0.0, slit3Centre) figaro.makeTypeElement("slit3") figaro.addComment("DETECTORS") figaro.addComment("64 tubes form the detector") figaro.addComponentRectangularDetector("detector", 0.0, 0.0, zDetector, idstart="1", idfillbyfirst="x", idstepbyrow="1") figaro.addComment("PIXEL, EACH PIXEL IS A DETECTOR") figaro.addRectangularDetector("detector", "pixel", xstart, xstep, xpixels, ystart, ystep, ypixels) figaro.addCuboidPixel("pixel", [-x, -y, z], [x, y, z], [-x, -y, -z], [x, -y, z], shape_id="pixel-shape") figaro.writeGeom("./ILL/IDF/" + instrumentName.upper() + "_Definition.xml")
d7 = MantidGeom(instrumentName, comment=comment, valid_from=validFrom) d7.addSnsDefaults(default_view='3D', axis_view_3d='z-', theta_sign_axis="x") d7.addComment("SOURCE") d7.addComponentILL('SOURCE', 0.0, 0.0, source, 'Source') d7.addComment("Sample position") d7.addComponentILL("sample_position", 0., 0., 0., "SamplePos") d7.addComment("MONITORS") d7.addMonitors(names=["monitor1", "monitor2"], distance=[zMon1, zMon2]) d7.addComment("MONITOR SHAPE") d7.addComment("FIXME: Do something real here.") d7.addDummyMonitor(0.01, 0.03) d7.addComment("MONITOR IDs") d7.addMonitorIds([repr(100000), repr(100001)]) d7.addComment("DETECTORS") d7.addComponentILL("detector", 0., 0., 0.) detector = d7.makeTypeElement("detector") # define detector banks d7.addDetectorIds("bank2_ids", [1, 44, 1]) d7.addDetectorIds("bank3_ids", [45, 88, 1]) d7.addDetectorIds("bank4_ids", [89, 132, 1]) bank = d7.makeTypeElement("bank") bank2 = d7.addComponent("bank", idlist="bank2_ids", root=detector) bank3 = d7.addComponent("bank", idlist="bank3_ids", root=detector) bank4 = d7.addComponent("bank", idlist="bank4_ids", root=detector) # define detector banks initial positions d7.addLocation(root=bank2, x=0, y=0, z=0,