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 makeMonitors(self, instrument, geometer, monitorRecords): i = 0 for record in monitorRecords: monid = record['id'] dist = record['distanceToModerator'] position = [dist, 0 * mm, 0 * mm] name = "monitor%s" % i debug.log("monitor position: %s, monitor name: '%s', id: %s" % (position, name, monid)) dimensions = record['dimensions'] width, height, thickness = dimensions monitor = elements.monitor(name, width, height, thickness, guid=instrument.getUniqueID()) instrument.addElement(monitor) i += 1 geometer.register(monitor, position, orientation=[0.0, 0.0, 0.0]) continue return
def makeMonitors(self, instrument, geometer, monitorRecords): i = 0 for record in monitorRecords: monid = record['id'] dist2Samp = record['distance']['value'] #unit: mm position = [-dist2Samp * mm, 0 * mm, 0 * mm] name = "monitor%s" % i debug.log("monitor position: %s, monitor name: '%s', id: %s" % (position, name, monid)) geometry = record['geometry'] width = height = geometry['radius'] * mm thickness = geometry['thickness'] * mm monitor = elements.monitor(name, width, height, thickness, guid=instrument.getUniqueID()) instrument.addElement(monitor) i += 1 geometer.register(monitor, position, orientation=[0.0, 0.0, 0.0]) continue return
def makeMonitors(self, instrument, geometer): # this is not used yet i = 1 for position, name, monid, monSize in zip(monitorPositions, monitorNames, monitorIDs, monSizes): debug.log("monitor position: %s, monitor name: '%s', id: %s" % (position, name, monid)) monID = instrument.getUniqueID() thickness, width, height = monSize monitor = elements.monitor(name, width, height, thickness, guid=monID, id=monid, type="watchful") instrument.addElement(monitor) i += 1 geometer.register(monitor, position, orientation=[0.0, 0.0, 0.0]) continue 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