Ejemplo n.º 1
0
def instrument():
    instrument = mcvine.instrument()
    source = mc.sources.Source_simple(
        name = 'source',
        radius = 0., width = 0.03, height = 0.03, dist = 1.,
        xw = 0.035, yh = 0.035,
        Lambda0 = 10., dLambda = 9.5,
    )
    instrument.append(source, position=(0,0,0.))
    guide = mc.optics.Guide(
        name = 'guide',
        w1=0.035, h1=0.035, w2=0.035, h2=0.035, l=10,
        R0=0.99, Qc=0.0219, alpha=6.07, m=3, W=0.003,
    )
    instrument.append(guide, position=(0, 0, 1.))
    Ixy = mc.monitors.PSD_monitor(
        name = 'Ixy', nx=250, ny=250, filename="Ixy.dat", xwidth=0.08, yheight=0.08,
        restore_neutron=True
    )
    instrument.append(Ixy, position=(0,0,12))
    Ixdivx = mc.monitors.DivPos_monitor(
        name = 'Ixdivx',
        npos=250, ndiv=250, filename="Ixdivx.dat", xwidth=0.08, yheight=0.08,
        restore_neutron=True
    )
    instrument.append(Ixdivx, position=(0,0,12))
    Iydivy = mc.monitors.DivPos_monitor(
        name = 'Iydivy',
        npos=250, ndiv=250, filename="Iydivy.dat", xwidth=0.08, yheight=0.08,
        restore_neutron=True
    )
    instrument.append(Iydivy, position=(0,0,12), orientation=(0, 0, 90))
    return instrument
Ejemplo n.º 2
0
def instrument(beam=None,
               sample='',
               angleMon1=45,
               angleMon2=135,
               detector_size=0.5,
               sourceTosample_x=0.,
               sourceTosample_y=0.,
               sourceTosample_z=0.):
    if beam is None:
        beam = os.path.join(thisdir, '../beam/Neutrons_mcvine.dat')
    instrument = mcvine.instrument()
    # a_source=mcvine.components.sources.Source_simple(Lambda0=1.4827, radius=0., width=0.001, height=0.001, dist=0.3, xw=0.001, yh=0.001)
    a_source = mcvine.components.sources.NeutronFromStorage('source', beam)
    instrument.append(a_source, position=(0, 0, 0))

    samplename = sample
    samplexml = os.path.join(thisdir,
                             '../sample/sampleassembly_%s.xml' % samplename)
    sample = mcvine.components.samples.SampleAssemblyFromXml(
        'sample', samplexml)
    instrument.append(sample,
                      position=(sourceTosample_x, sourceTosample_y,
                                sourceTosample_z),
                      relativeTo=a_source)

    save = mcvine.components.monitors.NeutronToStorage(
        'save', '{}.mcvine'.format(samplename))
    instrument.append(save, position=(0, 0, 0), relativeTo=sample)

    from detector import Detector
    angle1 = np.deg2rad(angleMon1)
    d = 0.5
    size = detector_size
    pixel_size = size / 256 / 3  #*1.00000001
    Npixels1D = 256 * 3
    NpixelsPerPanel = Npixels1D**2
    instrument.append(Detector('detector1', size, size, pixel_size, pixel_size,
                               'detector1'),
                      position=(d * np.sin(angle1), 0, d * np.cos(angle1)),
                      orientation=(0, np.rad2deg(angle1), 0),
                      relativeTo=sample)

    angle2 = np.deg2rad(angleMon2)
    instrument.append(Detector('detector2',
                               size,
                               size,
                               pixel_size,
                               pixel_size,
                               'detector2',
                               start_index=NpixelsPerPanel),
                      position=(d * np.sin(angle2), 0, d * np.cos(angle2)),
                      orientation=(0, np.rad2deg(angle2), 0),
                      relativeTo=sample)
    return instrument
Ejemplo n.º 3
0
def instrument(guide11_dat=None,
               guide11_len=10.99,
               guide11_mx=6.,
               guide11_my=6.):
    instrument = mcvine.instrument()
    source = Source_simple(
        name='source',
        radius=0.,
        width=0.03,
        height=0.03,
        dist=6.35,
        xw=0.35,
        yh=0.35,
        Lambda0=10.,
        dLambda=9.5,
    )
    instrument.append(source, position=(0, 0, 0.))

    if guide11_dat is None:
        guide11_dat = os.path.join(thisdir, "data", "VERDI_V01_guide1.1")
    guide = Guide(
        name='guide',
        option="file={}".format(guide11_dat),
        l=guide11_len,
        mx=guide11_mx,
        my=guide11_my,
    )
    instrument.append(guide, position=(0, 0, 6.35))
    z_guide_end = 6.35 + guide11_len

    Ixdivx = DivPos_monitor(
        name='Ixdivx',
        filename="Ixdivx.dat",
        npos=250,
        xwidth=0.25,
        yheight=0.25,
        ndiv=250,
        maxdiv=0.5,
        #    restore_neutron=True
    )
    instrument.append(Ixdivx, position=(0, 0, z_guide_end + 1e-3))
    '''
    # NOTE: having more than one component of the same type appears to not work with acc run_script
    Iydivy = DivPos_monitor(
        name = 'Iydivy', filename="Iydivy.dat",
        npos=250, xwidth=0.25, yheight=0.25,
        ndiv=250, maxdiv=0.5,
    #    restore_neutron=True
    )
    instrument.append(Iydivy, position=(0,0,z_guide_end+1e-3), orientation=(0, 0, 90))
    '''
    return instrument
Ejemplo n.º 4
0
def instrument(source_factory=None, ):
    instrument = mcvine.instrument()
    source = source_factory(name='source')
    instrument.append(source, position=(0, 0, 0.))
    Ixy = mc.monitors.PSD_monitor(name='Ixy',
                                  nx=250,
                                  ny=250,
                                  filename="Ixy.dat",
                                  xwidth=0.05,
                                  yheight=0.05,
                                  restore_neutron=True)
    instrument.append(Ixy, position=(0, 0, 5))
    return instrument
Ejemplo n.º 5
0
 def test1(self):
     'mcvine: simulate'
     # this is the example 1 in the mcvine package documentation
     import mcvine
     i = mcvine.instrument()
     g = mcvine.geometer()
     f = mcvine.componentfactory('sources', 'Source_simple', 'mcstas2')
     # help(f)
     s = f()
     i.append(s)
     g.register(s, (0, 0, 0), (0, 0, 0))
     neutrons = mcvine.neutron_buffer(5)
     print neutrons
     mcvine.simulate(i, g, neutrons)
     print neutrons
     return
Ejemplo n.º 6
0
 def test1(self):
     'mcvine: simulate'
     # this is the example 1 in the mcvine package documentation
     import mcvine
     i = mcvine.instrument()
     g = mcvine.geometer()
     f = mcvine.componentfactory('sources', 'Source_simple', 'mcstas2')
     # help(f)
     s = f()
     i.append(s)
     g.register(s, (0,0,0), (0,0,0))
     neutrons = mcvine.neutron_buffer(5)
     print neutrons
     mcvine.simulate(i, g, neutrons)
     print neutrons
     return
Ejemplo n.º 7
0
def instrument(sample='',
               angleMon1=45,
               angleMon2=135,
               beam=None,
               sourceTosample_x=0.0,
               sourceTosample_y=0.0,
               sourceTosample_z=0.0,
               detector_size=0.5):
    if beam is None:
        beam = os.path.join(thisdir, '../beam/Neutrons_mcvine.dat')
    instrument = mcvine.instrument()
    # a_source=mcvine.components.sources.Source_simple(Lambda0=1.4827, radius=0., width=0.001, height=0.001, dist=0.3, xw=0.001, yh=0.001)
    a_source = mcvine.components.sources.NeutronFromStorage('source', beam)
    instrument.append(a_source, position=(0, 0, 0))

    samplename = sample
    samplexml = os.path.join(thisdir,
                             '../sample/sampleassembly_%s.xml' % samplename)
    sample = mcvine.components.samples.SampleAssemblyFromXml(
        'sample', samplexml)
    instrument.append(sample,
                      position=(sourceTosample_x, sourceTosample_y,
                                sourceTosample_z),
                      relativeTo=a_source)

    save = mcvine.components.monitors.NeutronToStorage(
        'save', 'scattered-neutrons.mcvine')
    instrument.append(save, position=(0, 0, 0), relativeTo=sample)

    angle1 = np.deg2rad(angleMon1)
    d = 0.5
    instrument.append(EventMonitor_4D('monitor1', detector_size,
                                      detector_size),
                      position=(d * np.sin(angle1), 0, d * np.cos(angle1)),
                      orientation=(0, np.rad2deg(angle1), 0),
                      relativeTo=sample)

    angle2 = np.deg2rad(angleMon2)
    d = 0.5
    instrument.append(EventMonitor_4D('monitor2', detector_size,
                                      detector_size),
                      position=(d * np.sin(angle2), 0, d * np.cos(angle2)),
                      orientation=(0, np.rad2deg(angle2), 0),
                      relativeTo=sample)
    return instrument
Ejemplo n.º 8
0
def instrument():
    instrument = mcvine.instrument()
    source = Source_simple('src',
                           radius=0.,
                           width=0.03,
                           height=0.03,
                           dist=1.,
                           xw=0.035,
                           yh=0.035,
                           Lambda0=10.,
                           dLambda=9.5,
                           E0=0.,
                           dE=0.0,
                           flux=1,
                           gauss=0)
    instrument.append(source, position=(0, 0, 0.))

    guide1 = Guide(
        'guide',
        w1=0.035,
        h1=0.035,
        w2=0.035,
        h2=0.035,
        l=10,
        R0=0.99,
        Qc=0.0219,
        alpha=6.07,
        m=3,
        W=0.003,
    )
    instrument.append(guide1, position=(0, 0, 1.))

    mon = PosDiv_monitor(
        'mon',
        xwidth=0.08,
        yheight=0.08,
        maxdiv=2.,
        npos=250,
        ndiv=251,
    )
    instrument.append(mon, position=(0, 0, 10 + 1 + 1.))
    return instrument
Ejemplo n.º 9
0
def instrument(source_factory=None, ):
    instrument = mcvine.instrument()
    source = mc.sources.Source_simple('src',
                                      radius=0.,
                                      width=0.03,
                                      height=0.03,
                                      dist=1.,
                                      xw=0.035,
                                      yh=0.035,
                                      Lambda0=10.,
                                      dLambda=9.5,
                                      E0=0.,
                                      dE=0.0,
                                      flux=1,
                                      gauss=0)
    instrument.append(source, position=(0, 0, 0.))

    guide1 = mc.optics.Guide(
        'guide',
        w1=0.035,
        h1=0.035,
        w2=0.035,
        h2=0.035,
        l=10,
        R0=0.99,
        Qc=0.0219,
        alpha=6.07,
        m=3,
        W=0.003,
    )
    instrument.append(guide1, position=(0, 0, 1.))

    mon = mc.monitors.DivPos_monitor('mon',
                                     xwidth=0.08,
                                     yheight=0.08,
                                     maxdiv=2.,
                                     npos=250,
                                     ndiv=251,
                                     filename="divpos.dat")
    instrument.append(mon, position=(0, 0, 10 + 1 + 1.))
    return instrument
Ejemplo n.º 10
0
def instrument(guide_mod=None,
               guide_factory=None,
               guide11_dat=None,
               guide11_len=10.99,
               guide11_mx=6.,
               guide11_my=6.,
               save_neutrons_before_guide=False,
               save_neutrons_after_guide=False):
    instrument = mcvine.instrument()
    source = mc.sources.Source_simple(
        name='source',
        radius=0.,
        width=0.03,
        height=0.03,
        dist=6.35,
        xw=0.35,
        yh=0.35,
        Lambda0=10.,
        dLambda=9.5,
    )
    instrument.append(source, position=(0, 0, 0.))
    if save_neutrons_before_guide:
        before_guide = mc.monitors.NeutronToStorage(
            name='before_guide', path='before_tapered_guide.mcv')
        instrument.append(before_guide, position=(0, 0, 6.35))
    kwds = {}
    if guide_mod:
        import importlib
        mod = importlib.import_module(guide_mod)
        # assume factory name is "Guide" in the given module
        guide_factory = mod.Guide
        kwds = {'floattype': "float64"}
    elif guide_factory:
        guide_factory = eval(guide_factory)
    if guide11_dat is None:
        guide11_dat = os.path.join(thisdir, "data", "VERDI_V01_guide1.1")
    guide = guide_factory(name='guide',
                          option="file={}".format(guide11_dat),
                          l=guide11_len,
                          mx=guide11_mx,
                          my=guide11_my,
                          **kwds)
    instrument.append(guide, position=(0, 0, 6.35))
    z_guide_end = 6.35 + guide11_len
    if save_neutrons_after_guide:
        after_guide = mc.monitors.NeutronToStorage(
            name='after_guide', path='after_tapered_guide.mcv')
        instrument.append(after_guide, position=(0, 0, z_guide_end))
    Ixy = mc.monitors.PSD_monitor(name='Ixy',
                                  nx=250,
                                  ny=250,
                                  filename="Ixy.dat",
                                  xwidth=0.25,
                                  yheight=0.25,
                                  restore_neutron=True)
    instrument.append(Ixy, position=(0, 0, z_guide_end + 1e-3))
    Ixdivx = mc.monitors.DivPos_monitor(name='Ixdivx',
                                        filename="Ixdivx.dat",
                                        npos=250,
                                        xwidth=0.25,
                                        yheight=0.25,
                                        ndiv=250,
                                        maxdiv=0.5,
                                        restore_neutron=True)
    instrument.append(Ixdivx, position=(0, 0, z_guide_end + 1e-3))
    Iydivy = mc.monitors.DivPos_monitor(name='Iydivy',
                                        filename="Iydivy.dat",
                                        npos=250,
                                        xwidth=0.25,
                                        yheight=0.25,
                                        ndiv=250,
                                        maxdiv=0.5,
                                        restore_neutron=True)
    instrument.append(Iydivy,
                      position=(0, 0, z_guide_end + 1e-3),
                      orientation=(0, 0, 90))
    return instrument
Ejemplo n.º 11
0
def qikr(wl_0=1., center_wl=13.05):
    """
        @param wl_min: wavelength at the lower end of the bandwidth
    """
    running_length = 0
    k0 = 2*np.pi/wl_0
    e0_max = conversion.k2e(k0)
    kmin = 2*np.pi/40.0
    e0_min = conversion.k2e(kmin)
    instrument = mcvine.instrument()

    # Source - includes straight tube
    beam_width = 0.0266
    tube_length = 1.0
    mod = mcvine.components.sources.SNS_source_r1('moderator',
                                                  S_filename='./SNS-STS-ROT1-15_sp.dat',
                                                  width=beam_width, height=0.0266, dist=tube_length,
                                                  xw=beam_width, yh=0.0327, Emin=0, Emax=e0_max)
    instrument.append(mod, position=(0,0,0))
    #running_length += 0.001

    # Source Tube  ##################################################################
    #tube = mcvine.components.optics.Guide_channeled(name='source_tube',
    #                                                w1=beam_width, h1=0.0266, w2=beam_width, h2=0.0327,
    #                                                l=tube_length, mx=0, my=0)
    running_length += tube_length + 0.0001

    # Ballistic Guide 1 #############################################################
    # From 100 cm to 620 cm
    guide_1_length = 5.2
    guide1 = mcvine.components.optics.Guide_channeled(name='guide_1',
                                                      w1=beam_width, h1=0.0327, w2=beam_width, h2=0.0642,
                                                      l=guide_1_length, mx=5, my=5)
    instrument.append(guide1, position=(0,0,running_length))
    print ("Ballistic guide 1: %s m" % running_length)
    running_length += guide_1_length + 0.0001

    # T0 chopper ###################################################################
    # From 620 cm to 664.8 cm
    #t0_chopper = mcvine.components.optics.Vertical_T0(name='t0chopper', len=0.448,
    #                                                  w1=beam_width, w2=beam_width, nu=120, delta=0.0, tc=0., ymin=-.045, ymax=0.045)
    #instrument.append(t0_chopper, position=(0,0,6.2))
    running_length += 0.448

    # Ballistic Guide 2 #############################################################
    # From 664.8 cm to 714.8 cm
    guide_2_length = 0.5
    guide2 = mcvine.components.optics.Guide_channeled(name='guide_2',
                                                      w1=beam_width, h1=0.067, w2=beam_width, h2=0.07,
                                                      l=guide_2_length, mx=5, my=5)
    instrument.append(guide2, position=(0,0,running_length))
    print ("Ballistic guide 2: %s m" % running_length)
    running_length += guide_2_length + 0.0001

    # Bandwidth chopper ############################################################
    # From 714.8 cm to 722.1 cm
    instrument.append(mcvine.components.monitors.NeutronToStorage('save_pre', 'beam_pre_chopper.neutrons'),
                      position=(0,0,running_length))
    running_length += 0.0001
    b_chopper_length = 0.073
    b_chopper_dist = running_length + b_chopper_length/2.0  # center of chopper
    print ("Bandwidth chopper: %s m" % b_chopper_dist)

    aperture_bottom = 0.2689
    aperture_top = 0.33949
    radius_to_beam = 0.30390
    open_angle = 111.964

    kmid = 2*np.pi/center_wl
    v = conversion.k2v(kmid)
    delay = b_chopper_dist/v
    disk_chopper = mcvine.components.optics.DiskChopper_v2(name='band_chopper', 
                                                           yheight=aperture_top-aperture_bottom,
                                                           nslit=1,
                                                           radius=aperture_top,
                                                           theta_0=open_angle,
                                                           delay=delay, nu=7.5)
    running_length += 0.0001
    instrument.append(disk_chopper, position=(0,0, b_chopper_dist))
    instrument.append(mcvine.components.monitors.NeutronToStorage('save_post', 'beam_post_chopper.neutrons'),
                      position=(0,0,running_length))
    running_length += b_chopper_length + 0.0001

    # Ballistic Guide 3 #############################################################
    # From 722.1 cm to 1264 cm
    guide_3_length = 5.419
    guide3 = mcvine.components.optics.Guide_channeled(name='guide_3',
                                                      w1=beam_width, h1=0.07, w2=beam_width, h2=0.1033,
                                                      l=guide_3_length, mx=5, my=5)
    instrument.append(guide3, position=(0,0,running_length))
    running_length += guide_3_length + 0.0001


    # Tapered guide #################################################################
    # From 1264 cm to 1599 cm
    guide_4_length = 3.35
    guide4 = mcvine.components.optics.Guide_channeled(name='guide_4',
                                                      w1=beam_width, h1=0.1033, w2=beam_width, h2=0.02,
                                                      l=guide_4_length, mx=5, my=5)
    instrument.append(guide4, position=(0,0,running_length))
    running_length += guide_4_length + 0.0001

    instrument.append(mcvine.components.monitors.NeutronToStorage('save', 'beam.neutrons'),
                      position=(0,0,running_length))
    running_length += 0.0001
    print("End of instrument: %s m" % running_length)

    return instrument
Ejemplo n.º 12
0
def instrument(
    guide_mvalue=6.,
    sample_width=0.005,
    sample_height=0.005,
    moderator_datafile=os.path.join(thisdir,
                                    "source_rot2_cdr_cyl_3x3_20190417.dat"),
    source_width=0.03,
    source_height=0.03,
    secsource_size=0.02,
    xDivergence=2,
    yDivergence=2,
    guide1_start=6.35,
    guide1_len=10.99 + 9.56,
    ellipse1_major_axis_len=31.75,  # second source z position
    ellipse1_minor_axis_len=0.21,
    guide11_dat='_autogen_guide11.dat',
    guide12_dat='_autogen_guide12.dat',
    guide2_start=35.05,
    guide2_len=2.44 + 1.01,
    ellipse2_major_axis_len=40.0 - 31.75,
    ellipse2_minor_axis_len=0.1,
    guide21_dat='_autogen_guide21.dat',
    guide22_dat='_autogen_guide22.dat',
    guide_n_segments=500,
    Emin=0.1,
    Emax=1000.,
    use_gpu=True,
):
    # calc shield position
    # 1st mirror
    wall1 = SingleWall(
        a=ellipse1_minor_axis_len / 2,
        b=ellipse1_major_axis_len / 2,
        z_src=0.,
        z_guide_start=guide1_start,
        z_guide_end=guide1_start + guide1_len,
        z_target=ellipse1_major_axis_len,
        src_size=source_width,
        target_size=secsource_size,
    )
    shield1_x, shield1_z = wall1.calc_shield_xz()
    guide11_len = shield1_z - guide1_start
    guide12_len = guide1_len - guide11_len
    print('guide11, guide12:', guide11_len, guide12_len)
    print('shield1 stick out length: ', shield1_x)
    moderator_focusheight = moderator_focuswidth = ellipse_x(
        guide1_start, ellipse1_minor_axis_len / 2,
        ellipse1_major_axis_len / 2) * 2
    moderator_focusdistance = guide1_start * .99
    print('moderator focus distance and dims: ', moderator_focusdistance,
          moderator_focuswidth, moderator_focusheight)
    # 2nd mirror backward!
    z_guide_start = ellipse1_major_axis_len + ellipse2_major_axis_len - guide2_start - guide2_len
    wall2 = SingleWall(
        a=ellipse2_minor_axis_len / 2,
        b=ellipse2_major_axis_len / 2,
        z_src=0.,
        z_guide_start=z_guide_start,
        z_guide_end=z_guide_start + guide2_len,
        z_target=ellipse2_major_axis_len,
        src_size=sample_width,
        target_size=secsource_size,
    )
    shield2_x, shield2_z = wall2.calc_shield_xz()
    guide22_len = shield2_z - z_guide_start
    guide21_len = guide2_len - guide22_len
    guide21_start = ellipse1_major_axis_len + (ellipse2_major_axis_len -
                                               z_guide_start - guide2_len)
    print('guide21, guide22:', guide21_len, guide22_len)
    print('shield2 stick out length: ', shield2_x)

    # create guide data
    ellipse1_center = ellipse1_major_axis_len / 2.
    guide11_start = guide1_start
    guide12_start = guide11_end = guide11_start + guide11_len
    guide12_end = guide12_start + guide12_len
    create_guide_tapering_data(guide11_dat, ellipse1_center, guide11_start,
                               guide11_end, guide_n_segments,
                               ellipse1_major_axis_len,
                               ellipse1_minor_axis_len)
    create_guide_tapering_data(guide12_dat, ellipse1_center, guide12_start,
                               guide12_end, guide_n_segments,
                               ellipse1_major_axis_len,
                               ellipse1_minor_axis_len)
    # ellipse2 first focus overlaps with ellipse1 second focus
    ellipse2_center = ellipse1_major_axis_len + ellipse2_major_axis_len / 2
    guide22_start = guide21_end = guide21_start + guide21_len
    guide22_end = guide22_start + guide22_len
    create_guide_tapering_data(guide21_dat, ellipse2_center, guide21_start,
                               guide21_end, guide_n_segments,
                               ellipse2_major_axis_len,
                               ellipse2_minor_axis_len)
    create_guide_tapering_data(guide22_dat, ellipse2_center, guide22_start,
                               guide22_end, guide_n_segments,
                               ellipse2_major_axis_len,
                               ellipse2_minor_axis_len)

    instrument = mcvine.instrument()

    arm_factory = Arm if use_gpu else mcomps.optics.Arm
    origin = arm_factory(name='origin')
    instrument.append(origin, position=(0.0, 0.0, 0.0), orientation=(0, 0, 0))

    src_factory = SNS_source if use_gpu else mcomps.sources.SNS_source_2020
    moderator = src_factory('moderator',
                            filename=moderator_datafile,
                            Anorm=0.0009,
                            Emin=Emin,
                            Emax=Emax,
                            dist=moderator_focusdistance,
                            focus_xw=moderator_focuswidth,
                            focus_yh=moderator_focusheight,
                            xwidth=source_width,
                            yheight=source_height)
    instrument.append(moderator,
                      position=(0.0, 0.0, 0.0),
                      orientation=(0, 0, 0),
                      relativeTo=origin)

    L_mon_factory = Wavelength_monitor if use_gpu else mcomps.monitors.L_monitor
    ModeratorSpectrumL = L_mon_factory(
        name='ModeratorSpectrumL',
        Lmax=20,
        Lmin=0,
        filename="moderator_L.h5",
        nchan=100,
        # restore_neutron=1,
        xwidth=source_width * 1.1,
        yheight=source_height * 1.1,
        #xwidth=sample_width, yheight=sample_height,
    )
    instrument.append(ModeratorSpectrumL,
                      position=(0.0, 0.0, 1e-05),
                      orientation=(0, 0, 0),
                      relativeTo=moderator)

    PosDiv_mon_factory = PosDiv_monitor if use_gpu else mcomps.monitors.DivPos_monitor
    ModeratorDivergence_xpos = PosDiv_mon_factory(
        name='ModeratorDivergence_xpos',
        filename="moderator_divXpos.h5",
        maxdiv=xDivergence,
        ndiv=1000,
        npos=100,
        xwidth=source_width * 1.1,
        yheight=source_height * 1.1,
        #xwidth=sample_width, yheight=sample_height,
    )
    instrument.append(ModeratorDivergence_xpos,
                      position=(0.0, 0.0, 2e-05),
                      orientation=(0, 0, 0),
                      relativeTo=moderator)

    ModeratorDivergence_ypos = PosDiv_mon_factory(
        name='ModeratorDivergence_ypos',
        filename="moderator_divYpos.h5",
        maxdiv=yDivergence,
        ndiv=1000,
        npos=100,
        xwidth=source_width * 1.1,
        yheight=source_height * 1.1,
        #xwidth=sample_width, yheight=sample_height,
    )
    instrument.append(ModeratorDivergence_ypos,
                      position=(0.0, 0.0, 3e-05),
                      orientation=(0.0, 0.0, 90.0),
                      relativeTo=moderator)

    tapered_guide_factory = Guide_tapering if use_gpu else mcomps.optics.Guide_tapering
    Guide1_1 = tapered_guide_factory(name='Guide1_1',
                                     option="file={}".format(guide11_dat),
                                     l=guide11_len,
                                     mx=guide_mvalue,
                                     my=guide_mvalue)
    instrument.append(Guide1_1,
                      position=(0.0, 0.0, guide11_start),
                      orientation=(0, 0, 0),
                      relativeTo=moderator)

    beamstop_factory = Beamstop if use_gpu else mcomps.optics.Beamstop
    Shield1_1 = beamstop_factory(name='Shield1_1',
                                 xmax=shield1_x,
                                 xmin=-0.5,
                                 ymax=0.5,
                                 ymin=-0.5)
    instrument.append(Shield1_1,
                      position=(0.0, 0.0, guide11_len + 0.000001),
                      orientation=(0, 0, 0),
                      relativeTo=Guide1_1)

    Shield1_2 = beamstop_factory(name='Shield1_2',
                                 xmax=0.5,
                                 xmin=-0.5,
                                 ymax=shield1_x,
                                 ymin=-0.5)
    instrument.append(Shield1_2,
                      position=(0.0, 0.0, guide11_len + 0.000002),
                      orientation=(0, 0, 0),
                      relativeTo=Guide1_1)

    Guide1_2 = tapered_guide_factory(option="file={}".format(guide12_dat),
                                     name='Guide1_2',
                                     l=guide12_len,
                                     mx=guide_mvalue,
                                     my=guide_mvalue)
    instrument.append(Guide1_2,
                      position=(0.0, 0.0, guide11_len + 4e-6),
                      orientation=(0, 0, 0),
                      relativeTo=Guide1_1)

    SecSource = arm_factory(name='SecSource')
    instrument.append(SecSource,
                      position=(0.0, 0.0, ellipse1_major_axis_len),
                      orientation=(0, 0, 0),
                      relativeTo=origin)

    secsrc_divxpos = PosDiv_mon_factory(name='secsrc_divxpos',
                                        filename="secsrc_divXpos.h5",
                                        maxdiv=xDivergence,
                                        ndiv=1000,
                                        npos=100,
                                        xwidth=0.15,
                                        yheight=0.15)
    instrument.append(secsrc_divxpos,
                      position=(0.0, 0.0, 1e-07),
                      orientation=(0, 0, 0),
                      relativeTo=SecSource)

    secsrc_divypos = PosDiv_mon_factory(name='secsrc_divypos',
                                        filename="secsrc_divYpos.h5",
                                        maxdiv=yDivergence,
                                        ndiv=1000,
                                        npos=100,
                                        xwidth=0.15,
                                        yheight=0.15)
    instrument.append(secsrc_divypos,
                      position=(0.0, 0.0, 2e-07),
                      orientation=(0.0, 0.0, 90.0),
                      relativeTo=SecSource)

    slit_factory = Slit if use_gpu else mcomps.optics.Slit
    SecSourceSlit = slit_factory(name='SecSourceSlit',
                                 xmax=0.013,
                                 xmin=-0.01,
                                 ymax=0.013,
                                 ymin=-0.01)
    instrument.append(SecSourceSlit,
                      position=(0.0, 0.0, 1e-05),
                      orientation=(0, 0, 0),
                      relativeTo=SecSource)

    secsrc_IL = L_mon_factory(
        name='secsrc_IL',
        Lmax=20,
        Lmin=0,
        filename="secsrc_L.h5",
        nchan=100,
        # restore_neutron=1,
        xwidth=0.026,
        yheight=0.026)
    instrument.append(secsrc_IL,
                      position=(0.0, 0.0, 1e-6),
                      orientation=(0, 0, 0),
                      relativeTo=SecSourceSlit)

    Guide2_1 = tapered_guide_factory(option="file={}".format(guide21_dat),
                                     name='Guide2_1',
                                     l=guide21_len,
                                     mx=guide_mvalue,
                                     my=guide_mvalue)
    instrument.append(Guide2_1,
                      position=(0.0016, 0.0016, guide21_start),
                      orientation=(0, 0, 0),
                      relativeTo=moderator)

    Shield2_1 = beamstop_factory(name='Shield2_1',
                                 xmax=0.5,
                                 xmin=-shield2_x,
                                 ymax=0.5,
                                 ymin=-0.5)
    instrument.append(Shield2_1,
                      position=(0.0, 0.0, guide21_len + 1e-6),
                      orientation=(0, 0, 0),
                      relativeTo=Guide2_1)

    Shield2_2 = beamstop_factory(name='Shield2_2',
                                 xmax=0.5,
                                 xmin=-0.5,
                                 ymax=0.5,
                                 ymin=-shield2_x)
    instrument.append(Shield2_2,
                      position=(0.0, 0.0, guide21_len + 2e-6),
                      orientation=(0, 0, 0),
                      relativeTo=Guide2_1)

    Guide2_2 = tapered_guide_factory(option="file={}".format(guide22_dat),
                                     name='Guide2_2',
                                     l=guide22_len,
                                     mx=guide_mvalue,
                                     my=guide_mvalue)
    instrument.append(Guide2_2,
                      position=(0.0, 0.0, guide21_len + 4e-6),
                      orientation=(0, 0, 0),
                      relativeTo=Guide2_1)

    sampleMantid = arm_factory(name='sampleMantid')
    instrument.append(sampleMantid,
                      position=(0.001, 0.001, 40.0),
                      orientation=(0, 0, 0),
                      relativeTo=origin)

    sample0_IL = L_mon_factory(
        name='sample0_IL',
        Lmax=20,
        Lmin=0,
        filename="sample0_L.h5",
        nchan=100,
        # restore_neutron=1,
        xwidth=sample_width,
        yheight=sample_height)
    instrument.append(sample0_IL,
                      position=(0.0, 0.0, 0.),
                      orientation=(0, 0, 0),
                      relativeTo=sampleMantid)

    brilliancePack = arm_factory(name='brilliancePack')
    instrument.append(brilliancePack,
                      position=(0.0, 0.0, 0.0),
                      orientation=(0, 0, 0),
                      relativeTo=sampleMantid)

    Mask = slit_factory(name='Mask', width=sample_width, height=sample_height)
    instrument.append(Mask,
                      position=(0.0, 0.0, 0.0),
                      orientation=(0, 0, 0),
                      relativeTo=brilliancePack)

    psd_mon_factory = PSD_monitor if use_gpu else mcomps.monitors.PSD_monitor
    imagePlate = psd_mon_factory(
        name='imagePlate',
        filename="sample_xy.h5",
        nx=500,
        ny=500,
        # restore_neutron=1,
        xwidth=3 * sample_width,
        yheight=3 * sample_height)
    instrument.append(imagePlate,
                      position=(0.0, 0.0, 1e-05),
                      orientation=(0, 0, 0),
                      relativeTo=brilliancePack)

    sampleSpectrumL = L_mon_factory(
        name='sampleSpectrumL',
        Lmax=20,
        Lmin=0,
        filename="sample_L.h5",
        nchan=100,
        # restore_neutron=1,
        xwidth=sample_width,
        yheight=sample_height)
    instrument.append(sampleSpectrumL,
                      position=(0.0, 0.0, 2e-05),
                      orientation=(0, 0, 0),
                      relativeTo=brilliancePack)

    Divergence_xpos = PosDiv_mon_factory(name='Divergence_xpos',
                                         filename="sample_divXpos.h5",
                                         maxdiv=xDivergence,
                                         ndiv=1000,
                                         npos=100,
                                         xwidth=sample_width,
                                         yheight=sample_height)
    instrument.append(Divergence_xpos,
                      position=(0.0, 0.0, 3e-05),
                      orientation=(0, 0, 0),
                      relativeTo=brilliancePack)

    Divergence_ypos = PosDiv_mon_factory(name='Divergence_ypos',
                                         filename="sample_divYpos.h5",
                                         maxdiv=yDivergence,
                                         ndiv=1000,
                                         npos=100,
                                         xwidth=sample_width,
                                         yheight=sample_height)
    instrument.append(Divergence_ypos,
                      position=(0.0, 0.0, 4e-05),
                      orientation=(0.0, 0.0, 90.0),
                      relativeTo=brilliancePack)
    return instrument
Ejemplo n.º 13
0
import os
import mcvine, mcvine.components as mcomps
instrument = mcvine.instrument()

here = os.path.dirname(__file__) or '.'
here = os.path.abspath(here)
scattered = os.path.abspath(os.path.join(here, '../sample/out/scattered.mcvine'))

source = mcomps.sources.NeutronFromStorage(name='source', path=scattered)
instrument.append(source, position=(0.0, 0.0, 0.0), orientation=(0, 0, 0))

import mcvine.resources
arcs_res = mcvine.resources.instrument('ARCS')
xml = os.path.join(arcs_res, 'detsys', 'ARCS.xml.fornxs')
detector = mcomps.detectors.DetectorSystemFromXml(
    name='detector', instrumentxml=xml, tofparams=(0, 0.02, 1e-6), outfilename='arcs.dat')
instrument.append(detector, position=(0.0, 0.0, 0.0), orientation=(0, 0, 0))
Ejemplo n.º 14
0
def instrument(beam=None,
               sample_path=None,
               sample='',
               angleMons=[45, 135],
               detector_width=[0.5, 0.5],
               detector_height=[0.5, 0.5],
               sourceTosample_x=0.,
               sourceTosample_y=0.,
               sourceTosample_z=0.,
               sampleTodetector_z=[0.5, 0.5],
               number_detectors=2,
               number_pixels_in_height=[256, 256],
               number_pixels_in_width=[256, 256],
               number_of_box_in_height=[3, 3],
               number_of_box_in_width=[3, 3]):
    """

    Parameters
    ----------
    beam
    sample_path:
    sample
    angleMons
    detector_width
    detector_height
    sourceTosample_x
    sourceTosample_y
    sourceTosample_z
    sampleTodetector_z
    number_detectors
    number_pixels_in_height
    number_pixels_in_width
    number_of_box_in_height
    number_of_box_in_width

    Returns
    -------

    """
    if beam is None:
        beam = os.path.join(thisdir, '../../beam/Neutrons_mcvine.dat')
    instrument = mcvine.instrument()
    a_source = mcvine.components.sources.NeutronFromStorage('source', beam)
    instrument.append(a_source, position=(0, 0, 0))

    samplename = sample

    if sample_path is None:
        samplexml = os.path.join(
            thisdir, '../../sample/sampleassembly_%s.xml' % samplename)
    else:
        samplexml = os.path.join(sample_path,
                                 'sampleassembly_%s.xml' % samplename)

    sample = mcvine.components.samples.SampleAssemblyFromXml(
        'sample', samplexml)
    instrument.append(sample,
                      position=(sourceTosample_x, sourceTosample_y,
                                sourceTosample_z),
                      relativeTo=a_source)

    save = mcvine.components.monitors.NeutronToStorage(
        'save', '{}.mcvine'.format(samplename))
    instrument.append(save, position=(0, 0, 0), relativeTo=sample)

    from detector import Detector

    width = detector_width
    height = detector_height

    NpixelsPerPanel = 0
    for i in range(number_detectors):
        angle = np.deg2rad(angleMons[i])
        print('detector_angle: ', angleMons[i])
        pixel_width = detector_width[i] / number_pixels_in_width[
            i] / number_of_box_in_width[i]  # *1.00000001
        pixel_height = height[i] / number_pixels_in_height[
            i] / number_of_box_in_height[i]
        NpixelsPerPanel += number_pixels_in_height[i]\
                           *number_of_box_in_height[i]\
                           *number_pixels_in_width[i]\
                           *number_of_box_in_width[i]

        instrument.append(Detector('detector{}'.format(i + 1),
                                   width[i],
                                   height[i],
                                   pixel_width,
                                   pixel_height,
                                   'detector{}'.format(i + 1),
                                   start_index=NpixelsPerPanel * i),
                          position=(sampleTodetector_z[i] * np.sin(angle), 0,
                                    sampleTodetector_z[i] * np.cos(angle)),
                          orientation=(0, np.rad2deg(angle), 0),
                          relativeTo=sample)

    return instrument