예제 #1
0
    def test(self):
        a = numpy.arange(12, dtype = numpy.double)
        a.shape = 3,4
        ptr = numpyext.getdataptr( a )
        
        wp = bpext.wrap_native_ptr( ptr )
        
        shape = mccomponentsbp.vector_uint( 0 )
        for i in a.shape: shape.append( i )
        a1 = mccomponentsbp.new_NdArray_dblarr_2( wp, shape )
        a1.origin = a

        indexes = mccomponentsbp.vector_uint( 0 )
        indexes.append( 2 ); indexes.append( 1 )
        self.assertEqual( a1[ indexes ], 9 )
        return
예제 #2
0
 def eventmodemca( self, outfilename, detectorDims ):
     '''eventmodemca( outfilename, detectorDims ): new event-mode mca
     outfilename: output file name
     detectorDims: detector dimensions.
       For example, if a detectory system has 15 packs, 8 tubes per pack, 128 pixels per tube, then
         detectorDims = 15,8,128
         
     '''
     dims = b.vector_uint( 0 )
     for dim in detectorDims: dims.append(dim)
     return b.EventModeMCA( outfilename, dims )
예제 #3
0
 def eventmodemca(self, outfilename, detectorDims):
     '''eventmodemca( outfilename, detectorDims ): new event-mode mca
     outfilename: output file name
     detectorDims: detector dimensions.
       For example, if a detectory system has 15 packs, 8 tubes per pack, 128 pixels per tube, then
         detectorDims = 15,8,128
         
     '''
     dims = b.vector_uint(0)
     for dim in detectorDims:
         dims.append(dim)
     return b.EventModeMCA(outfilename, dims)
예제 #4
0
    def test(self):
        import numpyext
        import numpy
        a = numpy.arange(12, dtype=numpy.double)
        a.shape = 3, 4
        ptr = numpyext.getdataptr(a)

        import bpext
        wp = bpext.wrap_native_ptr(ptr)

        shape = mccomponentsbp.vector_uint(0)
        for i in a.shape:
            shape.append(i)
        a1 = mccomponentsbp.new_NdArray_dblarr_2(wp, shape)
        a1.origin = a

        indexes = mccomponentsbp.vector_uint(0)
        indexes.append(2)
        indexes.append(1)
        self.assertEqual(a1[indexes], 9)
        return
예제 #5
0
    def ndarray( self, npyarr ):
        '''create boost python instance of NdArray object
    arguments:
        npyarr: numpy array. it must be a contiguous array.
        '''
        assert npyarr.dtype == numpy.double, "only work for double array for this time"
        
        ptr = numpyext.getdataptr( npyarr )
        
        wp = bpext.wrap_native_ptr( ptr )
        
        shape = b.vector_uint( 0 )
        for i in npyarr.shape: shape.append( i )

        factory = 'new_NdArray_dblarr_%d' % len(shape)
        a1 = getattr(b,factory)( wp, shape )
        a1.origin = npyarr # keep a reference to avoid seg fault
        return a1
예제 #6
0
    def test(self):
        npixels = 100
        detlength = 1.  # meter
        tofmin = 1000.
        tofmax = 3000.
        tofstep = 1.
        detID = 23
        atm = 1.013e5
        pressure = 10 * atm
        prob = 3.3
        tof = 2000

        t2c = mccomponentsbp.Tof2Channel(tofmin, tofmax, tofstep)

        z_direction = mccompositebp.Vector(0, 0, 1)
        pixel0 = mccompositebp.Vector(0, 0, -0.5)
        z2c = mccomponentsbp.Z2Channel(detlength, npixels, z_direction, pixel0)

        datafile = "test.out"
        dims = mccomponentsbp.vector_uint(0)
        dims.append(
            detID + 1
        )  # The first dimension is for detectors. must be larger than the largest number of detector IDs.
        dims.append(npixels)
        mca = mccomponentsbp.EventModeMCA(datafile, dims)

        tube_channels = mccomponentsbp.vector_int(0)
        tube_channels.append(detID)

        tube = mccomponentsbp.He3TubeKernel(pressure, tube_channels, z2c, t2c,
                                            mca)

        event = mcni.neutron(r=(0, 0, 0.001), prob=prob, time=tof)
        tube.absorb(event)

        del tube, mca

        s = open(datafile).read()
        import struct
        pixelID, tofChannelNo, prob1 = struct.unpack('IId', s)
        self.assertEqual(pixelID, detID * npixels + npixels / 2)
        self.assertEqual(tofChannelNo, (tof - tofmin) / tofstep)
        self.assertEqual(prob, prob1)
        return
예제 #7
0
    def ndarray( self, npyarr ):
        '''create boost python instance of NdArray object
    arguments:
        npyarr: numpy array. it must be a contiguous array.
        '''
        assert npyarr.dtype == numpy.double, "only work for double array for this time"
        
        import numpyext
        ptr = numpyext.getdataptr( npyarr )
        
        import bpext
        wp = bpext.wrap_native_ptr( ptr )
        
        shape = b.vector_uint( 0 )
        for i in npyarr.shape: shape.append( i )

        factory = 'new_NdArray_dblarr_%d' % len(shape)
        a1 = getattr(b,factory)( wp, shape )
        a1.origin = npyarr # keep a reference to avoid seg fault
        return a1
예제 #8
0
    def test(self):
        npixels = 100
        detlength = 1. # meter
        tofmin = 1000. ; tofmax = 3000.; tofstep = 1.
        detID = 23
        atm = 1.013e5
        pressure = 10 * atm
        prob = 3.3
        tof = 2000
        
        t2c = mccomponentsbp.Tof2Channel(tofmin, tofmax, tofstep)

        z_direction = mccompositebp.Vector(0,0,1)
        pixel0 = mccompositebp.Vector(0,0,-0.5)
        z2c = mccomponentsbp.Z2Channel(detlength, npixels, z_direction, pixel0)

        datafile = "test.out"
        dims = mccomponentsbp.vector_uint(0)
        dims.append( detID+1 ) # The first dimension is for detectors. must be larger than the largest number of detector IDs.
        dims.append( npixels )
        mca = mccomponentsbp.EventModeMCA( datafile, dims )
        
        tube_channels = mccomponentsbp.vector_int(0)
        tube_channels.append( detID )
        
        tube = mccomponentsbp.He3TubeKernel( pressure, tube_channels, z2c, t2c, mca);

        event = mcni.neutron( r = (0,0,0.001), prob = prob, time = tof )
        tube.absorb( event );

        del tube, mca

        s = open( datafile ).read()
        import struct
        pixelID, tofChannelNo, prob1 = struct.unpack( 'IId', s )
        self.assertEqual( pixelID, detID * npixels + npixels/2 )
        self.assertEqual( tofChannelNo, (tof-tofmin)/tofstep)
        self.assertEqual( prob, prob1 )
        return
예제 #9
0
def bp_ndarray_getitem(self, indexes):
    import mccomponents.mccomponentsbp as binding
    cindexes = binding.vector_uint( 0 )
    for ind in indexes: cindexes.append( ind )
    return self._getitem_bp( cindexes )
예제 #10
0
def bp_ndarray_getitem(self, indexes):
    cindexes = b.vector_uint( 0 )
    for ind in indexes: cindexes.append( ind )
    return self._getitem_bp( cindexes )
예제 #11
0
def bp_eventmodemca( self, outfilename, detectorDims ):
    import mccomponents.mccomponentsbp as b
    dims = b.vector_uint( 0 )
    for dim in detectorDims: dims.append(dim)
    return b.EventModeMCA( outfilename, dims )
예제 #12
0
 def test(self):
     dims = mccomponentsbp.vector_uint( 0 )
     dims.append( 100 )
     mca = mccomponentsbp.EventModeMCA( "test.out", dims )
     return
예제 #13
0
def bp_ndarray_getitem(self, indexes):
    import mccomponents.mccomponentsbp as binding
    cindexes = binding.vector_uint(0)
    for ind in indexes:
        cindexes.append(ind)
    return self._getitem_bp(cindexes)
예제 #14
0
 def test(self):
     dims = mccomponentsbp.vector_uint(0)
     dims.append(100)
     mca = mccomponentsbp.EventModeMCA("test.out", dims)
     return