def test3(self): '''render and then parse''' from instrument.nixml import weave, parse_file instrument = parse_file('test.xml') weave(instrument, open('test.xml.weaved', 'w')) instrument1 = parse_file('test.xml.weaved') return
def test1(self): 'detector hierarchy from xml' from instrument.nixml import parse_file instrument = parse_file( 'ARCS.xml' ) import instrument.geometers as ig instrument.geometer.changeRequestCoordinateSystem( ig.coordinateSystem( coordinate_system ) ) assignLocalGeometers( instrument, coordinate_system = coordinate_system ) detectorSystem = instrument.getDetectorSystem() tofparams = 0, 10e-3, 1e-4 detectorSystem.tofparams = tofparams dims = getDetectorHierarchyDimensions( instrument ) dims = [ dim for name, dim in dims ] mca = md.eventModeMCA( outfilename, dims ) detectorSystem.mca = mca cds = mh.scattererEngine( detectorSystem, coordinate_system = coordinate_system ) for i in range(nevents): if i%1000 == 0: print i ev = mcni.neutron( r = (0,0,0), v = (1500,0,2000) ) cds.scatter(ev) continue instrument.geometer = instrument.global_geometer return
def test1(self): 'detector hierarchy from xml' from instrument.nixml import parse_file instrument = parse_file('ARCS.xml') import instrument.geometers as ig instrument.geometer.changeRequestCoordinateSystem( ig.coordinateSystem(coordinate_system)) assignLocalGeometers(instrument, coordinate_system=coordinate_system) detectorSystem = instrument.getDetectorSystem() tofparams = 0, 10e-3, 1e-4 detectorSystem.tofparams = tofparams dims = getDetectorHierarchyDimensions(instrument) dims = [dim for name, dim in dims] mca = md.eventModeMCA(outfilename, dims) detectorSystem.mca = mca cds = mh.scattererEngine(detectorSystem, coordinate_system=coordinate_system) for i in range(nevents): if i % 1000 == 0: print i ev = mcni.neutron(r=(0, 0, 0), v=(2000, 1500, 0)) cds.scatter(ev) continue instrument.geometer = instrument.global_geometer return
def detectorcomponent(name, instrumentxml, coordinate_system, tofparams, outfilename): import mccomposite.extensions.Copy import mccomposite.extensions.HollowCylinder import mccomponents.detector.optional_extensions.Detector from instrument.nixml import parse_file instrument = parse_file(instrumentxml) import instrument.geometers as ig instrument.geometer.changeRequestCoordinateSystem( ig.coordinateSystem(coordinate_system)) from mccomponents.detector.utils import \ getDetectorHierarchyDimensions, assignLocalGeometers assignLocalGeometers(instrument, coordinate_system=coordinate_system) detectorSystem = instrument.getDetectorSystem() detectorSystem.tofparams = tofparams dims = getDetectorHierarchyDimensions(instrument) dims = [dim for name, dim in dims] mca = eventModeMCA(outfilename, dims) detectorSystem.mca = mca import mccomponents.homogeneous_scatterer as mh cds = mh.scattererEngine(detectorSystem, coordinate_system=coordinate_system) instrument.geometer = instrument.global_geometer cds.name = name return cds
def test2(self): """ instrument.nixml.parser: Instrument Scientist Coordinate System """ from instrument.nixml import parse_file instrument = parse_file('test2.xml') return
def test2(self): """ instrument.nixml.weave """ from instrument.nixml import weave, parse_file instrument = parse_file('test.xml') weave(instrument) return
def test(self): """ instrument.nixml.render """ from instrument.nixml import render, parse_file instrument = parse_file('test.xml') text = render(instrument) print('\n'.join(text), file=open('test.xml.new', 'w')) return
def test0(self): """ instrument.nixml.parser """ from instrument.nixml import parse_file instrument = parse_file('test0.xml') pos = instrument.geometer.position("detectorSystem/det1") print(pos) pos = array(pos) / m self.assertVectorAlmostEqual(pos, (0.3, 0., 4)) return
def test3(self): """ instrument.nixml.parser: Instrument Scientist Coordinate System """ from instrument.nixml import parse_file instrument = parse_file('test-InstrumentScientistCS.xml') from instrument.elements.Instrument import Instrument self.assertTrue(isinstance(instrument, Instrument)) pos = instrument.geometer.position( "detectorSystem/detArray1/detPack1/det1/pix2") pos = array(pos) / m self.assertVectorAlmostEqual(pos, (9, 0.3, 0.1)) return
def test2(self): 'instrument.geometer.InstrumentGeometer: layered structure. check orientation' from instrument.nixml import parse_file instrument = parse_file('InstrumentGeometer-test2.xml') geometer = instrument.geometer self.assertVectorAlmostEqual(geometer.orientation('detectorSystem'), (0 * degree, 0 * degree, 90 * degree)) self.assertVectorAlmostEqual( geometer.orientation('detectorSystem/detPack1'), (0 * degree, 90 * degree, 90 * degree)) print(geometer.orientation('detectorSystem/detPack1/det1')) self.assertVectorAlmostEqual( geometer.orientation('detectorSystem/detPack1/det1'), (-90 * degree, 0 * degree, 180 * degree)) return
def geometricInfo(ARCSxml): #geometrical data for resolution=1 # positions from _getinstrumentinfo import getinstrumentinfo infos = getinstrumentinfo(ARCSxml) positions = infos['pixelID-position mapping array'] detaxes0 = infos['detector axes'] npacks, ndetsperpack, npixelsperdet = [axis.size() for axis in detaxes0] positions.shape = npacks, ndetsperpack, npixelsperdet, 3 # radii and heights from instrument.nixml import parse_file instrument = parse_file( ARCSxml ) from getpixelsizes import getpixelsizes radii, heights = getpixelsizes( instrument, npacks, ndetsperpack, npixelsperdet) return positions, radii, heights
def test1(self): """instrument.geometers.InstrumentGeometer: layered structure. check rotations on vector """ from instrument.nixml import parse_file instrument = parse_file('InstrumentGeometer-test1.xml') geometer = instrument.geometer det1position = geometer.position('detectorSystem/detPack1/det1') from numpy import array, sqrt from pyre.units.length import meter det1position /= meter packCenter = array([sqrt(3) / 2, 1. / 2, 0]) det1offset = array([-1. / 2, sqrt(3) / 2, 0]) * 0.3 expected = packCenter + det1offset print(det1position, expected) self.assertVectorAlmostEqual(det1position, expected) return
def main(): import sys if len(sys.argv) != 2: help() exit(1) arcsxml = sys.argv[1] from instrument.nixml import parse_file arcs = parse_file( arcsxml ) nPixelsPerDetector = 128 nDetectorsPerPack = 8 nPacks = len(arcs.getDetectorSystem().elements()) pixelID2position = createmap( arcs, nPixelsPerDetector, nDetectorsPerPack, nPacks ) import pickle pickle.dump( pixelID2position, open('pixelID2position.pkl','w')) open('pixelID2position.bin','w').write( pixelID2position.tostring() ) return
def getpixelinfo(ARCSxml): info.log('parsing acrs xml: %s' % ARCSxml) from instrument.nixml import parse_file instrument = parse_file(ARCSxml) info.log('getting detector axes') from arcseventdata.GetDetectorAxesInfo import getDetectorAxes detaxes = getDetectorAxes(instrument) npacks, ndetsperpack, npixelsperdet = [axis.size() for axis in detaxes] info.log('getting pixel radii and heights') from arcseventdata.getpixelsizes import getpixelsizes radii, heights = getpixelsizes( instrument, npacks, ndetsperpack, npixelsperdet) widths = radii*2. info.log('getting pixel L2, phis, psis') from arcseventdata import getinstrumentinfo ii = getinstrumentinfo(ARCSxml) dists = ii['dists'] phis = ii['phis'] psis = ii['psis'] sas = ii['solidangles'] from reduction.units import length, angle dists = dists.I phis = phis.I psis = psis.I sas = sas.I # 06/30/2009: was told that the last two columns are angles da1 = widths/dists da2 = sas/da1 dists.shape = phis.shape = psis.shape = widths.shape = heights.shape = -1, da1.shape = da2.shape = -1, #return dists, phis, psis, widths, heights return dists, phis, psis, da1, da2
def _updateCache(ARCSxml): ARCSxml = os.path.abspath( ARCSxml ) cache_dir = os.path.abspath( cache_path( ARCSxml ) ) if not os.path.exists( cache_dir ): os.makedirs( cache_dir ) assert isWritable( cache_dir ), "Cache path %s is not writable" % ( cache_dir, ) cwd = os.path.abspath( os.curdir ) os.chdir( cache_dir ) print "parsing ARCS instrument xml" from instrument.nixml import parse_file instrument = parse_file( ARCSxml ) geometer = instrument.geometer print "generating ARCS instrument info dictionary" from GetDetectorAxesInfo import getDetectorAxes detaxes = getDetectorAxes( instrument ) packAxis, tubeAxis, pixelAxis = detaxes nPacks = packAxis.size() nDetectorsPerPack = tubeAxis.size() nPixelsPerDetector = pixelAxis.size() from createmap_pixelID2position import createmap pixelID2position = createmap( instrument, nPixelsPerDetector, nDetectorsPerPack, nPacks ) print "saving ARCS instrumentn info to files" pickle.dump( pixelID2position, open('pixelID2position.pkl','w')) open('pixelID2position.bin','w').write( pixelID2position.tostring() ) mod2sample = geometer.distanceToSample( instrument.getModerator() ) mod2mon1 = geometer.distance( instrument.getModerator(), instrument.getMonitors()[0] ) mod2mon2 = geometer.distance( instrument.getModerator(), instrument.getMonitors()[1] ) infos = { 'detector-system-dimensions' : [nPacks, nDetectorsPerPack, nPixelsPerDetector], 'moderator-sample distance': mod2sample, 'moderator-monitor1 distance': mod2mon1, 'moderator-monitor2 distance': mod2mon2, } pickle.dump( infos, open('ARCS-instrument-info.pkl', 'w') ) from getpixelinfo import getpixelinfo phi_p, psi_p, dist_p, solidangle_p, dphi_p, dpsi_p = getpixelinfo( pixelID2position, detaxes, instrument ) pickle.dump( phi_p, open('phi_pdp.pkl', 'w') ) pickle.dump( psi_p, open('psi_pdp.pkl', 'w') ) pickle.dump( dist_p, open('dist_pdp.pkl', 'w') ) pickle.dump( solidangle_p, open('solidangle_pdp.pkl', 'w') ) pickle.dump( dphi_p, open('dphi_pdp.pkl', 'w') ) pickle.dump( dpsi_p, open('dpsi_pdp.pkl', 'w') ) os.chdir( cwd ) return
def _getdetaxes( ARCSxml ): from instrument.nixml import parse_file instrument = parse_file( ARCSxml ) from GetDetectorAxesInfo import getDetectorAxes detaxes = getDetectorAxes( instrument ) return detaxes
# # {LicenseText} # # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # eventsdat = 'events.dat' instrumentxml = 'Pharos.xml' Ei = 70 from mcni.utils import e2v vi = e2v( Ei ) #m/s from instrument.nixml import parse_file instrument = parse_file( instrumentxml ) geometer = instrument.geometer import mcni.units as units meter = units.length.meter mod2sample = geometer.distanceToSample( instrument.getModerator() ) / meter tmin = mod2sample/vi sample2det = instrument.getDetectorSystem().shape().in_radius tmax = tmin + sample2det/e2v( 5 ) tofparams = tmin, tmax, (tmax-tmin)/1000 print tofparams Idpt_filename = 'Idpt.h5' # version
eventsdat = 'events.dat' instrumentxml = 'Pharos.xml' Ei = 70 #incident energy Q = 5 #momentum transfer E = 30 #energy transfer from mcni.utils import e2v vi = e2v(Ei) #m/s from instrument.nixml import parse_file instrument = parse_file(instrumentxml) geometer = instrument.geometer import mcni.units as units meter = units.length.meter mod2sample = geometer.distanceToSample(instrument.getModerator()) / meter tmin = mod2sample / vi sample2det = instrument.getDetectorSystem().shape().in_radius tmax = tmin + sample2det / e2v(5) tofparams = tmin, tmax, (tmax - tmin) / 1000 Idpt_filename = 'Idpt.h5'