本文整理汇总了Python中PyMca5.PyMcaPhysics.Elements类的典型用法代码示例。如果您正苦于以下问题:Python Elements类的具体用法?Python Elements怎么用?Python Elements使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Elements类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __tableSlot
def __tableSlot(self,row, col):
if self.__fillingValues:
return
item = self.__table.item(row, col)
if item is not None:
_logger.debug("table item is None")
qstring = item.text()
else:
qstring = ""
if col == 0:
compound = str(qstring)
if Elements.isValidFormula(compound):
pass
else:
matkey = Elements.getMaterialKey(compound)
if matkey is not None:
item.setText(matkey)
else:
msg=qt.QMessageBox(self.__table)
msg.setIcon(qt.QMessageBox.Critical)
msg.setText("Invalid Formula %s" % compound)
msg.exec_()
self.__table.setCurrentCell(row, col)
return
else:
try:
float(str(qstring))
except:
msg=qt.QMessageBox(self.__table)
msg.setIcon(qt.QMessageBox.Critical)
msg.setText("Invalid Float")
msg.exec_()
self.__table.setCurrentCell(row, col)
return
self._updateCurrent()
示例2: importFile
def importFile(self, filename):
if not os.path.exists(filename):
qt.QMessageBox.critical(self, "ERROR opening file",
"File %s not found" % filename)
return 1
Elements.Material.read(filename)
error = 0
for material in list(Elements.Material.keys()):
keys = list(Elements.Material[material].keys())
compoundList = []
if "CompoundList" in keys:
compoundList = Elements.Material[material]["CompoundList"]
if "CompoundFraction" in keys:
compoundFraction = Elements.Material[material]["CompoundFraction"]
if (compoundList == []) or (compoundFraction == []):
#no message?
error = 1
del Elements.Material[material]
continue
#I should try to calculate the attenuation at one energy ...
try:
Elements.getMaterialMassAttenuationCoefficients(compoundList,
compoundFraction,
energy = 10.0)
except:
#no message?
error = 1
del Elements.Material[material]
if _logger.getEffectiveLevel() == logging.DEBUG:
raise
continue
return error
示例3: __tableSlot2
def __tableSlot2(self,row, col):
if self.__fillingValues:return
if self.__lastRow is None:
self.__lastRow = row
if self.__lastColumn is None:
self.__lastColumn = col
item = self.__table.item(self.__lastRow,
self.__lastColumn)
if item is None:
item = qt.QTableWidgetItem("",qt.QTableWidgetItem.Type)
self.__table.setItem(self.__lastRow,
self.__lastColumn,
item)
qstring = item.text()
if self.__lastColumn == 0:
compound = str(qstring)
if Elements.isValidFormula(compound):
pass
else:
matkey = Elements.getMaterialKey(compound)
if matkey is not None:
item = self.__table.item(self.__lastRow,
self.__lastColumn)
if item is None:
item = qt.QTableWidgetItem(matkey,
qt.QTableWidgetItem.Type)
self.__table.setItem(self.__lastRow,
self.__lastColumn,
item)
else:
item.setText(matkey)
else:
msg=qt.QMessageBox(self.__table)
msg.setIcon(qt.QMessageBox.Critical)
msg.setText("Invalid Formula %s" % compound)
msg.exec_()
self.__table.setCurrentCell(self.__lastRow, self.__lastColumn)
return
else:
try:
float(str(qstring))
except:
msg=qt.QMessageBox(self.__table)
msg.setIcon(qt.QMessageBox.Critical)
msg.setText("Invalid Float")
msg.exec_()
self.__table.setCurrentCell(self.__lastRow, self.__lastColumn)
return
self._updateCurrent()
示例4: setSelection
def setSelection(self, symbol=None):
if symbol is None:
if self.addnone:
self.setCurrentIndex(0)
else:
idx= self.addnone+Elements.getz(symbol)-1
self.setCurrentIndex(idx)
示例5: mySlot
def mySlot(self):
try:
energy = float(str(self.energy.text()))
except ValueError:
msg=qt.QMessageBox(self.energy)
msg.setIcon(qt.QMessageBox.Critical)
msg.setText("Invalid Energy Value")
msg.setWindowTitle("Invalid energy")
msg.exec_()
self.energy.setFocus()
return
threshold = float(str(self.threshold.text()))/1000.
lines=[]
if self.k.isChecked():
lines.append('K')
if self.l1.isChecked():
lines.append('L1')
if self.l2.isChecked():
lines.append('L2')
if self.l3.isChecked():
lines.append('L3')
if self.m.isChecked():
lines.append('M')
ddict=Elements.getcandidates(energy,threshold,lines)[0]
ddict['text'] =self.getHtmlText(ddict)
ddict['event']='Candidates'
ddict['lines']=lines
if self.__useviewer:
self.__browsertext.clear()
#self.__browsertext.insertHtml("<CENTER>"+dict['text']+\
# "</CENTER>")
self.__browsertext.insertHtml(ddict['text'])
self.sigPeakIdentifierSignal.emit(ddict)
示例6: __nameLineSlot
def __nameLineSlot(self):
_logger.debug("__nameLineSlot(self)")
qstring = self.__nameLine.text()
text = str(qstring)
if self.__toolMode:
if len(text):
matkey = Elements.getMaterialKey(text)
if matkey is not None:
self.setCurrent(matkey)
#Disable everything
self.__disableInput()
elif text in Elements.ElementList:
self.__disableInput()
name = Elements.Element[text]['name']
self._current['Comment'] = name[0].upper() + name[1:]
self._current['CompoundList'] = [text+"1"]
self._current['CompoundFraction'] = [1.0]
self._current['Density'] = Elements.Element[text]['density']
self._fillValues()
self._updateCurrent()
self.__nameLine.setText("%s" % text)
else:
self._current['Comment'] = text
self.__numberSpin.setEnabled(True)
self.__table.setEnabled(True)
self.__densityLine.setEnabled(True)
self.__thicknessLine.setEnabled(True)
else:
self._current['Comment'] = text
示例7: _referenceLineSlot
def _referenceLineSlot(self, ddict):
if ddict['event'] == "returnPressed":
current = str(self.referenceLine.text())
current = current.replace(' ', '')
if (current == '') or (current.upper() == 'AUTO'):
pass
elif len(current) == 2:
current = current.upper()[0] + current.lower()[1]
elif len(current) == 1:
current = current.upper()[0]
else:
self.referenceLine.setText('Auto')
msg = qt.QMessageBox(self.referenceLine)
msg.setIcon(qt.QMessageBox.Critical)
msg.setText("Invalid Element %s" % current)
msg.exec_()
self.referenceLine.setFocus()
return
if (current == '') or (current.upper() == 'AUTO'):
self.referenceLine.setText('Auto')
self._mySignal()
elif not Elements.isValidFormula(current):
self.referenceLine.setText('Auto')
msg = qt.QMessageBox(self.referenceLine)
msg.setIcon(qt.QMessageBox.Critical)
msg.setText("Invalid Element %s" % current)
if QTVERSION < '4.0.0':
msg.exec_loop()
else:
msg.exec_()
self.referenceLine.setFocus()
else:
self.referenceLine.setText(current)
self._mySignal()
示例8: setFitConfiguration
def setFitConfiguration(self, fitConfiguration):
# obtain the peak families fitted
_peakList = _getPeakList(fitConfiguration)
if not len(_peakList):
raise ValueError("No peaks to fit!!!!")
matrixDescription = _getMatrixDescription(fitConfiguration)
layerList = list(matrixDescription.keys())
layerList.sort()
materialList = list(Elements.Material.keys())
materialList.sort()
a = ["-"]
for key in materialList:
a.append(key)
# Material options
self._materialOptions.setOptions(a)
self._table.setMaterialOptions(a)
# If only one layer, all the elements are selectable
layerPeaks = {}
if len(layerList) == 1:
layerPeaks[layerList[0]] = _peakList
else:
inAllLayers = []
toDeleteFromAllLayers = []
toForgetAbout = []
for layer in layerList:
layerPeaks[layer] = []
for peak in _peakList:
element = peak.split()[0]
layersPresent = []
for layer in layerList:
material = matrixDescription[layer][0]
if element in Elements.getMaterialMassFractions(\
[material],
[1.0]).keys():
layersPresent.append(layer)
if len(layersPresent) == 1:
layerPeaks[layersPresent[0]].append(peak)
oldOption = qt.safe_str(self._layerOptions.currentText())
self._layerOptions.clear()
for item in layerList:
self._layerOptions.addItem(item)
self._layerList = layerList
if oldOption not in layerList:
oldOption = layerList[0]
self._layerOptions.setCurrentIndex(layerList.index(oldOption))
self._layerList = layerList
self._layerPeaks = layerPeaks
self._table.setLayerPeakFamilies(layerPeaks[oldOption])
strategy = fitConfiguration["fit"].get("strategy", "SingleLayerStrategy")
if strategy in fitConfiguration:
self.setParameters(fitConfiguration["SingleLayerStrategy"])
示例9: validate
def validate(self, qstring, pos):
text = str(qstring)
if text == '-':
return (self.Valid, pos)
try:
# this test is needed even if pyflakes complains!
float(text)
return (self.Invalid, pos)
except:
pass
if text.endswith(' '):
return (self.Invalid, pos)
if Elements.isValidFormula(text):
return (self.Valid, pos)
elif Elements.isValidMaterial(text):
return (self.Valid, pos)
else:
return (self.Invalid,pos)
示例10: fixup
def fixup(self, qstring):
if qstring is None:
return None
text = str(qstring)
key = Elements.getMaterialKey(text)
if key is not None:
return QString(key)
else:
return qstring
示例11: _checkDensityThickness
def _checkDensityThickness(self, text, row):
try:
currentDensity = float(str(self.text(row, 3)))
except:
currentDensity = 0.0
try:
currentThickness = float(str(self.text(row, 4)))
except:
currentThickness = 0.0
defaultDensity = -1.0
defaultThickness = -0.1
#check if default density is there
if Elements.isValidFormula(text):
#check if single element
if text in Elements.Element.keys():
defaultDensity = Elements.Element[text]['density']
else:
elts = [ w for w in re.split('[0-9]', text) if w != '']
nbs = [ int(w) for w in re.split('[a-zA-Z]', text) if w != '']
if len(elts) == 1 and len(nbs) == 1:
defaultDensity = Elements.Element[elts[0]]['density']
elif Elements.isValidMaterial(text):
key = Elements.getMaterialKey(text)
if key is not None:
if 'Density' in Elements.Material[key]:
defaultDensity = Elements.Material[key]['Density']
if 'Thickness' in Elements.Material[key]:
defaultThickness = Elements.Material[key]['Thickness']
if defaultDensity >= 0.0:
self.setText(row, 3, "%g" % defaultDensity)
elif currentDensity <= 0:
# should not be better to raise an exception if the
# entered density or thickness were negative?
self.setText(row, 3, "%g" % 1.0)
if defaultThickness >= 0.0:
self.setText(row, 4, "%g" % defaultThickness)
elif currentThickness <= 0.0:
# should not be better to raise an exception if the
# entered density or thickness were negative?
self.setText(row, 4, "%g" % 0.1)
示例12: setParameters
def setParameters(self, ddict):
layer = ddict.get("layer", "Auto")
if layer not in self._layerList:
if layer.upper() != "AUTO":
raise ValueError("Layer %s not among fitted layers" % layer)
else:
layerList = self._layerList + ["Auto"]
self._layerOptions.clear()
for item in layerList:
self._layerOptions.addItem(item)
self._layerList = layerList
nIterations = ddict.get("iterations", 3)
self._nIterations.setValue(nIterations)
layerList = self._layerList
layerPeaks = self._layerPeaks
self._layerOptions.setCurrentIndex(layerList.index(layer))
if layer in layerPeaks:
self._table.setLayerPeakFamilies(layerPeaks[layer])
completer = ddict.get("completer", "-")
self._materialOptions.setCurrentText(completer)
flags = ddict["flags"]
families = ddict["peaks"]
materials = ddict["materials"]
nItem = 0
for i in range(len(flags)):
doIt = 0
if (flags[i] in [1, True, "1", "True"]) and (layer in layerPeaks):
flag = 1
if families[i] in layerPeaks[layer]:
if materials[i] in ["-"]:
doIt = 1
else:
element = families[i].split()[0]
if element in Elements.getMaterialMassFractions( \
[materials[i]], [1.0]):
doIt = 1
if doIt:
self._table.setData(nItem, flag, families[i], materials[i])
else:
self._table.setData(nItem, flag, families[i], element)
else:
self._table.setData(nItem, 0, "-", "-")
nItem += 1
示例13: _massAttenuationSlot
def _massAttenuationSlot(self, ddict):
try:
compoundList = ddict['CompoundList']
fractionList = ddict['CompoundFraction']
energy = numpy.arange(1, 100, 0.1)
data=Elements.getMaterialMassAttenuationCoefficients(compoundList,
fractionList,
energy)
addButton = False
if self.graph is None:
# probably dead code (ScanWindow.ScanWindow not imported)
self.graphDialog = qt.QDialog(self)
self.graphDialog.mainLayout = qt.QVBoxLayout(self.graphDialog)
self.graphDialog.mainLayout.setContentsMargins(0, 0, 0, 0)
self.graphDialog.mainLayout.setSpacing(0)
#self.graph = ScanWindow.ScanWindow(self.graphDialog)
self.graph = ScanWindow(self.graphDialog)
self.graphDialog.mainLayout.addWidget(self.graph)
self.graph._togglePointsSignal()
self.graph.graph.crossPicker.setEnabled(False)
addButton = True
if addButton:
self._addGraphDialogButton()
self.graph.setGraphTitle(ddict['Comment'])
legend = 'Coherent'
self.graph.addCurve(energy, numpy.array(data[legend.lower()]),
legend=legend,
xlabel='Energy (keV)',
ylabel='Mass Att. (cm2/g)',
replace=True,
replot=False)
for legend in ['Compton', 'Photo','Total']:
self.graph.addCurve(energy, numpy.array(data[legend.lower()]),
legend=legend,
xlabel='Energy (keV)',
ylabel='Mass Att. (cm2/g)',
replace=False,
replot=False)
self.graph.setActiveCurve(legend+' '+'Mass Att. (cm2/g)')
self.graph.setGraphTitle(ddict['Comment'])
if self.graphDialog is not None:
self.graphDialog.exec_()
except:
msg=qt.QMessageBox(self)
msg.setIcon(qt.QMessageBox.Critical)
msg.setInformativeText(str(sys.exc_info()[1]))
msg.setDetailedText(traceback.format_exc())
msg.exec_()
示例14: _transmissionSlot
def _transmissionSlot(self, ddict):
try:
compoundList = ddict['CompoundList']
fractionList = ddict['CompoundFraction']
density = ddict['Density']
thickness = ddict.get('Thickness', 0.1)
energy = numpy.arange(1, 100, 0.1)
data=Elements.getMaterialTransmission(compoundList, fractionList, energy,
density=density, thickness=thickness, listoutput=False)
addButton = False
if self.graph is None:
# probably dead code (ScanWindow not imported)
self.graphDialog = qt.QDialog(self)
self.graphDialog.mainLayout = qt.QVBoxLayout(self.graphDialog)
self.graphDialog.mainLayout.setContentsMargins(0, 0, 0, 0)
self.graphDialog.mainLayout.setSpacing(0)
#self.graph = ScanWindow.ScanWindow(self.graphDialog)
self.graph = ScanWindow(self.graphDialog)
self.graphDialog.mainLayout.addWidget(self.graph)
self.graph._togglePointsSignal()
self.graph.graph.crossPicker.setEnabled(False)
addButton = True
if addButton:
self._addGraphDialogButton()
if self.__toolMode:
legend = ddict['Comment']
else:
legend = str(self.matCombo.currentText()) +\
" with density = %f g/cm3" % density +\
" and thickness = %f cm" % thickness
self.graph.addCurve(energy, data['transmission'],
legend=legend,
xlabel='Energy (keV)',
ylabel='Transmission',
replace=True)
self.graph.setGraphTitle(ddict['Comment'])
if self.graphDialog is not None:
self.graphDialog.exec_()
except:
msg=qt.QMessageBox(self)
msg.setIcon(qt.QMessageBox.Critical)
msg.setInformativeText(str(sys.exc_info()[1]))
msg.setDetailedText(traceback.format_exc())
msg.exec_()
示例15: setPeaksDisabled
def setPeaksDisabled(self,symbol):
z = self.__getZ(symbol)
if (z > 47) and (Elements.getomegam5('Cd') > 0.0):
#we have data available to support that
disabled = []
elif z > 66:
#self.peaks.setDisabled(['Ka','Kb'])
#disabled = ['Ka','Kb']
disabled = []
elif z > 17:
#self.peaks.setDisabled(['Ka','Kb','M'])
#disabled = ['Ka','Kb','M']
disabled = ['M']
elif z > 2:
#self.peaks.setDisabled(['Ka','Kb','L','L1','L2','L3','M'])
#disabled = ['Ka','Kb','L','L1','L2','L3','M']
disabled = ['L','L1','L2','L3','M']
else:
#self.peaks.setDisabled(['K','Ka','Kb','L','L1','L2','L3','M'])
#disabled = ['Ka','Kb','L','L1','L2','L3','M']
disabled = ['Ka', 'Kb','L','L1','L2','L3','M']
ele = symbol
if self.energyValue is not None:
for peak in ['K', 'Ka', 'Kb', 'L','L1','L2','L3','M']:
if peak not in disabled:
if peak == 'L':
if Elements.Element[ele]['binding']['L3'] > self.energyValue:
disabled.append(peak)
elif peak == 'M':
if Elements.Element[ele]['binding']['M5'] > self.energyValue:
disabled.append(peak)
elif peak == 'Ka':
if Elements.Element[ele]['binding']['K'] > self.energyValue:
disabled.append(peak)
elif peak == 'Kb':
if Elements.Element[ele]['binding']['K'] > self.energyValue:
disabled.append(peak)
elif Elements.Element[ele]['binding'][peak] > self.energyValue:
disabled.append(peak)
else:
pass
self.peaks.setDisabled(disabled)