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
Пример #2
0
    def _makePack(self, name, id, instrument, pressure, npixels, radius,
                  height, gap):
        '''make a unique 8-pack
        
all physical parameters must have units attached.
'''
        from .ARCS.packSize import getSize
        size = getSize(radius, height, gap)
        shape = shapes.block(**size)
        pack = elements.detectorPack(name,
                                     shape=shape,
                                     guid=instrument.getUniqueID(),
                                     id=id)
        packGeometer = geometers.geometer(pack)
        self.local_geometers.append(packGeometer)

        det0 = self._makeDetector('det0', 0, instrument, pressure, npixels,
                                  radius, height)
        pack.addElement(det0)

        #180 degree is an artifact of current limitation of simulation
        #package.
        from .ARCS.tubePositions import getPositions
        positions = getPositions(radius, gap)
        packGeometer.register(det0, (0 * m, positions[0], 0 * m), (0, 180, 0))

        for i in range(1, 8):
            det = elements.copy('det%s' % i,
                                det0.guid(),
                                guid=instrument.getUniqueID())
            pack.addElement(det)
            packGeometer.register(det, (0 * m, positions[i], 0 * m),
                                  (0, 180, 0))
            continue
        return pack
Пример #3
0
    def makeDetectorSystem( self, instrument, geometer, packs):

        #detector system
        detSystem = elements.detectorSystem(
            'detSystem', guid = instrument.getUniqueID())
        instrument.addElement( detSystem )
        geometer.register( detSystem, (0*m,0*m,0*m), (0,0,0),
                           relative = instrument.getSample() )
        
        detSystemGeometer = geometers.geometer(
            detSystem, registry_coordinate_system = 'InstrumentScientist' )
        self.local_geometers.append( detSystemGeometer )
        
        from numpy import array
        
        cache = {}
        for packinfo in packs:
            
            rotation = packinfo.orientation
            translation = tuple(array( packinfo.position )*mm)
            
            packID = packinfo.id
            name = 'pack%s' % packID
            
            packtype = packType(packinfo)
            pack = cache.get(packtype)

            if pack is None:
                pressure, ntubes, height, radius, gap, npixels = \
                    packtype
                
                assert ntubes == 8, "not implemented"
                
                pack = cache[packtype] = self._makePack(
                    name, packID, instrument,
                    pressure*atm, npixels, radius*mm, height*mm, gap*mm)
                
            else:
                copy = elements.copy(
                    'pack%s' % packID, pack.guid(),
                    id = packID,
                    guid = instrument.getUniqueID() )
                pack = copy
                pass
            
            detSystem.addElement( pack )
            detSystemGeometer.register(
                pack, translation, rotation )

            continue

        return # detArray # sequoia, geometer
    def test(self):
        """instrument.elements.DetectorVisitor
        """
        #create an instrument with layers and copies
        i = ie.instrument('test')
        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)

        counter = DetectorCounter()
        self.assertEqual(counter.render(i), 4)
        return
Пример #5
0
    def makeDetectorSystem(self, instrument, geometer, packRecords,
                           packInfoDict):

        #detector system
        detSystem = elements.detectorSystem('detSystem',
                                            guid=instrument.getUniqueID())
        instrument.addElement(detSystem)
        geometer.register(detSystem, (0 * m, 0 * m, 0 * m), (0, 0, 0),
                          relative=instrument.getSample())

        detSystemGeometer = geometers.geometer(
            detSystem, registry_coordinate_system='InstrumentScientist')
        self.local_geometers.append(detSystemGeometer)

        from numpy import array

        cache = {}
        for record in packRecords:

            packID, type, position, orientation = record

            rotation = 0, 0, 90 + orientation[2]
            translation = tuple(array(position) * mm)

            name = 'pack%s' % packID

            pack = cache.get(type)

            if pack is None:
                pressure, npixels, radius, height, gap = \
                          packInfoDict[ type ]
                pack = cache[type] = self._makePack(name, packID, instrument,
                                                    pressure, npixels, radius,
                                                    height, gap)

            else:
                copy = elements.copy('pack%s' % packID,
                                     pack.guid(),
                                     id=packID,
                                     guid=instrument.getUniqueID())
                pack = copy
                pass

            detSystem.addElement(pack)
            detSystemGeometer.register(pack, translation, rotation)

            continue

        return  # detArray # arcs, geometer
 def makeDetector(self, name, id, instrument, pressure, npixels, radius,
                  height):
     key = pressure, npixels, radius, height
     detectorModules = self._getDetectorModules()
     for key1 in detectorModules.keys():
         if _equal(key, key1):
             detM = detectorModules[key1]
             debug.log('detM=%s' % detM)
             new = elements.copy(name,
                                 detM.guid(),
                                 id=id,
                                 guid=instrument.getUniqueID())
             return new
         continue
     detector = self._makeDetector(name, id, instrument, pressure, npixels,
                                   radius, height)
     self._detectorModules[key] = detector
     return detector
Пример #7
0
def create(name,
           id,
           pressure,
           radius,
           height,
           npixels,
           pixelSolidAngle,
           guidGenerator,
           detectorFactory=None,
           pixelFactory=None,
           geometerFactory=None):
    '''make a unique detector module

all physical parameters must have units attached.
'''
    if detectorFactory is None:
        from instrument.elements import detector as detectorFactory
        pass

    if pixelFactory is None:
        from instrument.elements import pixel as pixelFactory
        pass

    if geometerFactory is None:
        from instrument.geometers import geometer as geometerFactory
        pass

    guid = guidGenerator.getUniqueID()

    # create detector itself
    detector = detectorFactory(
        name,
        radius=radius,
        height=height,
        pressure=pressure,
        guid=guid,
        id=id,
    )

    # geometer for pixels in the detector
    detectorGeometer = geometerFactory(detector)

    # now pixels
    #  first pixel
    #   pixel height
    pixelht = height / npixels
    # pixel must from down to up. this is a requirement from
    # instrument simulation
    bottom = (-(npixels) / 2.0 + 0.5) * pixelht
    pixel0 = pixelFactory(
        'pixel0',
        radius=radius,
        height=pixelht,
        solidAngle=pixelSolidAngle,
        guid=guidGenerator.getUniqueID(),
    )
    detector.addElement(pixel0)
    detectorGeometer.register(pixel0, (0 * pixelht, 0 * pixelht, bottom),
                              (0, 0, 0))

    #  all other pixels are copies of the first pixel
    from instrument.elements import copy
    for i in range(1, npixels):
        pixel = copy('pixel%s' % i,
                     reference=pixel0.guid(),
                     guid=guidGenerator.getUniqueID())
        z = bottom + i * pixelht
        detector.addElement(pixel)
        detectorGeometer.register(pixel, (0 * pixelht, 0 * pixelht, z),
                                  (0, 0, 0))
        continue

    return detector, detectorGeometer