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
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 )
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)
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
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
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
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
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
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 )
def bp_ndarray_getitem(self, indexes): cindexes = b.vector_uint( 0 ) for ind in indexes: cindexes.append( ind ) return self._getitem_bp( cindexes )
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 )
def test(self): dims = mccomponentsbp.vector_uint( 0 ) dims.append( 100 ) mca = mccomponentsbp.EventModeMCA( "test.out", dims ) return
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)
def test(self): dims = mccomponentsbp.vector_uint(0) dims.append(100) mca = mccomponentsbp.EventModeMCA("test.out", dims) return