def test_toString(self): """ Tests for method `toString`. """ version = Version.Version(1, 2, 3) stringRef = "1.2.3" versionString = version.toString() self.assertEquals(stringRef, versionString)
def getSimulationParametersReference(self, title): resultsParameters = ResultsParameters.ResultsParameters() if title == "AlMgBulk5keV_version_1_2_1": resultsParameters.version = Version.Version(1, 2, 1) resultsParameters.isComputeXrayCharacteristic = None resultsParameters.isComputeXrayBremsstrahlung = None resultsParameters.isComputeXrayPhirhoz = None elif title == "AlMgBulk5keV_version_1_4_1": resultsParameters.version = Version.Version(1, 4, 1) resultsParameters.isComputeXrayCharacteristic = True resultsParameters.isComputeXrayBremsstrahlung = True resultsParameters.isComputeXrayPhirhoz = True elif title == "AlMgBulk5keV_version_1_4_3": resultsParameters.version = Version.Version(1, 4, 3) resultsParameters.isComputeXrayCharacteristic = True resultsParameters.isComputeXrayBremsstrahlung = False resultsParameters.isComputeXrayPhirhoz = False resultsParameters.isComputeXraySimulatedSpectrum = False return resultsParameters
def test_fromString(self): """ Tests for method `fromString`. """ version = Version.Version(1, 2, 3) stringRef = "4.5.6" version.fromString(stringRef) versionString = version.toString() self.assertEquals(stringRef, versionString) self.assertEquals(4, version.major) self.assertEquals(5, version.minor) self.assertEquals(6, version.revision)
def test_writeLine(self): """ Tests for method `writeLine`. """ title = "AlMgBulk5keV_version_3_4_5" filepath = os.path.join(self.tempDataPath, "%s.sim" % (title)) logging.info(filepath) version = Version.Version(3, 4, 5) outputFile = open(filepath, 'w') version.writeLine(outputFile) outputFile.close() version = Version.Version(0, 0, 0) version.readFromFile(filepath) stringRef = "3.4.5" versionString = version.toString() self.assertEquals(stringRef, versionString) self.assertEquals(3, version.major) self.assertEquals(4, version.minor) self.assertEquals(5, version.revision)
def test_readFromFile_BadFile(self): """ Tests for method `readFromFile`. """ title = "AlMgBulk5keV_version_1_1_1" filepath = os.path.abspath(os.path.join(self.testDataPath, "inputs", "%s.snp" % (title))) version = Version.Version(0, 0, 0) version.readFromFile(filepath) stringRef = "1.1.1" versionString = version.toString() self.assertEquals(stringRef, versionString) self.assertEquals(1, version.major) self.assertEquals(1, version.minor) self.assertEquals(1, version.revision)
def test_write_1_4_1(self): """ Tests for method `write`. """ self.maxDiff = None simulationInputsRef = SimulationInputs.SimulationInputs() simulationInputsRef.version = copy.deepcopy(Version.VERSION_1_4_1) title = "AlMgBulk5keV_version_1_4_1" filepathReference = os.path.abspath( os.path.join(self.testDataPath, "inputs", "%s.sim" % (title))) simulationInputsRef.read(filepathReference) self.assertEquals(title, simulationInputsRef.title) filepath = os.path.join(self.tempDataPath, "%s.sim" % (title)) simulationInputs = SimulationInputs.SimulationInputs() simulationInputs.version = Version.Version(1, 4, 1) simulationInputs.write(filepath) self.assertEquals("%s.sam" % (title), simulationInputs.specimenFilename) self.assertEquals("%s.mdl" % (title), simulationInputs.modelFilename) self.assertEquals("%s.mic" % (title), simulationInputs.microsopeFilename) self.assertEquals("%s.par" % (title), simulationInputs.simulationParametersFilename) self.assertEquals("%s.mpp" % (title), simulationInputs.mapFilename) self.assertEquals("%s.rp" % (title), simulationInputs.resultParametersFilename) self.assertEquals(simulationInputsRef.version.major, simulationInputs.version.major) self.assertEquals(simulationInputsRef.version.minor, simulationInputs.version.minor) self.assertEquals(simulationInputsRef.version.revision, simulationInputs.version.revision) self.assertEquals(simulationInputsRef.version, simulationInputs.version) linesRef = open(filepathReference, 'r').readlines() lines = open(filepath, 'r').readlines() self.assertListEqual(linesRef, lines)
def getSpecimenReference(self, title): specimen = Specimen.Specimen() if title == "AuBC cyl": specimen.numberRegions = 4 specimen.version = Version.Version(1, 1, 1) region = Region.Region() region.numberElements = 1 element = Element.Element(6) region.elements.append(element) region.regionType = RegionType.REGION_TYPE_BOX parameters = [-10000000000.0, 10000000000.0, -10000000000.0, 10000000000.0, 0.0, 20000000000.0] region.regionDimensions = RegionDimensions.RegionDimensionsBox(parameters) specimen.regions.append(region) region = Region.Region() region.numberElements = 1 element = Element.Element(79) region.elements.append(element) region.regionType = RegionType.REGION_TYPE_BOX parameters = [0.0, 10000000000.0, -10000000000.0, 10000000000.0, 0.0, 20000000000.0] region.regionDimensions = RegionDimensions.RegionDimensionsBox(parameters) specimen.regions.append(region) region = Region.Region() region.numberElements = 1 element = Element.Element(5) region.elements.append(element) region.regionType = RegionType.REGION_TYPE_CYLINDER parameters = [-500.0, -500.0, 300.0, 0.0, 1.0, 0.35, 1000.0, 300.0] region.regionDimensions = RegionDimensions.RegionDimensionsCylinder(parameters) specimen.regions.append(region) region = Region.Region() region.numberElements = 1 element = Element.Element(5) region.elements.append(element) region.regionType = RegionType.REGION_TYPE_CYLINDER parameters = [500.0, 500.0, 300.0, 0.0, -1.0, 0.35, 1000.0, 300.0] region.regionDimensions = RegionDimensions.RegionDimensionsCylinder(parameters) specimen.regions.append(region) elif title == "BioRitchieNew111017": specimen.numberRegions = 7 specimen.version = Version.Version(1, 1, 1) region = Region.Region() region.numberElements = 3 element = Element.Element(6, 0.7) region.elements.append(element) element = Element.Element(8, 0.28) region.elements.append(element) element = Element.Element(17, 0.02) region.elements.append(element) region.regionMassDensity_g_cm3 = 1.14 region.regionType = RegionType.REGION_TYPE_BOX parameters = [-10000000000.0, 10000000000.0, -10000000000.0, 10000000000.0, 0.0, 20000000000.0] region.regionDimensions = RegionDimensions.RegionDimensionsBox(parameters) specimen.regions.append(region) region = Region.Region() region.numberElements = 2 element = Element.Element(8, 0.53) region.elements.append(element) element = Element.Element(14, 0.47) region.elements.append(element) region.regionMassDensity_g_cm3 = 2.2 region.regionType = RegionType.REGION_TYPE_CYLINDER parameters = [-20000.0, 0.0, 30000.0, 1.0, 0.0, 0.0, 40000.0, 30000.0] region.regionDimensions = RegionDimensions.RegionDimensionsCylinder(parameters) specimen.regions.append(region) region = Region.Region() region.numberElements = 3 element = Element.Element(6, 0.7) region.elements.append(element) element = Element.Element(8, 0.28) region.elements.append(element) element = Element.Element(17, 0.02) region.elements.append(element) region.regionMassDensity_g_cm3 = 1.14 region.regionType = RegionType.REGION_TYPE_CYLINDER parameters = [-20000.0, 0.0, 30000.0, 1.0, 0.0, 0.0, 40000.0, 29500.0] region.regionDimensions = RegionDimensions.RegionDimensionsCylinder(parameters) specimen.regions.append(region) region = Region.Region() region.numberElements = 7 region.elements.append(Element.Element(1, 0.071)) region.elements.append(Element.Element(6, 0.414)) region.elements.append(Element.Element(7, 0.168)) region.elements.append(Element.Element(8, 0.285)) region.elements.append(Element.Element(15, 0.036)) region.elements.append(Element.Element(16, 0.006)) region.elements.append(Element.Element(76, 0.02)) region.regionMassDensity_g_cm3 = 1.32 region.regionType = RegionType.REGION_TYPE_SPHERE parameters = [12000.0, 10000.0, 10000.0, 8000.0] region.regionDimensions = RegionDimensions.RegionDimensionsSphere(parameters) specimen.regions.append(region) region = Region.Region() region.numberElements = 9 region.elements.append(Element.Element(1, 0.11)) region.elements.append(Element.Element(6, 0.49)) region.elements.append(Element.Element(7, 0.12)) region.elements.append(Element.Element(8, 0.25)) region.elements.append(Element.Element(12, 0.003)) region.elements.append(Element.Element(15, 0.003)) region.elements.append(Element.Element(16, 0.003)) region.elements.append(Element.Element(25, 0.001)) region.elements.append(Element.Element(76, 0.02)) region.regionMassDensity_g_cm3 = 1.24 region.regionType = RegionType.REGION_TYPE_SPHERE parameters = [-10000.0, 0.0, 20000.0, 15000.0] region.regionDimensions = RegionDimensions.RegionDimensionsSphere(parameters) specimen.regions.append(region) region = Region.Region() region.numberElements = 9 region.elements.append(Element.Element(1, 0.11)) region.elements.append(Element.Element(6, 0.49)) region.elements.append(Element.Element(7, 0.12)) region.elements.append(Element.Element(8, 0.25)) region.elements.append(Element.Element(12, 0.003)) region.elements.append(Element.Element(15, 0.003)) region.elements.append(Element.Element(16, 0.003)) region.elements.append(Element.Element(25, 0.001)) region.elements.append(Element.Element(76, 0.02)) region.regionMassDensity_g_cm3 = 1.24 region.regionType = RegionType.REGION_TYPE_SPHERE parameters = [10000.0, -5000.0, 25000.0, 6000.0] region.regionDimensions = RegionDimensions.RegionDimensionsSphere(parameters) specimen.regions.append(region) region = Region.Region() region.numberElements = 7 region.elements.append(Element.Element(1, 0.077)) region.elements.append(Element.Element(6, 0.497)) region.elements.append(Element.Element(7, 0.11)) region.elements.append(Element.Element(8, 0.259)) region.elements.append(Element.Element(15, 0.031)) region.elements.append(Element.Element(16, 0.006)) region.elements.append(Element.Element(76, 0.02)) region.regionMassDensity_g_cm3 = 1.18 region.regionType = RegionType.REGION_TYPE_SPHERE parameters = [-23000.0, 4000.0, 33500.0, 2000.0] region.regionDimensions = RegionDimensions.RegionDimensionsSphere(parameters) specimen.regions.append(region) specimen._shortHeader = True elif title == "Bug Al Zr Sphere": specimen.numberRegions = 2 specimen.version = Version.Version(1, 1, 1) region = Region.Region() region.numberElements = 1 element = Element.Element(13) region.elements.append(element) region.regionType = RegionType.REGION_TYPE_BOX parameters = [-10000000000.0, 10000000000.0, -10000000000.0, 10000000000.0, 0.0, 1000.0] region.regionDimensions = RegionDimensions.RegionDimensionsBox(parameters) specimen.regions.append(region) region = Region.Region() region.numberElements = 1 element = Element.Element(40) region.elements.append(element) region.regionType = RegionType.REGION_TYPE_SPHERE parameters = [0.0, 0.0, 500.0, 499.9] region.regionDimensions = RegionDimensions.RegionDimensionsSphere(parameters) specimen.regions.append(region) elif title == "Mg2SiAlCube3kev": specimen.numberRegions = 2 specimen.version = Version.Version(1, 1, 1) region = Region.Region() region.numberElements = 2 element = Element.Element(12, 0.5) region.elements.append(element) element = Element.Element(13, 0.5) region.elements.append(element) region.regionType = RegionType.REGION_TYPE_BOX parameters = [-10000000000.0, 10000000000.0, -10000000000.0, 10000000000.0, 0.0, 20000000000.0] region.regionDimensions = RegionDimensions.RegionDimensionsBox(parameters) specimen.regions.append(region) region = Region.Region() region.numberElements = 1 element = Element.Element(6) region.elements.append(element) region.regionType = RegionType.REGION_TYPE_BOX parameters = (-10.0, 10.0, -10.0, 10.0, 0.0, 20.0) region.regionDimensions = RegionDimensions.RegionDimensionsBox(parameters) specimen.regions.append(region) elif title == "AlMgBulk5keV_version_1_1_1": specimen.numberRegions = 3 specimen.version = Version.Version(1, 1, 1) region = Region.Region() region.numberElements = 2 element = Element.Element(12, 0.5) region.elements.append(element) element = Element.Element(13, 0.5) region.elements.append(element) region.regionType = RegionType.REGION_TYPE_BOX parameters = [-10000000000.0, 10000000000.0, -10000000000.0, 10000000000.0, 0.0, 20000000000.0] region.regionDimensions = RegionDimensions.RegionDimensionsBox(parameters) specimen.regions.append(region) region = Region.Region() region.numberElements = 1 element = Element.Element(6) region.elements.append(element) region.regionType = RegionType.REGION_TYPE_CYLINDER parameters = [0.0, -5000.0, 0.0, 0.0, 1.0, -0.7, 10000.0, 100.0] region.regionDimensions = RegionDimensions.RegionDimensionsCylinder(parameters) specimen.regions.append(region) region = Region.Region() region.numberElements = 1 element = Element.Element(79) region.elements.append(element) region.regionType = RegionType.REGION_TYPE_SPHERE parameters = [0.0, 0.0, 101.0, 100.0] region.regionDimensions = RegionDimensions.RegionDimensionsSphere(parameters) specimen.regions.append(region) elif title == "AlMgBulk5keV_version_1_2_0": specimen.numberRegions = 3 specimen.version = Version.Version(1, 2, 0) region = Region.Region() region.numberElements = 2 element = Element.Element(14, 0.4) region.elements.append(element) element = Element.Element(15, 0.6) region.elements.append(element) region.regionMassDensity_g_cm3 = 23.0 region.regionType = RegionType.REGION_TYPE_BOX parameters = [-2000000000.0, 6000000000.0, -4000000000.0, 5000000000.0, 0.8, 70000.0] region.regionDimensions = RegionDimensions.RegionDimensionsBox(parameters) specimen.regions.append(region) region = Region.Region() region.numberElements = 1 element = Element.Element(7) region.elements.append(element) region.regionType = RegionType.REGION_TYPE_CYLINDER parameters = [0.4, -8000.0, 0.9, 0.1, 0.6, -0.8, 50000.0, 700.0] region.regionDimensions = RegionDimensions.RegionDimensionsCylinder(parameters) specimen.regions.append(region) region = Region.Region() region.numberElements = 1 element = Element.Element(56) region.elements.append(element) region.regionType = RegionType.REGION_TYPE_SPHERE parameters = [0.5, 0.6, 102.0, 101.0] region.regionDimensions = RegionDimensions.RegionDimensionsSphere(parameters) specimen.regions.append(region) elif title == "AlMgBulk5keV_version_1_2_1": specimen.numberRegions = 3 specimen.version = Version.Version(1, 2, 1) region = Region.Region() region.numberElements = 2 element = Element.Element(14, 0.4) region.elements.append(element) element = Element.Element(15, 0.6) region.elements.append(element) region.regionMassDensity_g_cm3 = 23.0 region.regionType = RegionType.REGION_TYPE_BOX parameters = [-2000000000.0, 6000000000.0, -4000000000.0, 5000000000.0, 0.8, 70000.0] region.regionDimensions = RegionDimensions.RegionDimensionsBox(parameters) specimen.regions.append(region) region = Region.Region() region.numberElements = 1 element = Element.Element(7) region.elements.append(element) region.regionType = RegionType.REGION_TYPE_CYLINDER parameters = [0.4, -8000.0, 0.9, 0.1, 0.6, -0.8, 50000.0, 700.0] region.regionDimensions = RegionDimensions.RegionDimensionsCylinder(parameters) specimen.regions.append(region) region = Region.Region() region.numberElements = 1 element = Element.Element(56) region.elements.append(element) region.regionType = RegionType.REGION_TYPE_SPHERE parameters = [0.5, 0.6, 102.0, 101.0] region.regionDimensions = RegionDimensions.RegionDimensionsSphere(parameters) specimen.regions.append(region) elif title == "AlMgBulk5keV_version_1_4_1": specimen.numberRegions = 3 specimen.version = Version.Version(1, 4, 1) region = Region.Region() region.numberElements = 2 element = Element.Element(14, 0.4) region.elements.append(element) element = Element.Element(15, 0.6) region.elements.append(element) region.regionMassDensity_g_cm3 = 23.0 region.regionType = RegionType.REGION_TYPE_BOX parameters = [-2000000000.0, 6000000000.0, -4000000000.0, 5000000000.0, 0.8, 70000.0] region.regionDimensions = RegionDimensions.RegionDimensionsBox(parameters) specimen.regions.append(region) region = Region.Region() region.numberElements = 1 element = Element.Element(7) region.elements.append(element) region.regionType = RegionType.REGION_TYPE_CYLINDER parameters = [0.4, -8000.0, 0.9, 0.1, 0.6, -0.8, 50000.0, 700.0] region.regionDimensions = RegionDimensions.RegionDimensionsCylinder(parameters) specimen.regions.append(region) region = Region.Region() region.numberElements = 1 element = Element.Element(56) region.elements.append(element) region.regionType = RegionType.REGION_TYPE_SPHERE parameters = [0.5, 0.6, 102.0, 101.0] region.regionDimensions = RegionDimensions.RegionDimensionsSphere(parameters) specimen.regions.append(region) return specimen
def getSimulationParametersReference(self, title): simulationParameters = SimulationParameters.SimulationParameters() if title == "AuBC cyl": baseFilenameRef = r"Results\%s Low Count" % (title) simulationParameters.baseFilename = baseFilenameRef simulationParameters.numberElectrons = 20 simulationParameters.numberPhotons = 500 simulationParameters.numberWindows = 32 simulationParameters.numberFilmsX = 64 simulationParameters.numberFilmsY = 64 simulationParameters.numberFilmsZ = 64 simulationParameters.numberChannels = 1024 simulationParameters.spectrumInterpolationModel = 2 simulationParameters.voxelSimplification = None elif title == "BioRitchieNew111017": baseFilenameRef = r"Results\Ritchie60" simulationParameters.baseFilename = baseFilenameRef simulationParameters.numberElectrons = 50 simulationParameters.numberPhotons = 10000 simulationParameters.numberWindows = 64 simulationParameters.numberFilmsX = 128 simulationParameters.numberFilmsY = 128 simulationParameters.numberFilmsZ = 128 simulationParameters.numberChannels = 1024 simulationParameters.spectrumInterpolationModel = 2 simulationParameters.voxelSimplification = 1 elif title == "Bug Al Zr Sphere": baseFilenameRef = r"Results\McXRay" simulationParameters.baseFilename = baseFilenameRef simulationParameters.numberElectrons = 1000 simulationParameters.numberPhotons = 10000 simulationParameters.numberWindows = 64 simulationParameters.numberFilmsX = 128 simulationParameters.numberFilmsY = 128 simulationParameters.numberFilmsZ = 128 simulationParameters.numberChannels = 1024 simulationParameters.spectrumInterpolationModel = 2 simulationParameters.voxelSimplification = None elif title == "Mg2SiAlCube3kev": baseFilenameRef = r"Results\%s" % (title) simulationParameters.baseFilename = baseFilenameRef simulationParameters.numberElectrons = 30 simulationParameters.numberPhotons = 1000 simulationParameters.numberWindows = 32 simulationParameters.numberFilmsX = 64 simulationParameters.numberFilmsY = 64 simulationParameters.numberFilmsZ = 64 simulationParameters.numberChannels = 1024 simulationParameters.spectrumInterpolationModel = 2 simulationParameters.voxelSimplification = None elif title == "AlMgBulk5keV_version_1_1_1": baseFilenameRef = r"Results\%s" % ("AlMgBulk5keV") simulationParameters.baseFilename = baseFilenameRef simulationParameters.version = Version.Version(1, 1, 1) simulationParameters.numberElectrons = 1000 simulationParameters.numberPhotons = 127678 simulationParameters.numberWindows = 64 simulationParameters.numberFilmsX = 128 simulationParameters.numberFilmsY = 128 simulationParameters.numberFilmsZ = 128 simulationParameters.numberChannels = 1024 simulationParameters.spectrumInterpolationModel = 2 simulationParameters.voxelSimplification = None elif title == "AlMgBulk5keV_version_1_2_0": baseFilenameRef = r"Results\%s" % ("AlMgBulk5keV_1_2_0") simulationParameters.baseFilename = baseFilenameRef simulationParameters.version = Version.Version(1, 2, 0) simulationParameters.numberElectrons = 10000 simulationParameters.numberPhotons = 1000 simulationParameters.numberWindows = 128 simulationParameters.numberFilmsX = 64 simulationParameters.numberFilmsY = 66 simulationParameters.numberFilmsZ = 70 simulationParameters.energyChannelWidth_eV = 5 simulationParameters.spectrumInterpolationModel = 1 simulationParameters.voxelSimplification = None elif title == "AlMgBulk5keV_version_1_2_1": baseFilenameRef = r"Results\%s" % ("AlMgBulk5keV_1_2_1") simulationParameters.baseFilename = baseFilenameRef simulationParameters.version = Version.Version(1, 2, 1) simulationParameters.numberElectrons = 10000 simulationParameters.numberPhotons = 1000 simulationParameters.numberWindows = 128 simulationParameters.numberFilmsX = 64 simulationParameters.numberFilmsY = 66 simulationParameters.numberFilmsZ = 70 simulationParameters.energyChannelWidth_eV = 5 simulationParameters.spectrumInterpolationModel = 1 simulationParameters.voxelSimplification = None elif title == "AlMgBulk5keV_version_1_4_1": baseFilenameRef = r"Results\%s" % ("AlMgBulk5keV_1_4_1") simulationParameters.baseFilename = baseFilenameRef simulationParameters.version = Version.Version(1, 4, 1) simulationParameters.numberElectrons = 10000 simulationParameters.numberPhotons = 1000 simulationParameters.numberWindows = 128 simulationParameters.numberFilmsX = 64 simulationParameters.numberFilmsY = 66 simulationParameters.numberFilmsZ = 70 simulationParameters.energyChannelWidth_eV = 5 simulationParameters.spectrumInterpolationModel = 1 simulationParameters.voxelSimplification = None elif title == "AlMgBulk5keV_version_1_4_4": baseFilenameRef = r"Results\%s" % ("AlMgBulk5keV_1_4_4") simulationParameters.baseFilename = baseFilenameRef simulationParameters.version = Version.Version(1, 4, 4) simulationParameters.numberElectrons = 10000 simulationParameters.numberPhotons = 1000 simulationParameters.numberWindows = 128 simulationParameters.numberFilmsX = 64 simulationParameters.numberFilmsY = 66 simulationParameters.numberFilmsZ = 70 simulationParameters.energyChannelWidth_eV = 5 simulationParameters.spectrumInterpolationModel = 1 simulationParameters.voxelSimplification = None simulationParameters.elasticCrossSectionScalingFactor = 1.3 simulationParameters.energyLossScalingFactor = 0.7 return simulationParameters