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 test2(self): """ instrument.nixml.weave """ from instrument.nixml import weave, parse_file instrument = parse_file('test.xml') weave(instrument) 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, 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