/usr/share/pyshared/PyMca/SGWindow.py is in pymca 4.5.0-4.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 | #/*##########################################################################
# Copyright (C) 2004-2011 European Synchrotron Radiation Facility
#
# This file is part of the PyMCA X-ray Fluorescence Toolkit developed at
# the ESRF by the Beamline Instrumentation Software Support (BLISS) group.
#
# This toolkit is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the Free
# Software Foundation; either version 2 of the License, or (at your option)
# any later version.
#
# PyMCA is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# PyMCA; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
# Suite 330, Boston, MA 02111-1307, USA.
#
# PyMCA follows the dual licensing model of Trolltech's Qt and Riverbank's PyQt
# and cannot be used as a free plugin for a non-free program.
#
# Please contact the ESRF industrial unit (industry@esrf.fr) if this license
# is a problem for you.
#############################################################################*/
__author__ = "V.A. Sole - ESRF Software Group"
import PyMcaQt as qt
from PyMca_Icons import IconDict
import MaskImageWidget
#RGBCorrelatorGraph
import ScanWindow
import sys
import SGModule
class HorizontalSpacer(qt.QWidget):
def __init__(self, *args):
qt.QWidget.__init__(self, *args)
self.setSizePolicy(qt.QSizePolicy(qt.QSizePolicy.Expanding,
qt.QSizePolicy.Fixed))
class SGParametersWidget(qt.QWidget):
def __init__(self, parent = None, length=2000):
qt.QWidget.__init__(self, parent)
self.mainLayout = qt.QGridLayout(self)
self.mainLayout.setMargin(0)
self.mainLayout.setSpacing(2)
i = 0
self._keyList = ['points', 'degree', 'order']
self.parametersDict = {'points':3,
'degree':1,
'order':0}
for text in ["Savitzky-Golay filter width:",
"Interpolating polynomial degree:",
"Derivative order (0=smoothing):"]:
label = qt.QLabel(self)
label.setText(text)
self.mainLayout.addWidget(label, i, 0)
#self.mainLayout.addWidget(HorizontalSpacer(self), i, 1)
i +=1
i = 0
self.widgetDict = {}
for key in self._keyList:
self.widgetDict[key] = qt.QSpinBox(self)
self.widgetDict[key].setMinimum(1)
self.widgetDict[key].setMaximum(100)
self.widgetDict[key].setValue(self.parametersDict[key])
self.connect(self.widgetDict[key],
qt.SIGNAL("valueChanged(int)"),
self._updateParameters)
self.mainLayout.addWidget(self.widgetDict[key], i, 1)
i += 1
self.widgetDict['order'].setMinimum(0)
self.widgetDict['order'].setValue(0)
self.widgetDict['order'].setMaximum(4)
def setParameters(self, ddict):
for key in ddict:
if key in self._keyList:
self.widgetDict[key].setValue(ddict[key])
dummy = 0
self._updateParameters(dummy)
def _updateParameters(self, val):
for key in self._keyList:
self.parametersDict[key] = self.widgetDict[key].value()
self.widgetDict['order'].setMaximum(self.parametersDict['degree'])
if self.parametersDict['order'] > self.parametersDict['degree']:
self.parametersDict['order']=self.parametersDict['degree']
self.widgetDict['order'].setValue(self.parametersDict['order'])
ddict = {}
ddict['event']='SGParametersChanged'
ddict.update(self.parametersDict)
self.emit(qt.SIGNAL('SGParametersSignal'), ddict)
def getParameters(self):
return self.parametersDict
class SGWindow(qt.QWidget):
def __init__(self, parent, data, image=None, x=None):
qt.QWidget.__init__(self, parent)
self.setWindowTitle("Savitzky-Golay Filter Configuration Window")
self.mainLayout = qt.QVBoxLayout(self)
self.mainLayout.setMargin(0)
self.mainLayout.setSpacing(2)
spectrum = data
if x is None:
self.xValues = range(len(spectrum))
else:
self.xValues = x
self.image = None
self.spectrum = spectrum
self.parametersWidget = SGParametersWidget(self, length=len(spectrum))
self.graph = ScanWindow.ScanWindow(self)
self.graph.newCurve(self.xValues,
spectrum, "Spectrum", replace=True)
self.mainLayout.addWidget(self.parametersWidget)
self.mainLayout.addWidget(self.graph)
self.getParameters = self.parametersWidget.getParameters
self.setParameters = self.parametersWidget.setParameters
self.connect(self.parametersWidget,
qt.SIGNAL('SGParametersSignal'),
self.updateGraph)
self.updateGraph(self.getParameters())
def updateGraph(self, ddict):
points = ddict['points']
degree = ddict['degree']
order = ddict['order']
self.background = SGModule.getSavitzkyGolay(self.spectrum,
points,
degree=degree,
order=order)
if order > 0:
maptoy2 = True
else:
maptoy2 = False
self.graph.newCurve(self.xValues,
self.background, "Filtered Spectrum",
replace=False,
maptoy2=maptoy2)
#Force information update
legend = self.graph.getActiveCurve(just_legend=True)
if legend.startswith('Filtered'):
self.graph.setActiveCurve(legend)
class SGDialog(qt.QDialog):
def __init__(self, parent, data, x=None):
qt.QDialog.__init__(self, parent)
self.setWindowTitle("Savitzky-Golay Configuration Dialog")
self.mainLayout = qt.QVBoxLayout(self)
self.mainLayout.setMargin(10)
self.mainLayout.setSpacing(2)
self.__image = False
if len(data.shape) == 2:
spectrum = data.ravel()
else:
spectrum = data
self.parametersWidget = SGWindow(self, spectrum, image=False, x=x)
self.graph = self.parametersWidget.graph
self.mainLayout.addWidget(self.parametersWidget)
hbox = qt.QWidget(self)
hboxLayout = qt.QHBoxLayout(hbox)
hboxLayout.setMargin(0)
hboxLayout.setSpacing(0)
self.okButton = qt.QPushButton(hbox)
self.okButton.setText("OK")
self.okButton.setAutoDefault(False)
self.dismissButton = qt.QPushButton(hbox)
self.dismissButton.setText("Cancel")
self.dismissButton.setAutoDefault(False)
hboxLayout.addWidget(self.okButton)
hboxLayout.addWidget(HorizontalSpacer(hbox))
hboxLayout.addWidget(self.dismissButton)
self.mainLayout.addWidget(hbox)
self.connect(self.dismissButton, qt.SIGNAL("clicked()"), self.reject)
self.connect(self.okButton, qt.SIGNAL("clicked()"), self.accept)
def getParameters(self):
parametersDict = self.parametersWidget.getParameters()
parametersDict['function'] = SGModule.replaceStackWithSavitzkyGolay
parametersDict['arguments'] = [parametersDict['points'],
parametersDict['degree'],
parametersDict['order']]
return parametersDict
def setParameters(self, ddict):
return self.parametersWidget.setParameters(ddict)
if __name__ == "__main__":
import numpy
app = qt.QApplication([])
if 1:
noise = numpy.random.randn(1000.)
y=numpy.arange(1000.)
w = SGDialog(None, y+numpy.sqrt(y)* noise)
w.show()
ret=w.exec_()
if ret:
print(w.getParameters())
|