def test4(self): "ARCSGeometer: instrument with layers" import instrument.elements as ies instrument = ies.instrument("instrument") sample = ies.sample('sample') instrument.addElement(sample) detSystem = ies.detectorSystem('detSystem') instrument.addElement(detSystem) det1 = ies.detector('det1', guid=instrument.getUniqueID()) detSystem.addElement(det1) pixel1 = ies.pixel('pixel1', guid=instrument.getUniqueID()) det1.addElement(pixel1) from .CoordinateSystem import McStasCS geometer = ARCSGeometer(instrument, registry_coordinate_system=McStasCS) geometer.register(sample, (0, 0, 0), (0, 0, 0)) geometer.register(detSystem, (0, 0, 0), (0, 0, 0)) geometer.register(det1, (1, 0, 0), (0, 90, 0), relative=detSystem) geometer.register(pixel1, (0, 1, 0), (0, 0, 0), relative=det1) geometer.finishRegistration() self.assertAlmostEqual( geometer.scatteringAngle('detSystem/det1/pixel1'), 90 * degree) self.assertAlmostEqual(geometer.phi('detSystem/det1/pixel1'), 90 * degree) return
def test2(self): """instrument.elements.DetectorVisitor: method 'elementSignature' """ print(""" You should see indexes are increasing from the last (highest) index to the lower index, one by one. Copies are printed out twice. """) #create an instrument with layers and copies i = ie.instrument('test') sample = ie.sample('sample') i.addElement(sample) ds = ie.detectorSystem('detSystem', guid=i.getUniqueID()) dp1 = ie.detectorPack('detPack1', guid=i.getUniqueID()) det1 = ie.detector('detector1', guid=i.getUniqueID()) det2 = ie.copy('detector2', det1.guid(), guid=i.getUniqueID()) dp1.addElement(det1) dp1.addElement(det2) dp2 = ie.copy('detPack2', dp1.guid(), guid=i.getUniqueID()) ds.addElement(dp1) ds.addElement(dp2) i.addElement(ds) i.guidRegistry.registerAll(i) import instrument.geometers as ig g = ig.arcs(i, registry_coordinate_system='McStas') g.register(sample, (0, 0, 0), (0, 0, 0)) g.register(ds, (0, 0, 0), (0, 0, 0)) g.register(dp1, (1, 0, 0), (0, 90, 0), relative=ds) g.register(det1, (0.1, 0, 0), (90, 0, 0), relative=dp1) g.register(det2, (-0.1, 0, 0), (90, 0, 0), relative=dp1) g.register(dp2, (-1, 0, 0), (0, 90, 0), relative=ds) g.finishRegistration() self.assertAlmostEqual( g.scatteringAngle('detSystem/detPack1') / degree, 90) class Visitor(DetectorVisitor): def onDetectorPack(self, pack): print(pack.name, self.elementSignature()) self.onElementContainer(pack) return def onDetector(self, detector): print(detector.name, self.elementSignature()) return def onCopy(self, copy): print(copy.name, self.elementSignature()) DetectorVisitor.onCopy(self, copy) return pass # end of Visitor Visitor().render(i, g) return
def construct(self, lrmecsDataFilename): import os if not os.path.exists(lrmecsDataFilename): raise RuntimeError("Cannot find file %s" % os.path.abspath(lrmecsDataFilename)) self._instrument = lrmecs = elements.instrument( "Lrmecs") # version="0.0.0") #instrument local geometer geometer = geometers.geometer( lrmecs, registry_coordinate_system='InstrumentScientist') self.local_geometers = [geometer] #parse the file and get all tube records and monitor records from .LrmecsDataFileParser import Parser self.distMod2Sample, monitorRecords, tubeRecords = Parser( lrmecsDataFilename, self.interpolateData).parse() # make Moderator self.makeModerator(lrmecs, geometer) # make monitors: adds elements to lrmecs & geometer self.makeMonitors(lrmecs, geometer, monitorRecords) #make sample sample = elements.sample('sample') lrmecs.addElement(sample) # sample is placed at origin to simplify computation geometer.register(sample, (0 * mm, 0 * mm, 0 * mm), (0, 0, 0)) # make detector array: adds elements to lrmecs & geometer self.makeDetectorSystem(lrmecs, geometer, tubeRecords) # set up guid registry lrmecs.guidRegistry.registerAll(lrmecs) # instrument global geometer instrumentGeometer = geometers.arcs( lrmecs, self.local_geometers, registry_coordinate_system='InstrumentScientist') lrmecs.geometer = instrumentGeometer # clean up temporary variables del self._detectorModules, self.distMod2Sample, self.local_geometers del self._instrument # save the xml description from instrument.nixml import weave import os f = '%s-interp%s.xml' % (os.path.basename(lrmecsDataFilename), self.interpolateData) print('write lrmecs instrument to %s' % f) weave(lrmecs, open(f, 'w')) return lrmecs, instrumentGeometer
def construct( self, packs, mod2sample = 20.0254*m, xmloutput = None ): '''construct a new SEQUOIA instrument Parameters: -packs: a list of PackInfo instances -mod2sample: moderator to sample distance ''' self._instrument = sequoia = elements.instrument( "SEQUOIA" )# version="0.0.0") #instrument local geometer geometer = geometers.geometer( sequoia, registry_coordinate_system = 'InstrumentScientist' ) self.local_geometers = [geometer] # make Moderator self.makeModerator( sequoia, geometer ) # make monitors: adds elements to sequoia & geometer self.makeMonitors( sequoia, geometer, monitorRecords) #make sample sample = elements.sample( 'sample',guid = sequoia.getUniqueID() ) sequoia.addElement( sample ) geometer.register( sample, (mod2sample,0*m,0*m), (0,0,0) ) # make detector array: adds elements to sequoia & geometer self.makeDetectorSystem(sequoia, geometer, packs) # set up guid registry sequoia.guidRegistry.registerAll( sequoia ) # instrument global geometer instrumentGeometer = geometers.arcs( sequoia, self.local_geometers, registry_coordinate_system = 'InstrumentScientist' ) sequoia.geometer = instrumentGeometer # clean up temporary variables del self.local_geometers, self._instrument # save the xml description if xmloutput: from instrument.nixml import weave print('write sequoia instrument to %s' % xmloutput) weave( sequoia, open(xmloutput, 'w') ) return sequoia, instrumentGeometer
def construct( self, packs, xmloutput = None ): '''construct a new HYSPEC instrument Parameters: -packs: a list of PackInfo instances ''' self._instrument = hyspec = elements.instrument( "HYSPEC" )# version="0.0.0") #instrument local geometer geometer = geometers.geometer( hyspec, registry_coordinate_system = 'InstrumentScientist' ) self.local_geometers = [geometer] # make Moderator # self.makeModerator( hyspec, geometer ) # make monitors: adds elements to hyspec & geometer # self.makeMonitors( hyspec, geometer, monitorRecords) #make sample sample = elements.sample( 'sample',guid = hyspec.getUniqueID() ) hyspec.addElement( sample ) geometer.register( sample, (0*m,0*m,0*m), (0,0,0) ) # make detector array: adds elements to hyspec & geometer self.makeDetectorSystem(hyspec, geometer, packs) # set up guid registry hyspec.guidRegistry.registerAll( hyspec ) # instrument global geometer instrumentGeometer = geometers.arcs( hyspec, self.local_geometers, registry_coordinate_system = 'InstrumentScientist' ) hyspec.geometer = instrumentGeometer # clean up temporary variables del self.local_geometers, self._instrument # save the xml description if xmloutput: from instrument.nixml import weave print('write hyspec instrument to %s' % xmloutput) weave( hyspec, open(xmloutput, 'w') ) return hyspec, instrumentGeometer
def construct(self, detPackFilename): pharos = elements.instrument("Pharos") #instrument local geometer geometer = geometers.geometer( pharos, registry_coordinate_system='InstrumentScientist') self.local_geometers = [geometer] # Pharos currently don't have monitors. The following are commented out # make monitors: adds elements to pharos & geometer # self.makeMonitors( pharos, geometer) # make detector array: adds elements to pharos & geometer import os if not os.path.exists(detPackFilename): raise RuntimeError("Cannot find file %s" % detPackFilename) self.makeDetectorSystem(pharos, geometer, detPackFilename) # make Moderator self.makeModerator(pharos, geometer) # make sample sample = elements.sample('sample') pharos.addElement(sample) geometer.register(sample, (0, 0, 0), (0, 0, 0)) # set up guid registry pharos.guidRegistry.registerAll(pharos) # instrument global geometer instrumentGeometer = geometers.arcs( pharos, self.local_geometers, registry_coordinate_system='InstrumentScientist') pharos.geometer = instrumentGeometer del self.local_geometers # save the xml description from instrument.nixml import weave import os f = '%s.xml' % (os.path.basename(detPackFilename), ) print('write pharos instrument to %s' % f) weave(pharos, open(f, 'w')) return pharos, instrumentGeometer
def construct(self): fake = elements.instrument("CylinderDetectors") #instrument local geometer geometer = geometers.geometer( fake, registry_coordinate_system='InstrumentScientist') self.local_geometers = [geometer] # make monitors: adds elements to arcs & geometer # self.makeMonitors( arcs, geometer) # make detector array: adds elements to arcs & geometer self.makeDetectorSystem(fake, geometer) # make Moderator self.makeModerator(fake, geometer) #make sample sample = elements.sample('sample') fake.addElement(sample) # sample is placed at origin to simplify computation geometer.register(sample, (0 * mm, 0 * mm, 0 * mm), (0, 0, 0)) # set up guid registry fake.guidRegistry.registerAll(fake) # instrument global geometer instrumentGeometer = geometers.arcs( fake, self.local_geometers, registry_coordinate_system='InstrumentScientist') fake.geometer = instrumentGeometer self._check(fake, instrumentGeometer) return fake, instrumentGeometer
def construct(self, detconfigfile, longpackinfo, shortpack1info, shortpack2info, mod2sample=13.6, xmloutput=None): '''construct a new ARCS instrument Parameters: -detconfigfile: detector configuration file from Doug -longpackinfo: long pack related info, a tuple of (pressure, npixels, radius, height, gap ) -shortpack1info: short pack type 1 info, a tuple too (pack 71) -shortpack2info: short pack type 2 info, a tuple too (pack 70) -mod2sample: moderator to sample distance ''' #read detector pack records import os if not os.path.exists(detconfigfile): raise IOError("Cannot find file %s" % (os.path.abspath(detconfigfile), )) self._instrument = arcs = elements.instrument( "ARCS") # version="0.0.0") #instrument local geometer geometer = geometers.geometer( arcs, registry_coordinate_system='InstrumentScientist') self.local_geometers = [geometer] #parse the file and get all tube records and monitor records from .ARCSDetPackCSVParser import readConf packRecords = readConf(detconfigfile) # make Moderator self.makeModerator(arcs, geometer) # make monitors: adds elements to arcs & geometer self.makeMonitors(arcs, geometer, monitorRecords) #make sample sample = elements.sample('sample', guid=arcs.getUniqueID()) arcs.addElement(sample) geometer.register(sample, (mod2sample * m, 0 * m, 0 * m), (0, 0, 0)) # make detector array: adds elements to arcs & geometer self.makeDetectorSystem( arcs, geometer, packRecords, { 'long': longpackinfo, 'short1': shortpack1info, 'short2': shortpack2info, }) # set up guid registry arcs.guidRegistry.registerAll(arcs) # instrument global geometer instrumentGeometer = geometers.arcs( arcs, self.local_geometers, registry_coordinate_system='InstrumentScientist') arcs.geometer = instrumentGeometer # clean up temporary variables del self.local_geometers, self._instrument # save the xml description if not xmloutput: xmloutput = '%s.xml' % (os.path.basename(detconfigfile), ) from instrument.nixml import weave import os print('write arcs instrument to %s' % xmloutput) weave(arcs, open(xmloutput, 'w')) return arcs, instrumentGeometer
def test4(self): "InstrumentGeometer: instrument with layers" import instrument.elements as ies from .Geometer import Geometer from instrument.elements.Element import Element from instrument.elements.ElementContainer import ElementContainer instrument = ies.instrument("instrument") moderator = ies.moderator("moderator", 100., 100., 10.) instrument.addElement(moderator) monitor1 = ies.monitor("monitor1", 100., 100., 10.) instrument.addElement(monitor1) sample = ies.sample("sample", None) instrument.addElement(sample) detectorSystem = ElementContainer("detectorSystem") instrument.addElement(detectorSystem) local_geometers = [] detectorSystem_geometer = Geometer(detectorSystem) local_geometers.append(detectorSystem_geometer) #add 8X10 detectors by brute force for i in range(10): detpack = ElementContainer("detpack%s" % i, guid=instrument.getUniqueID()) detpack_geometer = Geometer(detpack) for j in range(8): name = "det%s" % j det = Element(name, guid=instrument.getUniqueID()) exec('det_%s_%s = det' % (i, j)) detpack.addElement(det) detpack_geometer.register(det, (j - 3.5, 0, 0), (0, 0, 0)) continue detpack_geometer.finishRegistration() detectorSystem.addElement(detpack) local_geometers.append(detpack_geometer) detectorSystem_geometer.register(detpack, (10 * i, 0, 0), (0, 0, 0)) continue detectorSystem_geometer.finishRegistration() instrument_geometer = Geometer(instrument) instrument_geometer.register(moderator, (0, 0, -5), (0, 0, 0)) instrument_geometer.register(sample, (0, 0, 0), (0, 0, 0)) instrument_geometer.register(detectorSystem, (0, 0, 0), (0, 0, 0)) instrument_geometer.register(monitor1, (0, 0, -3), (0, 0, 0)) instrument_geometer.finishRegistration() local_geometers.append(instrument_geometer) global_instrument_geometer = InstrumentGeometer( instrument, local_geometers) moderator_pos = global_instrument_geometer.position( "moderator") / meter self.assertAlmostEqual(moderator_pos[0], 0) self.assertAlmostEqual(moderator_pos[1], 0) self.assertAlmostEqual(moderator_pos[2], -5) detector00_pos = global_instrument_geometer.position( "detectorSystem/detpack0/det0") / meter self.assertAlmostEqual(detector00_pos[0], -3.5) self.assertAlmostEqual(detector00_pos[1], 0) self.assertAlmostEqual(detector00_pos[2], 0) detector00_dist2sample = global_instrument_geometer.distanceToSample( "detectorSystem/detpack0/det0") / meter self.assertAlmostEqual(3.5, detector00_dist2sample) return