Skip to content

Commit

Permalink
Can export interpolated data
Browse files Browse the repository at this point in the history
added buttons to table
  • Loading branch information
grey committed Apr 16, 2014
1 parent 6f12577 commit d150bb5
Showing 1 changed file with 50 additions and 5 deletions.
55 changes: 50 additions & 5 deletions batch-iv-analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@

import os, sys, inspect, csv

from PyQt4.QtCore import QString, QThread, pyqtSignal, QTimer, QSettings, Qt
from PyQt4.QtGui import QApplication, QDialog, QMainWindow, QFileDialog, QTableWidgetItem, QCheckBox
from PyQt4.QtCore import QString, QThread, pyqtSignal, QTimer, QSettings, Qt, QSignalMapper
from PyQt4.QtGui import QApplication, QDialog, QMainWindow, QFileDialog, QTableWidgetItem, QCheckBox, QPushButton, QWidget

import platform
if not platform.system()=='Windows':
Expand Down Expand Up @@ -121,8 +121,7 @@ class col:
tooltip = ''

class MainWindow(QMainWindow):


workingDirectory = ''
def __init__(self):
QMainWindow.__init__(self)

Expand All @@ -131,6 +130,17 @@ def __init__(self):
self.rows = 0 #keep track of how many rows there are in the table

self.cols = OrderedDict()

thisKey = 'plotBtn'
self.cols[thisKey] = col()
self.cols[thisKey].header = 'Draw Plot'
self.cols[thisKey].tooltip = 'Click this button to draw a plot for that row'

thisKey = 'exportBtn'
self.cols[thisKey] = col()
self.cols[thisKey].header = 'Export'
self.cols[thisKey].tooltip = 'Click this button to export\ninterpolated data points from fits'

thisKey = 'file'
self.cols[thisKey] = col()
self.cols[thisKey].header = 'File'
Expand Down Expand Up @@ -246,10 +256,35 @@ def __init__(self):

#connect signals generated by gui elements to proper functions
self.ui.actionOpen.triggered.connect(self.openCall)
self.ui.tableWidget.cellDoubleClicked.connect(self.rowGraph)
#self.ui.tableWidget.cellDoubleClicked.connect(self.rowGraph)
#self.ui.tableWidget.itemChanged.connect(self.handleButton)
#self.signalMapper = QSignalMapper()
#self.signalMapper.mapped.connect(self.handleButton)
self.ui.actionSave.triggered.connect(self.handleSave)

self.ui.actionClear_Table.triggered.connect(self.clearTableCall)

def exportInterp(self,row):
fitX = self.graphData[row]['fitX']
modelY = self.graphData[row]['modelY']
splineY = self.graphData[row]['splineY']
a = np.asarray([fitX, modelY, splineY])
a = np.transpose(a)
saveFile = os.path.join(self.workingDirectory,str(self.ui.tableWidget.item(row,self.cols.keys().index('file')).text())+'.csv')
header = 'Voltage [V],CharEqn Current [A],Spline Current [A]'
np.savetxt(saveFile, a, delimiter=",",header=header)


def handleButton(self):
btn = self.sender()
#kinda hacky:
row = self.ui.tableWidget.indexAt(btn.pos()).row()
col = self.ui.tableWidget.indexAt(btn.pos()).column()
if col == 0:
self.rowGraph(row)
if col == 1:
self.exportInterp(row)


def rowGraph(self,row):
filename = str(self.ui.tableWidget.item(row,self.cols.keys().index('file')).text())
Expand Down Expand Up @@ -349,6 +384,8 @@ def openCall(self):
for thisFile in fileNames[0]:

thisPath = str(thisFile)
dirName = os.path.dirname(thisPath)
self.workingDirectory = dirName
fileName = os.path.split(thisPath)[-1]
self.ui.tableWidget.insertRow(self.rows)
print "computing: "+ fileName
Expand Down Expand Up @@ -634,6 +671,14 @@ def invCellPowerModel(voltageIn):
self.graphData.append({'origRow':self.rows,'lowerI':lowerI,'upperI':upperI,'fitX':fitX,'modelY':modelY,'splineY':splineY,'i':II,'v':VV,'Voc':Voc_nn,'Isc':Isc_nn,'Vmax':vMax,'Imax':iMax})


btn = QPushButton(self.ui.tableWidget)
btn.setText('Plot')
btn.clicked.connect(self.handleButton)
self.ui.tableWidget.setCellWidget(self.rows,self.cols.keys().index('plotBtn'), btn)
btn2 = QPushButton(self.ui.tableWidget)
btn2.setText('Export')
btn2.clicked.connect(self.handleButton)
self.ui.tableWidget.setCellWidget(self.rows,self.cols.keys().index('exportBtn'), btn2)
self.ui.tableWidget.item(self.rows,self.cols.keys().index('file')).setText(fileName)
self.ui.tableWidget.item(self.rows,self.cols.keys().index('file')).setToolTip(''.join(header))
self.ui.tableWidget.item(self.rows,self.cols.keys().index('pce')).setData(Qt.DisplayRole,float(pMax/area*1e3).__format__('.3f'))
Expand Down

0 comments on commit d150bb5

Please sign in to comment.