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
Ejemplo n.º 2
0
    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
Ejemplo n.º 3
0
    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
Ejemplo n.º 4
0
    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
Ejemplo n.º 5
0
    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
Ejemplo n.º 7
0
    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