def test5(self): ''' GlobalGeometer: request_coordinate_system ''' import instrument.elements as ies instrument = ies.instrument( "instrument" ) moderator = ies.moderator( "moderator", 100., 100., 10. ) instrument.addElement( moderator ) from .CoordinateSystem import McStasCS, InstrumentScientistCS instrumentGeomter = GlobalGeometer( instrument, registry_coordinate_system = InstrumentScientistCS, request_coordinate_system = McStasCS ) instrumentGeomter.register( moderator, (1,2,3), (0,0,0) ) instrumentGeomter.finishRegistration() pos = instrumentGeomter.position( moderator ) / meter self.assertAlmostEqual( pos[0], 2 ) self.assertAlmostEqual( pos[1], 3 ) self.assertAlmostEqual( pos[2], 1 ) return
def test3(self): "Geometer: instrument with one moderator and monitors given relative position" import instrument.elements as ies instrument = ies.instrument("instrument") moderator = ies.moderator('moderator', 100., 100., 10.) instrument.addElement(moderator) monitor1 = ies.monitor('monitor1', 100., 100., 10.) instrument.addElement(monitor1) monitor2 = ies.monitor('monitor2', 100., 100., 10.) instrument.addElement(monitor2) geometer = Geometer(instrument) geometer.register(moderator, (0, 0, -5), (0, 0, 0)) geometer.register(monitor1, (0, 0, -3), (0, 0, 0)) geometer.register(monitor2, (0, 0, 2), (0, 0, 0), relative=monitor1) geometer.finishRegistration() monitor1pos = geometer.position(monitor1) / meter self.assertAlmostEqual(monitor1pos[0], 0) self.assertAlmostEqual(monitor1pos[1], 0) self.assertAlmostEqual(monitor1pos[2], -3) monitor2pos = geometer.position(monitor2) / meter self.assertAlmostEqual(monitor2pos[0], 0) self.assertAlmostEqual(monitor2pos[1], 0) self.assertAlmostEqual(monitor2pos[2], -1) return
def test2(self): "Geometer: instrument with one moderator given abs position" import instrument.elements as ies instrument = ies.instrument("instrument") moderator = ies.moderator('moderator', 100., 100., 10.) instrument.addElement(moderator) geometer = Geometer(instrument) geometer.register(moderator, (0, 0, 0), (0, 0, 0)) geometer.finishRegistration() return
def makeModerator( self, instrument, geometer): #hard code moderator. this should be ok because #it should not change modXSize = 100.0*mm; modYSize = 100.0*mm; modZSize = 100.0*mm position = [0* mm, 0*mm, 0*mm] orientation = [0.0, 0.0, 0.0] modID = instrument.getUniqueID() moderator = elements.moderator( 'moderator', modXSize, modYSize, modZSize, type = "non-existant", guid = modID, ) instrument.addElement( moderator ) geometer.register( moderator, position, orientation) return
def makeModerator(self, instrument, geometer): modXSize = 100.0 * mm modYSize = 100.0 * mm modZSize = 100.0 * mm position = [-self.distMod2Sample, 0 * mm, 0 * mm] orientation = [0.0, 0.0, 0.0] modID = instrument.getUniqueID() moderator = elements.moderator( 'moderator', modXSize, modYSize, modZSize, type="non-existant", guid=modID, ) geometer.register(moderator, position, orientation) instrument.addElement(moderator) return
def makeModerator(self, instrument, geometer): modXSize = 100.0 modYSize = 100.0 modZSize = 100.0 modID = instrument.getUniqueID() moderator = elements.moderator( 'moderator', modXSize, modYSize, modZSize, type="non-existant", guid=modID, ) instrument.addElement(moderator) geometer.register(moderator, 0.0, 0.00000001 * mm) return
def test2(self): "GlobalGeometer: instrument with one moderator given abs position" import instrument.elements as ies from .Geometer import Geometer instrument = ies.instrument( "instrument" ) moderator = ies.moderator( "moderator", 100., 100., 10. ) instrument.addElement( moderator ) instrument_geometer = Geometer( instrument ) instrument_geometer.register( moderator, (0,0,-5), (0,0,0) ) instrument_geometer.finishRegistration() local_geometers = [ instrument_geometer ] global_geometer = GlobalGeometer( instrument, local_geometers ) mod_pos = global_geometer.position( moderator ) / meter self.assertAlmostEqual( mod_pos[0], 0 ) self.assertAlmostEqual( mod_pos[1], 0 ) self.assertAlmostEqual( mod_pos[2], -5 ) return
def test4a(self): '''GlobalGeometer: instrument with very simple layers. local geometers are created automatically. ''' import instrument.elements as ies instrument = ies.instrument( "instrument" ) moderator = ies.moderator( "moderator", 100., 100., 10. ) instrument.addElement( moderator ) from instrument.elements.Element import Element from instrument.elements.ElementContainer import ElementContainer detectorSystem = ElementContainer( 'detectorSystem' ) instrument.addElement( detectorSystem ) detpack = ElementContainer( 'detpack', guid = instrument.getUniqueID() ) detectorSystem.addElement( detpack ) detector = Element( 'detector', guid = instrument.getUniqueID() ) detpack.addElement( detector ) instrumentGeomter = GlobalGeometer( instrument ) instrumentGeomter.register( moderator, (0,0,0), (0,0,0) ) instrumentGeomter.register( detectorSystem, (0,0,10), (0,0,0) ) instrumentGeomter.register( detpack, (0,0,0), (0,0,0), relative = detectorSystem ) instrumentGeomter.register( detector, (0,0,0), (0,0,0), relative = detpack ) instrumentGeomter.finishRegistration() detposition = instrumentGeomter.position( 'detectorSystem/detpack/detector' ) / meter self.assertAlmostEqual( detposition[0], 0 ) self.assertAlmostEqual( detposition[1], 0 ) self.assertAlmostEqual( detposition[2], 10 ) return
def test3(self): "GlobalGeometer: instrument with one moderator and monitors given relative position" import instrument.elements as ies from .Geometer import Geometer instrument = ies.instrument( "instrument" ) moderator = ies.moderator( "moderator", 100., 100., 10. ) instrument.addElement( moderator ) monitor1 = ies.monitor( "monitor1", 100., 100., 10. ) instrument.addElement( monitor1 ) monitor2 = ies.monitor( "monitor2", 100., 100., 10. ) instrument.addElement( monitor2 ) instrument_geometer = Geometer( instrument ) instrument_geometer.register( moderator, (0,0,-5), (0,0,0)) instrument_geometer.register( monitor1, (0,0,-3), (0,0,0)) instrument_geometer.register( monitor2, (0,0,2), (0,0,0), relative = monitor1 ) instrument_geometer.finishRegistration() local_geometers = [ instrument_geometer ] global_geometer = GlobalGeometer( instrument, local_geometers ) moderator_pos = global_geometer.position( moderator ) / meter self.assertAlmostEqual( moderator_pos[0], 0 ) self.assertAlmostEqual( moderator_pos[1], 0 ) self.assertAlmostEqual( moderator_pos[2], -5 ) monitor1_pos = global_geometer.position( monitor1 ) / meter self.assertAlmostEqual( monitor1_pos[0], 0 ) self.assertAlmostEqual( monitor1_pos[1], 0 ) self.assertAlmostEqual( monitor1_pos[2], -3 ) monitor2_pos = global_geometer.position( monitor2 ) / meter self.assertAlmostEqual( monitor2_pos[0], 0 ) self.assertAlmostEqual( monitor2_pos[1], 0 ) self.assertAlmostEqual( monitor2_pos[2], -1 ) return
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
def test4b(self): '''GlobalGeometer: use elment identifier instead of element itself. local geometers are created automatically. ''' import instrument.elements as ies instrument = ies.instrument( "instrument" ) moderator = ies.moderator( "moderator", 100., 100., 10. ) instrument.addElement( moderator ) from instrument.elements.Element import Element from instrument.elements.ElementContainer import ElementContainer detectorSystem = ElementContainer( 'detectorSystem' ) instrument.addElement( detectorSystem ) detpack = ElementContainer( 'detpack', guid = instrument.getUniqueID() ) detectorSystem.addElement( detpack ) detector = Element( 'detector', guid = instrument.getUniqueID() ) detpack.addElement( detector ) from instrument.elements.Copy import Copy detpack2 = Copy( 'detpack2', reference= detpack.guid(), guid=instrument.getUniqueID() ) detectorSystem.addElement( detpack2 ) instrument.guidRegistry.registerAll( instrument ) instrumentGeomter = GlobalGeometer( instrument ) instrumentGeomter.register( moderator, (0,0,0), (0,0,0) ) instrumentGeomter.register( detectorSystem, (0,0,10), (0,0,0) ) instrumentGeomter.register( detpack, (0,0,0), (0,0,0), relative = detectorSystem ) instrumentGeomter.register( detector, (0,0,0), (0,0,0), relative = detpack ) instrumentGeomter.register( detpack2, (0,0,1), (0,0,0), relative = detectorSystem ) instrumentGeomter.finishRegistration() detposition = instrumentGeomter.position( 'detectorSystem/detpack/detector' ) / meter self.assertAlmostEqual( detposition[0], 0 ) self.assertAlmostEqual( detposition[1], 0 ) self.assertAlmostEqual( detposition[2], 10 ) self.assertRaises( RuntimeError, instrumentGeomter.position, 'detectorSystem/detpack/detector/abc' ) detposition = instrumentGeomter.position( 'detectorSystem/detpack2/detector' ) / meter self.assertAlmostEqual( detposition[0], 0 ) self.assertAlmostEqual( detposition[1], 0 ) self.assertAlmostEqual( detposition[2], 11 ) detposition = instrumentGeomter.position( (1,1,0) ) / meter self.assertAlmostEqual( detposition[0], 0 ) self.assertAlmostEqual( detposition[1], 0 ) self.assertAlmostEqual( detposition[2], 11 ) return