예제 #1
0
    def test_sizes(self):
        'ndmonitor: w; tests: xwidth, yheight'
        outdir = 'out-test_sizes'
        histfile = '%s/iw2.h5' % outdir
        cmd_fmt = 'mcvine-simulate -components=source,monitor --- \
                                -overwrite-datafiles=on \
                                -ncount=1 \
                                -buffer_size=1 \
                                -source=Source_simple \
                                -monitor="NDMonitor(w)" \
                                -source.xw=0.1 \
                                -source.yh=0.1 \
                                -source.radius=0.05 \
                                -source.dist=1.0 \
                                -source.dE=10.0 \
                                -source.E0=60.0 \
                                -source.gauss=0.0 \
                                -source.flux=1.0 \
                                -monitor.wmin=0 \
                                -monitor.wmax=100 \
                                -monitor.nw=100 \
                                -monitor.filename=iw2.h5 \
                                -monitor.xwidth=%f \
                                -monitor.yheight=%f \
                                -geometer.monitor="%s" \
                                --output-dir=%s'

        # Misses monitor
        (xw, yh) = (0.1, 0.1)
        position = "(0,1,1),(0,0,0)"
        cmd = cmd_fmt % (xw, yh, position, outdir)
        import os
        if os.system(cmd):
            raise RuntimeError, "%r failed" % cmd

        from histogram.hdf import load
        from histogram.hdf.utils import getOnlyEntry
        f = histfile
        h = load(f, getOnlyEntry(f))
        self.assertEqual(h.I.sum(), 0.0)

        # Hits monitor
        (xw, yh) = (0.1, 0.1)
        position = "(0,0,1),(0,0,0)"
        outdir = 'out-test_sizes-hits'
        histfile = '%s/iw2.h5' % outdir
        cmd = cmd_fmt % (xw, yh, position, outdir)
        if os.system(cmd):
            raise RuntimeError, "%r failed" % cmd

        f = histfile
        h = load(f, getOnlyEntry(f))
        self.assert_(h.I.sum() > 0)
예제 #2
0
    def test_sizes(self):
        'ndmonitor: w; tests: xwidth, yheight'
        outdir = 'out-test_sizes'
        histfile = '%s/iw2.h5' % outdir
        cmd_fmt = 'mcvine-simulate -components=source,monitor --- \
                                -overwrite-datafiles=on \
                                -ncount=1 \
                                -buffer_size=1 \
                                -source=Source_simple \
                                -monitor="NDMonitor(w)" \
                                -source.xw=0.1 \
                                -source.yh=0.1 \
                                -source.radius=0.05 \
                                -source.dist=1.0 \
                                -source.dE=10.0 \
                                -source.E0=60.0 \
                                -source.gauss=0.0 \
                                -source.flux=1.0 \
                                -monitor.wmin=0 \
                                -monitor.wmax=100 \
                                -monitor.nw=100 \
                                -monitor.filename=iw2.h5 \
                                -monitor.xwidth=%f \
                                -monitor.yheight=%f \
                                -geometer.monitor="%s" \
                                --output-dir=%s'

        # Misses monitor
        (xw, yh)    = (0.1, 0.1)
        position    = "(0,1,1),(0,0,0)"
        cmd = cmd_fmt % (xw, yh, position, outdir)
        import os
        if os.system(cmd):
            raise RuntimeError, "%r failed" % cmd

        from histogram.hdf import load
        from histogram.hdf.utils import getOnlyEntry
        f = histfile
        h = load(f, getOnlyEntry(f))
        self.assertEqual( h.I.sum() , 0.0)

        # Hits monitor
        (xw, yh)    = (0.1, 0.1)
        position    = "(0,0,1),(0,0,0)"
        outdir = 'out-test_sizes-hits'
        histfile = '%s/iw2.h5' % outdir
        cmd = cmd_fmt % (xw, yh, position, outdir)
        if os.system(cmd):
            raise RuntimeError, "%r failed" % cmd

        f = histfile
        h = load(f, getOnlyEntry(f))
        self.assert_( h.I.sum() > 0)
예제 #3
0
    def test1(self):
        # remove the output directory
        if os.path.exists(outputdir):
            shutil.rmtree(outputdir)
        
        # build the command to ru
        cmd = ['python E_monitor_TestCase_app2.py']
        if usempi():
            cmd.append('--%s.nodes=2' % launcher)
        cmd = ' '.join(cmd)
        
        # run command
        if os.system(cmd):
            raise RuntimeError, "%s failed" % cmd

        # checks
        import time
        ctime = time.time()

        #check output directory exists
        self.assert_( os.path.exists( outputdir ) )
        
        # make sure that the final histogram is identical to the 
        # sum of all the final histograms in different nodes
        from histogram.hdf import load
        from histogram.hdf.utils import getOnlyEntry
        p = os.path.join(outputdir, 'IE.h5')
        h = load(p, getOnlyEntry(p))
        
        self.assertEqual(h.I.sum(), 1)
        return
예제 #4
0
    def test1(self):
        # remove the output directory
        if os.path.exists(outputdir):
            shutil.rmtree(outputdir)
        
        # build the command to ru
        cmd = ['python E_monitor_TestCase_app2.py']
        if usempi:
            cmd.append('--mpirun.nodes=2')
        cmd = ' '.join(cmd)
        
        # run command
        if os.system(cmd):
            raise RuntimeError, "%s failed" % cmd

        # checks
        import time
        ctime = time.time()

        #check output directory exists
        self.assert_( os.path.exists( outputdir ) )
        
        # make sure that the final histogram is identical to the 
        # sum of all the final histograms in different nodes
        from histogram.hdf import load
        from histogram.hdf.utils import getOnlyEntry
        p = os.path.join(outputdir, 'IE.h5')
        h = load(p, getOnlyEntry(p))
        
        self.assertEqual(h.I.sum(), 1)
        return
예제 #5
0
 def _gethist(path):
     from histogram.hdf import load
     from histogram.hdf.utils import getOnlyEntry
     computation = domaccess.getComputationRecord('arcsbeamconfigurations', id)
     dds = director.dds
     p = dds.abspath(computation, path)
     return load(p, getOnlyEntry(p))
예제 #6
0
    def OnOpenHistogramFile(self, evt):
        open_data_default_dir = self.open_data_default_dir
        filename = self.toolkit.loadfileDialog(
            None, "Open histogram data file",
            defaultDir=open_data_default_dir)
        self.open_data_default_dir = os.path.dirname(filename)

        if filename.endswith('.pkl'): 
            from pickle import load
            hist = load(open(filename))
        elif filename.endswith('h5') or filename.endswith('hdf5'):
            from histogram.hdf.utils import getOnlyEntry
            entry = getOnlyEntry(filename)
            from histogram.hdf import load
            hist = load(filename, entry)
        else:
            toolkit = self.toolkit
            msg = "Don't know how to open file {0!s}\n" \
                  "Supported formats : \n" \
                  "  - python pickle\n"\
                  "  - hdf5\n".format(filename)
            toolkit.messageDialog(None, "Error",  msg)
            return

        name = hist.name()
        name = _validVariableName(name)
        if name in self.histograms.keys():
            msg = 'Histogram of name "{0!s}" already exists. \n'\
                  'Please rename or delete the existing histogram. \n'.format(name)
            toolkit = self.toolkit
            toolkit.messageDialog(None, "Error",  msg)
            return
        
        self.addNewHistogram(name, hist)
        return
예제 #7
0
def hist_mcs_sum(outdir, histogramfilename):
    """compute the summed histogram and summed number of mc samples"""
    import glob, os
    pattern = os.path.join(outdir, '*', histogramfilename)
    histfiles = glob.glob(pattern)
    pattern = os.path.join(outdir, '*', number_mc_samples_filename)
    mcsamplesfiles = glob.glob(pattern)
    assert len(histfiles) == len(mcsamplesfiles), "histogram files %s does not match #mcsample files %s" %(len(histfiles), len(mcsamplesfiles))
    if not histfiles:
        return None, None
    
    # load histograms
    from histogram.hdf import load
    from histogram.hdf.utils import getOnlyEntry
    loadhist = lambda f: load(f, getOnlyEntry(f))
    h1 = loadhist(histfiles[0])

    # XXX
    # due to a bug in h5py, we have to manually make a copy of the histogram
    # see http://code.google.com/p/h5py/issues/detail?id=121
    import histogram
    h1 = histogram.histogram(h1.name(), h1.axes(), h1.I, h1.E2)
    # XXX

    def _addhistfile(f):
        h = loadhist(f)
        h1.I += h.I
        h1.E2 += h.E2
        return
    map(_addhistfile, histfiles[1:])

    # load number_of_mc_samples
    loadmcs = lambda f: float(open(f).read())
    mcs = map(loadmcs, mcsamplesfiles)
    return h1, sum(mcs)
예제 #8
0
 def _gethist(path):
     from histogram.hdf import load
     from histogram.hdf.utils import getOnlyEntry
     computation = domaccess.getComputationRecord(
         'arcsbeamconfigurations', id)
     dds = director.dds
     p = dds.abspath(computation, path)
     return load(p, getOnlyEntry(p))
예제 #9
0
    def test3(self):
        'ndmonitor: energy'
        cmd = 'mcvine-simulate -components=source,monitor --- -ncount=1e4 -buffer_size=1000 -source=MonochromaticSource -monitor="NDMonitor(energy)" -geometer.monitor="(0,0,1),(0,0,0)" -source.energy=60 -monitor.energymin=0 -monitor.energymax=100 -monitor.nenergy=100 -monitor.filename=ienergy.h5 --output-dir=out-test3'
        import os
        if os.system(cmd):
            raise RuntimeError, "%r failed" % cmd

        from histogram.hdf import load
        from histogram.hdf.utils import getOnlyEntry
        f = 'out-test3/ienergy.h5'
        h = load(f, getOnlyEntry(f))
        self.assertEqual( h[(58, 62)].sum() , (1., 1.e-4))
        return
예제 #10
0
def plotH5File(
    h5filename, 
    pathinh5file = None, 
    min = None, max = None, 
    output=None,
    **kwds):
    if pathinh5file is None:
        from histogram.hdf.utils import getOnlyEntry
        pathinh5file = getOnlyEntry( h5filename )
    from histogram.hdf import load
    h = load( h5filename, pathinh5file )
    plotHist( h , min = min, max = max, output=output, **kwds)
    return
예제 #11
0
    def test3(self):
        'ndmonitor: energy'
        cmd = 'mcvine-simulate -components=source,monitor --- -ncount=1e4 -buffer_size=1000 -source=MonochromaticSource -monitor="NDMonitor(energy)" -geometer.monitor="(0,0,1),(0,0,0)" -source.energy=60 -monitor.energymin=0 -monitor.energymax=100 -monitor.nenergy=100 -monitor.filename=ienergy.h5 --output-dir=out-test3'
        import os
        if os.system(cmd):
            raise RuntimeError, "%r failed" % cmd

        from histogram.hdf import load
        from histogram.hdf.utils import getOnlyEntry
        f = 'out-test3/ienergy.h5'
        h = load(f, getOnlyEntry(f))
        self.assertEqual(h[(58, 62)].sum(), (1., 1.e-4))
        return
예제 #12
0
    def test3(self):
        outdir = 'out-testmpi'
        if os.path.exists(outdir):
            shutil.rmtree(outdir)
        cmd = './testmpi -mpirun.nodes=2'
        if os.system(cmd):
            raise RuntimeError, "%r failed" % cmd

        from histogram.hdf import load
        from histogram.hdf.utils import getOnlyEntry
        f = '%s/ienergy.h5' % (outdir, )
        h = load(f, getOnlyEntry(f))
        self.assertEqual(h[(58, 62)].sum(), (1., 1.e-4))
        return
예제 #13
0
    def test3(self):
        outdir = 'out-testmpi'
        if os.path.exists(outdir):
            shutil.rmtree(outdir)
        from mcni.pyre_support.MpiApplication \
            import mpi_launcher_choice as launcher            
        cmd = './testmpi -%s.nodes=2' % launcher
        if os.system(cmd):
            raise RuntimeError, "%r failed" % cmd

        from histogram.hdf import load
        from histogram.hdf.utils import getOnlyEntry
        f = '%s/ienergy.h5' % (outdir,)
        h = load(f, getOnlyEntry(f))
        self.assertEqual( h[(58, 62)].sum() , (1., 1.e-4))
        return
예제 #14
0
    def test3(self):
        'ndmonitor: energy'
        '''
        COMPONENT FChopper = Vitess_ChopperFermi(
                    GeomOption=2, zerotime=0, Nchannels=30,  Ngates=4,
                    freq=f1,   height=0.102,   width=0.05,
                    depth=0.017,  r_curv=2.2, diameter=0.08, Phase=-f1_tof_deg,
                    wallwidth=0.00015, sGeomFileName="FC_geom_circ.dat")
        '''
        cmd = 'mcvine-simulate -components=source,fc,monitor --- -ncount=1e4 -buffer_size=1000 -source=Source_simple -fc="Vitess(chopper_fermi_Linux)"  -fc.a=10.2 -fc.b=5 -fc.c=3 -fc.l=30 -fc.m=0.015 -fc.r=0.08 -fc.n=300 -fc.q=  -fc.G=FC_geom_circ.dat  -monitor="NDMonitor(energy)" -geometer.fc="(0,0,10),(0,0,0)" -geometer.monitor="(0,0,12),(0,0,0)" -source.E0=60 -source.dE=30 -dist=10 -width=0.05 -height=0.05 -xw=0.05 -yh=0.05 -fc. -monitor.energymin=0 -monitor.energymax=100 -monitor.nenergy=100 -monitor.filename=ienergy.h5 --output-dir=out-test3'
        import os
        if os.system(cmd):
            raise RuntimeError, "%r failed" % cmd

        from histogram.hdf import load
        from histogram.hdf.utils import getOnlyEntry
        f = 'out-test3/ienergy.h5'
        h = load(f, getOnlyEntry(f))
        self.assertEqual(h[(58, 62)].sum(), (1., 1.e-4))
        return
예제 #15
0
def hist_mcs_sum(outdir, histogramfilename):
    """compute the summed histogram and summed number of mc samples"""
    import glob, os
    pattern = os.path.join(outdir, '*', histogramfilename)
    histfiles = glob.glob(pattern)
    pattern = os.path.join(outdir, '*', number_mc_samples_filename)
    mcsamplesfiles = glob.glob(pattern)
    assert len(histfiles) == len(
        mcsamplesfiles
    ), "histogram files %s does not match #mcsample files %s" % (
        len(histfiles), len(mcsamplesfiles))
    if not histfiles:
        return None, None

    # load histograms
    from histogram.hdf import load
    from histogram.hdf.utils import getOnlyEntry
    loadhist = lambda f: load(f, getOnlyEntry(f))
    h1 = loadhist(histfiles[0])

    # XXX
    # due to a bug in h5py, we have to manually make a copy of the histogram
    # see http://code.google.com/p/h5py/issues/detail?id=121
    import histogram
    h1 = histogram.histogram(h1.name(), h1.axes(), h1.I, h1.E2)

    # XXX

    def _addhistfile(f):
        h = loadhist(f)
        h1.I += h.I
        h1.E2 += h.E2
        return

    map(_addhistfile, histfiles[1:])

    # load number_of_mc_samples
    loadmcs = lambda f: float(open(f).read())
    mcs = map(loadmcs, mcsamplesfiles)
    return h1, sum(mcs)
예제 #16
0
    def test1(self):
        # remove the output directory
        if os.path.exists(outputdir):
            shutil.rmtree(outputdir)

        # build the command to ru
        cmd = ['python E_monitor_TestCase_app.py']
        if usempi:
            cmd.append('--mpirun.nodes=2')
        cmd = ' '.join(cmd)

        # run command
        if os.system(cmd):
            raise RuntimeError, "%s failed" % cmd

        # checks
        import time
        ctime = time.time()

        #check output directory exists
        self.assert_(os.path.exists(outputdir))

        # make sure that the final histogram is identical to the
        # sum of all the final histograms in different nodes
        from mcni.components.HistogramBasedMonitorMixin import hist_mcs_sum
        h, n = hist_mcs_sum(outputdir, 'IE.h5')
        self.assertEqual(n, ncount)
        h.I /= n
        h.E2 /= n * n

        from histogram.hdf import load
        from histogram.hdf.utils import getOnlyEntry
        p = os.path.join(outputdir, 'IE.h5')
        ha = load(p, getOnlyEntry(p))

        self.assert_((h.I == ha.I).all())
        self.assert_((h.E2 == ha.E2).all())

        return
예제 #17
0
    def test3(self):
        "ndmonitor: energy"
        """
        COMPONENT FChopper = Vitess_ChopperFermi(
                    GeomOption=2, zerotime=0, Nchannels=30,  Ngates=4,
                    freq=f1,   height=0.102,   width=0.05,
                    depth=0.017,  r_curv=2.2, diameter=0.08, Phase=-f1_tof_deg,
                    wallwidth=0.00015, sGeomFileName="FC_geom_circ.dat")
        """
        cmd = 'mcvine-simulate -components=source,fc,monitor --- -ncount=1e4 -buffer_size=1000 -source=Source_simple -fc="Vitess(chopper_fermi_Linux)"  -fc.a=10.2 -fc.b=5 -fc.c=3 -fc.l=30 -fc.m=0.015 -fc.r=0.08 -fc.n=300 -fc.q=  -fc.G=FC_geom_circ.dat  -monitor="NDMonitor(energy)" -geometer.fc="(0,0,10),(0,0,0)" -geometer.monitor="(0,0,12),(0,0,0)" -source.E0=60 -source.dE=30 -dist=10 -width=0.05 -height=0.05 -xw=0.05 -yh=0.05 -fc. -monitor.energymin=0 -monitor.energymax=100 -monitor.nenergy=100 -monitor.filename=ienergy.h5 --output-dir=out-test3'
        import os

        if os.system(cmd):
            raise RuntimeError, "%r failed" % cmd

        from histogram.hdf import load
        from histogram.hdf.utils import getOnlyEntry

        f = "out-test3/ienergy.h5"
        h = load(f, getOnlyEntry(f))
        self.assertEqual(h[(58, 62)].sum(), (1.0, 1.0e-4))
        return
예제 #18
0
    def test1(self):
        # remove the output directory
        if os.path.exists(outputdir):
            shutil.rmtree(outputdir)
        
        # build the command to ru
        cmd = ['python E_monitor_TestCase_app.py']
        if usempi:
            cmd.append('--mpirun.nodes=2')
        cmd = ' '.join(cmd)

        # run command
        if os.system(cmd):
            raise RuntimeError, "%s failed" % cmd

        # checks
        import time
        ctime = time.time()

        #check output directory exists
        self.assert_( os.path.exists( outputdir ) )
        
        # make sure that the final histogram is identical to the 
        # sum of all the final histograms in different nodes
        from mcni.components.HistogramBasedMonitorMixin import hist_mcs_sum
        h, n = hist_mcs_sum(outputdir, 'IE.h5')
        self.assertEqual(n, ncount)
        h.I/=n; h.E2/=n*n
        
        from histogram.hdf import load
        from histogram.hdf.utils import getOnlyEntry
        p = os.path.join(outputdir, 'IE.h5')
        ha = load(p, getOnlyEntry(p))
        
        self.assert_((h.I == ha.I).all())
        self.assert_((h.E2 == ha.E2).all())
        
        return
예제 #19
0
 def loadhist(f):
     return load(f, getOnlyEntry(f))
 def loadhist(f):
     return load(f, getOnlyEntry(f))