parent
068b621ff2
commit
410902b753
@ -9,7 +9,9 @@ import numpy as np
|
|||||||
|
|
||||||
|
|
||||||
class GracePlot(object):
|
class GracePlot(object):
|
||||||
def __init__(self):
|
def __init__(self, fname):
|
||||||
|
self.fname = fname
|
||||||
|
|
||||||
self.ls_map = {"None":0, "-":1, ":":2, "--":3, "-.":4 }
|
self.ls_map = {"None":0, "-":1, ":":2, "--":3, "-.":4 }
|
||||||
|
|
||||||
# Symbols: 0:None 1:Circle 2:Square 3:Diamond 4:Triangle 5:up 6:left 7:down 8:right, 9:PLus 10:X 11:Star
|
# Symbols: 0:None 1:Circle 2:Square 3:Diamond 4:Triangle 5:up 6:left 7:down 8:right, 9:PLus 10:X 11:Star
|
||||||
@ -33,18 +35,16 @@ class GracePlot(object):
|
|||||||
tmp_fd, tmp_name = tempfile.mkstemp()
|
tmp_fd, tmp_name = tempfile.mkstemp()
|
||||||
self.tmpfiles.append(tmp_name)
|
self.tmpfiles.append(tmp_name)
|
||||||
np.savetxt(tmp_name, np.array([x, y]).T)
|
np.savetxt(tmp_name, np.array([x, y]).T)
|
||||||
#tmp_fd.close()
|
|
||||||
# read data in xmgrace
|
|
||||||
self.cmds.append('READ NXY "%s"\n'%tmp_name)
|
|
||||||
self.cmds.append('S%i SYMBOL SIZE 0.7\n'%(self.data_counter))
|
|
||||||
|
|
||||||
#self.cmds.append('S%i SYMBOL FILL COLOR %i\n'%(self.data_counter, self.data_counter))
|
# read data from temporary file
|
||||||
|
self.cmds.append('READ NXY "%s"\n'%tmp_name)
|
||||||
|
self.cmds.append('S%i SYMBOL SIZE 0.5\n'%(self.data_counter))
|
||||||
self.cmds.append('S%i SYMBOL FILL PATTERN 1\n'%(self.data_counter))
|
self.cmds.append('S%i SYMBOL FILL PATTERN 1\n'%(self.data_counter))
|
||||||
self.cmds.append('S%i SYMBOL 1\n'%(self.data_counter)) # No line
|
self.cmds.append('S%i SYMBOL 1\n'%(self.data_counter)) # No line
|
||||||
|
|
||||||
|
|
||||||
if "label" in kwds.keys():
|
if "label" in kwds.keys():
|
||||||
label = kwds["label"]
|
# TODO: implement at least greek symbols and lower upper case (_ and ^)?
|
||||||
|
label = unicode(kwds["label"]).encode('ascii', 'ignore')
|
||||||
self.cmds.append('S%i LEGEND "%s"\n'%(self.data_counter, label))
|
self.cmds.append('S%i LEGEND "%s"\n'%(self.data_counter, label))
|
||||||
|
|
||||||
if "ls" in kwds.keys():
|
if "ls" in kwds.keys():
|
||||||
@ -84,23 +84,23 @@ class GracePlot(object):
|
|||||||
|
|
||||||
def loglog(self, x,y, **kwds):
|
def loglog(self, x,y, **kwds):
|
||||||
self.cmds.append('YAXES SCALE LOGARITHMIC\n')
|
self.cmds.append('YAXES SCALE LOGARITHMIC\n')
|
||||||
self.cmds.append("YAXIS TICKLABEL FORMAT POWER\n")
|
self.cmds.append("YAXIS TICKLABEL FORMAT POWER\n")
|
||||||
self.cmds.append("YAXIS TICKLABEL PREC 0\n")
|
self.cmds.append("YAXIS TICKLABEL PREC 0\n")
|
||||||
self.cmds.append('XAXES SCALE LOGARITHMIC\n')
|
self.cmds.append('XAXES SCALE LOGARITHMIC\n')
|
||||||
self.cmds.append("XAXIS TICKLABEL FORMAT POWER\n")
|
self.cmds.append("XAXIS TICKLABEL FORMAT POWER\n")
|
||||||
self.cmds.append("XAXIS TICKLABEL PREC 0\n")
|
self.cmds.append("XAXIS TICKLABEL PREC 0\n")
|
||||||
self.plot(x, y, **kwds)
|
self.plot(x, y, **kwds)
|
||||||
|
|
||||||
def semilogx(self, x, y, **kwds):
|
def semilogx(self, x, y, **kwds):
|
||||||
self.cmds.append('XAXES SCALE LOGARITHMIC\n')
|
self.cmds.append('XAXES SCALE LOGARITHMIC\n')
|
||||||
self.cmds.append("xAXIS TICKLABEL FORMAT POWER\n")
|
self.cmds.append("xAXIS TICKLABEL FORMAT POWER\n")
|
||||||
self.cmds.append("xAXIS TICKLABEL PREC 0\n")
|
self.cmds.append("xAXIS TICKLABEL PREC 0\n")
|
||||||
self.plot(x, y, **kwds)
|
self.plot(x, y, **kwds)
|
||||||
|
|
||||||
def semilogy(self, x, y, **kwds):
|
def semilogy(self, x, y, **kwds):
|
||||||
self.cmds.append('YAXES SCALE LOGARITHMIC\n')
|
self.cmds.append('YAXES SCALE LOGARITHMIC\n')
|
||||||
self.cmds.append("YAXIS TICKLABEL FORMAT POWER\n")
|
self.cmds.append("YAXIS TICKLABEL FORMAT POWER\n")
|
||||||
self.cmds.append("YAXIS TICKLABEL PREC 0\n")
|
self.cmds.append("YAXIS TICKLABEL PREC 0\n")
|
||||||
self.plot(x, y, **kwds)
|
self.plot(x, y, **kwds)
|
||||||
|
|
||||||
|
|
||||||
@ -121,26 +121,26 @@ class GracePlot(object):
|
|||||||
self.cmds.append('LEGEND OFF\n')
|
self.cmds.append('LEGEND OFF\n')
|
||||||
|
|
||||||
|
|
||||||
def save(self, fname):
|
def save(self):
|
||||||
self.cmds.append('AUTOSCALE\n')
|
self.cmds.append('AUTOSCALE\n')
|
||||||
self.cmds.append('SAVEALL "%s"\n'%fname)
|
self.cmds.append('SAVEALL "%s"\n'%self.fname)
|
||||||
# write cmds to tmpfile
|
# write cmds to tmpfile
|
||||||
tmp_fd, tmp_name = tempfile.mkstemp()
|
tmp_fd, tmp_name = tempfile.mkstemp()
|
||||||
self.tmpfiles.append(tmp_name)
|
self.tmpfiles.append(tmp_name)
|
||||||
tmp_file = open(tmp_name, 'w')
|
tmp_file = open(tmp_name, 'w')
|
||||||
tmp_file.writelines(self.cmds)
|
tmp_file.writelines(self.cmds)
|
||||||
tmp_file.close()
|
tmp_file.close()
|
||||||
# excecute tempraray xmgrace file to create final agr
|
# excecute temporary xmgrace file to create final agr
|
||||||
os.system("xmgrace -batch %s -hardcopy -nosafe -printfile tmp.tmp"%tmp_name)
|
os.system("xmgrace -batch %s -hardcopy -nosafe -printfile tmp.tmp" % tmp_name)
|
||||||
os.remove("tmp.tmp")
|
os.remove("tmp.tmp")
|
||||||
# prepend color map to the new file
|
# prepend color map to the new file
|
||||||
with file(fname, 'r') as original_agr: data = original_agr.readlines()
|
with file(self.fname, 'r') as original_agr: data = original_agr.readlines()
|
||||||
# get the last "@map color ..." line
|
# get the last "@map color ..." line
|
||||||
last_color_lineno = 0
|
last_color_lineno = 0
|
||||||
for i,line in enumerate(data):
|
for i,line in enumerate(data):
|
||||||
if line.lower().startswith("@map color"):
|
if line.lower().startswith("@map color"):
|
||||||
last_color_lineno = i+1
|
last_color_lineno = i+1
|
||||||
with file(fname, 'w') as new_agr:
|
with file(self.fname, 'w') as new_agr:
|
||||||
new_agr.writelines(data[:last_color_lineno])
|
new_agr.writelines(data[:last_color_lineno])
|
||||||
for color in self.color_map:
|
for color in self.color_map:
|
||||||
new_agr.write(self.color_map[color][1])
|
new_agr.write(self.color_map[color][1])
|
||||||
@ -164,5 +164,5 @@ if __name__ == "__main__":
|
|||||||
gr.save("test.agr")
|
gr.save("test.agr")
|
||||||
print "created test.agr"
|
print "created test.agr"
|
||||||
os.system("xmgrace test.agr")
|
os.system("xmgrace test.agr")
|
||||||
print "deleting test.agr"
|
#print "deleting test.agr"
|
||||||
#os.remove("test.agr")
|
#os.remove("test.agr")
|
41
qds.py
41
qds.py
@ -130,11 +130,14 @@ class AppWindow(QMainWindow):
|
|||||||
previousFile.triggered.connect(self.previousFile)
|
previousFile.triggered.connect(self.previousFile)
|
||||||
fileMenu.addAction(previousFile)
|
fileMenu.addAction(previousFile)
|
||||||
|
|
||||||
saveFile = QAction("&Save Fit Result", self)
|
saveFile = QAction("&Save Fit Result (Data)", self)
|
||||||
saveFile.setShortcut(QKeySequence.Save)
|
saveFile.setShortcut(QKeySequence.Save)
|
||||||
saveFile.triggered.connect(self.saveFitResult)
|
saveFile.triggered.connect(self.saveFitResult)
|
||||||
fileMenu.addAction(saveFile)
|
fileMenu.addAction(saveFile)
|
||||||
|
|
||||||
|
self.ui.actionSave_FitResult.triggered.connect(lambda: self._saveFitFigure(mode="w"))
|
||||||
|
self.ui.actionAppend_Fit.triggered.connect(lambda: self._saveFitFigure(mode="a"))
|
||||||
|
|
||||||
# fitting methods
|
# fitting methods
|
||||||
fitMenu = self.menuBar().addMenu("Standard Fits")
|
fitMenu = self.menuBar().addMenu("Standard Fits")
|
||||||
# lm
|
# lm
|
||||||
@ -313,14 +316,14 @@ class AppWindow(QMainWindow):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
pars.insert(0, self.data.meta["T"])
|
pars.insert(0, self.data.meta["T"])
|
||||||
pars.insert(1, 1e3/self.data.meta["invT"])
|
pars.insert(1, 1e3/self.data.meta["T"])
|
||||||
pars.append(self.data.fit_limits[0])
|
pars.append(self.data.fit_limits[0])
|
||||||
pars.append(self.data.fit_limits[1])
|
pars.append(self.data.fit_limits[1])
|
||||||
pars = np.array([pars])
|
pars = np.array([pars])
|
||||||
np.savetxt(f, pars, fmt='%-12.3e', delimiter=" ")
|
np.savetxt(f, pars, fmt='%-12.3e', delimiter=" ")
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
def _saveFitFigure( self ):
|
def _saveFitFigure( self , mode="w"):
|
||||||
fig = pyplot.figure(figsize=(3.54*1.4, 2.75*1.4))
|
fig = pyplot.figure(figsize=(3.54*1.4, 2.75*1.4))
|
||||||
|
|
||||||
font = { 'family': 'sans serif',
|
font = { 'family': 'sans serif',
|
||||||
@ -348,26 +351,36 @@ class AppWindow(QMainWindow):
|
|||||||
pyplot.savefig(os.path.splitext(self.filepath)[0]+".pdf")
|
pyplot.savefig(os.path.splitext(self.filepath)[0]+".pdf")
|
||||||
fig.clear()
|
fig.clear()
|
||||||
del (fig)
|
del (fig)
|
||||||
self._saveFitFigureGrace()
|
self._saveFitFigureGrace(mode)
|
||||||
|
|
||||||
def _saveFitFigureGrace(self):
|
def _saveFitFigureGrace(self, mode="w"):
|
||||||
grace_plot = fileio.gracedriver.GracePlot()
|
fname = os.path.splitext(self.filepath)[0] + ".agr"
|
||||||
grace_plot.loglog(self.data.frequency, self.data.epsilon.imag, sym='o', ls="-", label="Data")
|
if mode == "w":
|
||||||
grace_plot.loglog(self.data.frequency_fit, self.data.epsilon_fit.imag, sym=None, ls="-", label="Fit")
|
self.grace_plot = fileio.gracedriver.GracePlot(fname)
|
||||||
|
elif mode == "a":
|
||||||
|
# FIXME: very ugly hack, should be global variable?
|
||||||
|
# Check if self.grace_plot attribute exists
|
||||||
|
try:
|
||||||
|
self.grace_plot is not None
|
||||||
|
except AttributeError:
|
||||||
|
self.grace_plot = fileio.gracedriver.GracePlot(fname)
|
||||||
|
|
||||||
|
self.grace_plot.loglog(self.data.frequency, self.data.epsilon.imag, sym='o', ls="-", label="Data")
|
||||||
|
self.grace_plot.loglog(self.data.frequency_fit, self.data.epsilon_fit.imag, sym=None, ls="-", label="Fit")
|
||||||
|
|
||||||
# loop over functions and add data to plot
|
# loop over functions and add data to plot
|
||||||
for fcn in self.function_registry.get_registered_functions():
|
for fcn in self.function_registry.get_registered_functions():
|
||||||
f, eps = fcn.get_data()
|
f, eps = fcn.get_data()
|
||||||
label = fcn.id_label
|
label = fcn.id_label
|
||||||
color = hex2color(str(fcn.color.name()))
|
color = hex2color(str(fcn.color.name()))
|
||||||
grace_plot.loglog(f, eps[1], ls=":", color=color, sym=None, label=label)
|
self.grace_plot.loglog(f, eps[1], ls=":", color=color, sym=None, label=label)
|
||||||
# vertical lines (fit limits)
|
# vertical lines (fit limits)
|
||||||
#for i in (0, 1): pyplot.axvline(x=self.data.fit_limits[i], color='b', ls="-", lw=0.5)
|
#for i in (0, 1): pyplot.axvline(x=self.data.fit_limits[i], color='b', ls="-", lw=0.5)
|
||||||
grace_plot.legend(True)
|
self.grace_plot.legend(True)
|
||||||
grace_plot.xlabel("f / Hz")
|
self.grace_plot.xlabel("f / Hz")
|
||||||
grace_plot.ylabel("eps")
|
self.grace_plot.ylabel("eps")
|
||||||
print grace_plot.cmds
|
print self.grace_plot.cmds
|
||||||
grace_plot.save(os.path.splitext(self.filepath)[0] + ".agr")
|
self.grace_plot.save()
|
||||||
|
|
||||||
|
|
||||||
def addContainer(self, selected_container, pos):
|
def addContainer(self, selected_container, pos):
|
||||||
|
@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
# Form implementation generated from reading ui file 'ui/QDSMain.ui'
|
# Form implementation generated from reading ui file 'ui/QDSMain.ui'
|
||||||
#
|
#
|
||||||
# Created: Tue Sep 30 15:34:02 2014
|
# Created: Fri Jan 9 21:17:26 2015
|
||||||
# by: PyQt4 UI code generator 4.11.2
|
# by: PyQt4 UI code generator 4.11.3
|
||||||
#
|
#
|
||||||
# WARNING! All changes made in this file will be lost!
|
# WARNING! All changes made in this file will be lost!
|
||||||
|
|
||||||
@ -125,6 +125,11 @@ class Ui_MainWindow(object):
|
|||||||
self.actionActionAbortFit.setObjectName(_fromUtf8("actionActionAbortFit"))
|
self.actionActionAbortFit.setObjectName(_fromUtf8("actionActionAbortFit"))
|
||||||
self.actionShow_Derivative = QtGui.QAction(MainWindow)
|
self.actionShow_Derivative = QtGui.QAction(MainWindow)
|
||||||
self.actionShow_Derivative.setObjectName(_fromUtf8("actionShow_Derivative"))
|
self.actionShow_Derivative.setObjectName(_fromUtf8("actionShow_Derivative"))
|
||||||
|
self.actionAppend_Fit = QtGui.QAction(MainWindow)
|
||||||
|
icon6 = QtGui.QIcon()
|
||||||
|
icon6.addPixmap(QtGui.QPixmap(_fromUtf8(":/icons/append_save_fit.png")), QtGui.QIcon.Normal, QtGui.QIcon.Off)
|
||||||
|
self.actionAppend_Fit.setIcon(icon6)
|
||||||
|
self.actionAppend_Fit.setObjectName(_fromUtf8("actionAppend_Fit"))
|
||||||
self.menuExtras.addAction(self.actionShow_Derivative)
|
self.menuExtras.addAction(self.actionShow_Derivative)
|
||||||
self.menubar.addAction(self.menuExtras.menuAction())
|
self.menubar.addAction(self.menuExtras.menuAction())
|
||||||
self.menubar.addAction(self.menuConfiguration.menuAction())
|
self.menubar.addAction(self.menuConfiguration.menuAction())
|
||||||
@ -136,6 +141,8 @@ class Ui_MainWindow(object):
|
|||||||
self.toolBar.addAction(self.actionYAFF)
|
self.toolBar.addAction(self.actionYAFF)
|
||||||
self.toolBar.addSeparator()
|
self.toolBar.addSeparator()
|
||||||
self.toolBar.addAction(self.actionSave_FitResult)
|
self.toolBar.addAction(self.actionSave_FitResult)
|
||||||
|
self.toolBar.addAction(self.actionAppend_Fit)
|
||||||
|
self.toolBar.addSeparator()
|
||||||
self.toolBar.addAction(self.actionActionAbortFit)
|
self.toolBar.addAction(self.actionActionAbortFit)
|
||||||
|
|
||||||
self.retranslateUi(MainWindow)
|
self.retranslateUi(MainWindow)
|
||||||
@ -160,6 +167,8 @@ class Ui_MainWindow(object):
|
|||||||
self.actionActionAbortFit.setText(_translate("MainWindow", "Abort Fit", None))
|
self.actionActionAbortFit.setText(_translate("MainWindow", "Abort Fit", None))
|
||||||
self.actionActionAbortFit.setShortcut(_translate("MainWindow", "Ctrl+C", None))
|
self.actionActionAbortFit.setShortcut(_translate("MainWindow", "Ctrl+C", None))
|
||||||
self.actionShow_Derivative.setText(_translate("MainWindow", "Show Derivative", None))
|
self.actionShow_Derivative.setText(_translate("MainWindow", "Show Derivative", None))
|
||||||
|
self.actionAppend_Fit.setText(_translate("MainWindow", "Append Fit", None))
|
||||||
|
self.actionAppend_Fit.setToolTip(_translate("MainWindow", "Appends current plot to existing plot.", None))
|
||||||
|
|
||||||
from pyqtgraph import PlotWidget
|
from pyqtgraph import PlotWidget
|
||||||
import images_rc
|
import images_rc
|
||||||
|
@ -109,6 +109,8 @@
|
|||||||
<addaction name="actionYAFF"/>
|
<addaction name="actionYAFF"/>
|
||||||
<addaction name="separator"/>
|
<addaction name="separator"/>
|
||||||
<addaction name="actionSave_FitResult"/>
|
<addaction name="actionSave_FitResult"/>
|
||||||
|
<addaction name="actionAppend_Fit"/>
|
||||||
|
<addaction name="separator"/>
|
||||||
<addaction name="actionActionAbortFit"/>
|
<addaction name="actionActionAbortFit"/>
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QDockWidget" name="dockWidget_3">
|
<widget class="QDockWidget" name="dockWidget_3">
|
||||||
@ -221,6 +223,18 @@
|
|||||||
<string>Show Derivative</string>
|
<string>Show Derivative</string>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
|
<action name="actionAppend_Fit">
|
||||||
|
<property name="icon">
|
||||||
|
<iconset resource="icons/images.qrc">
|
||||||
|
<normaloff>:/icons/append_save_fit.png</normaloff>:/icons/append_save_fit.png</iconset>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Append Fit</string>
|
||||||
|
</property>
|
||||||
|
<property name="toolTip">
|
||||||
|
<string>Appends current plot to existing plot.</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
</widget>
|
</widget>
|
||||||
<customwidgets>
|
<customwidgets>
|
||||||
<customwidget>
|
<customwidget>
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
<RCC>
|
<RCC>
|
||||||
<qresource prefix="icons">
|
<qresource prefix="icons">
|
||||||
<file>add_cond.svg</file>
|
<file>add_cond.svg</file>
|
||||||
|
<file>append_save_fit.png</file>
|
||||||
<file>add_yaff.png</file>
|
<file>add_yaff.png</file>
|
||||||
<file>add_eps_infty.png</file>
|
<file>add_eps_infty.png</file>
|
||||||
<file>qds_fit_abort.png</file>
|
<file>qds_fit_abort.png</file>
|
||||||
|
Binary file not shown.
1170
ui/images_rc.py
1170
ui/images_rc.py
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user