individual fitfunctions saved upon saving
This commit is contained in:
parent
e32fa8f834
commit
4913924222
58
QDS.py
58
QDS.py
@ -32,11 +32,11 @@ from CustomWidgets import ParameterWidget, YaffWidget
|
||||
USE_CROSSH=False
|
||||
|
||||
class AppWindow(QMainWindow):
|
||||
def __init__(self, parent=None):
|
||||
def __init__(self, files=[], parent=None):
|
||||
super(AppWindow, self).__init__(parent)
|
||||
self.ui = QDSMain.Ui_MainWindow()
|
||||
self.ui.setupUi(self)
|
||||
|
||||
self._file_paths = QStringList(files)
|
||||
|
||||
self._last_written_header = None
|
||||
actions = {
|
||||
@ -61,9 +61,16 @@ class AppWindow(QMainWindow):
|
||||
fileMenu = self.menuBar().addMenu("File")
|
||||
openFile = QAction("&Open", self)
|
||||
openFile.setShortcut(QKeySequence.Open)
|
||||
openFile.triggered.connect(self.openFile)
|
||||
openFile.triggered.connect(self.getFileNames)
|
||||
fileMenu.addAction(openFile)
|
||||
|
||||
nextFile = QAction("&Next", self)
|
||||
nextFile.setShortcut(QKeySequence.FindNext)
|
||||
nextFile.triggered.connect(self.nextFile)
|
||||
fileMenu.addAction(nextFile)
|
||||
|
||||
|
||||
|
||||
saveFile = QAction("&Save Fit Result", self)
|
||||
saveFile.setShortcut(QKeySequence.Save)
|
||||
saveFile.triggered.connect(self.saveFitResult)
|
||||
@ -149,6 +156,10 @@ class AppWindow(QMainWindow):
|
||||
sc_imag.sigMouseClicked.connect(self.mousePress)
|
||||
sc_imag.sigMouseMoved.connect(self.updateCrosshair)
|
||||
|
||||
# process cmd line args
|
||||
if files is not None:
|
||||
self.openFile(files[0])
|
||||
self._current_file_index = 0
|
||||
|
||||
|
||||
def updateCrosshair(self,evt):
|
||||
@ -238,10 +249,18 @@ class AppWindow(QMainWindow):
|
||||
# prepare header
|
||||
header="# T "
|
||||
pars = []
|
||||
for fcn in self.function_registry.get_registered_functions():
|
||||
for name in fcn.widget.names: # variable names
|
||||
bname = os.path.splitext(self.filepath)[0]
|
||||
for i_fcn, fcn in enumerate(self.function_registry.get_registered_functions()):
|
||||
for name in fcn.widget.names: # get variable names
|
||||
header += "{n:11}{n_sd:11}".format(n=name, n_sd=name+"_sd")
|
||||
|
||||
# write for each function extra file
|
||||
name_fcn = "%s_%i.fit"%(bname,i_fcn)
|
||||
f_fcn = open(name_fcn, 'w')
|
||||
f_fcn.write("# %s\n"%(fcn.id_string))
|
||||
f_fcn.flush()
|
||||
np.savetxt(f_fcn, fcn.resampleData(self.data.frequency))
|
||||
f_fcn.close()
|
||||
for i,par in enumerate(fcn._beta): # params # TODO: ughh
|
||||
if fcn._selector_mask is not None:
|
||||
if fcn._selector_mask[i]:
|
||||
@ -283,7 +302,7 @@ class AppWindow(QMainWindow):
|
||||
|
||||
for fcn in self.function_registry.get_registered_functions():
|
||||
f,eps = fcn.get_data()
|
||||
label = fcn.id_string
|
||||
label = fcn.id_label
|
||||
color = hex2color(str(fcn.color.name()))
|
||||
pyplot.loglog(f,eps[1], ls=":", color=color, lw=1, dashes=(1,1), label=label)
|
||||
|
||||
@ -369,7 +388,7 @@ class AppWindow(QMainWindow):
|
||||
def addPeak(self, pos):
|
||||
id_list = [ key.id_num for key in
|
||||
self.function_registry.get_registered_functions().keys()
|
||||
if key.id_string == 'hn']
|
||||
if key.id_label == 'hn']
|
||||
|
||||
self.peakId = 1
|
||||
while self.peakId in id_list:
|
||||
@ -465,9 +484,27 @@ class AppWindow(QMainWindow):
|
||||
i += num_p
|
||||
#self.updatePlot()
|
||||
|
||||
def openFile(self):
|
||||
def getFileNames(self):
|
||||
# TODO: multiple files, advance by button
|
||||
self._file_paths = QFileDialog.getOpenFileNames(self, "Open file", "", '*.dat')
|
||||
print "here", len(self._file_paths)
|
||||
self._current_file_index = 0
|
||||
path = unicode(self._file_paths[self._current_file_index])
|
||||
|
||||
self.openFile(path)
|
||||
#path = unicode(QFileDialog.getOpenFileName(self, "Open file"))
|
||||
path = "MCM42PG0_199.96K.dat"
|
||||
#path = "MCM42PG0_199.96K.dat"
|
||||
|
||||
def nextFile(self):
|
||||
if len(self._file_paths) > self._current_file_index+1: # wrap around
|
||||
self._current_file_index += 1
|
||||
else:
|
||||
self._current_file_index = 0
|
||||
path = unicode(self._file_paths[self._current_file_index])
|
||||
self.openFile(path)
|
||||
|
||||
def openFile(self,path):
|
||||
print "opening: %s"%path
|
||||
self.filepath=path
|
||||
# TODO analyize file (LF,MF, HF) and act accordingly
|
||||
data = np.loadtxt(path, skiprows=4)
|
||||
@ -539,11 +576,12 @@ def sigint_handler(*args):
|
||||
|
||||
if __name__ == '__main__':
|
||||
signal.signal(signal.SIGINT, sigint_handler)
|
||||
files = sys.argv[1:]
|
||||
app = QApplication(sys.argv)
|
||||
timer = QTimer()
|
||||
timer.start(1000) # Check every second for Strg-c on Cmd line
|
||||
timer.timeout.connect(lambda: None)
|
||||
main = AppWindow()
|
||||
main = AppWindow(files=files)
|
||||
main.showMaximized()
|
||||
main.raise_()
|
||||
sys.exit(app.exec_())
|
||||
|
33
data.py
33
data.py
@ -93,6 +93,7 @@ class BaseObject(QObject):
|
||||
self.functions = Functions()
|
||||
self._color = QColor("white")
|
||||
self._id = None
|
||||
self._id_string = None
|
||||
self._widget = None
|
||||
self._frequency = np.logspace(np.log10(limits[0]), np.log10(limits[1]), 256)
|
||||
self._data = None
|
||||
@ -112,10 +113,20 @@ class BaseObject(QObject):
|
||||
|
||||
@property
|
||||
def id_string(self):
|
||||
return self._id
|
||||
return self._id_string
|
||||
|
||||
@id_string.setter
|
||||
def id_string(self, id):
|
||||
#self._func = self.functions.get_function(id)
|
||||
self._id_string = id
|
||||
|
||||
|
||||
@property
|
||||
def id_label(self):
|
||||
return self._id
|
||||
|
||||
@id_label.setter
|
||||
def id_label(self, id):
|
||||
#self._func = self.functions.get_function(id)
|
||||
self._func = self.function
|
||||
self._id = id
|
||||
@ -169,6 +180,11 @@ class BaseObject(QObject):
|
||||
self.data_curve_imag.setData(x=self._frequency, y=self._data[1])
|
||||
self.changedData.emit()
|
||||
|
||||
def resampleData(self, x):
|
||||
data = self._func(self.getParameter(), x)
|
||||
return np.array([x,data[0],data[1]]).T
|
||||
|
||||
|
||||
def clearData(self):
|
||||
self.data_curve_real.setData(x=[np.nan], y=[np.nan])
|
||||
self.data_curve_imag.setData(x=[np.nan], y=[np.nan])
|
||||
@ -181,7 +197,8 @@ class Conductivity(BaseObject):
|
||||
super(Conductivity, self).__init__(plt_real=plt_real, plt_imag=plt_imag, limits=limits)
|
||||
self.widget = CustomWidgets.ConductivityWidget()
|
||||
self.color = QColor("blue")
|
||||
self.id_string = "Cond."
|
||||
self.id_label = "Cond."
|
||||
self.id_string = "cond"
|
||||
|
||||
self.param_number = 3
|
||||
|
||||
@ -198,7 +215,8 @@ class PowerComplex(BaseObject):
|
||||
super(PowerComplex, self).__init__(plt_real=plt_real, plt_imag=plt_imag, limits=limits)
|
||||
self.widget = CustomWidgets.PowerLawWidget()
|
||||
self.color = QColor("#ff44c4")
|
||||
self.id_string = 'Power Law'
|
||||
self.id_label = 'Power Law'
|
||||
self.id_string = "pwr"
|
||||
self.param_number = 2
|
||||
|
||||
def function( self, p, x ):
|
||||
@ -214,7 +232,8 @@ class Static(BaseObject):
|
||||
super(Static, self).__init__(plt_real=plt_real, plt_imag=plt_imag, limits=limits)
|
||||
self.widget = CustomWidgets.StaticWidget()
|
||||
self.color = QColor('#FF0F13')
|
||||
self.id_string = u'ε(∞)'
|
||||
self.id_label = u'ε(∞)'
|
||||
self.id_string = "eps_infty"
|
||||
self.param_number = 1
|
||||
|
||||
def function( self, p, x ):
|
||||
@ -232,6 +251,7 @@ class Peak(BaseObject):
|
||||
self.color = id_to_color(id_num)
|
||||
self.widget.setColor(self.color)
|
||||
self.id_num = id_num
|
||||
self.id_label = "Hav-Neg"
|
||||
self.id_string = "hn"
|
||||
self.param_number = 4
|
||||
|
||||
@ -249,7 +269,8 @@ class YAFF(BaseObject):
|
||||
self.widget.on_model_changed.connect(self.change_model)
|
||||
self.color = QColor(32, 120, 29, int(255*0.82))
|
||||
self._libyaff = libyaff.Yaff(self.widget.getYaffType())
|
||||
self.id_string = self._libyaff.label
|
||||
self.id_label = self._libyaff.label
|
||||
self.id_string = "yaff"
|
||||
self._param_number = self._libyaff.params
|
||||
self._selector_mask = self.widget.selector_mask
|
||||
|
||||
@ -264,7 +285,7 @@ class YAFF(BaseObject):
|
||||
def change_model(self):
|
||||
self._libyaff = libyaff.Yaff(self.widget.getYaffType())
|
||||
self._selector_mask = self.widget.selector_mask
|
||||
self.id_string = self._libyaff.label
|
||||
self.id_label = self._libyaff.label
|
||||
self.param_number = self._libyaff.params
|
||||
self.updateData()
|
||||
|
||||
|
@ -301,7 +301,7 @@ class FunctionRegister:
|
||||
|
||||
def register_function(self, obj):
|
||||
#print "FR: Registering:",obj
|
||||
id_string = obj.id_string
|
||||
id_string = obj.id_label
|
||||
if self.registry.has_key(obj):
|
||||
raise AssertionError,"The object is already registered! This should NOT happen"
|
||||
self.registry[obj]=id_string
|
||||
|
Loading…
Reference in New Issue
Block a user