コード例 #1
0
    def test2a(self):
        'normalize: large buffer'
        import mcni
        # create a dummy input
        neutrons = mcni.neutron_buffer(int(3e6))
        narr = neutrons.to_npyarr()
        narr[:, -1] = 1
        neutrons.from_npyarr(narr)
        out = 'tmp-nst-test2a.ns'
        mns.dump(neutrons, out)
        del neutrons

        # try normalize out-of-place
        out2 = 'tmp-nst-test2a-normalized.ns'
        if os.path.exists(out2): os.remove(out2)
        mns.normalize(out, 10., out2)
        neutrons2 = mns.load(out2)
        # and see if it is done correctly
        narr = neutrons2.to_npyarr()
        self.assertTrue((narr[:, -1] == .1).all())
        del neutrons2, narr

        # try normalize in-place
        mns.normalize(out, 10.)
        neutrons2 = mns.load(out)
        # and see if it is done correctly
        narr = neutrons2.to_npyarr()
        self.assertTrue((narr[:, -1] == .1).all())
        return
コード例 #2
0
 def test2a(self):
     'normalize: large buffer'
     import mcni
     # create a dummy input
     neutrons = mcni.neutron_buffer( int(3e6) )
     narr = neutrons.to_npyarr()
     narr[:, -1] = 1
     neutrons.from_npyarr(narr)
     out = 'tmp-nst-test2a.ns'
     mns.dump(neutrons, out)
     del neutrons
     
     # try normalize out-of-place
     out2 = 'tmp-nst-test2a-normalized.ns'
     if os.path.exists(out2): os.remove(out2)
     mns.normalize(out, 10., out2)
     neutrons2 = mns.load(out2)
     # and see if it is done correctly
     narr = neutrons2.to_npyarr()
     self.assertTrue((narr[:, -1] == .1).all())
     del neutrons2, narr
     
     # try normalize in-place
     mns.normalize(out, 10.)
     neutrons2 = mns.load(out)
     # and see if it is done correctly
     narr = neutrons2.to_npyarr()
     self.assertTrue((narr[:, -1] == .1).all())
     return
コード例 #3
0
    def test2(self):
        'normalize'
        import mcni
        # create a dummy input
        neutrons = mcni.neutron_buffer(10)
        for n in neutrons:
            n.probability = 1
            continue
        out = 'tmp-nst-test2.ns'
        mns.dump(neutrons, out)

        # try normalize out-of-place
        out2 = 'tmp-nst-test2-normalized.ns'
        if os.path.exists(out2): os.remove(out2)
        mns.normalize(out, 10., out2)
        neutrons2 = mns.load(out2)
        # and see if it is done correctly
        for n in neutrons2:
            self.assertAlmostEqual(n.probability, .1)
            continue

        # try normalize in-place
        mns.normalize(out, 10.)
        neutrons2 = mns.load(out)
        # and see if it is done correctly
        for n in neutrons2:
            self.assertAlmostEqual(n.probability, .1)
            continue
        return
コード例 #4
0
    def test2(self):
        'normalize'
        import mcni
        # create a dummy input
        neutrons = mcni.neutron_buffer( 10 )
        for n in neutrons:
            n.probability = 1
            continue
        out = 'tmp-nst-test2.ns'
        mns.dump(neutrons, out)

        # try normalize out-of-place
        out2 = 'tmp-nst-test2-normalized.ns'
        if os.path.exists(out2): os.remove(out2)
        mns.normalize(out, 10., out2)
        neutrons2 = mns.load(out2)
        # and see if it is done correctly
        for n in neutrons2:
            self.assertAlmostEqual(n.probability, .1)
            continue

        # try normalize in-place
        mns.normalize(out, 10.)
        neutrons2 = mns.load(out)
        # and see if it is done correctly
        for n in neutrons2:
            self.assertAlmostEqual(n.probability, .1)
            continue
        return
コード例 #5
0
def mcstas2mcvine(inpath, outpath):
    arr = np.loadtxt(inpath)
    N = len(arr)
    newarr = np.zeros((N, 10), dtype=float)
    newarr[:, list(range(10))] = arr[:, [1, 2, 3, 4, 5, 6, 8, 9, 7, 0]]
    neutrons = ns.neutrons_from_npyarr(newarr)
    ns.dump(neutrons, outpath)
    return
コード例 #6
0
 def test(self):
     'neutron_storage'
     import mcni
     neutrons = mcni.neutron_buffer(7)
     neutrons[5] = mcni.neutron(v=(8, 9, 10))
     mns.dump(neutrons, 'neutrons.dat')
     neutrons1 = mns.load('neutrons.dat')
     n5 = neutrons1[5]
     v = n5.state.velocity
     self.assertAlmostEqual(v[0], 8)
     self.assertAlmostEqual(v[1], 9)
     self.assertAlmostEqual(v[2], 10)
     return
コード例 #7
0
 def test(self):
     'neutron_storage'
     import mcni
     neutrons = mcni.neutron_buffer( 7 )
     neutrons[5] = mcni.neutron( v = (8,9,10) )
     mns.dump(neutrons, 'neutrons.dat')
     neutrons1 = mns.load( 'neutrons.dat' )
     n5 = neutrons1[5]
     v = n5.state.velocity
     self.assertAlmostEqual( v[0], 8 )
     self.assertAlmostEqual( v[1], 9 )
     self.assertAlmostEqual( v[2], 10 )
     return
コード例 #8
0
def mcstas2mcvine(inpath, outpath):
    """
     converting mcstas neutron events file to mcvine neutron events file
    Parameters
    ----------
    inpath: string
        path where mcstas event file exist
    outpath:string
        path where mcvine event file will be saved

    Returns
    -------

    """
    arr = np.loadtxt(inpath)
    N = len(arr)
    newarr = np.zeros((N, 10), dtype=float)
    newarr[:, list(range(10))] = arr[:, [1,2,3, 4,5,6, 8,9, 7, 0]]
    neutrons = ns.neutrons_from_npyarr(newarr)
    ns.dump(neutrons, outpath)