Esempio n. 1
0
    def test1(self):
        'NDMonitor'

        from mcni.components.NDMonitor import NDMonitor, Axis
        xaxis = Axis(
            name='x',
            expression='x',
            bins=100,
            range=(0, 1000.),
            unit='meter',
        )
        m = NDMonitor('abc', [xaxis])

        N = 100
        from mcni import neutron_buffer, neutron
        b = neutron_buffer(N)
        for i in range(N):
            b[i] = neutron()
            continue

        m.process(b)

        self.assertEqual(m.histogram.I[0], N)
        self.assertEqual(m.histogram.E2[0], N)
        self.assertEqual(m.histogram.I[1], 0.)
        self.assertEqual(m.histogram.E2[1], 0.)

        if interactive:
            from histogram.plotter import defaultPlotter as plotter
            plotter.plot(m.histogram)
        return
 def test1(self):
     from mccomponents.detector.reduction_utils import events2IQE
     eventsfile = 'events.dat'
     outfile = 'intensities.dat'
     nevents = 337
     arcs_res = os.path.join(
         mcvine_resources, 'instruments/ARCS/resources',)
     pixelpositionsfile = os.path.join(
         arcs_res, 'pixelID2position.bin')
     solidanglesfile = os.path.join(
         arcs_res, 'solidangles.bin')
     npixels = 117760
     import pyre.units.length
     import pyre.units.energy
     import pyre.units.time
     iqe = events2IQE(
         eventsfile, nevents, 
         outfile,
         pixelpositionsfile, 
         solidanglesfile,
         npixels,
         mod2sample=13.6*pyre.units.length.meter,
         Ei=700*pyre.units.energy.meV,
         Qaxis=(9.5,10.5,0.02), Eaxis=(30,120,1.),
         tofUnit=1*pyre.units.time.microsecond,
         toffset=0*pyre.units.time.s,
         tofmax=0.015*pyre.units.time.s,
         )
     global interactive
     if interactive:
         from histogram.plotter import defaultPlotter
         defaultPlotter.plot(iqe)
     return
Esempio n. 3
0
    def test1(self):
        'NDMonitor'
        
        from mcni.components.NDMonitor import NDMonitor, Axis
        xaxis = Axis(
            name = 'x', expression='x',
            bins = 100, range=(0, 1000.),
            unit = 'meter',
            )
        m = NDMonitor('abc', [xaxis])
        
        N = 100
        from mcni import neutron_buffer, neutron
        b = neutron_buffer(N)
        for i in range(N):
            b[i] = neutron()
            continue

        m.process(b)

        self.assertEqual(m.histogram.I[0], N)
        self.assertEqual(m.histogram.E2[0], N)
        self.assertEqual(m.histogram.I[1], 0.)
        self.assertEqual(m.histogram.E2[1], 0.)

        if interactive:
            from histogram.plotter import defaultPlotter as plotter
            plotter.plot(m.histogram)
        return
 def test1(self):
     from mccomponents.detector.reduction_utils import events2IQE
     eventsfile = 'events.dat'
     outfile = 'intensities.dat'
     nevents = 337
     arcs_res = os.path.join(
         mcvine_resources,
         'instruments/ARCS/resources',
     )
     pixelpositionsfile = os.path.join(arcs_res, 'pixelID2position.bin')
     solidanglesfile = os.path.join(arcs_res, 'solidangles.bin')
     npixels = 117760
     import pyre.units.length
     import pyre.units.energy
     import pyre.units.time
     iqe = events2IQE(
         eventsfile,
         nevents,
         outfile,
         pixelpositionsfile,
         solidanglesfile,
         npixels,
         mod2sample=13.6 * pyre.units.length.meter,
         Ei=700 * pyre.units.energy.meV,
         Qaxis=(9.5, 10.5, 0.02),
         Eaxis=(30, 120, 1.),
         tofUnit=1 * pyre.units.time.microsecond,
         toffset=0 * pyre.units.time.s,
         tofmax=0.015 * pyre.units.time.s,
     )
     global interactive
     if interactive:
         from histogram.plotter import defaultPlotter
         defaultPlotter.plot(iqe)
     return
Esempio n. 5
0
def run(
    ncount=1e7,
    nodes=5,
    Ei=700.,
    E_Q="Q*Q/3",
    S_Q="1",
    sigma_Q='Q/2.',
    Qmin=0,
    Qmax=10.,
    Qstep=0.1,
    Emin=0,
    Emax=50.,
    Estep=1.,
    mod2sample='../mod2sample',
):
    Ei_user = Ei
    Ei = computeAverageEnergy()
    if abs(Ei - Ei_user) / Ei > 0.1:
        raise ValueError, "nominal energy %s is too different from average energy at sample position %s" % (
            Ei_user, Ei)
    import os
    incident_neutrons = 'incident-neutrons'
    if not os.path.exists(incident_neutrons):
        os.link('../mod2sample/out/neutrons', 'incident-neutrons')

    # create scattering kernel file
    createScatteringKernel(
        E_Q=E_Q,
        S_Q=S_Q,
        sigma_Q=sigma_Q,
        Qmin=Qmin,
        Qmax=Qmax,
    )

    # run main sim
    cmd = './sssd --ncount=%s --mpirun.nodes=%s' % (ncount, nodes)
    execute(cmd)

    # reduce events to S(Q,E)
    eventsdat = 'out/events.dat'
    Qaxis = Qmin, Qmax, Qstep
    Eaxis = Emin, Emax, Estep
    Ei, toffset = getEiToffset(mod2sample)
    iqe = reduceToIQE(eventsdat, Ei, toffset, Qaxis, Eaxis)
    from histogram.hdf import dump
    dump(iqe, 'iqe.h5', '/', 'c')
    global interactive
    if interactive:
        from histogram.plotter import defaultPlotter
        defaultPlotter.plot(iqe)

    # quick analysis of S(Q,E) (without detector and sample size effects)
    cmd = ['./analyze-sqe ']
    cmd.append('--mpirun.nodes=%s' % nodes)
    cmd.append('--ncount=%s --monitor.Ei=%s' % (ncount, Ei))
    cmd.append(' --monitor.Qmin=%s --monitor.Qmax=%s' % (Qmin, Qmax))
    cmd.append(' --monitor.Emin=%s --monitor.Emax=%s' % (Emin, Emax))
    cmd = ' '.join(cmd)
    # execute(cmd)
    return
Esempio n. 6
0
def hist2png( h, filename = None ):
    p.plot( h )
    if filename is None: filename = h.name()
    ps = '%s.ps' % filename 
    png = '%s.png' % filename 
    pylab.savefig( ps )
    os.system( 'convert %s %s' % (ps, png) )
    return png
Esempio n. 7
0
def run(scattering_rundir, nodes, ncount=None):
    # sendneutronstodetsys(scattering_rundir, nodes, ncount=ncount)
    eventsdat = 'out/events.dat'
    iqe = reduceToIQE(eventsdat)
    from histogram.hdf import dump
    dump(iqe, 'iqe.h5', '/', 'c')
    from histogram.plotter import defaultPlotter
    defaultPlotter.plot(iqe)
    return
Esempio n. 8
0
    def test(self):
        "wrap IQE_monitor"

        from mcstas2 import componentfactory
        category = 'monitors'
        componentname = 'IQE_monitor'
        factory = componentfactory(category, componentname)

        Qmin = 0
        Qmax = 13.
        nQ = 130
        Emin = -50
        Emax = 50.
        nE = 100

        component = factory(
            'component',
            Ei=Ei,
            Qmin=Qmin,
            Qmax=Qmax,
            nQ=nQ,
            Emin=Emin,
            Emax=Emax,
            nE=nE,
            max_angle_out_of_plane=30,
            min_angle_out_of_plane=-30,
            max_angle_in_plane=120,
            min_angle_in_plane=-30,
        )

        scatterer = makeScatterer()

        import mcni
        N = 10000
        neutrons = mcni.neutron_buffer(N)
        for i in range(N):
            neutron = mcni.neutron(r=(0, 0, 0), v=(0, 0, vi), time=0, prob=1)
            scatterer.scatter(neutron)
            neutrons[i] = neutron
            #print neutrons[i]
            continue

        component.process(neutrons)

        hist = get_histogram(component)
        import os
        f = os.path.basename(__file__)
        filename = 'IQE-%s.h5' % f
        if os.path.exists(filename): os.remove(filename)
        import histogram.hdf as hh
        hh.dump(hist, filename, '/', 'c')

        if self.interactive:
            from histogram.plotter import defaultPlotter
            defaultPlotter.plot(hist)
        return
Esempio n. 9
0
 def test2(self):
     'create a SQE histogram from data and plot it'
     from histogram  import histogram, arange
     sqe = histogram(
         name = 'S(Q,E)',
         axes = [('Q', arange(0,12,0.1), 'angstrom**-1'),
                 ('E', arange(-50,50, 1.), 'meV')],
         )
     sqe.I[:] = 1
     if interactive:
         from histogram.plotter import defaultPlotter
         defaultPlotter.plot(sqe)
     return
Esempio n. 10
0
 def test1(self):
     'create a SQE histogram from function and plot it'
     from histogram  import histogram, arange
     sqe = histogram(
         name = 'S(Q,E)',
         axes = [('Q', arange(0,12,0.1), 'angstrom**-1'),
                 ('E', arange(-50,50, 1.), 'meV')],
         fromfunction = lambda q,e: q**2+e**2,
         )
     if interactive:
         from histogram.plotter import defaultPlotter
         defaultPlotter.plot(sqe)
     return
Esempio n. 11
0
def run(
    ncount=1e7,
    nodes=5,
    Ei=700.,
    E_Q="Q*Q/3",
    S_Q="1",
    sigma_Q='Q/2.',
    Qmin=0,
    Qmax=10.,
    Qstep=0.1,
    Emin=0,
    Emax=50.,
    Estep=1.,
):

    # create scattering kernel file
    createScatteringKernel(
        E_Q=E_Q,
        S_Q=S_Q,
        sigma_Q=sigma_Q,
        Qmin=Qmin,
        Qmax=Qmax,
    )

    # run main sim
    cmd = './sssd --source.energy=%s --ncount=%s --mpirun.nodes=%s' % (
        Ei, ncount, nodes)
    execute(cmd)

    # reduce events to S(Q,E)
    eventsdat = 'out/events.dat'
    Qaxis = Qmin, Qmax, Qstep
    Eaxis = Emin, Emax, Estep
    toffset = 0
    iqe = reduceToIQE(eventsdat, Ei, toffset, Qaxis, Eaxis)
    from histogram.hdf import dump
    dump(iqe, 'iqe.h5', '/', 'c')
    global interactive
    if interactive:
        from histogram.plotter import defaultPlotter
        defaultPlotter.plot(iqe)

    # quick analysis of S(Q,E) (without detector and sample size effects)
    cmd = ['./analyze-sqe ']
    cmd.append('--mpirun.nodes=%s' % nodes)
    cmd.append('--ncount=%s --monitor.Ei=%s' % (ncount, Ei))
    cmd.append(' --monitor.Qmin=%s --monitor.Qmax=%s' % (Qmin, Qmax))
    cmd.append(' --monitor.Emin=%s --monitor.Emax=%s' % (Emin, Emax))
    cmd = ' '.join(cmd)
    # execute(cmd)
    return
Esempio n. 12
0
def run(
    ncount=1e7, nodes=5, 
    Ei=700.,
    E_Q="Q*Q/3", S_Q="1", 
    Qmin=0, Qmax=10., Qstep=0.1,
    Emin=0, Emax=50., Estep=1.,
    mod2sample='../mod2sample',
    ):
    Ei_user = Ei
    Ei = computeAverageEnergy()
    if abs(Ei-Ei_user)/Ei > 0.1:
        raise ValueError, "nominal energy %s is too different from average energy at sample position %s" % (Ei_user, Ei)
    import os
    incident_neutrons = 'incident-neutrons'
    if not os.path.exists(incident_neutrons):
        os.link('../mod2sample/out/neutrons', 'incident-neutrons')
        
    # create scattering kernel file
    createScatteringKernel(
        E_Q=E_Q, S_Q=S_Q, 
        Qmin=Qmin, Qmax=Qmax,
        )

    # run main sim
    cmd = './sssd --ncount=%s --mpirun.nodes=%s' % (ncount, nodes)
    execute(cmd)

    # reduce events to S(Q,E)
    eventsdat = 'out/events.dat'
    Qaxis = Qmin, Qmax, Qstep
    Eaxis = Emin, Emax, Estep
    Ei, toffset = getEiToffset(mod2sample)
    iqe = reduceToIQE(eventsdat, Ei, toffset, Qaxis, Eaxis)
    from histogram.hdf import dump
    dump(iqe, 'iqe.h5', '/', 'c')
    global interactive
    if interactive:
        from histogram.plotter import defaultPlotter
        defaultPlotter.plot(iqe)

    # quick analysis of S(Q,E) (without detector and sample size effects)
    cmd = ['./analyze-sqe ']
    cmd.append('--mpirun.nodes=%s' % nodes)
    cmd.append('--ncount=%s --monitor.Ei=%s' % (ncount, Ei))
    cmd.append(' --monitor.Qmin=%s --monitor.Qmax=%s' % (Qmin, Qmax))
    cmd.append(' --monitor.Emin=%s --monitor.Emax=%s' % (Emin, Emax))
    cmd = ' '.join(cmd)
    execute(cmd)
    return
Esempio n. 13
0
    def test(self):
        "wrap IQE_monitor"

        from mcstas2 import componentfactory
        factory = componentfactory(category, componentname)

        Qmin = 0
        Qmax = 13.
        nQ = 130
        Emin = -50
        Emax = 50.
        nE = 100

        component = factory(
            'component',
            Ei=Ei,
            Qmin=Qmin,
            Qmax=Qmax,
            nQ=nQ,
            Emin=Emin,
            Emax=Emax,
            nE=nE,
            max_angle_out_of_plane=30,
            min_angle_out_of_plane=-30,
            max_angle_in_plane=120,
            min_angle_in_plane=-30,
        )

        kernel = makeKernel()

        import mcni
        N = 10000
        neutrons = mcni.neutron_buffer(N)
        for i in range(N):
            neutron = mcni.neutron(r=(0, 0, 0), v=(0, 0, vi), time=0, prob=1)
            kernel.scatter(neutron)
            neutrons[i] = neutron
            #print neutrons[i]
            continue

        component.process(neutrons)

        from mcstas2.pyre_support._component_interfaces.monitors.IQE_monitor import get_histogram
        hist = get_histogram(component)

        if interactive:
            from histogram.plotter import defaultPlotter
            defaultPlotter.plot(hist)
        return
    def test(self):
        "wrap IQE_monitor"
        
        from mcstas2 import componentfactory
        category = 'monitors'
        componentname = 'IQE_monitor'
        factory = componentfactory( category, componentname )

        Qmin=0; Qmax=13.; nQ=130
        Emin=-50; Emax=50.; nE=100
        
        component = factory(
            'component',
            Ei=Ei,
            Qmin=Qmin, Qmax=Qmax, nQ=nQ,
            Emin=Emin, Emax=Emax, nE=nE,
            max_angle_out_of_plane=30, min_angle_out_of_plane=-30,
            max_angle_in_plane=120, min_angle_in_plane=-30,
            )

        scatterer = makeScatterer()
        
        import mcni
        N = 10000
        neutrons = mcni.neutron_buffer( N )
        for i in range(N):
            neutron = mcni.neutron(r=(0,0,0), v=(0,0,vi), time=0, prob=1)
            scatterer.scatter(neutron)
            neutrons[i] = neutron
            #print neutrons[i]
            continue
        
        component.process( neutrons )
        
        hist = get_histogram(component)
        import os
        f = os.path.basename(__file__)
        filename = 'IQE-%s.h5' % f
        if os.path.exists(filename): os.remove(filename)
        import histogram.hdf as hh
        hh.dump(hist, filename, '/', 'c')
        
        if self.interactive:
            from histogram.plotter import defaultPlotter
            defaultPlotter.plot(hist)
        return
    def test(self):
        "wrap IQE_monitor"
        
        from mcstas2 import componentfactory
        factory = componentfactory( category, componentname )

        Ei = 70
        Qmin=0; Qmax=13.; nQ=130
        Emin=-50; Emax=50.; nE=100
        
        component = factory(
            'component',
            Ei=Ei,
            Qmin=Qmin, Qmax=Qmax, nQ=nQ,
            Emin=Emin, Emax=Emax, nE=nE,
            max_angle_out_of_plane=30, min_angle_out_of_plane=-30,
            max_angle_in_plane=120, min_angle_in_plane=-30,
            )
        
        import mcni
        from mcni.utils import conversion as C
        neutrons = mcni.neutron_buffer( nQ*nE )
        import numpy as N
        count = 0
        for Q in N.arange(Qmin, Qmax, (Qmax-Qmin)/nQ):
            for E in N.arange(Emin,Emax,(Emax-Emin)/nE):
                Ef = Ei-E
                cosphi = (Ei+Ef-C.k2e(Q))/(2*N.sqrt(Ei)*N.sqrt(Ef))
                vf = C.e2v(Ef)
                vfz = vf*cosphi
                sinphi = N.sqrt(1-cosphi*cosphi)
                vfx = vf*sinphi
                neutrons[count] = mcni.neutron(r=(0,0,0), v=(vfx,0,vfz), time = 0, prob = 1)
                count += 1
                continue
        component.process( neutrons )
        
        from mcstas2.pyre_support._component_interfaces.monitors.IQE_monitor import get_histogram
        hist = get_histogram(component)

        if interactive:
            from histogram.plotter import defaultPlotter
            defaultPlotter.plot(hist)
        return
    def test(self):
        "fccNi kernel constructed by hand"
        
        from mcstas2 import componentfactory
        category = 'monitors'
        componentname = 'IQE_monitor'
        factory = componentfactory( category, componentname )

        Qmin=0; Qmax=13.; nQ=130
        Emin=-50; Emax=50.; nE=100
        
        component = factory(
            'component',
            Ei=Ei,
            Qmin=Qmin, Qmax=Qmax, nQ=nQ,
            Emin=Emin, Emax=Emax, nE=nE,
            max_angle_out_of_plane=30, min_angle_out_of_plane=-30,
            max_angle_in_plane=120, min_angle_in_plane=-30,
            )

        kernel = makeKernel()
        
        import mcni
        # N = 500000 # needs about 20 minutes on a Intel Core2 Duo 2.53GHz virtual machine, ubuntu 10.04LTS on a 2.53GHz Intel Core 2 Duo Macbook
        N = 10000
        neutrons = mcni.neutron_buffer( N )
        for i in range(N):
            neutron = mcni.neutron(r=(0,0,0), v=(0,0,vi), time=0, prob=1)
            kernel.scatter(neutron)
            neutrons[i] = neutron
            #print neutrons[i]
            continue
        
        component.process( neutrons )
        
        hist = get_histogram(component)
        
        if self.interactive:
            from histogram.plotter import defaultPlotter
            defaultPlotter.plot(hist)
        return
Esempio n. 17
0
def run(
    ncount=1e7, nodes=5, 
    Ei=700.,
    E_Q="Q*Q/3", S_Q="1", sigma_Q='Q/2.',
    Qmin=0, Qmax=10., Qstep=0.1,
    Emin=0, Emax=50., Estep=1.,
    ):
        
    # create scattering kernel file
    createScatteringKernel(
        E_Q=E_Q, S_Q=S_Q, sigma_Q=sigma_Q,
        Qmin=Qmin, Qmax=Qmax,
        )

    # run main sim
    cmd = './sssd --source.energy=%s --ncount=%s --mpirun.nodes=%s' % (
        Ei, ncount, nodes)
    execute(cmd)

    # reduce events to S(Q,E)
    eventsdat = 'out/events.dat'
    Qaxis = Qmin, Qmax, Qstep
    Eaxis = Emin, Emax, Estep
    toffset = 0
    iqe = reduceToIQE(eventsdat, Ei, toffset, Qaxis, Eaxis)
    from histogram.hdf import dump
    dump(iqe, 'iqe.h5', '/', 'c')
    global interactive
    if interactive:
        from histogram.plotter import defaultPlotter
        defaultPlotter.plot(iqe)

    # quick analysis of S(Q,E) (without detector and sample size effects)
    cmd = ['./analyze-sqe ']
    cmd.append('--mpirun.nodes=%s' % nodes)
    cmd.append('--ncount=%s --monitor.Ei=%s' % (ncount, Ei))
    cmd.append(' --monitor.Qmin=%s --monitor.Qmax=%s' % (Qmin, Qmax))
    cmd.append(' --monitor.Emin=%s --monitor.Emax=%s' % (Emin, Emax))
    cmd = ' '.join(cmd)
    # execute(cmd)
    return
    def test(self):
        "wrap IQE_monitor"
        
        from mcstas2 import componentfactory
        factory = componentfactory( category, componentname )

        Qmin=0; Qmax=13.; nQ=130
        Emin=-50; Emax=50.; nE=100
        
        component = factory(
            'component',
            Ei=Ei,
            Qmin=Qmin, Qmax=Qmax, nQ=nQ,
            Emin=Emin, Emax=Emax, nE=nE,
            max_angle_out_of_plane=30, min_angle_out_of_plane=-30,
            max_angle_in_plane=120, min_angle_in_plane=-30,
            )

        kernel = makeKernel()
        
        import mcni
        N = 10000
        neutrons = mcni.neutron_buffer( N )
        for i in range(N):
            neutron = mcni.neutron(r=(0,0,0), v=(0,0,vi), time=0, prob=1)
            kernel.scatter(neutron)
            neutrons[i] = neutron
            #print neutrons[i]
            continue
        
        component.process( neutrons )
        
        from mcstas2.pyre_support._component_interfaces.monitors.IQE_monitor import get_histogram
        hist = get_histogram(component)
        
        if interactive:
            from histogram.plotter import defaultPlotter
            defaultPlotter.plot(hist)
        return
Esempio n. 19
0
#!/usr/bin/env python

# Note: Before using this script make sure that "out/ixyt.h5" is generated!
from histogram.hdf import load
from histogram.plotter import defaultPlotter as dp
import sys
f = sys.argv[1]
# h   = load('out/monitor_0.h5', 'ix_y_t')
# h   = load('out/monitor_1.h5', 'ix_y_t')
# h   = load('out/detector.h5', 'ix_y_t')
# h   = load('out/rank0-step0/detector.h5', 'ix_y_t')
h = load(f, 'ix_y_t')
ixy = h.sum('t')
iyt = h.sum('x')
it = iyt.sum('y')

dp.plot(ixy)
Esempio n. 20
0
#!/usr/bin/env python

# Note: Before using this script make sure that "out/ixyt.h5" is generated!
from histogram.hdf import load
from histogram.plotter import defaultPlotter as dp
import sys

f = sys.argv[1]
# h   = load('out/monitor_0.h5', 'ix_y_t')
# h   = load('out/monitor_1.h5', 'ix_y_t')
# h   = load('out/detector.h5', 'ix_y_t')
# h   = load('out/rank0-step0/detector.h5', 'ix_y_t')
h = load(f, "ix_y_t")
ixy = h.sum("t")
iyt = h.sum("x")
it = iyt.sum("y")

dp.plot(ixy)
Esempio n. 21
0
#!/usr/bin/env python
import sys
path = sys.argv[1]
from mccomponents.sample.idf  import readSQE
sqe = readSQE( path )
from histogram.plotter import defaultPlotter
defaultPlotter.plot( sqe )