コード例 #1
0
ファイル: MaterialEditor.py プロジェクト: jat255/pymca
 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
コード例 #2
0
ファイル: MaterialEditor.py プロジェクト: vasole/pymca
 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
0
 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()
コード例 #4
0
ファイル: MaterialEditor.py プロジェクト: vasole/pymca
 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_()