Пример #1
0
TUBE_THICKNESS = ("tube_thickness", 0.0008, "metre")
TUBE_TEMPERATURE = ("tube_temperature", 290.0, "K")

__author__="Stuart Campbell"
__date__ ="$Dec 14, 2010 3:13:15 PM$"

if __name__ == "__main__":

    inst_name = "BASIS"
    short_name = "BSS"

    xml_outfile = inst_name+"_Definition_new.xml"

    file = h5py.File(nexusfile, 'r')

    det = MantidGeom(inst_name, comment=" Created by Stuart Campbell ")
    det.addSnsDefaults()
    det.addComment("SOURCE AND SAMPLE POSITION")
    det.addModerator(-84.0)
    det.addSamplePosition()
    det.addComment("MONITORS")
    det.addMonitors(names=["monitor1"], distance=["-0.23368"])


    for i in range(banks):
        pixel_id = file["/entry/instrument/bank%d/pixel_id" % (i+1)].value
        distance = file["/entry/instrument/bank%d/distance" % (i+1)].value
        polar_angle = file["/entry/instrument/bank%d/polar_angle" % (i+1)].value
        polar_angle *= (180.0/math.pi)
        azimuthal_angle = file["/entry/instrument/bank%d/azimuthal_angle" % (i+1)].value
        azimuthal_angle *= (180.0/math.pi)
Пример #2
0
       Sample
       Maximum sample dimension is 15 mm x 15 mm

       Two detector multi-tube detectors
       Sample-detector distances range from 1.2 m to 12.8 m
       Detector 1 (rear):
       Single panel mono-block size 640 x 640 mm
       Pixel size 5 x 5 mm^2 ( 128 x 128 pixels )
       Detector 2 (front):
       4-panel mono-block, size 160 x 640 mm per panel
       Pixel size 5 x 5 mm^2 ( 32 x 128 pixels )

       For more information, please visit
       https://www.ill.eu/instruments-support/instruments-groups/instruments/d33/characteristics/
       """
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")
       Sample
       Default sample dimension is 10 mm x 300 mm

       Multi-detector:
       Size 1024 mm x 1024 mm
       Nominal resolution:
            128 x 256
            Pixel size 8 x 4 mm2
       Low resolution:
            128 x 128
            Pixel size 8 x 8 mm2

       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()
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.addComment("FIXME: Do something real here.")
d22.addDummyMonitor(0.01, 0.03)
d22.addComment("MONITOR IDs")
d22.addMonitorIds([repr(100000), repr(100001)])
d22.addComment("DETECTOR")
d22.addComponentRectangularDetector(detector0, 0., 0., zPos, idstart=id0, idfillbyfirst=FF, idstepbyrow=SR)
d22.addRectangularDetector(detector0, pixelName, xstart, xstep, xpixels, ystart, ystep, ypixels)
Пример #4
0
    from helper import MantidGeom
    import numpy as np
    try:
        np.set_printoptions(legacy='1.13')
    except TypeError:
        pass

    # Set header information
    comment = "Created by Ross Whitfield"
    # Time needs to be in UTC?
    valid_from = "2018-04-01 00:00:00"

    # Get geometry information file
    xml_outfile = INST_NAME + "_Definition.xml"

    det = MantidGeom(INST_NAME, comment=comment, valid_from=valid_from)
    det.addSnsDefaults(default_view="cylindrical_y")
    det.addComment("SOURCE AND SAMPLE POSITION")
    det.addModerator(-3.289, "monochromator")
    det.addSamplePosition()

    doc_handle = None
    for i in range(NUM_DETS):
        bank = det.addComponent("bank" + str(i + 1),
                                idlist="bank" + str(i + 1),
                                root=doc_handle)
        log = le.SubElement(bank, "parameter", **{"name": "y"})
        le.SubElement(
            log,
            "logfile",
            **{
       Size 1024 mm x 1024 mm
       Nominal resolution:
            128 x 256
            Pixel size 8 x 4 mm2
       Low resolution:
            128 x 128
            Pixel size 8 x 8 mm2

       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)
       - Diffraction:
          - wavelength 3.1 A, qmin = 0.4, qmax = 4.0
          - wavelength 4.8 A, qmin = 0.3, qmax = 2.5
          - wavelength 5.7 A, qmin = 0.2, qmax = 2.1
       - Spectroscopy time-of-flight 
          - using Fermi chopper, with the same possible wavelengths

       Source-to-sample distance is 0.48 m
       Three detector banks with 44 position-insensitive He3 detectors each
       Each detector located 1.5 m from the sample
       covering 2 Theta range from about 10 to 155 degrees
       Detector tubes have 25 mm in diameter and are 250 mm in height
       For more information, please visit 
       https://www.ill.eu/instruments-support/instruments-groups/instruments/d7/characteristics/
       """
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")
Пример #7
0
    try:
        geom_input_file = sys.argv[1]
    except IndexError:
        geom_input_file = "SNS/CORELLI/CORELLI_geom.txt"

    # Set header information
    comment = "Created by Ross Whitfield"
    # Time needs to be in UTC?
    valid_from = "2017-04-04 00:00:00"

    # 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(default_view="cylindrical_y")
    det.addComment("SOURCE AND SAMPLE POSITION")
    det.addModerator(-20.00)
    det.addSamplePosition()
    det.addComment("MONITORS")
    det.addMonitors(names=["monitor1", "monitor2", "monitor3"],
                    distance=["-2.046", "-1.948", "4.554"])

    #det.addChopper("single-disk-chopper",-7.669527)
    #det.addSingleDiskChopper("single-disk-chopper")
    det.addEmptyChopper("single-disk-chopper",-7.669527)

    #det.addChopper("double-disk-chopper",-11.79995,["Speed (Hz)","BL9:Chop:Skf2:MotorSpeed"],["Bandwidth (A)","BL9:Chop:Skf23:Bandwidth"],["Center (A)","BL9:Chop:Skf23:CenterWavelength"])
    #det.addDoubleDiskChopper("double-disk-chopper")
    det.addEmptyChopper("double-disk-chopper",-11.79995)

if __name__ == "__main__":
    logging.basicConfig(format="[%(levelname)s]%(asctime)s:%(message)s",
                        level=logging.INFO)
    #
    df = read_survey_measurements()
    #
    inst_name = "VULCAN"
    xml_outfile = f"{inst_name}_Definition_tmp.xml"
    authors = ["Peter Peterson", "Malcolm Guthrie", "Chen Zhang"]

    # -- ROOT --
    vulcan_geom = MantidGeom(
        inst_name,
        comment="Created by " + ", ".join(authors),
        valid_from="2022-05-15 00:00:01",
    )

    # -- MISC --
    vulcan_geom.addComment("DEFAULTS")
    vulcan_geom.addSnsDefaults()
    vulcan_geom.addComment("SOURCE")
    vulcan_geom.addModerator(L1)
    vulcan_geom.addComment("SAMPLE")
    vulcan_geom.addSamplePosition()

    # -- MONITOR --
    vulcan_geom.addComment("MONITORS")
    vulcan_geom.addMonitors(distance=[4.83, 1.50],
                            names=["monitor2", "monitor3"])
Пример #9
0
    #individual tube info
    di["TUBE_SIZE"] = sheet.cell_value(4, 8) * 1e-3
    di["TUBE_WIDTH"] = sheet.cell_value(8, 4) * 1e-3
    di["TUBE_THICKNESS"] = ("tube_thickness", sheet.cell_value(7, 8) * 1e-3,
                            "meter")
    di["TUBE_PRESSURE"] = ("tube_pressure", 10.0, "atm")
    di["TUBE_TEMPERATURE"] = ("tube_temperature", 290.0, "K")
    return di


if __name__ == "__main__":
    filename = 'SNS/HYSPEC/hyspec_MotorList4GG.xls'
    info = read_xls(filename)
    inst_name = "HYSPEC"
    xml_outfile = inst_name + "_Definition.xml"
    det = MantidGeom(inst_name)
    det.addSnsDefaults()
    det.addComment("SOURCE AND SAMPLE POSITION")
    det.addModerator(
        "msd -0.001*msd-38.980"
    )  # TODO: change moderator position to read from the excel sheet
    det.addSamplePosition()
    det.addComment("MONITORS")
    det.addMonitors(
        names=["monitor1", "monitor2", "monitor3"],
        distance=["msd -0.001*msd-3.340", "msd -0.001*msd-1.59643", "-0.200"])
    # TODO: change monitor positions to read from the excel sheet

    label = "Tank"
    tank = det.addComponent(label, label, blank_location=False)
    det.addLocationRTP(tank, "0", "s2 0.0+s2", "0", "0", "s2 0.0+s2", "0")
Пример #10
0
detector2 = "detector_right"
xstart_right = repr(-center_pixel_y * (number_of_pixels_per_tube - 1) / 2 -
                    x_gap)
xstep_right = xstep_left
xpixels_right = xpixels_left
ystart_right = ystart_left
ystep_right = ystep_left
ypixels_right = ypixels_left

comment = """ This is the instrument definition file of the D11B SANS instrument at the ILL.
       Generated file, PLEASE DO NOT EDIT THIS FILE!
       This file was automatically generated by mantidgeometry/ILL/IDF/d11b_generateIDF.py
       > python3 ./ILL/IDF/d11b_generateIDF.py
       """
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,
Пример #11
0

def mirror(x, y, z, analyser, project=False):
    r, t, p = topolar(x, y, z)
    if project:
        p = pi
        t = pi - atan2(x, z)
        r += 2 * analyser - psd
    else:
        p += pi
        t = pi - t
        r += 2 * analyser
    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.
Пример #12
0
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)
Пример #13
0
if __name__ == "__main__":

    inst_name = "BASIS"
    short_name = "BSS"

    # Set header information
    comment = "Created by Michael Reuter"
    # Time needs to be in UTC?
    valid_from = "2013-01-20 00:00:00"

    xml_outfile = inst_name+"_Definition.xml"

    nfile = h5py.File(nexusfile, 'r')

    det = MantidGeom(inst_name, comment=comment, valid_from=valid_from)
    det.addSnsDefaults()
    det.addComment("SOURCE AND SAMPLE POSITION")
    det.addModerator(-84.0)
    det.addSamplePosition()
    det.addComment("MONITORS")
    det.addMonitors(names=["monitor1"], distance=["-0.23368"])

    # Create the inelastic banks information
    # 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(-8)    
    
    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]
        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"],
                    distance=["-1.77808", "8.99184"])

    row_id = ""
    row_id_list = []
Пример #15
0
TUBE_THICKNESS = ("tube_thickness", 0.0008, "metre")
TUBE_TEMPERATURE = ("tube_temperature", 290.0, "K")

__author__ = "Stuart Campbell"
__date__ = "$Dec 14, 2010 3:13:15 PM$"

if __name__ == "__main__":

    inst_name = "BASIS"
    short_name = "BSS"

    xml_outfile = inst_name + "_Definition_new.xml"

    file = h5py.File(nexusfile, 'r')

    det = MantidGeom(inst_name, comment=" Created by Stuart Campbell ")
    det.addSnsDefaults()
    det.addComment("SOURCE AND SAMPLE POSITION")
    det.addModerator(-84.0)
    det.addSamplePosition()
    det.addComment("MONITORS")
    det.addMonitors(names=["monitor1"], distance=["-0.23368"])

    for i in range(banks):
        pixel_id = file["/entry/instrument/bank%d/pixel_id" % (i + 1)].value
        distance = file["/entry/instrument/bank%d/distance" % (i + 1)].value
        polar_angle = file["/entry/instrument/bank%d/polar_angle" %
                           (i + 1)].value
        polar_angle *= (180.0 / math.pi)
        azimuthal_angle = file["/entry/instrument/bank%d/azimuthal_angle" %
                               (i + 1)].value
    return [r, t, p]

def tocartesian(r, t, p):
    x = r * sin(t) * cos(p)
    y = r * sin(t) * sin(p)
    z = r * cos(t)
    return [x, y, z]

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)
       Sample
       Maximum sample dimension is 15 mm x 15 mm

       Two detector multi-tube detectors
       Sample-detector distances range from 1.2 m to 12.8 m
       Detector 1 (rear):
       Single panel mono-block size 640 x 640 mm
       Pixel size 5 x 5 mm^2 ( 128 x 128 pixels )
       Detector 2 (front):
       4-panel mono-block, size 160 x 640 mm per panel
       Pixel size 5 x 5 mm^2 ( 32 x 128 pixels )

       For more information, please visit
       https://www.ill.eu/instruments-support/instruments-groups/instruments/d33/characteristics/
       """
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")
Пример #18
0
 <value val="0.1460775 1.85816592 0.26850086 -0.00725352" />
</parameter>

</component-link>
</parameter-file>
'''

if __name__ == '__main__':
    valid_from = '2021-02-01 00:00:00'
    filename = 'MANDI_Definition_{}.xml'.format(valid_from.split()[0])

    # read in the detector calibration
    detcal = DetCal('SNS/MANDI/MaNDi-February2021.DetCal')

    # write the instrument geometry
    instr = MantidGeom('MANDI', valid_from=valid_from)
    instr.addComment('DEFAULTS')
    instr.addSnsDefaults(default_view='spherical_y')

    instr.addComment("SOURCE")
    instr.addModerator(detcal.l1)
    instr.addComment("SAMPLE")
    instr.addSamplePosition()

    instr.addComment("MONITORS")
    instr.addMonitors(distance=[-2.935, -0.898, 1.042],
                      names=["monitor1", 'monitor2', 'monitor3'])

    # add banks here
    for bank in detcal.banks:
        bank.addToXml(instr)
Пример #19
0
  di["NUM_TUBES_PER_BANK"]=int(sheet.cell_value(9,5))
  di["AIR_GAP_WIDTH"]=sheet.cell_value(7,4)*1e-3
  #individual tube info
  di["TUBE_SIZE"]=sheet.cell_value(4,8)*1e-3
  di["TUBE_WIDTH"]=sheet.cell_value(8,4)*1e-3
  di["TUBE_THICKNESS"]=("tube_thickness",sheet.cell_value(7,8)*1e-3,"meter")
  di["TUBE_PRESSURE"]=("tube_pressure",10.0,"atm")
  di["TUBE_TEMPERATURE"]=("tube_temperature",290.0,"K")
  return di
  
if __name__=="__main__":
  filename='SNS/HYSPEC/hyspec_MotorList4GG.xls'
  info=read_xls(filename)
  inst_name="HYSPEC"
  xml_outfile=inst_name+"_Definition.xml"
  det=MantidGeom(inst_name)
  det.addSnsDefaults()
  det.addComment("SOURCE AND SAMPLE POSITION")
  det.addModerator("msd -0.001*msd-38.980")# TODO: change moderator position to read from the excel sheet
  det.addSamplePosition()
  det.addComment("MONITORS")
  det.addMonitors(names=["monitor1", "monitor2", "monitor3"],distance=["msd -0.001*msd-3.340", "msd -0.001*msd-1.59643", "-0.200"])
  # TODO: change monitor positions to read from the excel sheet

  label = "Tank"
  tank=det.addComponent(label, label,blank_location=False)
  det.addLocationRTP(tank,"0","s2 0.0+s2","0","0","s2 0.0+s2","0")
  doc_handle = det.makeTypeElement(label)
  num_dets=len(info["name"])
  for i in range(num_dets):
    det.addComponent(info["name"][i], root=doc_handle)
Пример #20
0
    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

if __name__ == "__main__":
    inst_name = "NOMAD"
    xml_outfile = inst_name+"_Definition.xml"

    # boiler plate stuff
    instr = MantidGeom(inst_name,
                       comment=" Created by Peter Peterson",
                       valid_from="2017-06-05 00:00:01")
    instr.addComment("DEFAULTS")
    instr.addSnsDefaults()
    instr.addComment("SOURCE")
    instr.addModerator(-19.5)
    instr.addComment("SAMPLE")
    instr.addSamplePosition()

    # monitors
    instr.addComment("MONITORS")
    instr.addMonitorIds([-1,-2])
    instr.addMonitors([-0.879475,5.748782], ["monitor1", "monitor2"])
    instr.addComment("Shape for monitors")
    instr.addComment("TODO: Update to real shape")
    instr.addDummyMonitor(0.01, .03)
pixelRadius = 0.0127
tubeHeight = float(args.TubeHeight)
equator = float(args.EquatorialPixel)
pixelHeight = tubeHeight / numberOfPixelsPerTube
tubeVerticalShift = (numberOfPixelsPerTube / 2 - equator) * pixelHeight
monitorZ = -0.362

pixelSpacingDegrees = 0.605
tubeAngles = np.linspace(0., (numberOfTubes - 1) * pixelSpacingDegrees,
                         numberOfTubes)

comment = """ This is the instrument definition file of the SHARP spectrometer at the ILL.
       Generated file, PLEASE DO NOT EDIT THIS FILE!
       This file was automatically generated by mantidgeometry/ILL/IDF/sharp_generateIDF.py
       """
geometry = MantidGeom(instrumentName, comment=comment, valid_from=valid_from)
geometry.addSnsDefaults(theta_sign_axis='x')
geometry.addComponentILL('fermi_chopper', 0.0, 0.0, -l1, 'Source')
geometry.addComponentILL('sample-position', 0.0, 0.0, 0.0, 'SamplePos')
geometry.addMonitors(names=['monitor'], distance=[monitorZ])
geometry.addDummyMonitor(0.009, 0.036)  # the real radius is 0.09
geometry.addMonitorIds(['100000'])
geometry.addCylinderPixelAdvanced('pixel',
                                  center_bottom_base={
                                      'x': 0.,
                                      'y': -pixelHeight / 2.,
                                      'z': 0.
                                  },
                                  axis={
                                      'x': 0.,
                                      'y': 1.,
Пример #22
0
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()
Пример #23
0
            corner[2] = float(corner[2]) - self._L1
        (one, two, three, four) = corners
        # funny ordering copied from TS
        return Rectangle(three, four, one, two, tolerance_len=tolerance_len)


if __name__ == "__main__":
    inst_name = "PG3"
    xml_outfile = inst_name + "_Definition.xml"
    authors = [
        "Stuart Campbell", "Vickie Lynch", "Peter Peterson", "Janik Zikovsky"
    ]

    # boiler plate stuff
    instr = MantidGeom(inst_name,
                       comment="Created by " + ", ".join(authors),
                       valid_from="2013-08-01 00:00:01")
    instr.addComment("DEFAULTS")
    instr.addSnsDefaults()
    instr.addComment("SOURCE")
    instr.addModerator(L1)
    instr.addComment("SAMPLE")
    instr.addSamplePosition()

    # monitors
    instr.addComment("MONITORS")
    instr.addMonitors([-1.], ["monitor1"])
    #instr.addMonitors([L1+59., L1+62.5, L1+64], ["monitor1", "monitor2", "monitor3"])

    # choppers - copied verbatium from TS-geometry
    """
Пример #24
0
    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


if __name__ == "__main__":
    inst_name = "NOMAD"
    xml_outfile = inst_name + "_Definition.xml"

    # boiler plate stuff
    instr = MantidGeom(inst_name,
                       comment=" Created by Peter Peterson",
                       valid_from="2022-05-05 00:00:01")
    instr.addComment("DEFAULTS")
    instr.addSnsDefaults(theta_sign_axis="x")
    instr.addComment("SOURCE")
    instr.addModerator(-19.5)
    instr.addComment("SAMPLE")
    instr.addSamplePosition()

    # monitors
    instr.addComment("MONITORS")
    instr.addMonitorIds([-1, -2])
    instr.addMonitors([-0.879475, 5.748782], ["monitor1", "monitor2"])
    instr.addComment("Shape for monitors")
    instr.addComment("TODO: Update to real shape")
    instr.addDummyMonitor(0.01, .03)
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)
Пример #26
0
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)
Пример #27
0
    try:
        geom_input_file = sys.argv[1]
    except IndexError:
        geom_input_file = "SNS/CORELLI/CORELLI_geom.txt"

    # Set header information
    comment = "Created by Ross Whitfield"
    # Time needs to be in UTC?
    valid_from = "2014-02-25 00:00:00"

    # 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(default_view="cylindrical_y")
    det.addComment("SOURCE AND SAMPLE POSITION")
    det.addCuboidModerator(-20.00)
    det.addSamplePosition()
    det.addComment("MONITORS")
    det.addMonitors(names=["monitor1", "monitor2", "monitor3"],
                    distance=["-2.046", "-1.948", "4.554"])

    det.addChopper("single-disk-chopper",-7.669527)
    det.addSingleDiskChopper("single-disk-chopper")

    det.addChopper("double-disk-chopper",-11.79995,["Speed (Hz)","BL9:Chop:Skf2:MotorSpeed"],["Bandwidth (A)","BL9:Chop:Skf23:Bandwidth"],["Center (A)","BL9:Chop:Skf23:CenterWavelength"])
    det.addDoubleDiskChopper("double-disk-chopper")

    choppersequence="4.185 2.823 4.267 4.248 2.816 2.809 1.388 7.113 1.406 1.41 2.816 4.251 1.403 4.244 5.646 1.43 1.353 1.424 1.429 1.419 1.401 2.803 1.425 2.821 4.262 1.386 7.098 1.403 4.221 4.242 1.332 2.856 4.23 1.437 4.214 7.054 1.423 2.822 2.841 1.38 1.45 2.783 1.446 7.036 1.429 1.384 1.451 1.389 2.847 5.611 1.45 1.379 1.418 1.414 2.866 1.354 1.437 4.225 5.643 2.803 1.444 1.411 2.803 8.488 1.38 5.678 2.838 1.393 2.838 1.411 2.823 4.238 1.379 2.833 2.821 1.402 1.423 1.4 1.421 1.412 8.471 1.415 2.865 1.394 2.805 2.83 4.208 2.851 1.383 2.854 1.299 1.557 4.136 5.692 4.213 1.437 1.345 2.867 2.831 1.426 9.876 4.296 1.388 1.392 1.438 1.376 2.833 1.415 1.42 1.411 1.444 2.789 2.86 5.592 7.069 2.876 9.821 1.417 1.449 1.404 1.41 1.431 1.406 5.642 1.411 2.818 1.405 2.85"
        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"],
                    distance=["-1.77808", "8.99184"])

    row_id = ""
    row_id_list = []
Пример #29
0
    from helper import MantidGeom
    import numpy as np
    try:
        np.set_printoptions(legacy='1.13')
    except TypeError:
        pass

    # Set header information
    comment = "Created by Ross Whitfield"
    # Time needs to be in UTC?
    valid_from = "2018-04-01 00:00:00"

    # Get geometry information file
    xml_outfile = INST_NAME+"_Definition.xml"

    det = MantidGeom(INST_NAME, comment=comment, valid_from=valid_from)
    det.addSnsDefaults(default_view="cylindrical_y")
    det.addComment("SOURCE AND SAMPLE POSITION")
    det.addModerator(-3.289, "monochromator")
    det.addSamplePosition()

    doc_handle = None
    for i in range(NUM_DETS):
        bank = det.addComponent("bank"+str(i+1),
                                idlist="bank"+str(i+1),
                                root=doc_handle)
        log = le.SubElement(bank, "parameter", **{"name": "y"})
        le.SubElement(log, "logfile",
                      **{"id": "HB2C:Mot:detz.RBV", # detz is in mm
                         "eq": "rint(value*100)/100000", # Round to 0.01mm and convert to metres
                         "extract-single-value-as": "mean"})
Пример #30
0
if __name__ == "__main__":

    inst_name = "BASIS"
    short_name = "BSS"

    # Set header information
    comment = "Created by Michael Reuter & Jose Borreguero"
    # Time needs to be in UTC?
    valid_from = "2014-01-01 00:00:00"

    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)    
    
Пример #31
0
        # getting this far means all tests passed
        return True

    def __ne__(self, other):
        """Compare this to another object for inequality"""
        return not self.__eq__(other)


if __name__ == "__main__":
    inst_name = "NOMAD"
    xml_outfile = inst_name + "_Definition.xml"

    # boiler plate stuff
    instr = MantidGeom(inst_name,
                       comment=" Created by Peter Peterson and Vickie Lynch",
                       valid_from="2012-08-01 00:00:01")
    instr.addComment("DEFAULTS")
    instr.addSnsDefaults()
    instr.addComment("SOURCE")
    instr.addModerator(-19.5)
    instr.addComment("SAMPLE")
    instr.addSamplePosition()

    # monitors
    instr.addComment("MONITORS")
    instr.addMonitors([-0.879475, 5.748782], ["monitor1", "monitor2"])

    # add the empty components
    for i in range(1, 7):
        name = "Group%d" % i
Пример #32
0
            return False # any exception means it is not a DetPack

        # getting this far means all tests passed
        return True

    def __ne__(self, other):
        """Compare this to another object for inequality"""
        return not self.__eq__(other)

if __name__ == "__main__":
    inst_name = "NOMAD"
    xml_outfile = inst_name+"_Definition.xml"

    # boiler plate stuff
    instr = MantidGeom(inst_name,
                       comment=" Created by Peter Peterson and Vickie Lynch",
                       valid_from="2012-08-01 00:00:01")
    instr.addComment("DEFAULTS")
    instr.addSnsDefaults()
    instr.addComment("SOURCE")
    instr.addModerator(-19.5)
    instr.addComment("SAMPLE")
    instr.addSamplePosition()

    # monitors
    instr.addComment("MONITORS")
    instr.addMonitors([-0.879475,5.748782], ["monitor1", "monitor2"])

    # add the empty components
    for i in range(1,7):
        name = "Group%d" % i
Пример #33
0
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()
Пример #34
0
            corner[2] = float(corner[2]) - self._L1
        (one, two, three, four) = corners
        # funny ordering copied from TS
        return Rectangle(three, four, one, two, tolerance_len=tolerance_len)

if __name__ == "__main__":
    inst_name = "PG3"
    xml_outfile = inst_name+"_Definition.xml"
    authors = ["Stuart Campbell",
               "Vickie Lynch",
               "Peter Peterson",
               "Janik Zikovsky"]

    # boiler plate stuff
    instr = MantidGeom(inst_name,
                       comment="Created by " + ", ".join(authors),
                       valid_from="2013-08-01 00:00:01")
    instr.addComment("DEFAULTS")
    instr.addSnsDefaults()
    instr.addComment("SOURCE")
    instr.addModerator(L1)
    instr.addComment("SAMPLE")
    instr.addSamplePosition()

    # monitors
    instr.addComment("MONITORS")
    instr.addMonitors([-1.], ["monitor1"])
    #instr.addMonitors([L1+59., L1+62.5, L1+64], ["monitor1", "monitor2", "monitor3"])

    # choppers - copied verbatium from TS-geometry
    """
Пример #35
0
# detector name
detector0 = "detector"

# introductory comment
comment = """
       This is the instrument definition file of the 
       Generated file, PLEASE DO NOT EDIT THIS FILE!
       This file was automatically generated by mantidgeometry/ILL/IDF/salsa_generateIDF.py

       For more information, please visit
       https://www.ill.eu/instruments-support/instruments-groups/instruments/salsa/characteristics/
       """

# Instrument creation
salsa = MantidGeom(instrumentName, comment=comment, valid_from=validFrom)
salsa.addSnsDefaults(default_view='spherical_y',
                     axis_view_3d='z-',
                     theta_sign_axis="x")

salsa.addComment("SOURCE")
salsa.addComponentILL("monochromator", 0., 0., zSource, "Source")

# Sample is set as the origin
salsa.addComment("Sample position")
salsa.addComponentILL("sample_position", 0., 0., 0., "SamplePos")

salsa.addComment("MONITORS")
salsa.addMonitors(names=["monitor"], distance=[zMonitor])
salsa.addComment("MONITOR SHAPE")
salsa.addDummyMonitor(0.01, 0.01)
Пример #36
0
             source_sample_distance=1.0,
             monitors=(dict(name='monitor1', z=-10.5),
                       dict(name='timer', z=-10.5)),
             flat_array='detector1',  # name of the detector array
             flat_panel_types=dict(front='front-panel', back='back-panel'),
             bank_name='bank',
             tube_length=1.046,
             tube_diameter=0.00805,
             pixels_per_tube=256,
             tube_separation=0.0112522,
             fourpack_separation=0.008205216,
             fourpack_slip=0.0055103014,
             number_eightpacks=24)

# Instrument handle
det = MantidGeom(iinfo['instrument_name'], **kw(iinfo, 'comment', 'valid_from', 'valid_to'))
det.addSnsDefaults(default_view="3D", axis_view_3d="Z-")
fn = make_filename(*ag(iinfo, 'instrument_name', 'valid_from', 'valid_to'))
add_basic_types(det, iinfo)  # source, sample, pixel, tube, and fourpack
#
# Monitor Section
#
add_comment_section(det, 'COMPONENT, TYPE, and IDLIST: MONITORS')
det.addMonitors(distance=[m['z'] for m in iinfo['monitors']],
                names=[m['name'] for m in iinfo['monitors']])
det.addMonitorIds(ids=[-1, -2])
det.addDummyMonitor(0.01, 0.1)
#
# Insert the flat panel
#
double_panel = add_double_flat_panel_type(det, iinfo)
valid_from = "1901-01-01 00:00:00"
last_modified = strftime("%Y-%m-%d %H:%M:%S", gmtime())

pixel_per_tube = 256
tube_width = 0.685
tube_radius = 0.0127
number_of_tubes = 8

tube_angles = [12, 31, 50, 69, 88, 107, 126, 145]
vertical_offset = 0.015
distance_to_sample = 1.855

chopper_to_sample = -34.3
monitor_to_sample = -0.178

in16b = MantidGeom(instrument_name, comment=comment, valid_from=valid_from)
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)
monitorZ = -0.4955

boxGapAngle = 1.03
boxAngleWidth = 16.06
tubeAngleStep = boxAngleWidth / (numberOfTubesPerBox - 1)

boxAngles = list()
firstBoxCenterAngle = -0.5 * (boxAngleWidth + boxGapAngle)
for i in range(numberOfBoxes):
    boxAngles.append(firstBoxCenterAngle + i * (boxAngleWidth + boxGapAngle))

comment = """ This is the instrument definition file of the PANTHER spectrometer at the ILL.
       This file was automatically generated by mantidgeometry/ILL/IDF/panther_generateIDF.py
       """
validFrom = '1900-01-31 23:59:59'
geometry = MantidGeom(instrumentName, comment=comment, valid_from=validFrom)
geometry.addSnsDefaults(theta_sign_axis='x')
geometry.addComponentILL('fermi_chopper', 0.0, 0.0, -l1, 'Source')
geometry.addComponentILL('sample-position', 0.0, 0.0, 0.0, 'SamplePos')
geometry.addMonitors(names=['monitor'], distance=[monitorZ])
geometry.addDummyMonitor(0.01, 0.03)
geometry.addMonitorIds(['100000'])
geometry.addCylinderPixelAdvanced(
    'pixel', center_bottom_base={'x': 0., 'y': 0., 'z': -pixelHeight / 2.},
    axis={'x': 0., 'y': 1., 'z': 0.}, pixel_radius=pixelRadius,
    pixel_height=pixelHeight,
    algebra='pixel_shape')
root = geometry.getRoot()
bank = le.SubElement(root, 'type', name='bank')
tubes = le.SubElement(bank, 'component', type='tube')
for boxIndex, boxAngle in enumerate(boxAngles):
       Its resolution is 7 mm x 2 mm
       Sample-detector distance is 1.0 m - 2.8 m (3 m in text)
       Dead-time 34 ns

       It consists of 64 horizontal tubes, each has a height of 7.4 mm
       It consists of 256 pixels, each about 1.2 mm wide

       Beam area at sample position 40 mm x 10 mm (width x height)
       Scattering plane is vertical
       Q-range, up   0.0045 - 0.42 A-1
       Q-range, down 0.0045 - 0.27 A-1

       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")
Пример #40
0
        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)
    for i in range(num_dets):
        detname = BANKFMT % (i+1)
        roty = float(detinfo["BankAngle"][i]) + FLIPY
        xpos = convert(detinfo["Bank_xpos"][i])
Пример #41
0
        geom_input_file = sys.argv[1]
    except IndexError:
        geom_input_file = "SNS/CNCS/CNCS_geom_2017B.txt"
        
    # Set header information
    comment = "Created by Andrei Savici"
    # Time needs to be in UTC?
    valid_from = "2017-08-07 10: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)
    for i in range(num_dets):
        detname = BANKFMT % (i+1)
        roty = float(detinfo["BankAngle"][i]) + FLIPY
        xpos = convert(detinfo["Bank_xpos"][i])
       Its resolution is 7 mm x 2 mm
       Sample-detector distance is 1.0 m - 2.8 m (3 m in text)
       Dead-time 34 ns

       It consists of 64 horizontal tubes, each has a height of 7.4 mm
       It consists of 256 pixels, each about 1.2 mm wide

       Beam area at sample position 40 mm x 10 mm (width x height)
       Scattering plane is vertical
       Q-range, up   0.0045 - 0.42 A-1
       Q-range, down 0.0045 - 0.27 A-1

       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")
       Sample
       Typical sample dimension is 30 mm x 10 mm for diffraction and 7 mm x 7 mm for high resolution SANS.

       One detector
       Distance to sample: 0.3 to 1 m
       Single panel mono-block: 320 mm x 320 mm
       Rotation: -5 < 2*theta < 125
       Pixel size 1 x 1 mm^2 ( 320 x 320 pixels )

       For more information, please visit
       https://www.ill.eu/instruments-support/instruments-groups/instruments/d16/characteristics/
       """


# Instrument creation
d16 = MantidGeom(instrumentName, comment=comment, valid_from=validFrom)
d16.addSnsDefaults(default_view='3D', axis_view_3d='z-', theta_sign_axis="x")

d16.addComment("SOURCE")
d16.addComponentILL("monochromator", 0., 0., monochromator_source, "Source")

# Sample is set as the origin
d16.addComment("Sample position")
d16.addComponentILL("sample_position", 0., 0., 0., "SamplePos")

d16.addComment("MONITORS")
d16.addMonitors(names=["monitor1", "monitor2"], distance=[zMon1, zMon2])
d16.addComment("MONITOR SHAPE")
d16.addDummyMonitor(0.01, 0.01)
d16.addComment("MONITOR IDs")
d16.addMonitorIds([repr(500000), repr(500001)])